📄 definitionloaders.java
字号:
if (ctn != null && ctn.length() > 0) throw new UiException("You cannot specify the content if the href attribute is specified, "+el.getLocator()); ss = new StyleSheet(href, el.getAttributeValue("type")); } else if (ctn != null && ctn.length() > 0) { ss = new StyleSheet(ctn, el.getAttributeValue("type"), true); } else { throw new UiException("You must specify either the href attribute or the content, "+el.getLocator()); } langdef.addStyleSheet(ss); } for (Iterator it = root.getElements("zscript").iterator(); it.hasNext();) { final Element el = (Element)it.next(); final String s = el.getText(true); langdef.addScript(s); } for (Iterator it = root.getElements("component").iterator(); it.hasNext();) { final Element el = (Element)it.next(); final String name = IDOMs.getRequiredElementValue(el, "component-name"); final String macroUri = el.getElementValue("macro-uri", true); final ComponentDefinition compdef; if (macroUri != null && macroUri.length() != 0) { if (log.finerable()) log.finer("macro component definition: "+name); compdef = new ComponentDefinition(langdef, name, macroUri); langdef.initMacroDefinition(compdef); final String clsnm = el.getElementValue("component-class", true); if (clsnm != null && clsnm.length() > 0) { noEL("component-class", clsnm, el); compdef.setImplementationClass(locateClass(clsnm)); //resolve it now because it is part of lang-addon } langdef.addComponentDefinition(compdef); } else if (el.getElement("extends") != null) { //override if (log.finerable()) log.finer("Override component definition: "+name); final String extnm = el.getElementValue("extends", true); final ComponentDefinition ref = langdef.getComponentDefinition(extnm); if (ref.isMacro()) throw new UiException("Unable to extend from a macro component, "+el.getLocator()); if (extnm.equals(name)) { compdef = ref; } else { compdef = ref.clone(name); langdef.addComponentDefinition(compdef); } final String clsnm = el.getElementValue("component-class", true); if (clsnm != null && clsnm.length() > 0) { noEL("component-class", clsnm, el); compdef.setImplementationClass(locateClass(clsnm)); } } else { if (log.finerable()) log.finer("Add component definition: name="+name); final String clsnm = IDOMs.getRequiredElementValue(el, "component-class"); noEL("component-class", clsnm, el); compdef = new ComponentDefinition( langdef, name, locateClass(clsnm)); langdef.addComponentDefinition(compdef); } for (Iterator e = parseMolds(el).entrySet().iterator(); e.hasNext();) { final Map.Entry me = (Map.Entry)e.next(); compdef.addMold((String)me.getKey(), (String)me.getValue()); } for (Iterator e = parseParams(el).entrySet().iterator(); e.hasNext();) { final Map.Entry me = (Map.Entry)e.next(); compdef.addParam((String)me.getKey(), (String)me.getValue()); } for (Iterator e = parseProps(el).entrySet().iterator(); e.hasNext();) { final Map.Entry me = (Map.Entry)e.next(); compdef.addProperty( (String)me.getKey(), (String)me.getValue(), null); } parseAnnots(compdef, el); } } private static Class locateClass(String clsnm) throws Exception { try { return Classes.forNameByThread(clsnm); } catch (ClassNotFoundException ex) { throw new ClassNotFoundException("Not found: "+clsnm, ex); } } private static void noEL(String nm, String val, Element el) throws UiException { if (val != null && val.indexOf("${") >= 0) throw new UiException(nm+" does not support EL expressions, "+el.getLocator()); } /** Parse the processing instructions. */ private static void parsePI(LanguageDefinition langdef, Document doc) throws Exception { for (Iterator it = doc.getChildren().iterator(); it.hasNext();) { final Object o = it.next(); if (!(o instanceof ProcessingInstruction)) continue; final ProcessingInstruction pi = (ProcessingInstruction)o; final String target = pi.getTarget(); final Map params = pi.parseData(); if ("taglib".equals(target)) { final String uri = (String)params.remove("uri"); final String prefix = (String)params.remove("prefix"); if (!params.isEmpty()) log.warning("Ignored unknown attribute: "+params+", "+pi.getLocator()); if (uri == null || prefix == null) throw new IllegalSyntaxException("Both uri and prefix attribute are required, "+pi.getLocator()); if (log.debugable()) log.debug("taglib: prefix="+prefix+" uri="+uri); langdef.addTaglib(new Taglib(prefix, uri)); } else { log.warning("Unknown processing instruction: "+target); } } } /** Parse the component used to represent a label. */ private static void parseLabelTemplate(LanguageDefinition langdef, Element el) { el = el.getElement("label-template"); if (el != null) { final Element raw = el.getElement("raw"); langdef.setLabelTemplate( IDOMs.getRequiredElementValue(el, "component-name"), IDOMs.getRequiredElementValue(el, "component-attribute"), raw != null && !"false".equals(raw.getText(true))); } } private static void parseMacroTemplate(LanguageDefinition langdef, Element el) throws Exception { el = el.getElement("macro-template"); if (el != null) { langdef.setMacroTemplate( locateClass(IDOMs.getRequiredElementValue(el, "macro-class")), IDOMs.getRequiredElementValue(el, "macro-uri")); } } private static void parseDynamicTag(LanguageDefinition langdef, Element el) throws ClassNotFoundException { el = el.getElement("dynamic-tag"); if (el != null) { final String compnm = IDOMs.getRequiredElementValue(el, "component-name"); final Set reservedAttrs = new HashSet(5); for (Iterator it = el.getElements("reserved-attribute").iterator(); it.hasNext();) reservedAttrs.add(((Element)it.next()).getText(true)); langdef.setDynamicTagInfo(compnm, reservedAttrs); } //if (log.finerable()) log.finer(el); } private static List parseExtensions(Element elm) { final List exts = new LinkedList(); for (Iterator it = elm.getElements("extension").iterator(); it.hasNext();) { final Element el = (Element)it.next(); final String ext = el.getText(true); if (ext.length() != 0) { for (int j = 0, len = ext.length(); j < len; ++j) { final char cc = ext.charAt(j); if ((cc < 'a' || cc > 'z') && (cc < 'A' || cc > 'Z') && (cc < '0' || cc > '9')) throw new UiException("Invalid extension; only letters and numbers are allowed: "+ext); } exts.add(ext); } } ///if (log.finerable()) log.finer(exts); return exts; } private static Map parseProps(Element elm) { return IDOMs.parseParams(elm, "property", "property-name", "property-value"); } private static Map parseMolds(Element elm) { return IDOMs.parseParams(elm, "mold", "mold-name", "mold-uri"); } private static Map parseParams(Element elm) { return IDOMs.parseParams(elm, "param", "param-name", "param-value"); } private static Map parseAttrs(Element elm) { return IDOMs.parseParams(elm, "attribute", "attribute-name", "attribute-value"); } private static void parseAnnots(ComponentDefinition compdef, Element top) { for (Iterator it = top.getElements("annotation").iterator(); it.hasNext();) { final Element el = (Element)it.next(); final String annotName = IDOMs.getRequiredElementValue(el, "annotation-name"); final Map annotAttrs = parseAttrs(el); final String prop = el.getElementValue("property-name", true); if (prop == null || prop.length() == 0) compdef.addAnnotation(annotName, annotAttrs); else compdef.addAnnotation(prop, annotName, annotAttrs); } } private static class Addon { private final Document document; private final int priority; private Addon(Document document) { this.document = document; final String p = document.getRootElement().getElementValue("priority", true); this.priority = p != null && p.length() > 0 ? Integer.parseInt(p): 0; } private static void add(List addons, Document document) { final Addon addon = new Addon(document); for (ListIterator it = addons.listIterator(); it.hasNext();) { final Addon a = (Addon)it.next(); if (a.priority < addon.priority) { it.previous(); it.add(addon); return; //done } } addons.add(addon); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -