Java Code Examples for com.sun.org.apache.xpath.internal.NodeSet#addNode()

The following examples show how to use com.sun.org.apache.xpath.internal.NodeSet#addNode() . 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: Extensions.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
/**
 * Returns a NodeSet containing one text node for each token in the first argument.
 * Delimiters are specified in the second argument.
 * Tokens are determined by a call to <code>StringTokenizer</code>.
 * If the first argument is an empty string or contains only delimiters, the result
 * will be an empty NodeSet.
 *
 * Contributed to XalanJ1 by <a href="mailto:[email protected]">Benoit Cerrina</a>.
 *
 * @param toTokenize The string to be split into text tokens.
 * @param delims The delimiters to use.
 * @return a NodeSet as described above.
 */
public static NodeList tokenize(String toTokenize, String delims)
{

  Document doc = JdkXmlUtils.getDOMDocument();

  StringTokenizer lTokenizer = new StringTokenizer(toTokenize, delims);
  NodeSet resultSet = new NodeSet();

  synchronized (doc)
  {
    while (lTokenizer.hasMoreTokens())
    {
      resultSet.addNode(doc.createTextNode(lTokenizer.nextToken()));
    }
  }

  return resultSet;
}
 
Example 2
Source File: Extensions.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns a NodeSet containing one text node for each token in the first argument.
 * Delimiters are specified in the second argument.
 * Tokens are determined by a call to <code>StringTokenizer</code>.
 * If the first argument is an empty string or contains only delimiters, the result
 * will be an empty NodeSet.
 *
 * Contributed to XalanJ1 by <a href="mailto:[email protected]">Benoit Cerrina</a>.
 *
 * @param toTokenize The string to be split into text tokens.
 * @param delims The delimiters to use.
 * @return a NodeSet as described above.
 */
public static NodeList tokenize(String toTokenize, String delims)
{

  Document doc = JdkXmlUtils.getDOMDocument();

  StringTokenizer lTokenizer = new StringTokenizer(toTokenize, delims);
  NodeSet resultSet = new NodeSet();

  synchronized (doc)
  {
    while (lTokenizer.hasMoreTokens())
    {
      resultSet.addNode(doc.createTextNode(lTokenizer.nextToken()));
    }
  }

  return resultSet;
}
 
Example 3
Source File: Extensions.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
/**
 * Returns a NodeSet containing one text node for each token in the first argument.
 * Delimiters are specified in the second argument.
 * Tokens are determined by a call to <code>StringTokenizer</code>.
 * If the first argument is an empty string or contains only delimiters, the result
 * will be an empty NodeSet.
 *
 * Contributed to XalanJ1 by <a href="mailto:[email protected]">Benoit Cerrina</a>.
 *
 * @param toTokenize The string to be split into text tokens.
 * @param delims The delimiters to use.
 * @return a NodeSet as described above.
 */
public static NodeList tokenize(String toTokenize, String delims)
{

  Document doc = JdkXmlUtils.getDOMDocument();

  StringTokenizer lTokenizer = new StringTokenizer(toTokenize, delims);
  NodeSet resultSet = new NodeSet();

  synchronized (doc)
  {
    while (lTokenizer.hasMoreTokens())
    {
      resultSet.addNode(doc.createTextNode(lTokenizer.nextToken()));
    }
  }

  return resultSet;
}
 
Example 4
Source File: Extensions.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns a NodeSet containing one text node for each token in the first argument.
 * Delimiters are specified in the second argument.
 * Tokens are determined by a call to <code>StringTokenizer</code>.
 * If the first argument is an empty string or contains only delimiters, the result
 * will be an empty NodeSet.
 *
 * Contributed to XalanJ1 by <a href="mailto:[email protected]">Benoit Cerrina</a>.
 *
 * @param toTokenize The string to be split into text tokens.
 * @param delims The delimiters to use.
 * @return a NodeSet as described above.
 */
public static NodeList tokenize(String toTokenize, String delims)
{

  Document doc = getDocument();

  StringTokenizer lTokenizer = new StringTokenizer(toTokenize, delims);
  NodeSet resultSet = new NodeSet();

  synchronized (doc)
  {
    while (lTokenizer.hasMoreTokens())
    {
      resultSet.addNode(doc.createTextNode(lTokenizer.nextToken()));
    }
  }

  return resultSet;
}
 
Example 5
Source File: ExsltStrings.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * The str:split function splits up a string and returns a node set of token
 * elements, each containing one token from the string.
 * <p>
 * The first argument is the string to be split. The second argument is a pattern
 * string. The string given by the first argument is split at any occurrence of
 * this pattern. For example:
 * <pre>
 * str:split('a, simple, list', ', ') gives the node set consisting of:
 *
 * <token>a</token>
 * <token>simple</token>
 * <token>list</token>
 * </pre>
 * If the second argument is omitted, the default is the string '&#x20;' (i.e. a space).
 *
 * @param str The string to be split
 * @param pattern The pattern
 *
 * @return A node set of split tokens
 */
public static NodeList split(String str, String pattern)
{


  NodeSet resultSet = new NodeSet();
  resultSet.setShouldCacheNodes(true);

  boolean done = false;
  int fromIndex = 0;
  int matchIndex = 0;
  String token = null;

  while (!done && fromIndex < str.length())
  {
    matchIndex = str.indexOf(pattern, fromIndex);
    if (matchIndex >= 0)
    {
      token = str.substring(fromIndex, matchIndex);
      fromIndex = matchIndex + pattern.length();
    }
    else
    {
      done = true;
      token = str.substring(fromIndex);
    }

    Document doc = JdkXmlUtils.getDOMDocument();
    synchronized (doc)
    {
      Element element = doc.createElement("token");
      Text text = doc.createTextNode(token);
      element.appendChild(text);
      resultSet.addNode(element);
    }
  }

  return resultSet;
}
 
Example 6
Source File: DTMNodeProxy.java    From openjdk-jdk8u 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 7
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 8
Source File: DTMNodeProxy.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 *
 * @param tagname
 *
 *
 * @see org.w3c.dom.Document
 */
@Override
public final NodeList getElementsByTagName(String tagname)
{
     List<Node> listVector = new ArrayList<>();
     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(listVector.get(i));
     }
     return (NodeList) nodeSet;
}
 
Example 9
Source File: DTMNodeProxy.java    From JDKSourceCode1.8 with MIT License 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 JDKSourceCode1.8 with MIT License 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 11
Source File: ExsltStrings.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
/**
 * The str:split function splits up a string and returns a node set of token
 * elements, each containing one token from the string.
 * <p>
 * The first argument is the string to be split. The second argument is a pattern
 * string. The string given by the first argument is split at any occurrence of
 * this pattern. For example:
 * <pre>
 * str:split('a, simple, list', ', ') gives the node set consisting of:
 *
 * <token>a</token>
 * <token>simple</token>
 * <token>list</token>
 * </pre>
 * If the second argument is omitted, the default is the string '&#x20;' (i.e. a space).
 *
 * @param str The string to be split
 * @param pattern The pattern
 *
 * @return A node set of split tokens
 */
public static NodeList split(String str, String pattern)
{


  NodeSet resultSet = new NodeSet();
  resultSet.setShouldCacheNodes(true);

  boolean done = false;
  int fromIndex = 0;
  int matchIndex = 0;
  String token = null;

  while (!done && fromIndex < str.length())
  {
    matchIndex = str.indexOf(pattern, fromIndex);
    if (matchIndex >= 0)
    {
      token = str.substring(fromIndex, matchIndex);
      fromIndex = matchIndex + pattern.length();
    }
    else
    {
      done = true;
      token = str.substring(fromIndex);
    }

    Document doc = JdkXmlUtils.getDOMDocument();
    synchronized (doc)
    {
      Element element = doc.createElement("token");
      Text text = doc.createTextNode(token);
      element.appendChild(text);
      resultSet.addNode(element);
    }
  }

  return resultSet;
}
 
Example 12
Source File: DTMNodeProxy.java    From jdk8u60 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 13
Source File: ExsltStrings.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * The str:split function splits up a string and returns a node set of token
 * elements, each containing one token from the string.
 * <p>
 * The first argument is the string to be split. The second argument is a pattern
 * string. The string given by the first argument is split at any occurrence of
 * this pattern. For example:
 * <pre>
 * str:split('a, simple, list', ', ') gives the node set consisting of:
 *
 * <token>a</token>
 * <token>simple</token>
 * <token>list</token>
 * </pre>
 * If the second argument is omitted, the default is the string '&#x20;' (i.e. a space).
 *
 * @param str The string to be split
 * @param pattern The pattern
 *
 * @return A node set of split tokens
 */
public static NodeList split(String str, String pattern)
{


  NodeSet resultSet = new NodeSet();
  resultSet.setShouldCacheNodes(true);

  boolean done = false;
  int fromIndex = 0;
  int matchIndex = 0;
  String token = null;

  while (!done && fromIndex < str.length())
  {
    matchIndex = str.indexOf(pattern, fromIndex);
    if (matchIndex >= 0)
    {
      token = str.substring(fromIndex, matchIndex);
      fromIndex = matchIndex + pattern.length();
    }
    else
    {
      done = true;
      token = str.substring(fromIndex);
    }

    Document doc = getDocument();
    synchronized (doc)
    {
      Element element = doc.createElement("token");
      Text text = doc.createTextNode(token);
      element.appendChild(text);
      resultSet.addNode(element);
    }
  }

  return resultSet;
}
 
Example 14
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 15
Source File: DTMNodeProxy.java    From TencentKona-8 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 16
Source File: DTMNodeProxy.java    From TencentKona-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 17
Source File: ExsltStrings.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * The str:split function splits up a string and returns a node set of token
 * elements, each containing one token from the string.
 * <p>
 * The first argument is the string to be split. The second argument is a pattern
 * string. The string given by the first argument is split at any occurrence of
 * this pattern. For example:
 * <pre>
 * str:split('a, simple, list', ', ') gives the node set consisting of:
 *
 * <token>a</token>
 * <token>simple</token>
 * <token>list</token>
 * </pre>
 * If the second argument is omitted, the default is the string '&#x20;' (i.e. a space).
 *
 * @param str The string to be split
 * @param pattern The pattern
 *
 * @return A node set of split tokens
 */
public static NodeList split(String str, String pattern)
{


  NodeSet resultSet = new NodeSet();
  resultSet.setShouldCacheNodes(true);

  boolean done = false;
  int fromIndex = 0;
  int matchIndex = 0;
  String token = null;

  while (!done && fromIndex < str.length())
  {
    matchIndex = str.indexOf(pattern, fromIndex);
    if (matchIndex >= 0)
    {
      token = str.substring(fromIndex, matchIndex);
      fromIndex = matchIndex + pattern.length();
    }
    else
    {
      done = true;
      token = str.substring(fromIndex);
    }

    Document doc = JdkXmlUtils.getDOMDocument();
    synchronized (doc)
    {
      Element element = doc.createElement("token");
      Text text = doc.createTextNode(token);
      element.appendChild(text);
      resultSet.addNode(element);
    }
  }

  return resultSet;
}
 
Example 18
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 19
Source File: DTMNodeProxy.java    From jdk1.8-source-analysis with Apache License 2.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 20
Source File: ExsltStrings.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
/**
 * The str:split function splits up a string and returns a node set of token
 * elements, each containing one token from the string.
 * <p>
 * The first argument is the string to be split. The second argument is a pattern
 * string. The string given by the first argument is split at any occurrence of
 * this pattern. For example:
 * <pre>
 * str:split('a, simple, list', ', ') gives the node set consisting of:
 *
 * <token>a</token>
 * <token>simple</token>
 * <token>list</token>
 * </pre>
 * If the second argument is omitted, the default is the string '&#x20;' (i.e. a space).
 *
 * @param str The string to be split
 * @param pattern The pattern
 *
 * @return A node set of split tokens
 */
public static NodeList split(String str, String pattern)
{


  NodeSet resultSet = new NodeSet();
  resultSet.setShouldCacheNodes(true);

  boolean done = false;
  int fromIndex = 0;
  int matchIndex = 0;
  String token = null;

  while (!done && fromIndex < str.length())
  {
    matchIndex = str.indexOf(pattern, fromIndex);
    if (matchIndex >= 0)
    {
      token = str.substring(fromIndex, matchIndex);
      fromIndex = matchIndex + pattern.length();
    }
    else
    {
      done = true;
      token = str.substring(fromIndex);
    }

    Document doc = getDocument();
    synchronized (doc)
    {
      Element element = doc.createElement("token");
      Text text = doc.createTextNode(token);
      element.appendChild(text);
      resultSet.addNode(element);
    }
  }

  return resultSet;
}