[Practicalxml-commits] SF.net SVN: practicalxml:[56] trunk/src
Brought to you by:
kdgregory
|
From: Auto-Generated S. C. M. <pra...@li...> - 2008-12-17 03:36:46
|
Revision: 56
http://practicalxml.svn.sourceforge.net/practicalxml/?rev=56&view=rev
Author: kdgregory
Date: 2008-12-17 03:36:43 +0000 (Wed, 17 Dec 2008)
Log Message:
-----------
add package xpath.function
add Uppercase, Lowercase
Added Paths:
-----------
trunk/src/main/java/net/sf/practicalxml/xpath/function/
trunk/src/main/java/net/sf/practicalxml/xpath/function/Constants.java
trunk/src/main/java/net/sf/practicalxml/xpath/function/Lowercase.java
trunk/src/main/java/net/sf/practicalxml/xpath/function/Uppercase.java
trunk/src/main/java/net/sf/practicalxml/xpath/function/package.html
trunk/src/test/java/net/sf/practicalxml/xpath/function/
trunk/src/test/java/net/sf/practicalxml/xpath/function/TestLowercase.java
trunk/src/test/java/net/sf/practicalxml/xpath/function/TestUppercase.java
Added: trunk/src/main/java/net/sf/practicalxml/xpath/function/Constants.java
===================================================================
--- trunk/src/main/java/net/sf/practicalxml/xpath/function/Constants.java (rev 0)
+++ trunk/src/main/java/net/sf/practicalxml/xpath/function/Constants.java 2008-12-17 03:36:43 UTC (rev 56)
@@ -0,0 +1,12 @@
+package net.sf.practicalxml.xpath.function;
+
+/**
+ * Constants for use in this package.
+ */
+public class Constants
+{
+ /**
+ * All functions in this package use this as their namespace URI.
+ */
+ public final static String COMMON_NS_URI = "http://practicalxml.sourceforge.net/";
+}
Property changes on: trunk/src/main/java/net/sf/practicalxml/xpath/function/Constants.java
___________________________________________________________________
Added: svn:executable
+ *
Added: trunk/src/main/java/net/sf/practicalxml/xpath/function/Lowercase.java
===================================================================
--- trunk/src/main/java/net/sf/practicalxml/xpath/function/Lowercase.java (rev 0)
+++ trunk/src/main/java/net/sf/practicalxml/xpath/function/Lowercase.java 2008-12-17 03:36:43 UTC (rev 56)
@@ -0,0 +1,44 @@
+package net.sf.practicalxml.xpath.function;
+
+import org.w3c.dom.Node;
+
+import net.sf.practicalxml.xpath.AbstractFunction;
+
+
+/**
+ * Converts the string value of its argument — which must be
+ * either a literal string or a node/nodeset — to uppercase,
+ * using <code>java.lang.String.toUppercase()</code>.
+ */
+public class Lowercase
+extends AbstractFunction<String>
+{
+ public Lowercase()
+ {
+ super(Constants.COMMON_NS_URI, "lowercase", 1);
+ }
+
+ @Override
+ protected String processArg(int index, Node value, String helper)
+ throws Exception
+ {
+ return (value != null)
+ ? processArg(index, value.getTextContent(), helper)
+ : "";
+ }
+
+ @Override
+ protected String processArg(int index, String value, String helper)
+ throws Exception
+ {
+ return value.toLowerCase();
+ }
+
+
+ @Override
+ protected String processNullArg(int index, String helper)
+ throws Exception
+ {
+ return "";
+ }
+}
Property changes on: trunk/src/main/java/net/sf/practicalxml/xpath/function/Lowercase.java
___________________________________________________________________
Added: svn:executable
+ *
Added: trunk/src/main/java/net/sf/practicalxml/xpath/function/Uppercase.java
===================================================================
--- trunk/src/main/java/net/sf/practicalxml/xpath/function/Uppercase.java (rev 0)
+++ trunk/src/main/java/net/sf/practicalxml/xpath/function/Uppercase.java 2008-12-17 03:36:43 UTC (rev 56)
@@ -0,0 +1,44 @@
+package net.sf.practicalxml.xpath.function;
+
+import org.w3c.dom.Node;
+
+import net.sf.practicalxml.xpath.AbstractFunction;
+
+
+/**
+ * Converts the string value of its argument — which must be
+ * either a literal string or a node/nodeset — to uppercase,
+ * using <code>java.lang.String.toUppercase()</code>.
+ */
+public class Uppercase
+extends AbstractFunction<String>
+{
+ public Uppercase()
+ {
+ super(Constants.COMMON_NS_URI, "uppercase", 1);
+ }
+
+ @Override
+ protected String processArg(int index, Node value, String helper)
+ throws Exception
+ {
+ return (value != null)
+ ? processArg(index, value.getTextContent(), helper)
+ : "";
+ }
+
+ @Override
+ protected String processArg(int index, String value, String helper)
+ throws Exception
+ {
+ return value.toUpperCase();
+ }
+
+
+ @Override
+ protected String processNullArg(int index, String helper)
+ throws Exception
+ {
+ return "";
+ }
+}
Property changes on: trunk/src/main/java/net/sf/practicalxml/xpath/function/Uppercase.java
___________________________________________________________________
Added: svn:executable
+ *
Added: trunk/src/main/java/net/sf/practicalxml/xpath/function/package.html
===================================================================
--- trunk/src/main/java/net/sf/practicalxml/xpath/function/package.html (rev 0)
+++ trunk/src/main/java/net/sf/practicalxml/xpath/function/package.html 2008-12-17 03:36:43 UTC (rev 56)
@@ -0,0 +1,7 @@
+<html>
+<body>
+ This package contains reusable XPath functions, implemented using {@link
+ net.sf.practicalxml.xpath.AbstractFunction}. All such functions belong
+ to the namepspace "http://practicalxml.sourceforge.net/".
+</body>
+</html>
\ No newline at end of file
Property changes on: trunk/src/main/java/net/sf/practicalxml/xpath/function/package.html
___________________________________________________________________
Added: svn:executable
+ *
Added: trunk/src/test/java/net/sf/practicalxml/xpath/function/TestLowercase.java
===================================================================
--- trunk/src/test/java/net/sf/practicalxml/xpath/function/TestLowercase.java (rev 0)
+++ trunk/src/test/java/net/sf/practicalxml/xpath/function/TestLowercase.java 2008-12-17 03:36:43 UTC (rev 56)
@@ -0,0 +1,80 @@
+package net.sf.practicalxml.xpath.function;
+
+import java.util.Arrays;
+import java.util.Collections;
+
+import javax.xml.xpath.XPathFunctionException;
+
+import org.w3c.dom.Element;
+
+import net.sf.practicalxml.AbstractTestCase;
+import net.sf.practicalxml.DomUtil;
+
+
+public class TestLowercase
+extends AbstractTestCase
+{
+ public void testConstruction() throws Exception
+ {
+ Lowercase fn = new Lowercase();
+ assertEquals(Constants.COMMON_NS_URI, fn.getNamespaceUri());
+ assertEquals("lowercase", fn.getName());
+ assertEquals(1, fn.getMinArgCount());
+ assertEquals(1, fn.getMaxArgCount());
+ }
+
+ public void testLiteralString() throws Exception
+ {
+ assertEquals(
+ "test",
+ new Lowercase().evaluate(Arrays.asList("Test")));
+ }
+
+
+ public void testNodeList() throws Exception
+ {
+ Element root = DomUtil.newDocument("foo");
+ Element child1 = DomUtil.appendChild(root, "bar");
+ Element child2 = DomUtil.appendChild(root, "baz");
+ DomUtil.setText(root, "Test");
+ DomUtil.setText(child1, "Test2");
+ DomUtil.setText(child2, "Test3");
+
+ assertEquals(
+ "test2",
+ new Lowercase().evaluate(Arrays.asList(root.getChildNodes())));
+ }
+
+
+ public void testEmptyNodeList() throws Exception
+ {
+ Element root = DomUtil.newDocument("foo");
+
+ assertEquals(
+ "",
+ new Lowercase().evaluate(Arrays.asList(root.getChildNodes())));
+ }
+
+
+ public void testNull() throws Exception
+ {
+ assertEquals(
+ "",
+ new Lowercase().evaluate(Arrays.asList((String)null)));
+ }
+
+
+ public void testEmptyArglist() throws Exception
+ {
+ try
+ {
+ new Lowercase().evaluate(Collections.<String>emptyList());
+ fail("didn't throw on empty list");
+ }
+ catch (XPathFunctionException e)
+ {
+ // success
+ }
+ }
+
+}
Property changes on: trunk/src/test/java/net/sf/practicalxml/xpath/function/TestLowercase.java
___________________________________________________________________
Added: svn:executable
+ *
Added: trunk/src/test/java/net/sf/practicalxml/xpath/function/TestUppercase.java
===================================================================
--- trunk/src/test/java/net/sf/practicalxml/xpath/function/TestUppercase.java (rev 0)
+++ trunk/src/test/java/net/sf/practicalxml/xpath/function/TestUppercase.java 2008-12-17 03:36:43 UTC (rev 56)
@@ -0,0 +1,80 @@
+package net.sf.practicalxml.xpath.function;
+
+import java.util.Arrays;
+import java.util.Collections;
+
+import javax.xml.xpath.XPathFunctionException;
+
+import org.w3c.dom.Element;
+
+import net.sf.practicalxml.AbstractTestCase;
+import net.sf.practicalxml.DomUtil;
+
+
+public class TestUppercase
+extends AbstractTestCase
+{
+ public void testConstruction() throws Exception
+ {
+ Uppercase fn = new Uppercase();
+ assertEquals(Constants.COMMON_NS_URI, fn.getNamespaceUri());
+ assertEquals("uppercase", fn.getName());
+ assertEquals(1, fn.getMinArgCount());
+ assertEquals(1, fn.getMaxArgCount());
+ }
+
+ public void testLiteralString() throws Exception
+ {
+ assertEquals(
+ "TEST",
+ new Uppercase().evaluate(Arrays.asList("Test")));
+ }
+
+
+ public void testNodeList() throws Exception
+ {
+ Element root = DomUtil.newDocument("foo");
+ Element child1 = DomUtil.appendChild(root, "bar");
+ Element child2 = DomUtil.appendChild(root, "baz");
+ DomUtil.setText(root, "Test");
+ DomUtil.setText(child1, "Test2");
+ DomUtil.setText(child2, "Test3");
+
+ assertEquals(
+ "TEST2",
+ new Uppercase().evaluate(Arrays.asList(root.getChildNodes())));
+ }
+
+
+ public void testEmptyNodeList() throws Exception
+ {
+ Element root = DomUtil.newDocument("foo");
+
+ assertEquals(
+ "",
+ new Lowercase().evaluate(Arrays.asList(root.getChildNodes())));
+ }
+
+
+ public void testNull() throws Exception
+ {
+ assertEquals(
+ "",
+ new Uppercase().evaluate(Arrays.asList((String)null)));
+ }
+
+
+ public void testEmptyArglist() throws Exception
+ {
+ try
+ {
+ new Uppercase().evaluate(Collections.<String>emptyList());
+ fail("didn't throw on empty list");
+ }
+ catch (XPathFunctionException e)
+ {
+ // success
+ }
+ }
+
+}
Property changes on: trunk/src/test/java/net/sf/practicalxml/xpath/function/TestUppercase.java
___________________________________________________________________
Added: svn:executable
+ *
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|