📄 languagedefinition.java
字号:
public String getNamespace() { return _ns; } /** Returns the readonly list of extensions that this language definition * is associated with (never null). * @since 2.4.1 */ public List getExtensions() { return _exts; } /** Returns the map of components defined in this language (never null). */ public ComponentDefinitionMap getComponentDefinitionMap() { return _compdefs; } /** Returns {@link ComponentDefinition} of the specified name. * * <p>Note: anonymous component definition won't be returned by * this method. * * @param name the name of the component definition. * @exception DefinitionNotFoundException is thrown if the definition * is not found */ public ComponentDefinition getComponentDefinition(String name) { final ComponentDefinition compdef = (ComponentDefinition)_compdefs.get(name); if (compdef == null) throw new DefinitionNotFoundException("Component definition not found: "+name); return compdef; } /** Returns {@link ComponentDefinition} of the specified class. * * <p>Note: anonymous component definition won't be returned by * this method. * * @param klass the class that implements the component. * @exception DefinitionNotFoundException is thrown if the definition * is not found */ public ComponentDefinition getComponentDefinition(Class klass) { final ComponentDefinition compdef = (ComponentDefinition)_compdefs.get(klass); if (compdef == null) throw new DefinitionNotFoundException("Component definition not found: "+klass); return compdef; } /** Returns whether the specified component is defined. */ public boolean hasComponentDefinition(String name) { return _compdefs.contains(name); } /** Adds a component definition. */ public void addComponentDefinition(ComponentDefinition compdef) { _compdefs.add(compdef); } /** Adds the script that shall execute when a page's interpreter * is initialized. In other words, they are evaluated only once for each * page. * * <p>Note: it doesn't test the existence of the specified language, * such that you can add the scripting language later. * * @param zslang the scripting language, say, Java. */ public void addInitScript(String zslang, String script) { if (zslang == null || zslang.length() == 0) throw new IllegalArgumentException("null or empty language"); if (script != null && script.length() > 0) { zslang = zslang.toLowerCase(); synchronized (_initscripts) { final String s = (String)_initscripts.get(zslang); _initscripts.put(zslang, s != null ? s + '\n' + script: script); } } } /** Returns the intial scripts of * the specified language, or null if no script. */ public String getInitScript(String zslang) { zslang = zslang.toLowerCase(); synchronized (_initscripts) { return (String)_initscripts.get(zslang); } } /** Adds the script that shall execute each time before evaluating * zscript. * * <p>Note: it doesn't test the existence of the specified language, * such that you can add the scripting language later. * * @param zslang the scripting language, say, Java. */ public void addEachTimeScript(String zslang, String script) { if (zslang == null || zslang.length() == 0) throw new IllegalArgumentException("null or empty language"); if (script != null && script.length() > 0) { zslang = zslang.toLowerCase(); synchronized (_eachscripts) { final String s = (String)_eachscripts.get(zslang); _eachscripts.put(zslang, s != null ? s + '\n' + script: script); } } } /** Returns the each-time scripts of * the specified language, or null if no scripts. * * <p>The each-time script is evaluated each time before evaluating * zscript. */ public String getEachTimeScript(String zslang) { zslang = zslang.toLowerCase(); synchronized (_eachscripts) { return (String)_eachscripts.get(zslang); } } /** Adds a {@link JavaScript} required by this language. */ public void addJavaScript(JavaScript js) { if (js == null) throw new IllegalArgumentException("null js"); synchronized (_js) { _js.add(js); } } /** Returns a readonly list of all {@link JavaScript} required * by this language. */ public List getJavaScripts() { return _rojs; } /** Adds the definition of a JavaScript module to this language. * <p>A JavaScript module represents a JavaScript file. This definition * is mainly used to define its version, such that ZK could encode * its URL such that browsers know when to reload it. */ public void addJavaScriptModule(String name, String version) { if (name == null || name.length() == 0 || version == null || version.length() == 0) throw new IllegalArgumentException(); _jsmods.put(name, version); } /** Returns a map of definitions of JavaScript modules, * (String name, String version). */ public Map getJavaScriptModules() { return _rojsmods; } /** Adds a {@link StyleSheet} required by this language. */ public void addStyleSheet(StyleSheet ss) { if (ss == null) throw new IllegalArgumentException("null ss"); synchronized (_ss) { _ss.add(ss); } } /** Returns a readonly list of all {@link StyleSheet} required * by this language. */ public List getStyleSheets() { return _ross; } /** Returns whether the component names are case-insensitive. */ public boolean isCaseInsensitive() { return _compdefs.isCaseInsensitive(); } /** Return the URI to render a full page (which might be an expression). */ public String getDesktopURI() { return _desktopURI; } /** Return the URI to render a included page (which might be an expression). */ public String getPageURI() { return _pageURI; } /** Sets the macro template. * * @param moldURI the mold URI. If it starts with "class:", it * means a class that implements {@link org.zkoss.zk.ui.render.ComponentRenderer}. */ public void setMacroTemplate(Class klass, String moldURI) { _macrotmpl = klass != null ? new MacroTemplate(klass, moldURI): null; } /** Returns the component definition for the specified condition. * * @param pgdef the page definition the macro definitioin belongs to. * If null, it belongs to this language definition. * @exception UnsupportedOperationException if this language doesn't * support the macros * @since 3.0.0 */ public ComponentDefinition getMacroDefinition( String name, String macroURI, boolean inline, PageDefinition pgdef) { if (_macrotmpl == null) throw new UiException("Macro not supported by "+this); final ComponentDefinition compdef = ComponentDefinitionImpl.newMacroDefinition( pgdef != null ? null: this, pgdef, name, _macrotmpl.klass, macroURI, inline); compdef.addMold("default", _macrotmpl.moldURI); return compdef; } /** Sets the native template. * @since 3.0.0 */ public void setNativeTemplate(Class klass) { if (klass == null || !Component.class.isAssignableFrom(klass) || !Native.class.isAssignableFrom(klass)) throw new IllegalArgumentException("Illegal native class: "+klass); _nativedef = ComponentDefinitionImpl.newNativeDefinition(this, "native", klass);; } /** Returns the component definition for the native components. * * @exception UnsupportedOperationException if this language doesn't * support the native namespace * @since 3.0.0 */ public ComponentDefinition getNativeDefinition() { if (_nativedef == null) throw new UnsupportedOperationException("Native not supported by "+this); return _nativedef; } /** Sets the component and attribute names used to represent a label. * Since label is used a lot in a page, there is a simple way to create * an {@link ComponentInfo} by calling {@link #newLabelInfo}. * * <p>To be able to call {@link #newLabelInfo}, this method must * be called to define the component and attribute names used to create * an {@link ComponentInfo} for a label. */ public void setLabelTemplate(String compName, String propName, boolean raw) { _labeltmpl = compName != null ? new LabelTemplate(compName, propName, raw): null; } /** Constructs and returns an {@link ComponentInfo} for * the specified parent and text, */ public ComponentInfo newLabelInfo(ComponentInfo parent, String text) { if (_labeltmpl == null) throw new UiException("No default label component is supported by "+this); return _labeltmpl.newComponentInfo(parent, text); } /** Returns whether the raw label is required. * If true, the parser won't trim the text, and the text is generated * directly to the output without any wrapping. */ public boolean isRawLabel() { return _labeltmpl != null && _labeltmpl.raw; } /** Adds the definition for the dynamic tag. * * @param compnm the component name used to represent any of dynamic * tags for this language. If null, it means this language definition * doesn't support the dynamic tag. * @param reservedAttrs a set of reserved attributes that * the dynamic tag support. The reserved attributes are the if, unless * and use attributes. */ public void setDynamicTagInfo(String compnm, Set reservedAttrs) { if (compnm != null && _dyntagnm != null) log.warning("Overwriting the definition of dynamic tag. Previous="+_dyntagnm+" New="+compnm+" for "+this); _dyntagnm = compnm; _dyntagDefn = null; _dyntagRvAttrs = compnm == null || reservedAttrs.isEmpty() ? null: Collections.unmodifiableSet(new HashSet(reservedAttrs)); } /** Returns the component defintion of the dynamic tag, or null if * this language doesn't support the dynamic tag. * @exception DefinitionNotFoundException is thrown if the definition * is not found */ public ComponentDefinition getDynamicTagDefinition() { if (_dyntagDefn == null) { //no sync since racing is OK if (_dyntagnm == null) return null; _dyntagDefn = getComponentDefinition(_dyntagnm); } return _dyntagDefn; } /** Returns whether a reserved attribute is used by the dynamic tag * ({@link #getDynamicTagDefinition}). */ public boolean isDynamicReservedAttributes(String attr) { return _dyntagRvAttrs != null && _dyntagRvAttrs.contains(attr); } /** Adds a tag lib. */ public void addTaglib(Taglib taglib) { synchronized (_taglibs) { _taglibs.add(taglib); _eval = null; //ask for re-gen } } /** Returns the evaluator based on this language definition (never null). * @since 3.0.0 */ public Evaluator getEvaluator() { if (_eval == null) _eval = newEvaluator(); return _eval; } private Evaluator newEvaluator() { return new SimpleEvaluator( Taglibs.getFunctionMapper(_taglibs, _locator), null); } /** Returns the evaluator reference (never null). * <p>This method is used only for implementation only. * @since 3.0.0 */ public EvaluatorRef getEvaluatorRef() { if (_evalr == null) _evalr = newEvaluatorRef(); return _evalr; } private EvaluatorRef newEvaluatorRef() { return new LangEvalRef(this); } //Object// public String toString() { return "[LanguageDefinition: "+_name+']'; } private static class MacroTemplate { private final Class klass; private final String moldURI; private MacroTemplate(Class klass, String moldURI) { if (moldURI == null || moldURI.length() == 0) throw new IllegalArgumentException("Macro mold UI required"); if (klass == null || !Component.class.isAssignableFrom(klass) || !Macro.class.isAssignableFrom(klass)) throw new IllegalArgumentException("Illegal macro class: "+klass); this.klass = klass; this.moldURI = moldURI; } } private class LabelTemplate { /** The component definition. */ private ComponentDefinition _compdef; /** The component name used for contructing a label. */ private final String _name; /** The component property used for contructing a label. */ private final String _prop; /** Whether the raw label is required. */ private final boolean raw; private LabelTemplate(String name, String prop, boolean raw) { if (name == null || name.length() == 0 || prop == null || prop.length() == 0) throw new IllegalArgumentException(); _name = name; _prop = prop; this.raw = raw; } private ComponentInfo newComponentInfo(ComponentInfo parent, String text) { if (_compdef == null) //no sync since racing is OK _compdef = getComponentDefinition(_name); final ComponentInfo info = new ComponentInfo(parent, _compdef); info.addProperty(_prop, text, null); return info; } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -