xsltelementdef.java
来自「java jdk 1.4的源码」· Java 代码 · 共 871 行 · 第 1/2 页
JAVA
871 行
*/ private String m_nameAlias; /** * Get the name of this element. * * @return A potential alias for the name, or null. */ String getNameAlias() { return m_nameAlias; } /** * The allowed elements for this type. */ private XSLTElementDef[] m_elements; /** * Get the allowed elements for this type. * * @return An array of allowed child element defs, or null. */ XSLTElementDef[] getElements() { return m_elements; } /** * Set the allowed elements for this type. * * @param defs An array of allowed child element defs, or null. */ void setElements(XSLTElementDef[] defs) { m_elements = defs; } /** * Tell if the namespace URI and local name match this * element. * @param uri The namespace uri, which may be null. * @param localName The local name of an element, which may be null. * * @return true if the uri and local name arguments are considered * to match the uri and local name of this element def. */ private boolean QNameEquals(String uri, String localName) { return (equalsMayBeNullOrZeroLen(m_namespace, uri) && (equalsMayBeNullOrZeroLen(m_name, localName) || equalsMayBeNullOrZeroLen(m_nameAlias, localName))); } /** * Given a namespace URI, and a local name, get the processor * for the element, or return null if not allowed. * * @param uri The Namespace URI, or an empty string. * @param localName The local name (without prefix), or empty string if not namespace processing. * * @return The element processor that matches the arguments, or null. */ XSLTElementProcessor getProcessorFor(String uri, String localName) { XSLTElementProcessor elemDef = null; // return value if (null == m_elements) return null; int n = m_elements.length; int order = -1; boolean multiAllowed = true; for (int i = 0; i < n; i++) { XSLTElementDef def = m_elements[i]; // A "*" signals that the element allows literal result // elements, so just assign the def, and continue to // see if anything else matches. if (def.m_name.equals("*")) { // Don't allow xsl elements if (!equalsMayBeNullOrZeroLen(uri, Constants.S_XSLNAMESPACEURL)) { elemDef = def.m_elementProcessor; order = def.getOrder(); multiAllowed = def.getMultiAllowed(); } } else if (def.QNameEquals(uri, localName)) { if (def.getRequired()) this.setRequiredFound(def.getName(), true); order = def.getOrder(); multiAllowed = def.getMultiAllowed(); elemDef = def.m_elementProcessor; break; } } if (elemDef != null && this.isOrdered()) { int lastOrder = getLastOrder(); if (order > lastOrder) setLastOrder(order); else if (order == lastOrder && !multiAllowed) { return null; } else if (order < lastOrder && order > 0) { return null; } } return elemDef; } /** * Given an unknown element, get the processor * for the element. * * @param uri The Namespace URI, or an empty string. * @param localName The local name (without prefix), or empty string if not namespace processing. * * @return normally a {@link ProcessorUnknown} reference. * @see ProcessorUnknown */ XSLTElementProcessor getProcessorForUnknown(String uri, String localName) { // XSLTElementProcessor lreDef = null; // return value if (null == m_elements) return null; int n = m_elements.length; for (int i = 0; i < n; i++) { XSLTElementDef def = m_elements[i]; if (def.m_name.equals("unknown") && uri.length() > 0) { return def.m_elementProcessor; } } return null; } /** * The allowed attributes for this type. */ private XSLTAttributeDef[] m_attributes; /** * Get the allowed attributes for this type. * * @return An array of allowed attribute defs, or null. */ XSLTAttributeDef[] getAttributes() { return m_attributes; } /** * Given a namespace URI, and a local name, return the element's * attribute definition, if it has one. * * @param uri The Namespace URI, or an empty string. * @param localName The local name (without prefix), or empty string if not namespace processing. * * @return The attribute def that matches the arguments, or null. */ XSLTAttributeDef getAttributeDef(String uri, String localName) { XSLTAttributeDef defaultDef = null; XSLTAttributeDef[] attrDefs = getAttributes(); int nAttrDefs = attrDefs.length; for (int k = 0; k < nAttrDefs; k++) { XSLTAttributeDef attrDef = attrDefs[k]; String uriDef = attrDef.getNamespace(); String nameDef = attrDef.getName(); if (nameDef.equals("*") && (equalsMayBeNullOrZeroLen(uri, uriDef) || (uriDef != null && uriDef.equals("*") && uri!=null && uri.length() > 0 ))) { return attrDef; } else if (nameDef.equals("*") && (uriDef == null)) { // In this case, all attributes are legal, so return // this as the last resort. defaultDef = attrDef; } else if (equalsMayBeNullOrZeroLen(uri, uriDef) && localName.equals(nameDef)) { return attrDef; } } if (null == defaultDef) { if (uri.length() > 0 && !equalsMayBeNullOrZeroLen(uri, Constants.S_XSLNAMESPACEURL)) { return XSLTAttributeDef.m_foreignAttr; } } return defaultDef; } /** * If non-null, the ContentHandler/TransformerFactory for this element. */ private XSLTElementProcessor m_elementProcessor; /** * Return the XSLTElementProcessor for this element. * * @return The element processor for this element. */ XSLTElementProcessor getElementProcessor() { return m_elementProcessor; } /** * Set the XSLTElementProcessor for this element. * * @param handler The element processor for this element. */ void setElementProcessor(XSLTElementProcessor handler) { if (handler != null) { m_elementProcessor = handler; m_elementProcessor.setElemDef(this); } } /** * If non-null, the class object that should in instantiated for * a Xalan instance of this element. */ private Class m_classObject; /** * Return the class object that should in instantiated for * a Xalan instance of this element. * * @return The class of the object that this element def should produce, or null. */ Class getClassObject() { return m_classObject; } /** * If true, this has a required element. */ private boolean m_has_required = false; /** * Get whether or not this has a required element. * * @return true if this this has a required element. */ boolean hasRequired() { return m_has_required; } /** * If true, this is a required element. */ private boolean m_required = false; /** * Get whether or not this is a required element. * * @return true if this is a required element. */ boolean getRequired() { return m_required; } Hashtable m_requiredFound; /** * Set this required element found. * */ void setRequiredFound(String elem, boolean found) { if (m_requiredFound.get(elem) != null) m_requiredFound.remove(elem); } /** * Get whether all required elements were found. * * @return true if all required elements were found. */ boolean getRequiredFound() { if (m_requiredFound == null) return true; return m_requiredFound.isEmpty(); } /** * Get required elements that were not found. * * @return required elements that were not found. */ String getRequiredElem() { if (m_requiredFound == null) return null; Enumeration elems = m_requiredFound.elements(); String s = ""; boolean first = true; while (elems.hasMoreElements()) { if (first) first = false; else s = s + ", "; s = s + (String)elems.nextElement(); } return s; } boolean m_isOrdered = false; /** * Get whether this element requires ordered children. * * @return true if this element requires ordered children. */ boolean isOrdered() { /*if (!m_CheckedOrdered) { m_CheckedOrdered = true; m_isOrdered = false; if (null == m_elements) return false; int n = m_elements.length; for (int i = 0; i < n; i++) { if (m_elements[i].getOrder() > 0) { m_isOrdered = true; return true; } } return false; } else*/ return m_isOrdered; } /** * the order that this element should appear, or -1 if not ordered */ private int m_order = -1; /** * Get the order that this element should appear . * * @return the order that this element should appear. */ int getOrder() { return m_order; } /** * the highest order of child elements have appeared so far, * or -1 if not ordered */ private int m_lastOrder = -1; /** * Get the highest order of child elements have appeared so far . * * @return the highest order of child elements have appeared so far. */ int getLastOrder() { return m_lastOrder; } /** * Set the highest order of child elements have appeared so far . * * @param order the highest order of child elements have appeared so far. */ void setLastOrder(int order) { m_lastOrder = order ; } /** * True if this element can appear multiple times */ private boolean m_multiAllowed = true; /** * Get whether this element can appear multiple times * * @return true if this element can appear multiple times */ boolean getMultiAllowed() { return m_multiAllowed; }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?