Java Code Examples for com.sun.org.apache.xml.internal.dtm.DTM#DOCUMENT_NODE

The following examples show how to use com.sun.org.apache.xml.internal.dtm.DTM#DOCUMENT_NODE . 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 File: SAXImpl.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the name of a node (attribute or element).
 */
public String getNodeName(final int node)
{
    // Get the node type and make sure that it is within limits
    int nodeh = node;
    final short type = getNodeType(nodeh);
    switch(type)
    {
        case DTM.ROOT_NODE:
        case DTM.DOCUMENT_NODE:
        case DTM.TEXT_NODE:
        case DTM.COMMENT_NODE:
            return EMPTYSTRING;
        case DTM.NAMESPACE_NODE:
            return this.getLocalName(nodeh);
        default:
            return super.getNodeName(nodeh);
    }
}
 
Example 2
Source File: SAXImpl.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the name of a node (attribute or element).
 */
public String getNodeName(final int node)
{
    // Get the node type and make sure that it is within limits
    int nodeh = node;
    final short type = getNodeType(nodeh);
    switch(type)
    {
        case DTM.ROOT_NODE:
        case DTM.DOCUMENT_NODE:
        case DTM.TEXT_NODE:
        case DTM.COMMENT_NODE:
            return EMPTYSTRING;
        case DTM.NAMESPACE_NODE:
            return this.getLocalName(nodeh);
        default:
            return super.getNodeName(nodeh);
    }
}
 
Example 3
Source File: SAXImpl.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns the name of a node (attribute or element).
 */
public String getNodeName(final int node)
{
    // Get the node type and make sure that it is within limits
    int nodeh = node;
    final short type = getNodeType(nodeh);
    switch(type)
    {
        case DTM.ROOT_NODE:
        case DTM.DOCUMENT_NODE:
        case DTM.TEXT_NODE:
        case DTM.COMMENT_NODE:
            return EMPTYSTRING;
        case DTM.NAMESPACE_NODE:
            return this.getLocalName(nodeh);
        default:
            return super.getNodeName(nodeh);
    }
}
 
Example 4
Source File: DTMNodeProxy.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 *
 * @param tagname
 *
 *
 * @see org.w3c.dom.Document
 */
@Override
public final NodeList getElementsByTagName(String tagname)
{
     Vector listVector = new Vector();
     Node retNode = dtm.getNode(node);
     if (retNode != null)
     {
       boolean isTagNameWildCard = "*".equals(tagname);
       if (DTM.ELEMENT_NODE == retNode.getNodeType())
       {
         NodeList nodeList = retNode.getChildNodes();
         for (int i = 0; i < nodeList.getLength(); i++)
         {
           traverseChildren(listVector, nodeList.item(i), tagname,
                            isTagNameWildCard);
         }
       } else if (DTM.DOCUMENT_NODE == retNode.getNodeType()) {
         traverseChildren(listVector, dtm.getNode(node), tagname,
                          isTagNameWildCard);
       }
     }
     int size = listVector.size();
     NodeSet nodeSet = new NodeSet(size);
     for (int i = 0; i < size; i++)
     {
       nodeSet.addNode((Node) listVector.elementAt(i));
     }
     return (NodeList) nodeSet;
}
 
Example 5
Source File: SAXImpl.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Prints the whole tree to standard output
 */
public void print(int node, int level)
{
    switch(getNodeType(node))
    {
        case DTM.ROOT_NODE:
        case DTM.DOCUMENT_NODE:
            print(getFirstChild(node), level);
            break;
        case DTM.TEXT_NODE:
        case DTM.COMMENT_NODE:
        case DTM.PROCESSING_INSTRUCTION_NODE:
            System.out.print(getStringValueX(node));
            break;
        default:
            final String name = getNodeName(node);
            System.out.print("<" + name);
            for (int a = getFirstAttribute(node); a != DTM.NULL; a = getNextAttribute(a))
            {
                System.out.print("\n" + getNodeName(a) + "=\"" + getStringValueX(a) + "\"");
            }
            System.out.print('>');
            for (int child = getFirstChild(node); child != DTM.NULL;
                child = getNextSibling(child)) {
                print(child, level + 1);
            }
            System.out.println("</" + name + '>');
            break;
    }
}
 
Example 6
Source File: DTMNodeProxy.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 *
 * @param tagname
 *
 *
 * @see org.w3c.dom.Document
 */
@Override
public final NodeList getElementsByTagName(String tagname)
{
     Vector listVector = new Vector();
     Node retNode = dtm.getNode(node);
     if (retNode != null)
     {
       boolean isTagNameWildCard = "*".equals(tagname);
       if (DTM.ELEMENT_NODE == retNode.getNodeType())
       {
         NodeList nodeList = retNode.getChildNodes();
         for (int i = 0; i < nodeList.getLength(); i++)
         {
           traverseChildren(listVector, nodeList.item(i), tagname,
                            isTagNameWildCard);
         }
       } else if (DTM.DOCUMENT_NODE == retNode.getNodeType()) {
         traverseChildren(listVector, dtm.getNode(node), tagname,
                          isTagNameWildCard);
       }
     }
     int size = listVector.size();
     NodeSet nodeSet = new NodeSet(size);
     for (int i = 0; i < size; i++)
     {
       nodeSet.addNode((Node) listVector.elementAt(i));
     }
     return (NodeList) nodeSet;
}
 
Example 7
Source File: DTMNodeProxy.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 *
 * @param tagname
 *
 *
 * @see org.w3c.dom.Document
 */
@Override
public final NodeList getElementsByTagName(String tagname)
{
     Vector listVector = new Vector();
     Node retNode = dtm.getNode(node);
     if (retNode != null)
     {
       boolean isTagNameWildCard = "*".equals(tagname);
       if (DTM.ELEMENT_NODE == retNode.getNodeType())
       {
         NodeList nodeList = retNode.getChildNodes();
         for (int i = 0; i < nodeList.getLength(); i++)
         {
           traverseChildren(listVector, nodeList.item(i), tagname,
                            isTagNameWildCard);
         }
       } else if (DTM.DOCUMENT_NODE == retNode.getNodeType()) {
         traverseChildren(listVector, dtm.getNode(node), tagname,
                          isTagNameWildCard);
       }
     }
     int size = listVector.size();
     NodeSet nodeSet = new NodeSet(size);
     for (int i = 0; i < size; i++)
     {
       nodeSet.addNode((Node) listVector.elementAt(i));
     }
     return (NodeList) nodeSet;
}
 
Example 8
Source File: DTMNodeProxy.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 *
 * @param tagname
 *
 *
 * @see org.w3c.dom.Document
 */
@Override
public final NodeList getElementsByTagName(String tagname)
{
     Vector listVector = new Vector();
     Node retNode = dtm.getNode(node);
     if (retNode != null)
     {
       boolean isTagNameWildCard = "*".equals(tagname);
       if (DTM.ELEMENT_NODE == retNode.getNodeType())
       {
         NodeList nodeList = retNode.getChildNodes();
         for (int i = 0; i < nodeList.getLength(); i++)
         {
           traverseChildren(listVector, nodeList.item(i), tagname,
                            isTagNameWildCard);
         }
       } else if (DTM.DOCUMENT_NODE == retNode.getNodeType()) {
         traverseChildren(listVector, dtm.getNode(node), tagname,
                          isTagNameWildCard);
       }
     }
     int size = listVector.size();
     NodeSet nodeSet = new NodeSet(size);
     for (int i = 0; i < size; i++)
     {
       nodeSet.addNode((Node) listVector.elementAt(i));
     }
     return (NodeList) nodeSet;
}
 
Example 9
Source File: DTMNodeProxy.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
/**
 *
 * @param namespaceURI
 * @param localName
 *
 *
 * @see org.w3c.dom.Document as of DOM Level 2
 */
@Override
public final NodeList getElementsByTagNameNS(String namespaceURI,
                                             String localName)
{
  Vector listVector = new Vector();
  Node retNode = dtm.getNode(node);
  if (retNode != null)
  {
    boolean isNamespaceURIWildCard = "*".equals(namespaceURI);
    boolean isLocalNameWildCard    = "*".equals(localName);
    if (DTM.ELEMENT_NODE == retNode.getNodeType())
    {
      NodeList nodeList = retNode.getChildNodes();
      for(int i = 0; i < nodeList.getLength(); i++)
      {
        traverseChildren(listVector, nodeList.item(i), namespaceURI, localName, isNamespaceURIWildCard, isLocalNameWildCard);
      }
    }
    else if(DTM.DOCUMENT_NODE == retNode.getNodeType())
    {
      traverseChildren(listVector, dtm.getNode(node), namespaceURI, localName, isNamespaceURIWildCard, isLocalNameWildCard);
    }
  }
  int size = listVector.size();
  NodeSet nodeSet = new NodeSet(size);
  for (int i = 0; i < size; i++)
  {
    nodeSet.addNode((Node)listVector.elementAt(i));
  }
  return (NodeList) nodeSet;
}
 
Example 10
Source File: DTMNodeProxy.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 *
 * @param namespaceURI
 * @param localName
 *
 *
 * @see org.w3c.dom.Document as of DOM Level 2
 */
@Override
public final NodeList getElementsByTagNameNS(String namespaceURI,
                                             String localName)
{
  Vector listVector = new Vector();
  Node retNode = dtm.getNode(node);
  if (retNode != null)
  {
    boolean isNamespaceURIWildCard = "*".equals(namespaceURI);
    boolean isLocalNameWildCard    = "*".equals(localName);
    if (DTM.ELEMENT_NODE == retNode.getNodeType())
    {
      NodeList nodeList = retNode.getChildNodes();
      for(int i = 0; i < nodeList.getLength(); i++)
      {
        traverseChildren(listVector, nodeList.item(i), namespaceURI, localName, isNamespaceURIWildCard, isLocalNameWildCard);
      }
    }
    else if(DTM.DOCUMENT_NODE == retNode.getNodeType())
    {
      traverseChildren(listVector, dtm.getNode(node), namespaceURI, localName, isNamespaceURIWildCard, isLocalNameWildCard);
    }
  }
  int size = listVector.size();
  NodeSet nodeSet = new NodeSet(size);
  for (int i = 0; i < size; i++)
  {
    nodeSet.addNode((Node)listVector.elementAt(i));
  }
  return (NodeList) nodeSet;
}
 
Example 11
Source File: NodeTest.java    From jdk1.8-source-analysis with Apache License 2.0 4 votes vote down vote up
/**
 * Tell what node type to test, if not DTMFilter.SHOW_ALL.
 *
 * @param whatToShow Bit set defined mainly by
 *        {@link com.sun.org.apache.xml.internal.dtm.DTMFilter}.
 * @return the node type for the whatToShow.  Since whatToShow can specify
 *         multiple types, it will return the first bit tested that is on,
 *         so the caller of this function should take care that this is
 *         the function they really want to call.  If none of the known bits
 *         are set, this function will return zero.
 */
public static int getNodeTypeTest(int whatToShow)
{
  // %REVIEW% Is there a better way?
  if (0 != (whatToShow & DTMFilter.SHOW_ELEMENT))
    return DTM.ELEMENT_NODE;

  if (0 != (whatToShow & DTMFilter.SHOW_ATTRIBUTE))
    return DTM.ATTRIBUTE_NODE;

  if (0 != (whatToShow & DTMFilter.SHOW_TEXT))
    return DTM.TEXT_NODE;

  if (0 != (whatToShow & DTMFilter.SHOW_DOCUMENT))
    return DTM.DOCUMENT_NODE;

  if (0 != (whatToShow & DTMFilter.SHOW_DOCUMENT_FRAGMENT))
    return DTM.DOCUMENT_FRAGMENT_NODE;

  if (0 != (whatToShow & DTMFilter.SHOW_NAMESPACE))
    return DTM.NAMESPACE_NODE;

  if (0 != (whatToShow & DTMFilter.SHOW_COMMENT))
    return DTM.COMMENT_NODE;

  if (0 != (whatToShow & DTMFilter.SHOW_PROCESSING_INSTRUCTION))
    return DTM.PROCESSING_INSTRUCTION_NODE;

  if (0 != (whatToShow & DTMFilter.SHOW_DOCUMENT_TYPE))
    return DTM.DOCUMENT_TYPE_NODE;

  if (0 != (whatToShow & DTMFilter.SHOW_ENTITY))
    return DTM.ENTITY_NODE;

  if (0 != (whatToShow & DTMFilter.SHOW_ENTITY_REFERENCE))
    return DTM.ENTITY_REFERENCE_NODE;

  if (0 != (whatToShow & DTMFilter.SHOW_NOTATION))
    return DTM.NOTATION_NODE;

  if (0 != (whatToShow & DTMFilter.SHOW_CDATA_SECTION))
    return DTM.CDATA_SECTION_NODE;


  return 0;
}
 
Example 12
Source File: SAXImpl.java    From JDKSourceCode1.8 with MIT License 4 votes vote down vote up
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 13
Source File: SAXImpl.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
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 14
Source File: SAXImpl.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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 15
Source File: SAXImpl.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
/**
 * 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 16
Source File: SAXImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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 17
Source File: DTMTreeWalker.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
/**
 * End processing of given node
 *
 *
 * @param node Node we just finished processing
 *
 * @throws org.xml.sax.SAXException
 */
protected void endNode(int node) throws org.xml.sax.SAXException
{

  switch (m_dtm.getNodeType(node))
  {
  case DTM.DOCUMENT_NODE :
    this.m_contentHandler.endDocument();
    break;
  case DTM.ELEMENT_NODE :
    String ns = m_dtm.getNamespaceURI(node);
    if(null == ns)
      ns = "";
    this.m_contentHandler.endElement(ns,
                                       m_dtm.getLocalName(node),
                                       m_dtm.getNodeName(node));

    for (int nsn = m_dtm.getFirstNamespaceNode(node, true); DTM.NULL != nsn;
         nsn = m_dtm.getNextNamespaceNode(node, nsn, true))
    {
      // String prefix = m_dtm.getPrefix(nsn);
      String prefix = m_dtm.getNodeNameX(nsn);

      this.m_contentHandler.endPrefixMapping(prefix);
    }
    break;
  case DTM.CDATA_SECTION_NODE :
    break;
  case DTM.ENTITY_REFERENCE_NODE :
  {
    if (m_contentHandler instanceof LexicalHandler)
    {
      LexicalHandler lh = ((LexicalHandler) this.m_contentHandler);

      lh.endEntity(m_dtm.getNodeName(node));
    }
  }
  break;
  default :
  }
}
 
Example 18
Source File: SAXImpl.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
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 19
Source File: DTMTreeWalker.java    From jdk1.8-source-analysis with Apache License 2.0 4 votes vote down vote up
/**
 * End processing of given node
 *
 *
 * @param node Node we just finished processing
 *
 * @throws org.xml.sax.SAXException
 */
protected void endNode(int node) throws org.xml.sax.SAXException
{

  switch (m_dtm.getNodeType(node))
  {
  case DTM.DOCUMENT_NODE :
    this.m_contentHandler.endDocument();
    break;
  case DTM.ELEMENT_NODE :
    String ns = m_dtm.getNamespaceURI(node);
    if(null == ns)
      ns = "";
    this.m_contentHandler.endElement(ns,
                                       m_dtm.getLocalName(node),
                                       m_dtm.getNodeName(node));

    for (int nsn = m_dtm.getFirstNamespaceNode(node, true); DTM.NULL != nsn;
         nsn = m_dtm.getNextNamespaceNode(node, nsn, true))
    {
      // String prefix = m_dtm.getPrefix(nsn);
      String prefix = m_dtm.getNodeNameX(nsn);

      this.m_contentHandler.endPrefixMapping(prefix);
    }
    break;
  case DTM.CDATA_SECTION_NODE :
    break;
  case DTM.ENTITY_REFERENCE_NODE :
  {
    if (m_contentHandler instanceof LexicalHandler)
    {
      LexicalHandler lh = ((LexicalHandler) this.m_contentHandler);

      lh.endEntity(m_dtm.getNodeName(node));
    }
  }
  break;
  default :
  }
}
 
Example 20
Source File: SAXImpl.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
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);
    }

}