garyp 00/10/29 10:25:26
Modified: java/src/org/apache/xalan/lib Extensions.java
Log:
Implement tokenize extension function.
Revision Changes Path
1.4 +46 -1 xml-xalan/java/src/org/apache/xalan/lib/Extensions.java
Index: Extensions.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/lib/Extensions.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- Extensions.java 2000/10/17 23:33:32 1.3
+++ Extensions.java 2000/10/29 18:25:25 1.4
@@ -69,8 +69,8 @@
import org.apache.xpath.XPathContext;
import org.xml.sax.SAXNotSupportedException;
import java.util.Hashtable;
+import java.util.StringTokenizer;
-
import org.apache.xalan.extensions.ExpressionContext;
/**
@@ -237,5 +237,50 @@
else
throw new SAXNotSupportedException("Invalid context passed to evaluate
" + myContext);
}
+
+ /**
+ * 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 myContext an <code>ExpressionContext</code> passed in by the
+ * extension mechanism. This must be an XPathContext.
+ * @param toTokenize The string to be split into text tokens.
+ * @param delims The delimiters to use.
+ * @return a NodeSet as described above.
+ *
+ */
+ public static NodeSet tokenize(ExpressionContext myContext, String
toTokenize, String delims)
+ {
+ Document lDoc = myContext.getContextNode().getOwnerDocument();
+ StringTokenizer lTokenizer = new StringTokenizer(toTokenize, delims);
+ NodeSet resultSet = new NodeSet();
+ while (lTokenizer.hasMoreTokens())
+ {
+ resultSet.addNode(lDoc.createTextNode(lTokenizer.nextToken()));
+ }
+ return resultSet;
+}
+
+ /**
+ * Returns a NodeSet containing one text node for each token in the
first argument.
+ * Delimiters are whitespace. That is, the delimiters that are used are
tab (	),
+ * linefeed (
), return (
), and space ( ).
+ * 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 myContext an <code>ExpressionContext</code> passed in by the
+ * extension mechanism. This must be an XPathContext.
+ * @param toTokenize The string to be split into text tokens.
+ * @return a NodeSet as described above.
+ *
+ */
+ public static NodeSet tokenize(ExpressionContext myContext, String
toTokenize)
+ {
+ return tokenize(myContext, toTokenize, " \t\n\r");
+ }
}