⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 definitionloaders.java

📁 ZK 基础介绍 功能操作 模块 结合数据库操作
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
			final List exts = parseExtensions(root);			if (exts.isEmpty())				throw new UiException("The extension must be specified for "+lang);			String ignoreCase = root.getElementValue("case-insensitive", true);			String bNative = root.getElementValue("native-namespace", true);			langdef = new LanguageDefinition(				deviceType, lang, ns, exts, desktopURI, pageURI,				"true".equals(ignoreCase), "true".equals(bNative), locator);		}		parsePI(langdef, doc);		parseLabelTemplate(langdef, root);		parseDynamicTag(langdef, root);		parseMacroTemplate(langdef, root);		parseNativeTemplate(langdef, root);		for (Iterator it = root.getElements("javascript").iterator();		it.hasNext();) {			final Element el = (Element)it.next();			final String src = el.getAttributeValue("src");			final String ctn = el.getText(true);			final JavaScript js;			if (src != null && src.length() > 0) {				if (ctn != null && ctn.length() > 0)					throw new UiException("You cannot specify the content if the src attribute is specified, "+el.getLocator());				final String charset = el.getAttributeValue("charset");				js = new JavaScript(src, charset);			} else if (ctn != null && ctn.length() > 0) {				js = new JavaScript(ctn);			} else {				throw new UiException("You must specify either the src attribute or the content, "+el.getLocator());			}			langdef.addJavaScript(js);		}		for (Iterator it = root.getElements("javascript-module").iterator();		it.hasNext();) {			final Element el = (Element)it.next();			langdef.addJavaScriptModule(				IDOMs.getRequiredAttributeValue(el, "name"),				IDOMs.getRequiredAttributeValue(el, "version"));		}		for (Iterator it = root.getElements("stylesheet").iterator();		it.hasNext();) {			final Element el = (Element)it.next();			final String href = el.getAttributeValue("href");			final String ctn = el.getText(true);			final StyleSheet ss;			if (href != null && href.length() > 0) {				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 zslang;			final Attribute attr = el.getAttributeItem("language");			if (attr == null) {				zslang = "Java";			} else {				zslang = attr.getValue();				if (zslang == null || zslang.length() == 0)					throw new UiException("The language attribute cannot be empty, "+attr.getLocator());			}			final String s = el.getText(true);			final String eachTime = el.getAttributeValue("each-time");			if ("true".equals(eachTime))				langdef.addEachTimeScript(zslang, s);			else				langdef.addInitScript(zslang, 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 ComponentDefinitionImpl compdef;			if (macroURI != null && macroURI.length() != 0) {				if (log.finerable()) log.finer("macro component definition: "+name);				final String inline = el.getElementValue("inline", true);				compdef = (ComponentDefinitionImpl)					langdef.getMacroDefinition(						name, macroURI, "true".equals(inline), null);				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 = (ComponentDefinitionImpl)ref;				} else {					compdef = (ComponentDefinitionImpl)						ref.clone(ref.getLanguageDefinition(), 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 ComponentDefinitionImpl(					langdef, null, name, locateClass(clsnm));				langdef.addComponentDefinition(compdef);			}			final String textAs = el.getElementValue("text-as", true);			if (textAs != null) { //empty means cleanup (for overriding)				noEL("text-as", textAs, el);				compdef.setTextAs(textAs);			}			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 = parseCustAttrs(el).entrySet().iterator(); e.hasNext();) {				final Map.Entry me = (Map.Entry)e.next();				compdef.addCustomAttribute((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());			}			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 UiException("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 parseNativeTemplate(LanguageDefinition langdef, Element el)	throws Exception {		el = el.getElement("native-template");		if (el != null) {			langdef.setNativeTemplate(				locateClass(IDOMs.getRequiredElementValue(el, "native-class")));		}	}	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 parseCustAttrs(Element elm) {		return IDOMs.parseParams(elm, "custom-attribute", "attribute-name", "attribute-value");	}	private static Map parseAttrs(Element elm) {		return IDOMs.parseParams(elm, "attribute", "attribute-name", "attribute-value");	}	private static void parseAnnots(ComponentDefinitionImpl 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 + -