/** Checks and returns whether the loaded document's version is correct. * It is the same as checkVersion(url, doc, false). * @since 3.5.0 */ public static boolean checkVersion(URL url, Document doc) throws Exception { return checkVersion(url, doc, false); }
private static void parseSubSystemConfig(Configuration config, Element root) throws Exception { for (Element el : root.getElements("system-config")) { if (config != null) { parseSystemConfig(config, el); } else { Class<org.zkoss.zk.ui.util.ConfigParser> cls = parseClass(el, "au-writer-class", AuWriter.class); if (cls != null) AuWriters.setImplementationClass(cls); cls = parseClass(el, "config-parser-class", org.zkoss.zk.ui.util.ConfigParser.class); if (cls != null) { if (_parsers == null) _parsers = new LinkedList<org.zkoss.zk.ui.util.ConfigParser>(); _parsers.add(cls.newInstance()); } } } }
/** Unlike other private parseXxx, config might be null. */ private static void parseSubClientConfig(Configuration config, Element root) throws Exception { for (Element el : root.getElements("client-config")) { if (config != null) { parseClientConfig(config, el); } } }
parseListener(config, el); } else if ("richlet".equals(elnm)) { final String clsnm = IDOMs.getRequiredElementValue(el, "richlet-class"); parseDesktopConfig(config, el); parseClientConfig(config, el); //backward compatible with 2.4 parseClientConfig(config, el); Integer v = parseInteger(el, "session-timeout", ANY_VALUE); if (v != null) config.setSessionMaxInactiveInterval(v.intValue()); v = parseInteger(el, "max-desktops-per-session", ANY_VALUE); if (v != null) config.setSessionMaxDesktops(v.intValue()); v = parseInteger(el, "max-requests-per-session", ANY_VALUE); if (v != null) config.setSessionMaxRequests(v.intValue()); v = parseInteger(el, "max-pushes-per-session", ANY_VALUE); if (v != null) config.setSessionMaxPushes(v.intValue()); parseTimeoutURI(config, el); } else if ("language-config".equals(elnm)) { parseLangConfig(locator, el);
log.debug("Loading " + res.url); try { if (checkVersion(res.url, res.document)) { try { String path = res.url.toExternalForm(); parseSubZScriptConfig(el); parseSubDeviceConfig(el); parseSubSystemConfig(config, el); parseSubClientConfig(config, el); parseProperties(el); parseLangConfigs(locator, el); parseListeners(config, el); parsePreferences(config, el); parseBinderConfig(config, el);
final ConfigParser parser = new ConfigParser(); parser.parseConfigXml(null); //only system default configs try { final Document doc = new SAXBuilder(true, false, true).build(url); if (ConfigParser.checkVersion(url, doc, true)) parseLang(doc, locator, url, false); } catch (Exception ex) { for (XMLResourcesLocator.Resource res : xmls) { try { if (ConfigParser.checkVersion(res.url, res.document, true)) parseLang(res.document, locator, res.url, true); } catch (Exception ex) {
final ConfigParser parser = new ConfigParser(); parser.parseConfigXml(config); } catch (Throwable ex) { log.error("Unable to load metainfo/zk/config.xml", ex); final URL cfgUrl = res.url; try { parser.parse(cfgUrl, config, loc); } catch (Throwable ex) { log.error("Unable to load " + cfgUrl, ex); final URL cfgUrl = _ctx.getResource(XML); if (cfgUrl != null) parser.parse(cfgUrl, config, new ServletContextLocator(_ctx, true)); is = Servlets.getResourceAsStream(_ctx, XML); if (is != null) parser.parse(is, config, new ServletContextLocator(_ctx, true)); else log.error("File not found: " + XML);
Integer v = parseInteger(el, "max-spare-threads", ANY_VALUE); if (v != null) config.setMaxSpareThreads(v.intValue()); v = parseInteger(el, "max-suspended-threads", ANY_VALUE); if (v != null) config.setMaxSuspendedThreads(v.intValue()); v = parseInteger(el, "event-time-warning", ANY_VALUE); if (v != null) config.setEventTimeWarning(v.intValue()); v = parseInteger(el, "max-upload-size", ANY_VALUE); if (v != null) config.setMaxUploadSize(v.intValue()); v = parseInteger(el, "file-size-threshold", ANY_VALUE); if (v != null) config.setFileSizeThreshold(v.intValue()); v = parseInteger(el, "max-process-time", POSITIVE_ONLY); if (v != null) config.setMaxProcessTime(v.intValue()); Class cls = parseClass(el, "upload-charset-finder-class", CharsetFinder.class); if (cls != null) config.setUploadCharsetFinder((CharsetFinder) cls.newInstance()); cls = parseClass(el, "cache-provider-class", DesktopCacheProvider.class);
Integer v = parseInteger(conf, "processing-prompt-delay", POSITIVE_ONLY); if (v != null) config.setProcessingPromptDelay(v.intValue()); v = parseInteger(conf, "tooltip-delay", POSITIVE_ONLY); if (v != null) config.setTooltipDelay(v.intValue()); v = parseInteger(conf, "auto-resend-timeout", POSITIVE_ONLY); if (v != null) config.setAutoResendTimeout(v.intValue()); v = parseInteger(conf, "init-crash-timeout", NON_NEGATIVE); if (v != null) config.setInitCrashTimeout(v.intValue()); v = parseInteger(el, "error-code", NON_NEGATIVE); if (v == null) throw new UiException(message("error-code is required", el)); String uri = IDOMs.getRequiredElementValue(el, "reload-uri"); if ("false".equals(uri))
/** Parse a class, if specified, whether it implements cls. */ private static <T> Class<T> parseClass(Element el, String elnm, Class cls) { return parseClass(el, elnm, cls, false); }
/** Parses zk.xml, specified by url, into the configuration. * * @param url the URL of zk.xml. */ public void parse(URL url, Configuration config, Locator locator) throws Exception { if (url == null || config == null) throw new IllegalArgumentException("null"); log.info("Parsing " + url); parse(new SAXBuilder(true, false, true).build(url).getRootElement(), config, locator); }
/** Configures an integer. * @param flag one of POSTIVE_ONLY, NON_NEGATIVE and ANY_VALUE. */ private static Integer parseInteger(Element el, String subnm, int flag) throws UiException { //Note: we throw exception rather than warning to make sure //the developer correct it String val = el.getElementValue(subnm, true); if (val != null && val.length() > 0) { try { final int v = Integer.parseInt(val); if ((flag == POSITIVE_ONLY && v <= 0) || (flag == NON_NEGATIVE && v < 0)) throw new UiException(message( "The " + subnm + " element must be a " + (flag == POSITIVE_ONLY ? "positive" : "non-negative") + " number, not " + val, el)); return new Integer(v); } catch (NumberFormatException ex) { //eat throw new UiException(message("The " + subnm + " element must be a number, not " + val, el)); } } return null; }
cls = parseClass(conf, "theme-provider-class", ThemeProvider.class); if (cls != null) { if (!cls.getName().startsWith("org.zkoss.")) cls = parseClass(conf, "theme-registry-class", ThemeRegistry.class); if (cls != null) { if (!cls.getName().startsWith("org.zkoss.")) cls = parseClass(conf, "theme-resolver-class", ThemeResolver.class); if (cls != null) { if (!cls.getName().startsWith("org.zkoss.")) Integer v = parseInteger(conf, "desktop-timeout", ANY_VALUE); if (v != null) config.setDesktopMaxInactiveInterval(v.intValue()); v = parseInteger(conf, "file-check-period", POSITIVE_ONLY); if (v != null) Library.setProperty("org.zkoss.util.resource.checkPeriod", v.toString()); v = parseInteger(conf, "extendlet-check-period", POSITIVE_ONLY); if (v != null) Library.setProperty("org.zkoss.util.resource.extendlet.checkPeriod", v.toString());
private static void parseListener(Configuration config, Element el) { try { config.addListener(parseClass(el, "listener-class", null, true)); } catch (Exception ex) { log.error("Unable to load a listener, " + el.getLocator(), ex); } }
/** Parses zk.xml from an input stream into the configuration. * @param is the input stream of zk.xml * @since 5.0.7 */ public void parse(InputStream is, Configuration config, Locator locator) throws Exception { if (is == null || config == null) throw new IllegalArgumentException("null"); parse(new SAXBuilder(true, false, true).build(is).getRootElement(), config, locator); }
private static <T> Class<T> parseClass(Element el, String elnm, Class<?> cls, boolean required) { //Note: we throw exception rather than warning to make sure //the developer correct it final String clsnm = el.getElementValue(elnm, true); if (clsnm != null && clsnm.length() != 0) { try { final Class<?> klass = Classes.forNameByThread(clsnm); if (cls != null && !cls.isAssignableFrom(klass)) { String msg = message(clsnm + " must implement " + cls.getName(), el); if (required) throw new UiException(msg); log.error(msg); return null; } // if (log.debuggable()) log.debug("Using "+clsnm+" for "+cls); return cast(klass); } catch (Throwable ex) { String msg = ex instanceof ClassNotFoundException ? clsnm + " not found" : "Unable to load " + clsnm; msg = message(msg, el); if (required) throw new UiException(msg, ex); log.error(msg); return null; } } else if (required) throw new UiException(message(elnm + " required", el)); return null; }