You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by mu...@apache.org on 2023/05/29 17:25:07 UTC
[xalan-java] branch xalan-j_xslt3.0 updated: committing implementation of xpath 3.1 functions fn:upper-case, fn:lower-case. also committing few related test cases as well.
This is an automated email from the ASF dual-hosted git repository.
mukulg pushed a commit to branch xalan-j_xslt3.0
in repository https://gitbox.apache.org/repos/asf/xalan-java.git
The following commit(s) were added to refs/heads/xalan-j_xslt3.0 by this push:
new c540addb committing implementation of xpath 3.1 functions fn:upper-case, fn:lower-case. also committing few related test cases as well.
c540addb is described below
commit c540addb5d3da6f66be9e5746c1d4516199f0c20
Author: Mukul Gandhi <ga...@gmail.com>
AuthorDate: Mon May 29 22:54:09 2023 +0530
committing implementation of xpath 3.1 functions fn:upper-case, fn:lower-case. also committing few related test cases as well.
---
src/org/apache/xpath/compiler/FunctionTable.java | 16 +++-
src/org/apache/xpath/compiler/Keywords.java | 14 +--
src/org/apache/xpath/functions/FuncLowerCase.java | 53 ++++++++++++
src/org/apache/xpath/functions/FuncUpperCase.java | 53 ++++++++++++
tests/fn_current_datetime/README | 4 +-
tests/org/apache/xalan/xpath3/StringTests.java | 100 ++++++++++++++++++++++
tests/org/apache/xalan/xslt3/AllXsl3Tests.java | 3 +-
tests/strings/gold/test1.out | 7 ++
tests/strings/test1.xsl | 39 +++++++++
tests/strings/test1_a.xml | 7 ++
10 files changed, 287 insertions(+), 9 deletions(-)
diff --git a/src/org/apache/xpath/compiler/FunctionTable.java b/src/org/apache/xpath/compiler/FunctionTable.java
index 1364f039..449ceb11 100644
--- a/src/org/apache/xpath/compiler/FunctionTable.java
+++ b/src/org/apache/xpath/compiler/FunctionTable.java
@@ -167,6 +167,12 @@ public class FunctionTable
/** The 'current-time()' id. */
public static final int FUNC_CURRENT_TIME = 48;
+
+ /** The 'upper-case()' id. */
+ public static final int FUNC_UPPER_CASE = 49;
+
+ /** The 'lower-case()' id. */
+ public static final int FUNC_LOWER_CASE = 50;
// Proprietary
@@ -195,7 +201,7 @@ public class FunctionTable
* Number of built in functions. Be sure to update this as
* built-in functions are added.
*/
- private static final int NUM_BUILT_IN_FUNCS = 49;
+ private static final int NUM_BUILT_IN_FUNCS = 51;
/**
* Number of built-in functions that may be added.
@@ -285,6 +291,10 @@ public class FunctionTable
org.apache.xpath.functions.FuncCurrentDate.class;
m_functions[FUNC_CURRENT_TIME] =
org.apache.xpath.functions.FuncCurrentTime.class;
+ m_functions[FUNC_UPPER_CASE] =
+ org.apache.xpath.functions.FuncUpperCase.class;
+ m_functions[FUNC_LOWER_CASE] =
+ org.apache.xpath.functions.FuncLowerCase.class;
}
static{
@@ -382,6 +392,10 @@ public class FunctionTable
new Integer(FunctionTable.FUNC_CURRENT_DATE));
m_functionID.put(Keywords.FUNC_CURRENT_TIME,
new Integer(FunctionTable.FUNC_CURRENT_TIME));
+ m_functionID.put(Keywords.FUNC_UPPER_CASE,
+ new Integer(FunctionTable.FUNC_UPPER_CASE));
+ m_functionID.put(Keywords.FUNC_LOWER_CASE,
+ new Integer(FunctionTable.FUNC_LOWER_CASE));
}
public FunctionTable(){
diff --git a/src/org/apache/xpath/compiler/Keywords.java b/src/org/apache/xpath/compiler/Keywords.java
index 2d4c5780..5a512658 100644
--- a/src/org/apache/xpath/compiler/Keywords.java
+++ b/src/org/apache/xpath/compiler/Keywords.java
@@ -243,6 +243,12 @@ public class Keywords
/** current-time function string. */
public static final String FUNC_CURRENT_TIME = "current-time";
+
+ /** upper-case function string. */
+ public static final String FUNC_UPPER_CASE = "upper-case";
+
+ /** lower-case function string. */
+ public static final String FUNC_LOWER_CASE = "lower-case";
// Proprietary, built in functions
@@ -293,7 +299,6 @@ public class Keywords
new Integer(FunctionTable.FUNC_ID));
m_keywords.put(FUNC_KEY_STRING,
new Integer(FunctionTable.FUNC_KEY));
-
m_nodetests.put(NODETYPE_COMMENT_STRING,
new Integer(OpCodes.NODETYPE_COMMENT));
m_nodetests.put(NODETYPE_TEXT_STRING,
@@ -301,10 +306,9 @@ public class Keywords
m_nodetests.put(NODETYPE_PI_STRING,
new Integer(OpCodes.NODETYPE_PI));
m_nodetests.put(NODETYPE_NODE_STRING,
- new Integer(OpCodes.NODETYPE_NODE));
-
- m_keywords.put(FUNC_KEY_STRING,
- new Integer(FunctionTable.FUNC_KEY));
+ new Integer(OpCodes.NODETYPE_NODE));
+ /*m_keywords.put(FUNC_KEY_STRING,
+ new Integer(FunctionTable.FUNC_KEY));*/
}
static Object getAxisName(String key){
diff --git a/src/org/apache/xpath/functions/FuncLowerCase.java b/src/org/apache/xpath/functions/FuncLowerCase.java
new file mode 100644
index 00000000..2373e22f
--- /dev/null
+++ b/src/org/apache/xpath/functions/FuncLowerCase.java
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/*
+ * $Id$
+ */
+package org.apache.xpath.functions;
+
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.objects.XObject;
+import org.apache.xpath.objects.XString;
+
+/**
+ * Implementation of the lower-case() function.
+ *
+ * @author Mukul Gandhi <mu...@apache.org>
+ *
+ * @xsl.usage advanced
+ */
+public class FuncLowerCase extends FunctionDef1Arg
+{
+
+ private static final long serialVersionUID = 1547894171087866269L;
+
+ /**
+ * 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 strValueOfArg = (getArg0AsString(xctxt)).toString();
+
+ return new XString((new String(strValueOfArg)).toLowerCase());
+ }
+}
diff --git a/src/org/apache/xpath/functions/FuncUpperCase.java b/src/org/apache/xpath/functions/FuncUpperCase.java
new file mode 100644
index 00000000..27ef9972
--- /dev/null
+++ b/src/org/apache/xpath/functions/FuncUpperCase.java
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/*
+ * $Id$
+ */
+package org.apache.xpath.functions;
+
+import org.apache.xpath.XPathContext;
+import org.apache.xpath.objects.XObject;
+import org.apache.xpath.objects.XString;
+
+/**
+ * Implementation of the upper-case() function.
+ *
+ * @author Mukul Gandhi <mu...@apache.org>
+ *
+ * @xsl.usage advanced
+ */
+public class FuncUpperCase extends FunctionDef1Arg
+{
+
+ private static final long serialVersionUID = 2596924943524147578L;
+
+ /**
+ * 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 strValueOfArg = (getArg0AsString(xctxt)).toString();
+
+ return new XString((new String(strValueOfArg)).toUpperCase());
+ }
+}
diff --git a/tests/fn_current_datetime/README b/tests/fn_current_datetime/README
index c5403d05..086e7322 100644
--- a/tests/fn_current_datetime/README
+++ b/tests/fn_current_datetime/README
@@ -17,7 +17,7 @@
<!-- Author: mukulg@apache.org -->
-Currently, we don't have a unit tests automation for tests within this folder,
-because these tests emit strings corresponding to XPath 3.1 functions
+Currently, we don't have a unit tests automation for tests present within this
+folder, because these tests emit strings corresponding to XPath 3.1 functions
fn:current-dateTime(), fn:current-date(), fn:current-time(). Though, anyone
may run these tests manually, and verify the results produced by these tests.
\ No newline at end of file
diff --git a/tests/org/apache/xalan/xpath3/StringTests.java b/tests/org/apache/xalan/xpath3/StringTests.java
new file mode 100644
index 00000000..83ccfb35
--- /dev/null
+++ b/tests/org/apache/xalan/xpath3/StringTests.java
@@ -0,0 +1,100 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.xalan.xpath3;
+
+import java.io.StringWriter;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+import javax.xml.transform.stream.StreamSource;
+
+import org.apache.xalan.xslt3.XSLConstants;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.w3c.dom.Node;
+import org.xml.sax.InputSource;
+
+import junit.framework.Assert;
+
+/**
+ * XPath test cases, for string functions.
+ *
+ * @author Mukul Gandhi <mu...@apache.org>
+ *
+ * @xsl.usage advanced
+ */
+public class StringTests {
+
+ private static final String xslTransformInputDirPath = XSLConstants.XSL_TRANSFORM_INPUT_DIR_PATH_PREFIX + "strings/";
+
+ private static final String xslTransformGoldDirPath = XSLConstants.XSL_TRANSFORM_GOLD_DIR_PATH_PREFIX + "strings/gold/";
+
+ private static TransformerFactory tfactory = null;
+
+ private static DocumentBuilderFactory dfactory = null;
+
+ private static DocumentBuilder docBuilder = null;
+
+ @BeforeClass
+ public static void setUpBeforeClass() throws Exception {
+ System.setProperty(XSLConstants.XERCES_DOCUMENT_BUILDER_FACTORY_KEY, XSLConstants.XERCES_DOCUMENT_BUILDER_FACTORY_VALUE);
+ System.setProperty(XSLConstants.XSLT_TRANSFORMER_FACTORY_KEY, XSLConstants.XSLT_TRANSFORMER_FACTORY_VALUE);
+
+ tfactory = TransformerFactory.newInstance();
+
+ dfactory = DocumentBuilderFactory.newInstance();
+ docBuilder = dfactory.newDocumentBuilder();
+ }
+
+ @AfterClass
+ public static void tearDownAfterClass() throws Exception {
+ tfactory = null;
+ dfactory = null;
+ docBuilder = null;
+ }
+
+ @Test
+ public void test1() {
+ String xmlFilePath = xslTransformInputDirPath + "test1_a.xml";
+ String xslFilePath = xslTransformInputDirPath + "test1.xsl";
+
+ String goldFilePath = xslTransformGoldDirPath + "test1.out";
+
+ try {
+ Node xmlDomSource = docBuilder.parse(new InputSource(xmlFilePath));
+
+ Transformer xslTransformer = tfactory.newTransformer(new StreamSource(xslFilePath));
+ StringWriter resultStrWriter = new StringWriter();
+ xslTransformer.transform(new DOMSource(xmlDomSource), new StreamResult(resultStrWriter));
+
+ byte[] goldFileBytes = Files.readAllBytes(Paths.get(goldFilePath));
+
+ Assert.assertEquals(new String(goldFileBytes), resultStrWriter.toString());
+ }
+ catch (Exception ex) {
+ Assert.fail();
+ }
+ }
+
+}
diff --git a/tests/org/apache/xalan/xslt3/AllXsl3Tests.java b/tests/org/apache/xalan/xslt3/AllXsl3Tests.java
index 1a0d22ff..7cf538fe 100644
--- a/tests/org/apache/xalan/xslt3/AllXsl3Tests.java
+++ b/tests/org/apache/xalan/xslt3/AllXsl3Tests.java
@@ -20,6 +20,7 @@ import org.apache.xalan.xpath3.FnAbsTests;
import org.apache.xalan.xpath3.FnStringJoinTests;
import org.apache.xalan.xpath3.FnTokenizeTests;
import org.apache.xalan.xpath3.FnUnparsedTextTests;
+import org.apache.xalan.xpath3.StringTests;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
@@ -40,7 +41,7 @@ import org.junit.runners.Suite.SuiteClasses;
@SuiteClasses({ AnalyzeStringTests.class, AttributeTests.class, GroupingTests.class,
GroupingWithSortTests.class, RtfMigrationTests.class,
FnUnparsedTextTests.class, FnTokenizeTests.class, FnStringJoinTests.class,
- FnAbsTests.class })
+ FnAbsTests.class, StringTests.class })
public class AllXsl3Tests {
}
diff --git a/tests/strings/gold/test1.out b/tests/strings/gold/test1.out
new file mode 100644
index 00000000..720be5e3
--- /dev/null
+++ b/tests/strings/gold/test1.out
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?><result>
+ <one>false</one>
+ <two>true</two>
+ <three>true</three>
+ <four>true</four>
+ <five>false</five>
+</result>
diff --git a/tests/strings/test1.xsl b/tests/strings/test1.xsl
new file mode 100644
index 00000000..4f88dae7
--- /dev/null
+++ b/tests/strings/test1.xsl
@@ -0,0 +1,39 @@
+<?xml version="1.0"?>
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+ version="3.0">
+
+ <!-- Author: mukulg@apache.org -->
+
+ <!-- use with test1_a.xml -->
+
+ <xsl:output method="xml" indent="yes"/>
+
+ <xsl:template match="/elem">
+ <result>
+ <one><xsl:value-of select="a = b"/></one>
+ <two><xsl:value-of select="a = c"/></two>
+ <three><xsl:value-of select="a = lower-case(d)"/></three>
+ <four><xsl:value-of select="upper-case(a) = upper-case(c)"/></four>
+ <five><xsl:value-of select="a = upper-case(c)"/></five>
+ </result>
+ </xsl:template>
+
+ <!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ -->
+
+</xsl:stylesheet>
\ No newline at end of file
diff --git a/tests/strings/test1_a.xml b/tests/strings/test1_a.xml
new file mode 100644
index 00000000..0f2506df
--- /dev/null
+++ b/tests/strings/test1_a.xml
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<elem>
+ <a>hello</a>
+ <b>world</b>
+ <c>hello</c>
+ <d>heLLo</d>
+</elem>
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xalan.apache.org
For additional commands, e-mail: commits-help@xalan.apache.org