Java Code Examples for jdk.xml.internal.JdkXmlUtils#getDOMDocument()

The following examples show how to use jdk.xml.internal.JdkXmlUtils#getDOMDocument() . 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 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 2
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 3
Source File: Extensions.java    From openjdk-jdk8u 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 4
Source File: Extensions.java    From openjdk-jdk8u-backup 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 5
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 6
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 7
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 8
Source File: ExsltStrings.java    From openjdk-jdk8u 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 9
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 10
Source File: ExsltStrings.java    From Bytecoder 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 = JdkXmlUtils.getDOMDocument();
    synchronized (doc)
    {
      Element element = doc.createElement("token");
      Text text = doc.createTextNode(token);
      element.appendChild(text);
      resultSet.addNode(element);
    }
  }

  return resultSet;
}
 
Example 11
Source File: Extensions.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * This method is an extension that implements as a Xalan extension
 * the node-set function also found in xt and saxon.
 * If the argument is a Result Tree Fragment, then <code>nodeset</code>
 * returns a node-set consisting of a single root node as described in
 * section 11.1 of the XSLT 1.0 Recommendation.  If the argument is a
 * node-set, <code>nodeset</code> returns a node-set.  If the argument
 * is a string, number, or boolean, then <code>nodeset</code> returns
 * a node-set consisting of a single root node with a single text node
 * child that is the result of calling the XPath string() function on the
 * passed parameter.  If the argument is anything else, then a node-set
 * is returned consisting of a single root node with a single text node
 * child that is the result of calling the java <code>toString()</code>
 * method on the passed argument.
 * Most of the
 * actual work here is done in <code>MethodResolver</code> and
 * <code>XRTreeFrag</code>.
 * @param myProcessor Context passed by the extension processor
 * @param rtf Argument in the stylesheet to the nodeset extension function
 *
 * NEEDSDOC ($objectName$) @return
 */
public static NodeSet nodeset(ExpressionContext myProcessor, Object rtf)
{

  String textNodeValue;

  if (rtf instanceof NodeIterator)
  {
    return new NodeSet((NodeIterator) rtf);
  }
  else
  {
    if (rtf instanceof String)
    {
      textNodeValue = (String) rtf;
    }
    else if (rtf instanceof Boolean)
    {
      textNodeValue = new XBoolean(((Boolean) rtf).booleanValue()).str();
    }
    else if (rtf instanceof Double)
    {
      textNodeValue = new XNumber(((Double) rtf).doubleValue()).str();
    }
    else
    {
      textNodeValue = rtf.toString();
    }

    // This no longer will work right since the DTM.
    // Document myDoc = myProcessor.getContextNode().getOwnerDocument();
      Document myDoc = JdkXmlUtils.getDOMDocument();

      Text textNode = myDoc.createTextNode(textNodeValue);
      DocumentFragment docFrag = myDoc.createDocumentFragment();

      docFrag.appendChild(textNode);

      return new NodeSet(docFrag);
  }
}
 
Example 12
Source File: Extensions.java    From JDKSourceCode1.8 with MIT License 4 votes vote down vote up
/**
 * This method is an extension that implements as a Xalan extension
 * the node-set function also found in xt and saxon.
 * If the argument is a Result Tree Fragment, then <code>nodeset</code>
 * returns a node-set consisting of a single root node as described in
 * section 11.1 of the XSLT 1.0 Recommendation.  If the argument is a
 * node-set, <code>nodeset</code> returns a node-set.  If the argument
 * is a string, number, or boolean, then <code>nodeset</code> returns
 * a node-set consisting of a single root node with a single text node
 * child that is the result of calling the XPath string() function on the
 * passed parameter.  If the argument is anything else, then a node-set
 * is returned consisting of a single root node with a single text node
 * child that is the result of calling the java <code>toString()</code>
 * method on the passed argument.
 * Most of the
 * actual work here is done in <code>MethodResolver</code> and
 * <code>XRTreeFrag</code>.
 * @param myProcessor Context passed by the extension processor
 * @param rtf Argument in the stylesheet to the nodeset extension function
 *
 * NEEDSDOC ($objectName$) @return
 */
public static NodeSet nodeset(ExpressionContext myProcessor, Object rtf)
{

  String textNodeValue;

  if (rtf instanceof NodeIterator)
  {
    return new NodeSet((NodeIterator) rtf);
  }
  else
  {
    if (rtf instanceof String)
    {
      textNodeValue = (String) rtf;
    }
    else if (rtf instanceof Boolean)
    {
      textNodeValue = new XBoolean(((Boolean) rtf).booleanValue()).str();
    }
    else if (rtf instanceof Double)
    {
      textNodeValue = new XNumber(((Double) rtf).doubleValue()).str();
    }
    else
    {
      textNodeValue = rtf.toString();
    }

    // This no longer will work right since the DTM.
    // Document myDoc = myProcessor.getContextNode().getOwnerDocument();
      Document myDoc = JdkXmlUtils.getDOMDocument();

      Text textNode = myDoc.createTextNode(textNodeValue);
      DocumentFragment docFrag = myDoc.createDocumentFragment();

      docFrag.appendChild(textNode);

      return new NodeSet(docFrag);
  }
}
 
Example 13
Source File: Extensions.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
 * This method is an extension that implements as a Xalan extension
 * the node-set function also found in xt and saxon.
 * If the argument is a Result Tree Fragment, then <code>nodeset</code>
 * returns a node-set consisting of a single root node as described in
 * section 11.1 of the XSLT 1.0 Recommendation.  If the argument is a
 * node-set, <code>nodeset</code> returns a node-set.  If the argument
 * is a string, number, or boolean, then <code>nodeset</code> returns
 * a node-set consisting of a single root node with a single text node
 * child that is the result of calling the XPath string() function on the
 * passed parameter.  If the argument is anything else, then a node-set
 * is returned consisting of a single root node with a single text node
 * child that is the result of calling the java <code>toString()</code>
 * method on the passed argument.
 * Most of the
 * actual work here is done in <code>MethodResolver</code> and
 * <code>XRTreeFrag</code>.
 * @param myProcessor Context passed by the extension processor
 * @param rtf Argument in the stylesheet to the nodeset extension function
 *
 * NEEDSDOC ($objectName$) @return
 */
public static NodeSet nodeset(ExpressionContext myProcessor, Object rtf)
{

  String textNodeValue;

  if (rtf instanceof NodeIterator)
  {
    return new NodeSet((NodeIterator) rtf);
  }
  else
  {
    if (rtf instanceof String)
    {
      textNodeValue = (String) rtf;
    }
    else if (rtf instanceof Boolean)
    {
      textNodeValue = new XBoolean(((Boolean) rtf).booleanValue()).str();
    }
    else if (rtf instanceof Double)
    {
      textNodeValue = new XNumber(((Double) rtf).doubleValue()).str();
    }
    else
    {
      textNodeValue = rtf.toString();
    }

    // This no longer will work right since the DTM.
    // Document myDoc = myProcessor.getContextNode().getOwnerDocument();
      Document myDoc = JdkXmlUtils.getDOMDocument();

      Text textNode = myDoc.createTextNode(textNodeValue);
      DocumentFragment docFrag = myDoc.createDocumentFragment();

      docFrag.appendChild(textNode);

      return new NodeSet(docFrag);
  }
}
 
Example 14
Source File: Extensions.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
/**
 * This method is an extension that implements as a Xalan extension
 * the node-set function also found in xt and saxon.
 * If the argument is a Result Tree Fragment, then <code>nodeset</code>
 * returns a node-set consisting of a single root node as described in
 * section 11.1 of the XSLT 1.0 Recommendation.  If the argument is a
 * node-set, <code>nodeset</code> returns a node-set.  If the argument
 * is a string, number, or boolean, then <code>nodeset</code> returns
 * a node-set consisting of a single root node with a single text node
 * child that is the result of calling the XPath string() function on the
 * passed parameter.  If the argument is anything else, then a node-set
 * is returned consisting of a single root node with a single text node
 * child that is the result of calling the java <code>toString()</code>
 * method on the passed argument.
 * Most of the
 * actual work here is done in <code>MethodResolver</code> and
 * <code>XRTreeFrag</code>.
 * @param myProcessor Context passed by the extension processor
 * @param rtf Argument in the stylesheet to the nodeset extension function
 *
 * NEEDSDOC ($objectName$) @return
 */
public static NodeSet nodeset(ExpressionContext myProcessor, Object rtf)
{

  String textNodeValue;

  if (rtf instanceof NodeIterator)
  {
    return new NodeSet((NodeIterator) rtf);
  }
  else
  {
    if (rtf instanceof String)
    {
      textNodeValue = (String) rtf;
    }
    else if (rtf instanceof Boolean)
    {
      textNodeValue = new XBoolean(((Boolean) rtf).booleanValue()).str();
    }
    else if (rtf instanceof Double)
    {
      textNodeValue = new XNumber(((Double) rtf).doubleValue()).str();
    }
    else
    {
      textNodeValue = rtf.toString();
    }

    // This no longer will work right since the DTM.
    // Document myDoc = myProcessor.getContextNode().getOwnerDocument();
      Document myDoc = JdkXmlUtils.getDOMDocument();

      Text textNode = myDoc.createTextNode(textNodeValue);
      DocumentFragment docFrag = myDoc.createDocumentFragment();

      docFrag.appendChild(textNode);

      return new NodeSet(docFrag);
  }
}
 
Example 15
Source File: Extensions.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
/**
 * This method is an extension that implements as a Xalan extension
 * the node-set function also found in xt and saxon.
 * If the argument is a Result Tree Fragment, then <code>nodeset</code>
 * returns a node-set consisting of a single root node as described in
 * section 11.1 of the XSLT 1.0 Recommendation.  If the argument is a
 * node-set, <code>nodeset</code> returns a node-set.  If the argument
 * is a string, number, or boolean, then <code>nodeset</code> returns
 * a node-set consisting of a single root node with a single text node
 * child that is the result of calling the XPath string() function on the
 * passed parameter.  If the argument is anything else, then a node-set
 * is returned consisting of a single root node with a single text node
 * child that is the result of calling the java <code>toString()</code>
 * method on the passed argument.
 * Most of the
 * actual work here is done in <code>MethodResolver</code> and
 * <code>XRTreeFrag</code>.
 * @param myProcessor Context passed by the extension processor
 * @param rtf Argument in the stylesheet to the nodeset extension function
 *
 * NEEDSDOC ($objectName$) @return
 */
public static NodeSet nodeset(ExpressionContext myProcessor, Object rtf)
{

  String textNodeValue;

  if (rtf instanceof NodeIterator)
  {
    return new NodeSet((NodeIterator) rtf);
  }
  else
  {
    if (rtf instanceof String)
    {
      textNodeValue = (String) rtf;
    }
    else if (rtf instanceof Boolean)
    {
      textNodeValue = new XBoolean(((Boolean) rtf).booleanValue()).str();
    }
    else if (rtf instanceof Double)
    {
      textNodeValue = new XNumber(((Double) rtf).doubleValue()).str();
    }
    else
    {
      textNodeValue = rtf.toString();
    }

    // This no longer will work right since the DTM.
    // Document myDoc = myProcessor.getContextNode().getOwnerDocument();
    Document myDoc = JdkXmlUtils.getDOMDocument();

      Text textNode = myDoc.createTextNode(textNodeValue);
      DocumentFragment docFrag = myDoc.createDocumentFragment();

      docFrag.appendChild(textNode);

    return new NodeSet(docFrag);
  }
}