From 05844413907036e170feb7b24034411ab7fc6c03 Mon Sep 17 00:00:00 2001 From: Joe Wang Date: Thu, 1 Feb 2018 15:53:51 -0800 Subject: [PATCH] 8193830: Xalan Update: Xalan Java 2.7.2 Reviewed-by: lancea --- .../xsltc/compiler/FunctionAvailableCall.java | 3 +- .../xalan/internal/xsltc/compiler/Sort.java | 21 ++- .../xsltc/dom/AdaptiveResultTreeImpl.java | 4 +- .../internal/xsltc/runtime/BasisLibrary.java | 4 +- .../xml/internal/dtm/ref/DTMDefaultBase.java | 2 +- .../apache/xml/internal/utils/NodeVector.java | 5 +- src/java.xml/share/legal/xalan.md | 7 +- .../unittest/transform/sort/SortTest.java | 129 ++++++++++++++++++ .../transform/sort/sort-alphabet-english.out | 30 ++++ .../transform/sort/sort-alphabet-english.xml | 46 +++++++ .../transform/sort/sort-alphabet-english.xsl | 40 ++++++ .../transform/sort/sort-alphabet-polish.out | 37 +++++ .../transform/sort/sort-alphabet-polish.xml | 52 +++++++ .../transform/sort/sort-alphabet-polish.xsl | 39 ++++++ .../transform/sort/sort-alphabet-russian.out | 38 ++++++ .../transform/sort/sort-alphabet-russian.xml | 53 +++++++ .../transform/sort/sort-alphabet-russian.xsl | 39 ++++++ 17 files changed, 527 insertions(+), 22 deletions(-) create mode 100644 test/jaxp/javax/xml/jaxp/unittest/transform/sort/SortTest.java create mode 100644 test/jaxp/javax/xml/jaxp/unittest/transform/sort/sort-alphabet-english.out create mode 100644 test/jaxp/javax/xml/jaxp/unittest/transform/sort/sort-alphabet-english.xml create mode 100644 test/jaxp/javax/xml/jaxp/unittest/transform/sort/sort-alphabet-english.xsl create mode 100644 test/jaxp/javax/xml/jaxp/unittest/transform/sort/sort-alphabet-polish.out create mode 100644 test/jaxp/javax/xml/jaxp/unittest/transform/sort/sort-alphabet-polish.xml create mode 100644 test/jaxp/javax/xml/jaxp/unittest/transform/sort/sort-alphabet-polish.xsl create mode 100644 test/jaxp/javax/xml/jaxp/unittest/transform/sort/sort-alphabet-russian.out create mode 100644 test/jaxp/javax/xml/jaxp/unittest/transform/sort/sort-alphabet-russian.xml create mode 100644 test/jaxp/javax/xml/jaxp/unittest/transform/sort/sort-alphabet-russian.xsl diff --git a/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/compiler/FunctionAvailableCall.java b/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/compiler/FunctionAvailableCall.java index 5e2bed87608..8a836537fc1 100644 --- a/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/compiler/FunctionAvailableCall.java +++ b/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/compiler/FunctionAvailableCall.java @@ -97,7 +97,6 @@ final class FunctionAvailableCall extends FunctionCall { * the specified method is found in the specifed class. */ private boolean hasMethods() { - LiteralExpr arg = (LiteralExpr)_arg; // Get the class name from the namespace uri String className = getClassNameFromUri(_namespaceOfFunct); @@ -110,7 +109,7 @@ final class FunctionAvailableCall extends FunctionCall { int lastDotIndex = functionName.lastIndexOf('.'); if (lastDotIndex > 0) { methodName = functionName.substring(lastDotIndex+1); - if (className != null && !className.equals("")) + if (className != null && className.length() != 0) className = className + "." + functionName.substring(0, lastDotIndex); else className = functionName.substring(0, lastDotIndex); diff --git a/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/compiler/Sort.java b/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/compiler/Sort.java index e9abb50d062..c7ae5ea68f6 100644 --- a/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/compiler/Sort.java +++ b/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/compiler/Sort.java @@ -66,7 +66,7 @@ final class Sort extends Instruction implements Closure { private AttributeValue _order; private AttributeValue _caseOrder; private AttributeValue _dataType; - private String _lang; // bug! see 26869 + private AttributeValue _lang; // bug! see 26869, see XALANJ-2546 private String _className = null; private List _closureVars = null; @@ -154,13 +154,11 @@ final class Sort extends Instruction implements Closure { } _dataType = AttributeValue.create(this, val, parser); - _lang = getAttribute("lang"); // bug! see 26869 - // val = getAttribute("lang"); - // _lang = AttributeValue.create(this, val, parser); + val = getAttribute("lang"); + _lang = AttributeValue.create(this, val, parser); // Get the case order; default is language dependant - val = getAttribute("case-order"); - _caseOrder = AttributeValue.create(this, val, parser); - + val = getAttribute("case-order"); + _caseOrder = AttributeValue.create(this, val, parser); } /** @@ -179,6 +177,7 @@ final class Sort extends Instruction implements Closure { _order.typeCheck(stable); _caseOrder.typeCheck(stable); _dataType.typeCheck(stable); + _lang.typeCheck(stable); return Type.Void; } @@ -196,16 +195,14 @@ final class Sort extends Instruction implements Closure { _order.translate(classGen, methodGen); } - public void translateCaseOrder(ClassGenerator classGen, + public void translateCaseOrder(ClassGenerator classGen, MethodGenerator methodGen) { - _caseOrder.translate(classGen, methodGen); + _caseOrder.translate(classGen, methodGen); } public void translateLang(ClassGenerator classGen, MethodGenerator methodGen) { - final ConstantPoolGen cpg = classGen.getConstantPool(); - final InstructionList il = methodGen.getInstructionList(); - il.append(new PUSH(cpg, _lang)); // bug! see 26869 + _lang.translate(classGen, methodGen); } /** diff --git a/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/dom/AdaptiveResultTreeImpl.java b/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/dom/AdaptiveResultTreeImpl.java index cb50cf5d779..e92574c131c 100644 --- a/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/dom/AdaptiveResultTreeImpl.java +++ b/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/dom/AdaptiveResultTreeImpl.java @@ -570,7 +570,7 @@ public class AdaptiveResultTreeImpl extends SimpleResultTreeImpl if (_openElementName != null) { int index; - if ((index =_openElementName.indexOf(":")) < 0) + if ((index =_openElementName.indexOf(':')) < 0) _dom.startElement(null, _openElementName, _openElementName, _attributes); else { String uri =_dom.getNamespaceURI(_openElementName.substring(0,index)); @@ -682,7 +682,7 @@ public class AdaptiveResultTreeImpl extends SimpleResultTreeImpl public void addAttribute(String qName, String value) { // "prefix:localpart" or "localpart" - int colonpos = qName.indexOf(":"); + int colonpos = qName.indexOf(':'); String uri = EMPTY_STRING; String localName = qName; if (colonpos >0) diff --git a/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/runtime/BasisLibrary.java b/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/runtime/BasisLibrary.java index 16c9a226868..bb976e4c6eb 100644 --- a/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/runtime/BasisLibrary.java +++ b/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/runtime/BasisLibrary.java @@ -1425,8 +1425,8 @@ public final class BasisLibrary { * This method should only be invoked if the name attribute is an AVT */ public static void checkAttribQName(String name) { - final int firstOccur = name.indexOf(":"); - final int lastOccur = name.lastIndexOf(":"); + final int firstOccur = name.indexOf(':'); + final int lastOccur = name.lastIndexOf(':'); final String localName = name.substring(lastOccur + 1); if (firstOccur > 0) { diff --git a/src/java.xml/share/classes/com/sun/org/apache/xml/internal/dtm/ref/DTMDefaultBase.java b/src/java.xml/share/classes/com/sun/org/apache/xml/internal/dtm/ref/DTMDefaultBase.java index f01a5fa5bc1..ef8c178444f 100644 --- a/src/java.xml/share/classes/com/sun/org/apache/xml/internal/dtm/ref/DTMDefaultBase.java +++ b/src/java.xml/share/classes/com/sun/org/apache/xml/internal/dtm/ref/DTMDefaultBase.java @@ -354,7 +354,7 @@ public abstract class DTMDefaultBase implements DTM while (low <= high) { - int mid = (low + high) / 2; + int mid = (low + high) >>> 1; int c = list[mid]; if (c > value) diff --git a/src/java.xml/share/classes/com/sun/org/apache/xml/internal/utils/NodeVector.java b/src/java.xml/share/classes/com/sun/org/apache/xml/internal/utils/NodeVector.java index 6f54e22d4dd..d18fa6f2f25 100644 --- a/src/java.xml/share/classes/com/sun/org/apache/xml/internal/utils/NodeVector.java +++ b/src/java.xml/share/classes/com/sun/org/apache/xml/internal/utils/NodeVector.java @@ -669,9 +669,10 @@ public class NodeVector implements Serializable, Cloneable /* * Pick a pivot and move it out of the way */ - int pivot = a[(lo + hi) / 2]; + int mid = (lo + hi) >>> 1; + int pivot = a[mid]; - a[(lo + hi) / 2] = a[hi]; + a[mid] = a[hi]; a[hi] = pivot; while (lo < hi) diff --git a/src/java.xml/share/legal/xalan.md b/src/java.xml/share/legal/xalan.md index 94b293164df..54141ef6614 100644 --- a/src/java.xml/share/legal/xalan.md +++ b/src/java.xml/share/legal/xalan.md @@ -1,4 +1,4 @@ -## Apache Xalan v2.7.1 +## Apache Xalan v2.7.2 ### Apache Xalan Notice
@@ -11,6 +11,11 @@
    This product includes software developed by
    The Apache Software Foundation (http://www.apache.org/).
 
+   Specifically, we only include the XSLTC portion of the source from the Xalan distribution. 
+   The Xalan project has two processors: an interpretive one (Xalan Interpretive) and a 
+   compiled one (The XSLT Compiler (XSLTC)). We *only* use the XSLTC part of Xalan; We use
+   the source from the packages that are part of the XSLTC sources.
+
    Portions of this software was originally based on the following:
 
      - software copyright (c) 1999-2002, Lotus Development Corporation., http://www.lotus.com.
diff --git a/test/jaxp/javax/xml/jaxp/unittest/transform/sort/SortTest.java b/test/jaxp/javax/xml/jaxp/unittest/transform/sort/SortTest.java
new file mode 100644
index 00000000000..8966ffeea12
--- /dev/null
+++ b/test/jaxp/javax/xml/jaxp/unittest/transform/sort/SortTest.java
@@ -0,0 +1,129 @@
+/*
+ * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package transform.sort;
+
+import static jaxp.library.JAXPTestUtilities.getSystemProperty;
+import java.io.StringWriter;
+import java.net.URI;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.List;
+
+import javax.xml.transform.Result;
+import javax.xml.transform.Source;
+import javax.xml.transform.Templates;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.stream.StreamResult;
+import javax.xml.transform.stream.StreamSource;
+
+import org.testng.Assert;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Listeners;
+import org.testng.annotations.Test;
+
+/*
+ * @test
+ * @bug 8193830
+ * @library /javax/xml/jaxp/libs /javax/xml/jaxp/unittest
+ * @run testng/othervm -DrunSecMngr=true transform.sort.SortTest
+ * @run testng/othervm transform.sort.SortTest
+ * @summary verify xsl:sort lang attribute
+ */
+@Listeners({jaxp.library.FilePolicy.class})
+public class SortTest {
+
+    static final String LAND_EN = "en";
+    static final String LAND_PL = "pl";
+    static final String LAND_RU = "ru";
+
+    String filepath;
+    String slash = "";
+
+    @BeforeClass
+    public void setUpClass() throws Exception {
+        String file1 = getClass().getResource("sort-alphabet-english.xml").getFile();
+        if (getSystemProperty("os.name").contains("Windows")) {
+            filepath = file1.substring(1, file1.lastIndexOf("/") + 1);
+            slash = "/";
+        } else {
+            filepath = file1.substring(0, file1.lastIndexOf("/") + 1);
+        }
+    }
+
+    /*
+     * DataProvider fields:
+     * lang, xml, xsl, gold file
+     */
+    @DataProvider(name = "parameters")
+    public Object[][] getParameters() {
+
+        return new Object[][]{
+            {LAND_EN, "sort-alphabet-english.xml", "sort-alphabet-english.xsl", "sort-alphabet-english.out"},
+            {LAND_PL, "sort-alphabet-polish.xml", "sort-alphabet-polish.xsl", "sort-alphabet-polish.out"},
+            {LAND_RU, "sort-alphabet-russian.xml", "sort-alphabet-russian.xsl", "sort-alphabet-russian.out"},};
+    }
+
+    @Test(dataProvider = "parameters")
+    public final void testTransform(String lang, String xml, String xsl, String gold)
+            throws Exception {
+
+        StringWriter sw = new StringWriter();
+        // Create transformer factory
+        TransformerFactory factory = TransformerFactory.newInstance();
+
+        // Use the factory to create a template containing the xsl file
+        Templates template = factory.newTemplates(new StreamSource(getClass().getResourceAsStream(xsl)));
+        // Use the template to create a transformer
+        Transformer xformer = template.newTransformer();
+        xformer.setParameter("lang", lang);
+        // Prepare the input and output files
+        Source source = new StreamSource(getClass().getResourceAsStream(xml));
+
+        /*
+             * The following may be used to produce gold files.
+             * Using however the original gold files, and compare without considering
+             * the format
+         */
+        //String output = getClass().getResource(gold).getPath();
+        //Result result = new StreamResult(new FileOutputStream(output));
+        // use the following to verify the output against the pre-generated one
+        Result result = new StreamResult(sw);
+
+        // Apply the xsl file to the source file and write the result to the
+        // output file
+        xformer.transform(source, result);
+
+        String out = sw.toString();
+
+        List lines = Files.readAllLines(Paths.get(filepath + gold));
+        String[] resultLines = out.split("\n");
+        int i = 0;
+
+        // the purpose is to test sort, so ignore the format of the output
+        for (String line : lines) {
+            Assert.assertEquals(resultLines[i++].trim(), line.trim());
+        }
+    }
+}
diff --git a/test/jaxp/javax/xml/jaxp/unittest/transform/sort/sort-alphabet-english.out b/test/jaxp/javax/xml/jaxp/unittest/transform/sort/sort-alphabet-english.out
new file mode 100644
index 00000000000..a34c49ab47e
--- /dev/null
+++ b/test/jaxp/javax/xml/jaxp/unittest/transform/sort/sort-alphabet-english.out
@@ -0,0 +1,30 @@
+
+

lang: en

+
    +
  • A
  • +
  • C
  • +
  • D
  • +
  • E
  • +
  • F
  • +
  • G
  • +
  • H
  • +
  • I
  • +
  • J
  • +
  • K
  • +
  • L
  • +
  • M
  • +
  • N
  • +
  • O
  • +
  • P
  • +
  • Q
  • +
  • R
  • +
  • S
  • +
  • T
  • +
  • U
  • +
  • V
  • +
  • W
  • +
  • X
  • +
  • Y
  • +
  • Z
  • +
+
\ No newline at end of file diff --git a/test/jaxp/javax/xml/jaxp/unittest/transform/sort/sort-alphabet-english.xml b/test/jaxp/javax/xml/jaxp/unittest/transform/sort/sort-alphabet-english.xml new file mode 100644 index 00000000000..7093d67c532 --- /dev/null +++ b/test/jaxp/javax/xml/jaxp/unittest/transform/sort/sort-alphabet-english.xml @@ -0,0 +1,46 @@ + + + + A + E + C + D + F + G + H + I + J + K + L + M + N + Y + O + P + Q + U + R + S + V + W + T + X + Z + + diff --git a/test/jaxp/javax/xml/jaxp/unittest/transform/sort/sort-alphabet-english.xsl b/test/jaxp/javax/xml/jaxp/unittest/transform/sort/sort-alphabet-english.xsl new file mode 100644 index 00000000000..ef57a3d543d --- /dev/null +++ b/test/jaxp/javax/xml/jaxp/unittest/transform/sort/sort-alphabet-english.xsl @@ -0,0 +1,40 @@ + + + + + + + + +

lang:

+
    + + + +
+
+
+ +
  • + +
  • +
    +
    + diff --git a/test/jaxp/javax/xml/jaxp/unittest/transform/sort/sort-alphabet-polish.out b/test/jaxp/javax/xml/jaxp/unittest/transform/sort/sort-alphabet-polish.out new file mode 100644 index 00000000000..5219d79d9d6 --- /dev/null +++ b/test/jaxp/javax/xml/jaxp/unittest/transform/sort/sort-alphabet-polish.out @@ -0,0 +1,37 @@ + +

    lang: pl

    +
      +
    • A
    • +
    • Ą
    • +
    • B
    • +
    • C
    • +
    • Ć
    • +
    • D
    • +
    • E
    • +
    • Ę
    • +
    • F
    • +
    • G
    • +
    • H
    • +
    • I
    • +
    • J
    • +
    • K
    • +
    • L
    • +
    • Ł
    • +
    • M
    • +
    • N
    • +
    • Ń
    • +
    • O
    • +
    • Ó
    • +
    • P
    • +
    • R
    • +
    • S
    • +
    • Ś
    • +
    • T
    • +
    • U
    • +
    • W
    • +
    • Y
    • +
    • Z
    • +
    • Ź
    • +
    • Ż
    • +
    +
    \ No newline at end of file diff --git a/test/jaxp/javax/xml/jaxp/unittest/transform/sort/sort-alphabet-polish.xml b/test/jaxp/javax/xml/jaxp/unittest/transform/sort/sort-alphabet-polish.xml new file mode 100644 index 00000000000..cf08ac1bfc3 --- /dev/null +++ b/test/jaxp/javax/xml/jaxp/unittest/transform/sort/sort-alphabet-polish.xml @@ -0,0 +1,52 @@ + + + + A + Ż + B + C + Ć + D + Ł + E + Ę + F + G + H + I + J + K + L + Z + Ź + M + N + Ń + O + Ó + P + R + S + Ś + T + U + W + Ą + Y + \ No newline at end of file diff --git a/test/jaxp/javax/xml/jaxp/unittest/transform/sort/sort-alphabet-polish.xsl b/test/jaxp/javax/xml/jaxp/unittest/transform/sort/sort-alphabet-polish.xsl new file mode 100644 index 00000000000..e91e53c6195 --- /dev/null +++ b/test/jaxp/javax/xml/jaxp/unittest/transform/sort/sort-alphabet-polish.xsl @@ -0,0 +1,39 @@ + + + + + + + + +

    lang:

    +
      + + + +
    +
    +
    + +
  • + +
  • +
    +
    \ No newline at end of file diff --git a/test/jaxp/javax/xml/jaxp/unittest/transform/sort/sort-alphabet-russian.out b/test/jaxp/javax/xml/jaxp/unittest/transform/sort/sort-alphabet-russian.out new file mode 100644 index 00000000000..724d22d6e83 --- /dev/null +++ b/test/jaxp/javax/xml/jaxp/unittest/transform/sort/sort-alphabet-russian.out @@ -0,0 +1,38 @@ + +

    lang: ru

    +
      +
    • А
    • +
    • Б
    • +
    • В
    • +
    • Г
    • +
    • Д
    • +
    • Е
    • +
    • Ё
    • +
    • Ж
    • +
    • З
    • +
    • И
    • +
    • Й
    • +
    • К
    • +
    • Л
    • +
    • М
    • +
    • Н
    • +
    • О
    • +
    • П
    • +
    • Р
    • +
    • С
    • +
    • Т
    • +
    • У
    • +
    • Ф
    • +
    • Х
    • +
    • Ц
    • +
    • Ч
    • +
    • Ш
    • +
    • Щ
    • +
    • Ъ
    • +
    • Ы
    • +
    • Ь
    • +
    • Э
    • +
    • Ю
    • +
    • Я
    • +
    +
    \ No newline at end of file diff --git a/test/jaxp/javax/xml/jaxp/unittest/transform/sort/sort-alphabet-russian.xml b/test/jaxp/javax/xml/jaxp/unittest/transform/sort/sort-alphabet-russian.xml new file mode 100644 index 00000000000..6811b16c934 --- /dev/null +++ b/test/jaxp/javax/xml/jaxp/unittest/transform/sort/sort-alphabet-russian.xml @@ -0,0 +1,53 @@ + + + + А + Б + В + Г + Д + Е + Ё + Ж + З + Й + П + Я + К + Л + С + М + Н + О + Р + И + Т + Ф + Х + Ц + У + Ш + Щ + Ъ + Ы + Ч + Ь + Э + Ю + diff --git a/test/jaxp/javax/xml/jaxp/unittest/transform/sort/sort-alphabet-russian.xsl b/test/jaxp/javax/xml/jaxp/unittest/transform/sort/sort-alphabet-russian.xsl new file mode 100644 index 00000000000..e91e53c6195 --- /dev/null +++ b/test/jaxp/javax/xml/jaxp/unittest/transform/sort/sort-alphabet-russian.xsl @@ -0,0 +1,39 @@ + + + + + + + + +

    lang:

    +
      + + + +
    +
    +
    + +
  • + +
  • +
    +
    \ No newline at end of file