Package org.zkoss.idom

Examples of org.zkoss.idom.Element


   * @since 5.0.0
   */
  public static
  boolean checkVersion(URL url, Document doc, boolean zk5required)
  throws Exception {
    final Element el = doc.getRootElement().getElement("version");
    if (el == null)
      return true; //version is optional (3.0.5)

    if (_zkver == null)
      _zkver = Utils.parseVersion(Version.UID);

    String s = el.getElementValue("zk-version", true);
    if (s != null) {
      final int[] reqzkver = Utils.parseVersion(s);
      if (Utils.compareVersion(_zkver, reqzkver) < 0) {
        log.info("Ignore "+url+"\nCause: ZK version must be "+s+" or later, not "+Version.UID);
        return false;
      }
      if (zk5required && reqzkver.length > 0 && reqzkver[0] < 5) {
        log.info("Ingore "+url+"\nCause: version "+s+" not supported");
        return false;
      }
    }

    final String clsnm = el.getElementValue("version-class", true);
    if (clsnm == null) {
      return true; //version is optional 3.0.5
    }
   
    if (clsnm.length() == 0)
      log.warning("Ignored: empty version-class, "+el.getLocator());

    final String uid = IDOMs.getRequiredElementValue(el, "version-uid");
    final Class cls = Classes.forNameByThread(clsnm);
    final Field fld = cls.getField("UID");
    final String uidInClass = (String)fld.get(null);
View Full Code Here


      for (Iterator it = xmls.iterator(); it.hasNext();) {
        final ClassLocator.Resource res = (ClassLocator.Resource)it.next();
        if (log.debugable()) log.debug("Loading "+res.url);
        try {
          if (checkVersion(res.url, res.document)) {
            final Element el = res.document.getRootElement();
            if (!syscfgLoaded) {
              parseSubZScriptConfig(el);
              parseSubDeviceConfig(el);
              parseSubSystemConfig(config, el);
              parseSubClientConfig(config, el);
View Full Code Here

    }
  }
  private static void parseSubZScriptConfig(Element root) {
    for (Iterator it = root.getElements("zscript-config").iterator();
    it.hasNext();) {
      final Element el = (Element)it.next();
      Interpreters.add(el);
        //Note: zscript-config is applied to the whole system, not just langdef
    }
  }
View Full Code Here

    }
  }
  private static void parseSubDeviceConfig(Element root) {
    for (Iterator it = root.getElements("device-config").iterator();
    it.hasNext();) {
      final Element el = (Element)it.next();
      Devices.add(el);
    }
  }
View Full Code Here

  private static
  void parseSubSystemConfig(Configuration config, Element root)
  throws Exception {
    for (Iterator it = root.getElements("system-config").iterator();
    it.hasNext();) {
      final Element el = (Element)it.next();
      if (config != null) {
        parseSystemConfig(config, el);
      } else {
        Class cls = parseClass(el, "au-writer-class", AuWriter.class);
        if (cls != null)
View Full Code Here

  private static
  void parseSubClientConfig(Configuration config, Element root)
  throws Exception {
    for (Iterator it = root.getElements("client-config").iterator();
    it.hasNext();) {
      final Element el = (Element)it.next();
      if (config != null) {
        parseClientConfig(config, el);
      } else {
        Integer v = parseInteger(el, "resend-delay", false);
        if (v != null)
View Full Code Here

   */
  public void parse(Element root, Configuration config, Locator locator)
  throws Exception {
    l_out:
    for (Iterator it = root.getElements().iterator(); it.hasNext();) {
      final Element el = (Element)it.next();
      final String elnm = el.getName();
      if ("listener".equals(elnm)) {
        parseListener(config, el);
      } else if ("richlet".equals(elnm)) {
        final String clsnm =
          IDOMs.getRequiredElementValue(el, "richlet-class");
        final Map params =
          IDOMs.parseParams(el, "init-param", "param-name", "param-value");

        String path = el.getElementValue("richlet-url", true);
        if (path != null) {
        //deprecated since 2.4.0, but backward compatible
          final int cnt;
          synchronized (this) {
            cnt = _richletnm++;
          }
          final String name = "z_obs_" + Integer.toHexString(cnt);
          try {
            config.addRichlet(name, clsnm, params);
            config.addRichletMapping(name, path);
          } catch (Throwable ex) {
            log.error("Illegal richlet definition at "+el.getLocator(), ex);
          }
        } else { //syntax since 2.4.0
          final String nm =
            IDOMs.getRequiredElementValue(el, "richlet-name");
          try {
            config.addRichlet(nm, clsnm, params);
          } catch (Throwable ex) {
            log.error("Illegal richlet definition at "+el.getLocator(), ex);
          }
        }
      } else if ("richlet-mapping".equals(elnm)) { //syntax since 2.4.0
        final String nm =
          IDOMs.getRequiredElementValue(el, "richlet-name");
        final String path =
          IDOMs.getRequiredElementValue(el, "url-pattern");
        try {
          config.addRichletMapping(nm, path);
        } catch (Throwable ex) {
          log.error("Illegal richlet mapping at "+el.getLocator(), ex);
        }
      } else if ("desktop-config".equals(elnm)) {
      //desktop-config
      //  desktop-timeout
      //  disable-theme-uri
      //  file-check-period
      //  extendlet-check-period
      //  theme-provider-class
      //  theme-uri
      //  repeat-uuid
        parseDesktopConfig(config, el);
        parseClientConfig(config, el); //backward compatible with 2.4

      } else if ("client-config".equals(elnm)) { //since 3.0.0
      //client-config
      //  click-filter-delay
      //  keep-across-visits
      //  processing-prompt-delay
      //  error-reload
      //  tooltip-delay
      //  resend-delay
      //  debug-js
        parseClientConfig(config, el);

      } else if ("session-config".equals(elnm)) {
      //session-config
      //  session-timeout
      //  max-desktops-per-session
      //  max-requests-per-session
      //  max-pushes-per-session
      //  timer-keep-alive
      //  timeout-uri
      //  automatic-timeout
        Integer v = parseInteger(el, "session-timeout", false);
        if (v != null) config.setSessionMaxInactiveInterval(v.intValue());

        v = parseInteger(el, "max-desktops-per-session", false);
        if (v != null) config.setSessionMaxDesktops(v.intValue());

        v = parseInteger(el, "max-requests-per-session", false);
        if (v != null) config.setSessionMaxRequests(v.intValue());

        v = parseInteger(el, "max-pushes-per-session", false);
        if (v != null) config.setSessionMaxPushes(v.intValue());

        String s = el.getElementValue("timer-keep-alive", true);
        if (s != null) config.setTimerKeepAlive("true".equals(s));

        parseTimeoutURI(config, el);
      } else if ("language-config".equals(elnm)) {
      //language-config
      //  addon-uri
        parseLangAddon(locator, el);
      } else if ("language-mapping".equals(elnm)) {
      //language-mapping
      //  language-name/extension
        DefinitionLoaders.addExtension(
          IDOMs.getRequiredElementValue(el, "extension"),
          IDOMs.getRequiredElementValue(el, "language-name"));
        //Note: we don't add it to LanguageDefinition now
        //since addon-uri might be specified later
        //(so we cannot load definitions now)
      } else if ("system-config".equals(elnm)) {
      //system-config
      //  disable-event-thread
      //  max-spare-threads
      //  max-suspended-threads
      //  event-time-warning
      //  max-upload-size
      //  upload-charset
      //  upload-charset-finder-class
      //  max-process-time
      //  response-charset
      //  cache-provider-class
      //  ui-factory-class
      //  failover-manager-class
      //  engine-class
      //  id-generator-class
      //  web-app-class
      //  method-cache-class
      //  url-encoder-class
      //  au-writer-class
      //  au-decoder-class
        parseSystemConfig(config, el);
      } else if ("xel-config".equals(elnm)) {
      //xel-config
      //  evaluator-class
        Class cls = parseClass(el, "evaluator-class", ExpressionFactory.class);
        if (cls != null) config.setExpressionFactoryClass(cls);
      } else if ("zscript-config".equals(elnm)) {
      //zscript-config
        Interpreters.add(el);
          //Note: zscript-config is applied to the whole system, not just langdef
      } else if ("device-config".equals(elnm)) {
      //device-config
        Devices.add(el);
          //Note: device-config is applied to the whole system, not just langdef
        parseTimeoutURI(config, el);
          //deprecated since 3.6.3, but to be backward-compatible
      } else if ("log".equals(elnm)) {
        final String base = el.getElementValue("log-base", true);
        if (base != null)
          org.zkoss.util.logging.LogService.init(base, null); //start the log service
      } else if ("error-page".equals(elnm)) {
      //error-page
        final Class cls =
          parseClass(el, "exception-type", Throwable.class, true);
        final String loc =
          IDOMs.getRequiredElementValue(el, "location");
        String deviceType = el.getElementValue("device-type", true);
        if (deviceType == null) deviceType = "ajax";
        else if (deviceType.length() == 0)
          log.error("device-type not specified at "+el.getLocator());

        config.addErrorPage(deviceType, cls, loc);
      } else if ("preference".equals(elnm)) {
        parsePreference(config, el);
      } else if ("library-property".equals(elnm)) {
        parseLibProperty(el);
      } else if ("system-property".equals(elnm)) {
        parseSysProperty(el);
      } else {
        if (_parsers != null)
          for (Iterator e = _parsers.iterator(); e.hasNext();) {
            org.zkoss.zk.ui.util.ConfigParser parser =
              (org.zkoss.zk.ui.util.ConfigParser)e.next();
            if (parser.parse(config, el))
              continue l_out;
          }
        log.error("Unknown element: "+elnm+", at "+el.getLocator());
      }
    }
  }
View Full Code Here

  private static void parseDesktopConfig(Configuration config, Element conf)
  throws Exception {
    //theme-uri
    for (Iterator it = conf.getElements("theme-uri").iterator();
    it.hasNext();) {
      final Element el = (Element)it.next();
      final String uri = el.getText(true);
      if (uri.length() != 0) config.addThemeURI(uri);
    }

    //disable-theme-uri
    for (Iterator it = conf.getElements("disable-theme-uri").iterator();
    it.hasNext();) {
      final Element el = (Element)it.next();
      final String uri = el.getText(true);
      if (uri.length() != 0) config.addDisabledThemeURI(uri);
    }

    //theme-provider-class
    Class cls = parseClass(conf, "theme-provider-class",
View Full Code Here

    }

    //error-reload
    for (Iterator it = conf.getElements("error-reload").iterator();
    it.hasNext();) {
      final Element el = (Element)it.next();

      String deviceType = el.getElementValue("device-type", true);
      String connType = el.getElementValue("connection-type", true);
      v = parseInteger(el, "error-code", true);
      if (v == null)
        throw new UiException("error-code is required, "+el.getLocator());
      String uri = IDOMs.getRequiredElementValue(el, "reload-uri");
      if ("false".equals(uri)) uri = null;

      config.setClientErrorReload(deviceType, v.intValue(), uri, connType);
    }
View Full Code Here

  /** Parse language-config/addon-uri. */
  private static void parseLangAddon(Locator locator, Element conf) {
    for (Iterator it = conf.getElements("addon-uri").iterator();
    it.hasNext();) {
      final Element el = (Element)it.next();
      final String path = el.getText(true);

      final URL url = locator.getResource(path);
      if (url == null)
        log.error("File not found: "+path+", at "+el.getLocator());
      else
        DefinitionLoaders.addAddon(locator, url);
    }
  }
View Full Code Here

TOP

Related Classes of org.zkoss.idom.Element

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.