/** Returns the language definition that this richlet belongs to. * Don't return null. * * <p> It is called when creating a new page for this richlet to serve. * * <p>Default: return the language definition called "xul/html". */ public LanguageDefinition getLanguageDefinition() { return LanguageDefinition.lookup("xul/html"); } }
private void fixModeOnly() { //called by afterCompose if ("auto".equals(_mode)) { if (_src != null && !_progressing && !_localized) { // according to the spec if query string exists, it should be defer // mode automatically. if (_src.contains("?")) { _instantMode = false; } else { String ext = Servlets.getExtension(_src); // ZK-2567: use defer mode for unrecognized files try { LanguageDefinition lang = LanguageDefinition.getByExtension(ext); _instantMode = ("xhtml".equals(lang.getName()) || "xul/html".equals(lang.getName())); } catch (DefinitionNotFoundException e) { _instantMode = false; } } } else _instantMode = false; } else _instantMode = "instant".equals(_mode); }
private void readObject(java.io.ObjectInputStream s) throws java.io.IOException, ClassNotFoundException { s.defaultReadObject(); final Object v = s.readObject(); if (v instanceof String) { final LanguageDefinition langdef = LanguageDefinition.lookup((String) v); final String name = (String) s.readObject(); try { _compdef = langdef.getComponentDefinition(name); } catch (DefinitionNotFoundException e) { // Bug ZK-1918 if ("native".equals(name)) { _compdef = langdef.getNativeDefinition(); } else { throw e; } } } else { _compdef = (ComponentDefinition) v; } }
/** Returns the component definition of the specified class in all * language of the specified device, or null if not found * * @param deviceType the device type ({@link org.zkoss.zk.device.Device}), * such as ajax. It cannot be null. * @param cls the implementation class of the component. * @since 5.0.0 */ public static final ComponentDefinition getDefinitionByDeviceType(String deviceType, Class cls) { for (LanguageDefinition ld : LanguageDefinition.getByDeviceType(deviceType)) { try { return ld.getComponentDefinition(cls); } catch (DefinitionNotFoundException ex) { //ignore } } return null; }
/** Associates an extension to a language. * * @param lang the language name. It cannot be null. * @param ext the extension, e.g., "svg". It cannot be null. * @since 3.0.0 */ public static final void addExtension(String ext, String lang) { if (lang == null || ext == null) throw new IllegalArgumentException(); init(); final LanguageDefinition langdef = lookup(lang); //ensure it exists synchronized (_ldefsByExt) { _ldefsByExt.put(ext, langdef); } }
public ComponentDefinition getComponentDefinition(Class<? extends Component> cls, boolean recurse) { final ComponentDefinition compdef = _compdefs.get(cls); if (!recurse || compdef != null) return compdef; try { return _langdef.getComponentDefinition(cls); } catch (DefinitionNotFoundException ex) { try { // try with shadow element return _langdef.getShadowDefinition(cls); } catch (DefinitionNotFoundException eex) { } } return null; }
if (log.isDebugEnabled()) log.debug("Addon language to " + lang + " from " + root.getElementValue("addon-name", true)); langdef = LanguageDefinition.lookup(lang); device = Devices.getDevice(langdef.getDeviceType()); langdef = new LanguageDefinition(deviceType, lang, ns, exts, pageRenderer, "true".equals(ignoreCase), "true".equals(bNative), locator, treeBuilderClass); device = Devices.getDevice(deviceType); throw new UiException("Empty class name of message loader for " + lang); MessageLoader msgLoader = (MessageLoader) locateClass(clsname).newInstance(); langdef.addMessageLoader(msgLoader); if (pkg != null && pkg.length() > 0) { if (ondemand) { //ondemand has the higher priority than merge langdef.removeJavaScript("~." + device.packageToPath(pkg)); langdef.unmergeJavaScriptPackage(pkg, mergeTo); } else { //merge must be true langdef.mergeJavaScriptPackage(pkg, mergeTo); langdef.addJavaScript(js); langdef.addJavaScriptModule(IDOMs.getRequiredAttributeValue(el, "name"), IDOMs.getRequiredAttributeValue(el, "version")); langdef.addStyleSheet(ss); final String eachTime = el.getAttributeValue("each-time"); if ("true".equals(eachTime))
final String uri = ns != null ? ns.getURI() : ""; LanguageDefinition langdef = pgdef.getLanguageDefinition(); final String langName = langdef.getName(); || "native".equals(uri); if (!bNative && langdef.isNative() && !langdef.getNamespace().equals(uri)) bNative = prefRequired = ("".equals(pref) && "".equals(uri)) || !LanguageDefinition.exists(uri); compInfo = ni = new NativeInfo(parent, langdef.getNativeDefinition(), prefRequired && pref.length() > 0 ? pref + ":" + nm : nm); } else { final boolean defaultNS = isDefaultNS(langdef, pref, uri); final LanguageDefinition complangdef = defaultNS ? langdef : LanguageDefinition.lookup(uri); ComponentDefinition compdef = defaultNS ? pgdef.getComponentDefinitionMap().get(nm) : null; if (compdef != null) { compInfo = new ComponentInfo(parent, compdef, nm); } else if (complangdef.hasComponentDefinition(nm)) { compdef = complangdef.getComponentDefinition(nm); compInfo = new ComponentInfo(parent, compdef, nm); langdef = complangdef; } else { compdef = complangdef.getDynamicTagDefinition(); if (compdef == null) throw new DefinitionNotFoundException(
final String clsnm = params.remove("class"); final String lang = params.remove("language"); final LanguageDefinition langdef = lang != null ? LanguageDefinition.lookup(lang) : pgdef.getLanguageDefinition(); ComponentDefinition compdef; compdef = langdef.getShadowDefinition(name, pgdef, toAbsoluteURI(templateURI)); if (!isEmpty(clsnm)) { noEL("class", clsnm, pi); compdef = langdef.getMacroDefinition(name, toAbsoluteURI(macroURI), bInline, pgdef); if (!isEmpty(clsnm)) { if (bInline) ref = langdef.getComponentDefinition(extds); } else { try { final Class cls = pgdef.getImportedClassResolver().resolveClass(clsnm); if (lang != null) { ref = langdef.getComponentDefinition(cls); ref = Components.getDefinitionByDeviceType(langdef.getDeviceType(), cls);
/** Returns whether it is a Shadow element. * @param pref namespace's prefix * @param uri namespace's URI * @param bNativeContent whether to ignore if URI not specified explicitly */ private static final boolean isShadowElement(LanguageDefinition langdef, PageDefinition pgdef, String nm, String pref, String uri, boolean bNativeContent) { // feature in 8.0.0, no need to check namespace, if any. if ("true".equalsIgnoreCase(Library.getProperty("org.zkoss.zk.namespace.tolerant", "false"))) return langdef.hasShadowDefinition(nm) || (!"xul/html".equals(langdef.getName()) && LanguageDefinition.lookup("xul/html").hasShadowDefinition(nm)); ComponentDefinition componentDefinition = pgdef.getComponentDefinitionMap().get(nm); // F80 - support another namespace if (componentDefinition instanceof ShadowDefinitionImpl || LanguageDefinition.SHADOW_NAMESPACE.equals(uri) || LanguageDefinition.SHADOW_NAME.equals(uri)) return true; if (isDefaultNS(langdef, pref, uri)) return !bNativeContent && langdef.hasShadowDefinition(nm); return false; }
break; //found final boolean isXHTML = "xhtml".equals(parentlang.getName()); final boolean isAllBlankPreserved = !"false".equals(Library.getProperty("preserve-all-blank")); boolean breakLine = false; breakLine = false; if (parentlang.isNative() || isXHTML) { String label = "<!--" + ((Item) o).getText() + "-->"; final ComponentInfo labelInfo = parentlang.newLabelInfo(parent, label); labelInfo.addProperty("encode", "false", null); final String labelAttr = parentlang.getLabelAttribute(); for (Property prop : ((ComponentInfo) children.get(children.size() - 1)).getProperties()) { if (prop.getName().equals(labelAttr)) { continue; //ignore if (isTrimLabel() && !parentlang.isRawLabel()) { if (isEmpty(trimLabel)) continue; //ignore preNativeInfo.addEpilogChild(new TextInfo(null, label)); } else { final ComponentInfo labelInfo = parentlang.newLabelInfo(parent, label); if (isEmpty(trimLabel)) labelInfo.setReplaceableText(" "); //yes, it can be replaced by a text, and it's possible to replace multiple whitespace characters with single space
? LanguageDefinition.getByExtension(extension) : LanguageDefinition.lookup(lang); final PageDefinition pgdef = new PageDefinition(langdef, getLocator());
String ifc = null, unless = null, name = el.getLocalName(); AnnotationHelper attrAnnHelper = null; final LanguageDefinition lookup = LanguageDefinition.lookup("xul/html"); ComponentDefinition shadowDefinition = lookup.hasShadowDefinition(name) ? lookup.getShadowDefinition(name) : pgdef.getComponentDefinitionMap().get(name); final ShadowInfo compInfo = new ShadowInfo(parent, shadowDefinition, name,
/** Generates all widgets in the specified language. * @param lang the language to look at */ public static String outWidgetListJavaScript(String lang) { final StringBuffer sb = new StringBuffer(4096).append("zk.wgt.WidgetInfo.register(["); boolean first = true; for (Iterator it = LanguageDefinition.lookup(lang).getComponentDefinitions().iterator(); it.hasNext();) { final ComponentDefinition compdef = (ComponentDefinition) it.next(); for (Iterator e = compdef.getMoldNames().iterator(); e.hasNext();) { final String mold = (String) e.next(); final String wgtcls = compdef.getWidgetClass(null, mold); if (wgtcls != null) { if (first) first = false; else sb.append(','); sb.append('\'').append(wgtcls).append('\''); } } } return sb.append("]);").toString(); }
private synchronized void writeObject(java.io.ObjectOutputStream s) throws java.io.IOException { s.defaultWriteObject(); s.writeObject(_langdef != null ? _langdef.getName() : null); }
LanguageDefinition langdef = null; try { langdef = LanguageDefinition.lookup((String) def); } catch (DefinitionNotFoundException ex) { _def = langdef.getComponentDefinitionIfAny((String) s.readObject());
ComponentDefinition compdef; if (_macroURI != null) { compdef = page.getLanguageDefinition().getMacroDefinition(_name, _macroURI, _inline, null); .getComponentDefinition(_extends); if (ref.isMacro()) throw new UiException("Unable to extend from a macro component, "+_extends);
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")); write(out, wgtflnm); write(out, '\''); WidgetDefinition wgtdef = langdef != null ? langdef.getWidgetDefinitionIfAny(wgtflnm) : null; if (wgtdef != null && wgtdef.isBlankPreserved()) write(out, ",true");
public Desktop newDesktop(RequestInfo ri, String updateURI, String path) { String deviceType = null; if (path != null) { //convert to directory //though UiEngine.execNewPage will set the device type later, //we 'guess' a value first by use of the extension //reason: less dependent of how UiEngine is implemented final int k = path.lastIndexOf('.') + 1; if (k > 0 && path.indexOf('/', k) < 0 && k < path.length()) { final String ext = path.substring(k); try { deviceType = LanguageDefinition.getByExtension(ext).getDeviceType(); } catch (DefinitionNotFoundException ex) { //ignore } } } return new DesktopImpl(ri.getWebApp(), updateURI, path, deviceType, ri.getNativeRequest()); }
/** * Creates a tree builder depended on its file extension. * <p> If the file extension is missing in the {@link LanguageDefinition}, and the class of * {@link XmlTreeBuilder} is assumed. */ public static TreeBuilder makeBuilder(String extension) { LanguageDefinition ldf = LanguageDefinition.getByExtension(extension); String treeBuilderClass = ldf.getTreeBuilderClass(); if (treeBuilderClass == null || "org.zkoss.zk.ui.metainfo.XulTreeBuilder".equals(treeBuilderClass)) return new XmlTreeBuilder(); try { return (TreeBuilder) Classes.newInstance(Classes.forNameByThread(treeBuilderClass), null); } catch (Exception ex) { throw UiException.Aide.wrap(ex); } } }