📄 saximpl.java
字号:
if (getNSType(nextNode) == nsType) { break; } } _currentNode = nextNode; return returnNode(node); } } // end of NamespaceAttributeIterator /** * Returns an iterator with all descendants of a node that are of * a given type. */ public DTMAxisIterator getTypedDescendantIterator(int type) { return new TypedDescendantIterator(type); } /** * Returns the nth descendant of a node */ public DTMAxisIterator getNthDescendant(int type, int n, boolean includeself) { DTMAxisIterator source = (DTMAxisIterator) new TypedDescendantIterator(type); return new NthDescendantIterator(n); } /** * Copy the string value of a node directly to an output handler */ public void characters(final int node, SerializationHandler handler) throws TransletException { if (node != DTM.NULL) { try { dispatchCharactersEvents(node, handler, false); } catch (SAXException e) { throw new TransletException(e); } } } /** * Copy a node-set to an output handler */ public void copy(DTMAxisIterator nodes, SerializationHandler handler) throws TransletException { int node; while ((node = nodes.next()) != DTM.NULL) { copy(node, handler); } } /** * Copy the whole tree to an output handler */ public void copy(SerializationHandler handler) throws TransletException { copy(getDocument(), handler); } /** * Performs a deep copy (ref. XSLs copy-of()) * * TODO: Copy namespace declarations. Can't be done until we * add namespace nodes and keep track of NS prefixes * TODO: Copy comment nodes */ public void copy(final int node, SerializationHandler handler) throws TransletException { copy(node, handler, false ); } private final void copy(final int node, SerializationHandler handler, boolean isChild) throws TransletException { int nodeID = makeNodeIdentity(node); int eType = _exptype2(nodeID); int type = _exptype2Type(eType); try { switch(type) { case DTM.ROOT_NODE: case DTM.DOCUMENT_NODE: for(int c = _firstch2(nodeID); c != DTM.NULL; c = _nextsib2(c)) { copy(makeNodeHandle(c), handler, true); } break; case DTM.PROCESSING_INSTRUCTION_NODE: copyPI(node, handler); break; case DTM.COMMENT_NODE: handler.comment(getStringValueX(node)); break; case DTM.TEXT_NODE: boolean oldEscapeSetting = false; boolean escapeBit = false; if (_dontEscape != null) { escapeBit = _dontEscape.getBit(getNodeIdent(node)); if (escapeBit) { oldEscapeSetting = handler.setEscaping(false); } } copyTextNode(nodeID, handler); if (escapeBit) { handler.setEscaping(oldEscapeSetting); } break; case DTM.ATTRIBUTE_NODE: copyAttribute(nodeID, eType, handler); break; case DTM.NAMESPACE_NODE: handler.namespaceAfterStartElement(getNodeNameX(node), getNodeValue(node)); break; default: if (type == DTM.ELEMENT_NODE) { // Start element definition final String name = copyElement(nodeID, eType, handler); //if(isChild) => not to copy any namespaces from parents // else copy all namespaces in scope copyNS(nodeID, handler,!isChild); copyAttributes(nodeID, handler); // Copy element children for (int c = _firstch2(nodeID); c != DTM.NULL; c = _nextsib2(c)) { copy(makeNodeHandle(c), handler, true); } // Close element definition handler.endElement(name); } // Shallow copy of attribute to output handler else { final String uri = getNamespaceName(node); if (uri.length() != 0) { final String prefix = getPrefix(node); handler.namespaceAfterStartElement(prefix, uri); } handler.addAttribute(getNodeName(node), getNodeValue(node)); } break; } } catch (Exception e) { throw new TransletException(e); } } /** * Copies a processing instruction node to an output handler */ private void copyPI(final int node, SerializationHandler handler) throws TransletException { final String target = getNodeName(node); final String value = getStringValueX(node); try { handler.processingInstruction(target, value); } catch (Exception e) { throw new TransletException(e); } } /** * Performs a shallow copy (ref. XSLs copy()) */ public String shallowCopy(final int node, SerializationHandler handler) throws TransletException { int nodeID = makeNodeIdentity(node); int exptype = _exptype2(nodeID); int type = _exptype2Type(exptype); try { switch(type) { case DTM.ELEMENT_NODE: final String name = copyElement(nodeID, exptype, handler); copyNS(nodeID, handler, true); return name; case DTM.ROOT_NODE: case DTM.DOCUMENT_NODE: return EMPTYSTRING; case DTM.TEXT_NODE: copyTextNode(nodeID, handler); return null; case DTM.PROCESSING_INSTRUCTION_NODE: copyPI(node, handler); return null; case DTM.COMMENT_NODE: handler.comment(getStringValueX(node)); return null; case DTM.NAMESPACE_NODE: handler.namespaceAfterStartElement(getNodeNameX(node), getNodeValue(node)); return null; case DTM.ATTRIBUTE_NODE: copyAttribute(nodeID, exptype, handler); return null; default: final String uri1 = getNamespaceName(node); if (uri1.length() != 0) { final String prefix = getPrefix(node); handler.namespaceAfterStartElement(prefix, uri1); } handler.addAttribute(getNodeName(node), getNodeValue(node)); return null; } } catch (Exception e) { throw new TransletException(e); } } /** * Returns a node' defined language for a node (if any) */ public String getLanguage(int node) { int parent = node; while (DTM.NULL != parent) { if (DTM.ELEMENT_NODE == getNodeType(parent)) { int langAttr = getAttributeNode(parent, "http://www.w3.org/XML/1998/namespace", "lang"); if (DTM.NULL != langAttr) { return getNodeValue(langAttr); } } parent = getParent(parent); } return(null); } /** * Returns an instance of the DOMBuilder inner class * This class will consume the input document through a SAX2 * interface and populate the tree. */ public DOMBuilder getBuilder() { return this; } /** * Return a SerializationHandler for output handling. * This method is used by Result Tree Fragments. */ public SerializationHandler getOutputDomBuilder() { return new ToXMLSAXHandler(this, "UTF-8"); } /** * Return a instance of a DOM class to be used as an RTF */ public DOM getResultTreeFrag(int initSize, int rtfType) { return getResultTreeFrag(initSize, rtfType, true); } /** * Return a instance of a DOM class to be used as an RTF * * @param initSize The initial size of the DOM. * @param rtfType The type of the RTF * @param addToManager true if the RTF should be registered with the DTMManager. * @return The DOM object which represents the RTF. */ public DOM getResultTreeFrag(int initSize, int rtfType, boolean addToManager) { if (rtfType == DOM.SIMPLE_RTF) { if (addToManager) { int dtmPos = _dtmManager.getFirstFreeDTMID(); SimpleResultTreeImpl rtf = new SimpleResultTreeImpl(_dtmManager, dtmPos << DTMManager.IDENT_DTM_NODE_BITS); _dtmManager.addDTM(rtf, dtmPos, 0); return rtf; } else { return new SimpleResultTreeImpl(_dtmManager, 0); } } else if (rtfType == DOM.ADAPTIVE_RTF) { if (addToManager) { int dtmPos = _dtmManager.getFirstFreeDTMID(); AdaptiveResultTreeImpl rtf = new AdaptiveResultTreeImpl(_dtmManager, dtmPos << DTMManager.IDENT_DTM_NODE_BITS, m_wsfilter, initSize, m_buildIdIndex); _dtmManager.addDTM(rtf, dtmPos, 0); return rtf; } else { return new AdaptiveResultTreeImpl(_dtmManager, 0, m_wsfilter, initSize, m_buildIdIndex); } } else { return (DOM) _dtmManager.getDTM(null, true, m_wsfilter, true, false, false, initSize, m_buildIdIndex); } } /** * %HZ% Need Javadoc */ public Hashtable getElementsWithIDs() { if (m_idAttributes == null) { return null; } // Convert a java.util.Hashtable to an xsltc.runtime.Hashtable Enumeration idValues = m_idAttributes.keys(); if (!idValues.hasMoreElements()) { return null; } Hashtable idAttrsTable = new Hashtable(); while (idValues.hasMoreElements()) { Object idValue = idValues.nextElement(); idAttrsTable.put(idValue, m_idAttributes.get(idValue)); } return idAttrsTable; } /** * The getUnparsedEntityURI function returns the URI of the unparsed * entity with the specified name in the same document as the context * node (see [3.3 Unparsed Entities]). It returns the empty string if * there is no such entity. */ public String getUnparsedEntityURI(String name) { // Special handling for DOM input if (_document != null) { String uri = ""; DocumentType doctype = _document.getDoctype(); if (doctype != null) { NamedNodeMap entities = doctype.getEntities(); if (entities == null) { return uri; } Entity entity = (Entity) entities.getNamedItem(name); if (entity == null) { return uri; } String notationName = entity.getNotationName(); if (notationName != null) { uri = entity.getSystemId(); if (uri == null) { uri = entity.getPublicId(); } } } return uri; } else { return super.getUnparsedEntityURI(name); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -