Servlets.setBrowserIdentifier(new BrowserIdentifier());
//plugin device-dependent browser identifier
//load config as soon as possible since it might set some system props
final Configuration config = new Configuration();
final ConfigParser parser = new ConfigParser();
//load metainfo/zk/config.xml
try {
parser.parseConfigXml(config);
} catch (Throwable ex) {
log.error("Unable to load metainfo/zk/config.xml", ex);
}
//load metainfo/zk/zk.xml
try {
final ClassLocator loc = new ClassLocator();
for (Enumeration en = loc.getResources("metainfo/zk/zk.xml");
en.hasMoreElements();) {
final URL cfgUrl = (URL)en.nextElement();
try {
parser.parse(cfgUrl, config, loc);
} catch (Throwable ex) {
log.error("Unable to load "+cfgUrl, ex);
}
}
} catch (Throwable ex) {
log.error("Unable to load metainfo/zk/zk.xml", ex);
}
//load /WEB-INF/zk.xml
try {
final URL cfgUrl = _ctx.getResource("/WEB-INF/zk.xml");
if (cfgUrl != null)
parser.parse(cfgUrl, config, new ServletContextLocator(_ctx));
} catch (Throwable ex) {
log.error("Unable to load /WEB-INF/zk.xml", ex);
}
//after zk.xml is loaded since it depends on the configuration
_cwr = ClassWebResource.getInstance(_ctx, _updateURI);
_cwr.setCompress(new String[] {"js", "css", "html", "xml"});
String s = Library.getProperty("org.zkoss.web.util.resource.dir");
if (s != null && s.length() > 0) {
if (s.charAt(0) != '/') s = '/' + s;
_cwr.setExtraLocator(new ServletContextLocator(_ctx, null, s));
}
Labels.register(new ServletLabelLocator(_ctx));
Labels.setVariableResolver(new ServletLabelResovler());
//create a WebApp instance
final Class cls = config.getWebAppClass();
if (cls == null) {
_wapp = new SimpleWebApp();
} else {
try {
_wapp = (WebApp)cls.newInstance();
} catch (Exception ex) {
throw UiException.Aide.wrap(ex, "Unable to construct "+cls);
}
}
((WebAppCtrl)_wapp).init(_ctx, config);
_cwr.setEncodeURLPrefix(getCWRURLPrefix());
_cwr.setDebugJS(config.isDebugJS());
_cwr.addExtendlet("wpd", new WpdExtendlet()); //add after _cwr.setDebugJS (since it calls back)
_cwr.addExtendlet("wcs", new WcsExtendlet());
//Register resource processors for each extension
//FUTURE: Extendlet can be specified in zk.xml