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

The following examples show how to use com.sun.org.apache.xml.internal.dtm.DTM#ELEMENT_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: SAX2DTM2.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Get the next node in the iteration.
 *
 * @return The next node handle in the iteration, or END.
 */
public int next() {
  if (_currentNode == DTM.NULL) {
    return DTM.NULL;
  }

  int node = _currentNode;
  final int nodeType = _nodeType;

  if (nodeType != DTM.ELEMENT_NODE) {
    while ((node = _nextsib2(node)) != DTM.NULL && _exptype2(node) != nodeType) {}
  } else {
    while ((node = _nextsib2(node)) != DTM.NULL && _exptype2(node) < DTM.NTYPES) {}
  }

  _currentNode = node;

  return (node == DTM.NULL)
                  ? DTM.NULL
                  : returnNode(makeNodeHandle(node));
}
 
Example 2
Source File: SAX2DTM2.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Get the next node in the iteration.
 *
 * @return The next node handle in the iteration, or END.
 */
public int next() {
  int node = _currentNode;
  if (node == DTM.NULL)
    return DTM.NULL;

  final int nodeType = _nodeType;

  if (nodeType != DTM.ELEMENT_NODE) {
    while (node != DTM.NULL && _exptype2(node) != nodeType) {
      node = _nextsib2(node);
    }
  }
  // %OPT% If the nodeType is element (matching child::*), we only
  // need to compare the expType with DTM.NTYPES. A child node of
  // an element can be either an element, text, comment or
  // processing instruction node. Only element node has an extended
  // type greater than or equal to DTM.NTYPES.
  else {
    int eType;
    while (node != DTM.NULL) {
      eType = _exptype2(node);
      if (eType >= DTM.NTYPES)
        break;
      else
        node = _nextsib2(node);
    }
  }

  if (node == DTM.NULL) {
    _currentNode = DTM.NULL;
    return DTM.NULL;
  } else {
    _currentNode = _nextsib2(node);
    return returnNode(makeNodeHandle(node));
  }
}
 
Example 3
Source File: SAX2DTM2.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * The optimized version of DTMDefaultBase.getFirstAttribute().
 * <p>
 * Given a node handle, get the index of the node's first attribute.
 *
 * @param nodeHandle int Handle of the node.
 * @return Handle of first attribute, or DTM.NULL to indicate none exists.
 */
public final int getFirstAttribute(int nodeHandle)
{
  int nodeID = makeNodeIdentity(nodeHandle);

  if (nodeID == DTM.NULL)
    return DTM.NULL;

  int type = _type2(nodeID);

  if (DTM.ELEMENT_NODE == type)
  {
    // Assume that attributes and namespaces immediately follow the element.
    while (true)
    {
      nodeID++;
      // Assume this can not be null.
      type = _type2(nodeID);

      if (type == DTM.ATTRIBUTE_NODE)
      {
        return makeNodeHandle(nodeID);
      }
      else if (DTM.NAMESPACE_NODE != type)
      {
        break;
      }
    }
  }

  return DTM.NULL;
}
 
Example 4
Source File: FuncNamespace.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Execute the function.  The function must return
 * a valid object.
 * @param xctxt The current execution context.
 * @return A valid XObject.
 *
 * @throws javax.xml.transform.TransformerException
 */
public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
{

  int context = getArg0AsNode(xctxt);

  String s;
  if(context != DTM.NULL)
  {
    DTM dtm = xctxt.getDTM(context);
    int t = dtm.getNodeType(context);
    if(t == DTM.ELEMENT_NODE)
    {
      s = dtm.getNamespaceURI(context);
    }
    else if(t == DTM.ATTRIBUTE_NODE)
    {

      // This function always returns an empty string for namespace nodes.
      // We check for those here.  Fix inspired by Davanum Srinivas.

      s = dtm.getNodeName(context);
      if(s.startsWith("xmlns:") || s.equals("xmlns"))
        return XString.EMPTYSTRING;

      s = dtm.getNamespaceURI(context);
    }
    else
      return XString.EMPTYSTRING;
  }
  else
    return XString.EMPTYSTRING;

  return ((null == s) ? XString.EMPTYSTRING : new XString(s));
}
 
Example 5
Source File: SAXImpl.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the internal type associated with an expanded QName
 */
public int getGeneralizedType(final String name, boolean searchOnly) {
    String lName, ns = null;
    int index = -1;
    int code;

    // Is there a prefix?
    if ((index = name.lastIndexOf(":"))> -1) {
        ns = name.substring(0, index);
    }

    // Local part of name is after colon.  lastIndexOf returns -1 if
    // there is no colon, so lNameStartIdx will be zero in that case.
    int lNameStartIdx = index+1;

    // Distinguish attribute and element names.  Attribute has @ before
    // local part of name.
    if (name.charAt(lNameStartIdx) == '@') {
        code = DTM.ATTRIBUTE_NODE;
        lNameStartIdx++;
    }
    else {
        code = DTM.ELEMENT_NODE;
    }

    // Extract local name
    lName = (lNameStartIdx == 0) ? name : name.substring(lNameStartIdx);

    return m_expandedNameTable.getExpandedTypeID(ns, lName, code, searchOnly);
}
 
Example 6
Source File: FuncNamespace.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
/**
 * Execute the function.  The function must return
 * a valid object.
 * @param xctxt The current execution context.
 * @return A valid XObject.
 *
 * @throws javax.xml.transform.TransformerException
 */
public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
{

  int context = getArg0AsNode(xctxt);

  String s;
  if(context != DTM.NULL)
  {
    DTM dtm = xctxt.getDTM(context);
    int t = dtm.getNodeType(context);
    if(t == DTM.ELEMENT_NODE)
    {
      s = dtm.getNamespaceURI(context);
    }
    else if(t == DTM.ATTRIBUTE_NODE)
    {

      // This function always returns an empty string for namespace nodes.
      // We check for those here.  Fix inspired by Davanum Srinivas.

      s = dtm.getNodeName(context);
      if(s.startsWith("xmlns:") || s.equals("xmlns"))
        return XString.EMPTYSTRING;

      s = dtm.getNamespaceURI(context);
    }
    else
      return XString.EMPTYSTRING;
  }
  else
    return XString.EMPTYSTRING;

  return ((null == s) ? XString.EMPTYSTRING : new XString(s));
}
 
Example 7
Source File: SAX2DTM2.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * Return the node at the given position.
 */
public int getNodeByPosition(int position) {
  if (position <= 0)
    return DTM.NULL;

  int node = _currentNode;
  int pos = 0;

  final int nodeType = _nodeType;
  if (nodeType != DTM.ELEMENT_NODE) {
    while (node != DTM.NULL) {
      if (_exptype2(node) == nodeType) {
        pos++;
        if (pos == position)
          return makeNodeHandle(node);
      }

      node = _nextsib2(node);
    }
    return NULL;
  } else {
    while (node != DTM.NULL) {
      if (_exptype2(node) >= DTM.NTYPES) {
        pos++;
        if (pos == position)
          return makeNodeHandle(node);
      }
      node = _nextsib2(node);
    }
    return NULL;
  }
}
 
Example 8
Source File: DTMNodeProxy.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
/**
 *
 * @param listVector
 * @param tempNode
 * @param namespaceURI
 * @param localname
 * @param isNamespaceURIWildCard
 * @param isLocalNameWildCard
 *
 * Private method to be used for recursive iterations to obtain elements by tag name
 * and namespaceURI.
 */
private final void traverseChildren
(
 Vector listVector,
 Node tempNode,
 String namespaceURI,
 String localname,
 boolean isNamespaceURIWildCard,
 boolean isLocalNameWildCard)
 {
  if (tempNode == null)
  {
    return;
  }
  else
  {
    if (tempNode.getNodeType() == DTM.ELEMENT_NODE
            && (isLocalNameWildCard
                    || tempNode.getLocalName().equals(localname)))
    {
      String nsURI = tempNode.getNamespaceURI();
      if ((namespaceURI == null && nsURI == null)
             || isNamespaceURIWildCard
             || (namespaceURI != null && namespaceURI.equals(nsURI)))
      {
        listVector.add(tempNode);
      }
    }
    if(tempNode.hasChildNodes())
    {
      NodeList nl = tempNode.getChildNodes();
      for(int i = 0; i < nl.getLength(); i++)
      {
        traverseChildren(listVector, nl.item(i), namespaceURI, localname,
                         isNamespaceURIWildCard, isLocalNameWildCard);
      }
    }
  }
}
 
Example 9
Source File: DTMNodeProxy.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 *
 * @param listVector
 * @param tempNode
 * @param tagname
 * @param isTagNameWildCard
 *
 *
 * Private method to be used for recursive iterations to obtain elements by tag name.
 */
private final void traverseChildren
(
  Vector listVector,
  Node tempNode,
  String tagname,
  boolean isTagNameWildCard) {
  if (tempNode == null)
  {
    return;
  }
  else
  {
    if (tempNode.getNodeType() == DTM.ELEMENT_NODE
          && (isTagNameWildCard || tempNode.getNodeName().equals(tagname)))
    {
      listVector.add(tempNode);
    }
    if(tempNode.hasChildNodes())
    {
      NodeList nodeList = tempNode.getChildNodes();
      for (int i = 0; i < nodeList.getLength(); i++)
      {
        traverseChildren(listVector, nodeList.item(i), tagname,
                         isTagNameWildCard);
      }
    }
  }
}
 
Example 10
Source File: DTMNodeProxy.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 *
 * @param listVector
 * @param tempNode
 * @param namespaceURI
 * @param localname
 * @param isNamespaceURIWildCard
 * @param isLocalNameWildCard
 *
 * Private method to be used for recursive iterations to obtain elements by tag name
 * and namespaceURI.
 */
private final void traverseChildren(List<Node> listVector, Node tempNode,
        String namespaceURI, String localname, boolean isNamespaceURIWildCard,
        boolean isLocalNameWildCard)
 {
  if (tempNode == null)
  {
    return;
  }
  else
  {
    if (tempNode.getNodeType() == DTM.ELEMENT_NODE
            && (isLocalNameWildCard
                    || tempNode.getLocalName().equals(localname)))
    {
      String nsURI = tempNode.getNamespaceURI();
      if ((namespaceURI == null && nsURI == null)
             || isNamespaceURIWildCard
             || (namespaceURI != null && namespaceURI.equals(nsURI)))
      {
        listVector.add(tempNode);
      }
    }
    if(tempNode.hasChildNodes())
    {
      NodeList nl = tempNode.getChildNodes();
      for(int i = 0; i < nl.getLength(); i++)
      {
        traverseChildren(listVector, nl.item(i), namespaceURI, localname,
                         isNamespaceURIWildCard, isLocalNameWildCard);
      }
    }
  }
}
 
Example 11
Source File: DTMNodeProxy.java    From openjdk-8 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 12
Source File: FuncLang.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Execute the function.  The function must return
 * a valid object.
 * @param xctxt The current execution context.
 * @return A valid XObject.
 *
 * @throws javax.xml.transform.TransformerException
 */
public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
{

  String lang = m_arg0.execute(xctxt).str();
  int parent = xctxt.getCurrentNode();
  boolean isLang = false;
  DTM dtm = xctxt.getDTM(parent);

  while (DTM.NULL != parent)
  {
    if (DTM.ELEMENT_NODE == dtm.getNodeType(parent))
    {
      int langAttr = dtm.getAttributeNode(parent, "http://www.w3.org/XML/1998/namespace", "lang");

      if (DTM.NULL != langAttr)
      {
        String langVal = dtm.getNodeValue(langAttr);
        // %OPT%
        if (langVal.toLowerCase().startsWith(lang.toLowerCase()))
        {
          int valLen = lang.length();

          if ((langVal.length() == valLen)
                  || (langVal.charAt(valLen) == '-'))
          {
            isLang = true;
          }
        }

        break;
      }
    }

    parent = dtm.getParent(parent);
  }

  return isLang ? XBoolean.S_TRUE : XBoolean.S_FALSE;
}
 
Example 13
Source File: FuncNamespace.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Execute the function.  The function must return
 * a valid object.
 * @param xctxt The current execution context.
 * @return A valid XObject.
 *
 * @throws javax.xml.transform.TransformerException
 */
public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
{

  int context = getArg0AsNode(xctxt);

  String s;
  if(context != DTM.NULL)
  {
    DTM dtm = xctxt.getDTM(context);
    int t = dtm.getNodeType(context);
    if(t == DTM.ELEMENT_NODE)
    {
      s = dtm.getNamespaceURI(context);
    }
    else if(t == DTM.ATTRIBUTE_NODE)
    {

      // This function always returns an empty string for namespace nodes.
      // We check for those here.  Fix inspired by Davanum Srinivas.

      s = dtm.getNodeName(context);
      if(s.startsWith("xmlns:") || s.equals("xmlns"))
        return XString.EMPTYSTRING;

      s = dtm.getNamespaceURI(context);
    }
    else
      return XString.EMPTYSTRING;
  }
  else
    return XString.EMPTYSTRING;

  return ((null == s) ? XString.EMPTYSTRING : new XString(s));
}
 
Example 14
Source File: FuncNamespace.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * Execute the function.  The function must return
 * a valid object.
 * @param xctxt The current execution context.
 * @return A valid XObject.
 *
 * @throws javax.xml.transform.TransformerException
 */
public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
{

  int context = getArg0AsNode(xctxt);

  String s;
  if(context != DTM.NULL)
  {
    DTM dtm = xctxt.getDTM(context);
    int t = dtm.getNodeType(context);
    if(t == DTM.ELEMENT_NODE)
    {
      s = dtm.getNamespaceURI(context);
    }
    else if(t == DTM.ATTRIBUTE_NODE)
    {

      // This function always returns an empty string for namespace nodes.
      // We check for those here.  Fix inspired by Davanum Srinivas.

      s = dtm.getNodeName(context);
      if(s.startsWith("xmlns:") || s.equals("xmlns"))
        return XString.EMPTYSTRING;

      s = dtm.getNamespaceURI(context);
    }
    else
      return XString.EMPTYSTRING;
  }
  else
    return XString.EMPTYSTRING;

  return ((null == s) ? XString.EMPTYSTRING : new XString(s));
}
 
Example 15
Source File: NodeTest.java    From openjdk-jdk8u with GNU General Public License v2.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 16
Source File: SAXImpl.java    From hottub 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 17
Source File: SAXImpl.java    From openjdk-8 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 18
Source File: NodeTest.java    From jdk8u60 with GNU General Public License v2.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 19
Source File: SAXImpl.java    From JDKSourceCode1.8 with MIT License 4 votes vote down vote up
/**
 * Returns 'true' if a specific node is an element (of any type)
 */
public boolean isElement(final int node) {
    return getNodeType(node) == DTM.ELEMENT_NODE;
}
 
Example 20
Source File: SAXImpl.java    From jdk8u60 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);
    }

}