Java Code Examples for com.sun.org.apache.xml.internal.serializer.SerializationHandler#namespaceAfterStartElement()
The following examples show how to use
com.sun.org.apache.xml.internal.serializer.SerializationHandler#namespaceAfterStartElement() .
These examples are extracted from open source projects.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: openjdk-jdk9 File: SAX2DTM2.java License: GNU General Public License v2.0 | 5 votes |
/** * Copy an Attribute node to a SerializationHandler * * @param nodeID The node identity * @param exptype The expanded type of the Element node * @param handler The SerializationHandler */ protected final void copyAttribute(int nodeID, int exptype, SerializationHandler handler) throws SAXException { final ExtendedType extType = m_extendedTypes[exptype]; final String uri = extType.getNamespace(); final String localName = extType.getLocalName(); String prefix = null; String qname = null; int dataIndex = _dataOrQName(nodeID); int valueIndex = dataIndex; if (dataIndex <= 0) { int prefixIndex = m_data.elementAt(-dataIndex); valueIndex = m_data.elementAt(-dataIndex+1); qname = m_valuesOrPrefixes.indexToString(prefixIndex); int colonIndex = qname.indexOf(':'); if (colonIndex > 0) { prefix = qname.substring(0, colonIndex); } } if (uri.length() != 0) { handler.namespaceAfterStartElement(prefix, uri); } String nodeName = (prefix != null) ? qname : localName; String nodeValue = m_values.get(valueIndex); handler.addAttribute(uri, localName, nodeName, "CDATA", nodeValue); }
Example 2
Source Project: openjdk-jdk9 File: SAX2DTM2.java License: GNU General Public License v2.0 | 5 votes |
/** * Copy an Element node to a SerializationHandler. * * @param nodeID The node identity * @param exptype The expanded type of the Element node * @param handler The SerializationHandler * @return The qualified name of the Element node. */ protected final String copyElement(int nodeID, int exptype, SerializationHandler handler) throws SAXException { final ExtendedType extType = m_extendedTypes[exptype]; String uri = extType.getNamespace(); String name = extType.getLocalName(); if (uri.length() == 0) { handler.startElement(name); return name; } else { int qnameIndex = m_dataOrQName.elementAt(nodeID); if (qnameIndex == 0) { handler.startElement(name); handler.namespaceAfterStartElement(EMPTY_STR, uri); return name; } if (qnameIndex < 0) { qnameIndex = -qnameIndex; qnameIndex = m_data.elementAt(qnameIndex); } String qName = m_valuesOrPrefixes.indexToString(qnameIndex); handler.startElement(qName); int prefixIndex = qName.indexOf(':'); String prefix; if (prefixIndex > 0) { prefix = qName.substring(0, prefixIndex); } else { prefix = null; } handler.namespaceAfterStartElement(prefix, uri); return qName; } }
Example 3
Source Project: openjdk-jdk8u File: SAX2DTM2.java License: GNU General Public License v2.0 | 5 votes |
/** * Copy an Attribute node to a SerializationHandler * * @param nodeID The node identity * @param exptype The expanded type of the Element node * @param handler The SerializationHandler */ protected final void copyAttribute(int nodeID, int exptype, SerializationHandler handler) throws SAXException { /* final String uri = getNamespaceName(node); if (uri.length() != 0) { final String prefix = getPrefix(node); handler.namespaceAfterStartElement(prefix, uri); } handler.addAttribute(getNodeName(node), getNodeValue(node)); */ final ExtendedType extType = m_extendedTypes[exptype]; final String uri = extType.getNamespace(); final String localName = extType.getLocalName(); String prefix = null; String qname = null; int dataIndex = _dataOrQName(nodeID); int valueIndex = dataIndex; if (dataIndex <= 0) { int prefixIndex = m_data.elementAt(-dataIndex); valueIndex = m_data.elementAt(-dataIndex+1); qname = m_valuesOrPrefixes.indexToString(prefixIndex); int colonIndex = qname.indexOf(':'); if (colonIndex > 0) { prefix = qname.substring(0, colonIndex); } } if (uri.length() != 0) { handler.namespaceAfterStartElement(prefix, uri); } String nodeName = (prefix != null) ? qname : localName; String nodeValue = (String)m_values.elementAt(valueIndex); handler.addAttribute(uri, localName, nodeName, "CDATA", nodeValue); }
Example 4
Source Project: jdk8u60 File: SAX2DTM2.java License: GNU General Public License v2.0 | 5 votes |
/** * Copy an Attribute node to a SerializationHandler * * @param nodeID The node identity * @param exptype The expanded type of the Element node * @param handler The SerializationHandler */ protected final void copyAttribute(int nodeID, int exptype, SerializationHandler handler) throws SAXException { /* final String uri = getNamespaceName(node); if (uri.length() != 0) { final String prefix = getPrefix(node); handler.namespaceAfterStartElement(prefix, uri); } handler.addAttribute(getNodeName(node), getNodeValue(node)); */ final ExtendedType extType = m_extendedTypes[exptype]; final String uri = extType.getNamespace(); final String localName = extType.getLocalName(); String prefix = null; String qname = null; int dataIndex = _dataOrQName(nodeID); int valueIndex = dataIndex; if (dataIndex <= 0) { int prefixIndex = m_data.elementAt(-dataIndex); valueIndex = m_data.elementAt(-dataIndex+1); qname = m_valuesOrPrefixes.indexToString(prefixIndex); int colonIndex = qname.indexOf(':'); if (colonIndex > 0) { prefix = qname.substring(0, colonIndex); } } if (uri.length() != 0) { handler.namespaceAfterStartElement(prefix, uri); } String nodeName = (prefix != null) ? qname : localName; String nodeValue = (String)m_values.elementAt(valueIndex); handler.addAttribute(uri, localName, nodeName, "CDATA", nodeValue); }
Example 5
Source Project: openjdk-8-source File: SAX2DTM2.java License: GNU General Public License v2.0 | 5 votes |
/** * Copy an Attribute node to a SerializationHandler * * @param nodeID The node identity * @param exptype The expanded type of the Element node * @param handler The SerializationHandler */ protected final void copyAttribute(int nodeID, int exptype, SerializationHandler handler) throws SAXException { /* final String uri = getNamespaceName(node); if (uri.length() != 0) { final String prefix = getPrefix(node); handler.namespaceAfterStartElement(prefix, uri); } handler.addAttribute(getNodeName(node), getNodeValue(node)); */ final ExtendedType extType = m_extendedTypes[exptype]; final String uri = extType.getNamespace(); final String localName = extType.getLocalName(); String prefix = null; String qname = null; int dataIndex = _dataOrQName(nodeID); int valueIndex = dataIndex; if (dataIndex <= 0) { int prefixIndex = m_data.elementAt(-dataIndex); valueIndex = m_data.elementAt(-dataIndex+1); qname = m_valuesOrPrefixes.indexToString(prefixIndex); int colonIndex = qname.indexOf(':'); if (colonIndex > 0) { prefix = qname.substring(0, colonIndex); } } if (uri.length() != 0) { handler.namespaceAfterStartElement(prefix, uri); } String nodeName = (prefix != null) ? qname : localName; String nodeValue = (String)m_values.elementAt(valueIndex); handler.addAttribute(uri, localName, nodeName, "CDATA", nodeValue); }
Example 6
Source Project: openjdk-8-source File: SAXImpl.java License: GNU General Public License v2.0 | 4 votes |
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); } }
Example 7
Source Project: openjdk-8-source File: SAX2DTM2.java License: GNU General Public License v2.0 | 4 votes |
/** * Copy namespace nodes. * * @param nodeID The Element node identity * @param handler The SerializationHandler * @param inScope true if all namespaces in scope should be copied, * false if only the namespace declarations should be copied. */ protected final void copyNS(final int nodeID, SerializationHandler handler, boolean inScope) throws SAXException { // %OPT% Optimization for documents which does not have any explicit // namespace nodes. For these documents, there is an implicit // namespace node (xmlns:xml="http://www.w3.org/XML/1998/namespace") // declared on the root element node. In this case, there is no // need to do namespace copying. We can safely return without // doing anything. if (m_namespaceDeclSetElements != null && m_namespaceDeclSetElements.size() == 1 && m_namespaceDeclSets != null && ((SuballocatedIntVector)m_namespaceDeclSets.elementAt(0)) .size() == 1) return; SuballocatedIntVector nsContext = null; int nextNSNode; // Find the first namespace node if (inScope) { nsContext = findNamespaceContext(nodeID); if (nsContext == null || nsContext.size() < 1) return; else nextNSNode = makeNodeIdentity(nsContext.elementAt(0)); } else nextNSNode = getNextNamespaceNode2(nodeID); int nsIndex = 1; while (nextNSNode != DTM.NULL) { // Retrieve the name of the namespace node int eType = _exptype2(nextNSNode); String nodeName = m_extendedTypes[eType].getLocalName(); // Retrieve the node value of the namespace node int dataIndex = m_dataOrQName.elementAt(nextNSNode); if (dataIndex < 0) { dataIndex = -dataIndex; dataIndex = m_data.elementAt(dataIndex + 1); } String nodeValue = (String)m_values.elementAt(dataIndex); handler.namespaceAfterStartElement(nodeName, nodeValue); if (inScope) { if (nsIndex < nsContext.size()) { nextNSNode = makeNodeIdentity(nsContext.elementAt(nsIndex)); nsIndex++; } else return; } else nextNSNode = getNextNamespaceNode2(nextNSNode); } }
Example 8
Source Project: openjdk-jdk9 File: SAXImpl.java License: GNU General Public License v2.0 | 4 votes |
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); } }
Example 9
Source Project: openjdk-8-source File: SAXImpl.java License: GNU General Public License v2.0 | 4 votes |
/** * 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); } }
Example 10
Source Project: openjdk-jdk8u File: SAX2DTM2.java License: GNU General Public License v2.0 | 4 votes |
/** * Copy namespace nodes. * * @param nodeID The Element node identity * @param handler The SerializationHandler * @param inScope true if all namespaces in scope should be copied, * false if only the namespace declarations should be copied. */ protected final void copyNS(final int nodeID, SerializationHandler handler, boolean inScope) throws SAXException { // %OPT% Optimization for documents which does not have any explicit // namespace nodes. For these documents, there is an implicit // namespace node (xmlns:xml="http://www.w3.org/XML/1998/namespace") // declared on the root element node. In this case, there is no // need to do namespace copying. We can safely return without // doing anything. if (m_namespaceDeclSetElements != null && m_namespaceDeclSetElements.size() == 1 && m_namespaceDeclSets != null && ((SuballocatedIntVector)m_namespaceDeclSets.elementAt(0)) .size() == 1) return; SuballocatedIntVector nsContext = null; int nextNSNode; // Find the first namespace node if (inScope) { nsContext = findNamespaceContext(nodeID); if (nsContext == null || nsContext.size() < 1) return; else nextNSNode = makeNodeIdentity(nsContext.elementAt(0)); } else nextNSNode = getNextNamespaceNode2(nodeID); int nsIndex = 1; while (nextNSNode != DTM.NULL) { // Retrieve the name of the namespace node int eType = _exptype2(nextNSNode); String nodeName = m_extendedTypes[eType].getLocalName(); // Retrieve the node value of the namespace node int dataIndex = m_dataOrQName.elementAt(nextNSNode); if (dataIndex < 0) { dataIndex = -dataIndex; dataIndex = m_data.elementAt(dataIndex + 1); } String nodeValue = (String)m_values.elementAt(dataIndex); handler.namespaceAfterStartElement(nodeName, nodeValue); if (inScope) { if (nsIndex < nsContext.size()) { nextNSNode = makeNodeIdentity(nsContext.elementAt(nsIndex)); nsIndex++; } else return; } else nextNSNode = getNextNamespaceNode2(nextNSNode); } }
Example 11
Source Project: TencentKona-8 File: SAXImpl.java License: GNU General Public License v2.0 | 4 votes |
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); } }
Example 12
Source Project: TencentKona-8 File: SAXImpl.java License: GNU General Public License v2.0 | 4 votes |
/** * 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); } }
Example 13
Source Project: TencentKona-8 File: SAX2DTM2.java License: GNU General Public License v2.0 | 4 votes |
/** * Copy an Element node to a SerializationHandler. * * @param nodeID The node identity * @param exptype The expanded type of the Element node * @param handler The SerializationHandler * @return The qualified name of the Element node. */ protected final String copyElement(int nodeID, int exptype, SerializationHandler handler) throws SAXException { final ExtendedType extType = m_extendedTypes[exptype]; String uri = extType.getNamespace(); String name = extType.getLocalName(); if (uri.length() == 0) { handler.startElement(name); return name; } else { int qnameIndex = m_dataOrQName.elementAt(nodeID); if (qnameIndex == 0) { handler.startElement(name); handler.namespaceAfterStartElement(EMPTY_STR, uri); return name; } if (qnameIndex < 0) { qnameIndex = -qnameIndex; qnameIndex = m_data.elementAt(qnameIndex); } String qName = m_valuesOrPrefixes.indexToString(qnameIndex); handler.startElement(qName); int prefixIndex = qName.indexOf(':'); String prefix; if (prefixIndex > 0) { prefix = qName.substring(0, prefixIndex); } else { prefix = null; } handler.namespaceAfterStartElement(prefix, uri); return qName; } }
Example 14
Source Project: openjdk-jdk8u File: SAX2DTM2.java License: GNU General Public License v2.0 | 4 votes |
/** * Copy an Element node to a SerializationHandler. * * @param nodeID The node identity * @param exptype The expanded type of the Element node * @param handler The SerializationHandler * @return The qualified name of the Element node. */ protected final String copyElement(int nodeID, int exptype, SerializationHandler handler) throws SAXException { final ExtendedType extType = m_extendedTypes[exptype]; String uri = extType.getNamespace(); String name = extType.getLocalName(); if (uri.length() == 0) { handler.startElement(name); return name; } else { int qnameIndex = m_dataOrQName.elementAt(nodeID); if (qnameIndex == 0) { handler.startElement(name); handler.namespaceAfterStartElement(EMPTY_STR, uri); return name; } if (qnameIndex < 0) { qnameIndex = -qnameIndex; qnameIndex = m_data.elementAt(qnameIndex); } String qName = m_valuesOrPrefixes.indexToString(qnameIndex); handler.startElement(qName); int prefixIndex = qName.indexOf(':'); String prefix; if (prefixIndex > 0) { prefix = qName.substring(0, prefixIndex); } else { prefix = null; } handler.namespaceAfterStartElement(prefix, uri); return qName; } }
Example 15
Source Project: jdk8u60 File: SAX2DTM2.java License: GNU General Public License v2.0 | 4 votes |
/** * Copy an Element node to a SerializationHandler. * * @param nodeID The node identity * @param exptype The expanded type of the Element node * @param handler The SerializationHandler * @return The qualified name of the Element node. */ protected final String copyElement(int nodeID, int exptype, SerializationHandler handler) throws SAXException { final ExtendedType extType = m_extendedTypes[exptype]; String uri = extType.getNamespace(); String name = extType.getLocalName(); if (uri.length() == 0) { handler.startElement(name); return name; } else { int qnameIndex = m_dataOrQName.elementAt(nodeID); if (qnameIndex == 0) { handler.startElement(name); handler.namespaceAfterStartElement(EMPTY_STR, uri); return name; } if (qnameIndex < 0) { qnameIndex = -qnameIndex; qnameIndex = m_data.elementAt(qnameIndex); } String qName = m_valuesOrPrefixes.indexToString(qnameIndex); handler.startElement(qName); int prefixIndex = qName.indexOf(':'); String prefix; if (prefixIndex > 0) { prefix = qName.substring(0, prefixIndex); } else { prefix = null; } handler.namespaceAfterStartElement(prefix, uri); return qName; } }
Example 16
Source Project: jdk8u60 File: SAX2DTM2.java License: GNU General Public License v2.0 | 4 votes |
/** * Copy namespace nodes. * * @param nodeID The Element node identity * @param handler The SerializationHandler * @param inScope true if all namespaces in scope should be copied, * false if only the namespace declarations should be copied. */ protected final void copyNS(final int nodeID, SerializationHandler handler, boolean inScope) throws SAXException { // %OPT% Optimization for documents which does not have any explicit // namespace nodes. For these documents, there is an implicit // namespace node (xmlns:xml="http://www.w3.org/XML/1998/namespace") // declared on the root element node. In this case, there is no // need to do namespace copying. We can safely return without // doing anything. if (m_namespaceDeclSetElements != null && m_namespaceDeclSetElements.size() == 1 && m_namespaceDeclSets != null && ((SuballocatedIntVector)m_namespaceDeclSets.elementAt(0)) .size() == 1) return; SuballocatedIntVector nsContext = null; int nextNSNode; // Find the first namespace node if (inScope) { nsContext = findNamespaceContext(nodeID); if (nsContext == null || nsContext.size() < 1) return; else nextNSNode = makeNodeIdentity(nsContext.elementAt(0)); } else nextNSNode = getNextNamespaceNode2(nodeID); int nsIndex = 1; while (nextNSNode != DTM.NULL) { // Retrieve the name of the namespace node int eType = _exptype2(nextNSNode); String nodeName = m_extendedTypes[eType].getLocalName(); // Retrieve the node value of the namespace node int dataIndex = m_dataOrQName.elementAt(nextNSNode); if (dataIndex < 0) { dataIndex = -dataIndex; dataIndex = m_data.elementAt(dataIndex + 1); } String nodeValue = (String)m_values.elementAt(dataIndex); handler.namespaceAfterStartElement(nodeName, nodeValue); if (inScope) { if (nsIndex < nsContext.size()) { nextNSNode = makeNodeIdentity(nsContext.elementAt(nsIndex)); nsIndex++; } else return; } else nextNSNode = getNextNamespaceNode2(nextNSNode); } }
Example 17
Source Project: openjdk-jdk8u-backup File: SAX2DTM2.java License: GNU General Public License v2.0 | 4 votes |
/** * Copy an Element node to a SerializationHandler. * * @param nodeID The node identity * @param exptype The expanded type of the Element node * @param handler The SerializationHandler * @return The qualified name of the Element node. */ protected final String copyElement(int nodeID, int exptype, SerializationHandler handler) throws SAXException { final ExtendedType extType = m_extendedTypes[exptype]; String uri = extType.getNamespace(); String name = extType.getLocalName(); if (uri.length() == 0) { handler.startElement(name); return name; } else { int qnameIndex = m_dataOrQName.elementAt(nodeID); if (qnameIndex == 0) { handler.startElement(name); handler.namespaceAfterStartElement(EMPTY_STR, uri); return name; } if (qnameIndex < 0) { qnameIndex = -qnameIndex; qnameIndex = m_data.elementAt(qnameIndex); } String qName = m_valuesOrPrefixes.indexToString(qnameIndex); handler.startElement(qName); int prefixIndex = qName.indexOf(':'); String prefix; if (prefixIndex > 0) { prefix = qName.substring(0, prefixIndex); } else { prefix = null; } handler.namespaceAfterStartElement(prefix, uri); return qName; } }
Example 18
Source Project: JDKSourceCode1.8 File: SAXImpl.java License: MIT License | 4 votes |
/** * 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); } }
Example 19
Source Project: openjdk-jdk8u File: SAXImpl.java License: GNU General Public License v2.0 | 4 votes |
/** * 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); } }
Example 20
Source Project: JDKSourceCode1.8 File: SAX2DTM2.java License: MIT License | 4 votes |
/** * Copy namespace nodes. * * @param nodeID The Element node identity * @param handler The SerializationHandler * @param inScope true if all namespaces in scope should be copied, * false if only the namespace declarations should be copied. */ protected final void copyNS(final int nodeID, SerializationHandler handler, boolean inScope) throws SAXException { // %OPT% Optimization for documents which does not have any explicit // namespace nodes. For these documents, there is an implicit // namespace node (xmlns:xml="http://www.w3.org/XML/1998/namespace") // declared on the root element node. In this case, there is no // need to do namespace copying. We can safely return without // doing anything. if (m_namespaceDeclSetElements != null && m_namespaceDeclSetElements.size() == 1 && m_namespaceDeclSets != null && ((SuballocatedIntVector)m_namespaceDeclSets.elementAt(0)) .size() == 1) return; SuballocatedIntVector nsContext = null; int nextNSNode; // Find the first namespace node if (inScope) { nsContext = findNamespaceContext(nodeID); if (nsContext == null || nsContext.size() < 1) return; else nextNSNode = makeNodeIdentity(nsContext.elementAt(0)); } else nextNSNode = getNextNamespaceNode2(nodeID); int nsIndex = 1; while (nextNSNode != DTM.NULL) { // Retrieve the name of the namespace node int eType = _exptype2(nextNSNode); String nodeName = m_extendedTypes[eType].getLocalName(); // Retrieve the node value of the namespace node int dataIndex = m_dataOrQName.elementAt(nextNSNode); if (dataIndex < 0) { dataIndex = -dataIndex; dataIndex = m_data.elementAt(dataIndex + 1); } String nodeValue = (String)m_values.elementAt(dataIndex); handler.namespaceAfterStartElement(nodeName, nodeValue); if (inScope) { if (nsIndex < nsContext.size()) { nextNSNode = makeNodeIdentity(nsContext.elementAt(nsIndex)); nsIndex++; } else return; } else nextNSNode = getNextNamespaceNode2(nextNSNode); } }