if (name.length() == 0)
throw new UiException("The name attribute must be specified, "+root.getLocator()+", "+path);
final boolean zk = "zk".equals(name),
aaas = "zk.aaas".equals(name);
final String lang = root.getAttributeValue("language");
final LanguageDefinition langdef = //optional
lang != null ? LanguageDefinition.lookup(lang): null;
final String dir = path.substring(0, path.lastIndexOf('/') + 1);
final boolean cacheable = !"false".equals(root.getAttributeValue("cacheable"));
final WpdContent wc =
zk || aaas || !cacheable || isWpdContentRequired(root) ?
new WpdContent(dir, zk, cacheable): null;
final Provider provider = getProvider();
final ByteArrayOutputStream out = new ByteArrayOutputStream(1024*16);
String depends = null;
if (zk) {
write(out, "if(!window.zk){\n");
//may be loaded multiple times because specified in lang.xml
} else if (!aaas) {
depends = root.getAttributeValue("depends");
if (depends != null && depends.length() == 0)
depends = null;
if (depends != null) {
write(out, "zk.load('");
write(out, depends);
write(out, "',");
} else
write(out, '(');
write(out, "function(){if(zk._p=zkpi('");
write(out, name);
write(out, '\'');
if (provider != null && provider.getResource(dir + "wv/zk.wpd") != null)
write(out, ",true");
write(out, "))try{\n");
}
final Map moldInfos = new HashMap();
for (Iterator it = root.getElements().iterator(); it.hasNext();) {
final Element el = (Element)it.next();
final String elnm = el.getName();
if ("widget".equals(elnm)) {
final String wgtnm = IDOMs.getRequiredAttributeValue(el, "name");
final String jspath = wgtnm + ".js"; //eg: /js/zul/wgt/Div.js
if (!writeResource(out, jspath, dir, false)) {
log.error("Widget "+wgtnm+": "+jspath+" not found, "+el.getLocator()+", "+path);
continue;
}
final String wgtflnm = name + "." + wgtnm;
write(out, "zkreg('");
write(out, wgtflnm);
write(out, '\'');
WidgetDefinition wgtdef = langdef != null ? langdef.getWidgetDefinitionIfAny(wgtflnm): null;
if (wgtdef != null && wgtdef.isBlankPreserved())
write(out, ",true");
write(out, ");");
if (wgtdef == null)
continue;