You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ws.apache.org by ve...@apache.org on 2017/06/04 14:09:00 UTC

svn commit: r1797581 - in /webservices/axiom/trunk/testing: axiom-testsuite/src/main/java/org/apache/axiom/ts/om/ jaxp-testsuite/ jaxp-testsuite/src/main/java/org/apache/axiom/ts/jaxp/ jaxp-testsuite/src/test/ jaxp-testsuite/src/test/java/ jaxp-testsui...

Author: veithen
Date: Sun Jun  4 14:08:59 2017
New Revision: 1797581

URL: http://svn.apache.org/viewvc?rev=1797581&view=rev
Log:
Automatically detect XSLT implementation capabilities.

Added:
    webservices/axiom/trunk/testing/jaxp-testsuite/src/main/java/org/apache/axiom/ts/jaxp/TestContentHandler.java   (with props)
    webservices/axiom/trunk/testing/jaxp-testsuite/src/test/
    webservices/axiom/trunk/testing/jaxp-testsuite/src/test/java/
    webservices/axiom/trunk/testing/jaxp-testsuite/src/test/java/org/
    webservices/axiom/trunk/testing/jaxp-testsuite/src/test/java/org/apache/
    webservices/axiom/trunk/testing/jaxp-testsuite/src/test/java/org/apache/axiom/
    webservices/axiom/trunk/testing/jaxp-testsuite/src/test/java/org/apache/axiom/ts/
    webservices/axiom/trunk/testing/jaxp-testsuite/src/test/java/org/apache/axiom/ts/jaxp/
    webservices/axiom/trunk/testing/jaxp-testsuite/src/test/java/org/apache/axiom/ts/jaxp/XSLTImplementationTest.java   (with props)
Modified:
    webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java
    webservices/axiom/trunk/testing/jaxp-testsuite/pom.xml
    webservices/axiom/trunk/testing/jaxp-testsuite/src/main/java/org/apache/axiom/ts/jaxp/XSLTImplementation.java

Modified: webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java?rev=1797581&r1=1797580&r2=1797581&view=diff
==============================================================================
--- webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java (original)
+++ webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java Sun Jun  4 14:08:59 2017
@@ -196,8 +196,7 @@ public class OMTestSuiteBuilder extends
         addTest(new org.apache.axiom.ts.om.document.TestGetOMDocumentElementAfterDetach(metaFactory));
         addTest(new org.apache.axiom.ts.om.document.TestGetOMDocumentElementWithParser(metaFactory));
         for (XSLTImplementation xsltImplementation : getInstances(XSLTImplementation.class)) {
-            // TODO: the XSLT implementation in the JRE is badly broken when it comes to serializing DTDs; refine this
-            if (!xsltImplementation.getName().equals("jre") && xsltImplementation.supportsLexicalHandlerWithStreamSource()) {
+            if (xsltImplementation.supportsLexicalHandlerWithStreamSource()) {
                 for (XMLSample file : getInstances(XMLSample.class)) {
                     addTest(new org.apache.axiom.ts.om.document.TestGetSAXResult(metaFactory, xsltImplementation, file));
                 }

Modified: webservices/axiom/trunk/testing/jaxp-testsuite/pom.xml
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/testing/jaxp-testsuite/pom.xml?rev=1797581&r1=1797580&r2=1797581&view=diff
==============================================================================
--- webservices/axiom/trunk/testing/jaxp-testsuite/pom.xml (original)
+++ webservices/axiom/trunk/testing/jaxp-testsuite/pom.xml Sun Jun  4 14:08:59 2017
@@ -59,5 +59,15 @@
             <artifactId>crimson</artifactId>
             <version>1.1.3</version>
         </dependency>
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>com.google.truth</groupId>
+            <artifactId>truth</artifactId>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 </project>

Added: webservices/axiom/trunk/testing/jaxp-testsuite/src/main/java/org/apache/axiom/ts/jaxp/TestContentHandler.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/testing/jaxp-testsuite/src/main/java/org/apache/axiom/ts/jaxp/TestContentHandler.java?rev=1797581&view=auto
==============================================================================
--- webservices/axiom/trunk/testing/jaxp-testsuite/src/main/java/org/apache/axiom/ts/jaxp/TestContentHandler.java (added)
+++ webservices/axiom/trunk/testing/jaxp-testsuite/src/main/java/org/apache/axiom/ts/jaxp/TestContentHandler.java Sun Jun  4 14:08:59 2017
@@ -0,0 +1,49 @@
+/*
+ * 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.axiom.ts.jaxp;
+
+import org.xml.sax.ext.DefaultHandler2;
+
+final class TestContentHandler extends DefaultHandler2 {
+    private int lexicalEventsReceived;
+
+    @Override
+    public void startDTD(String name, String publicId, String systemId) {
+        lexicalEventsReceived++;
+    }
+
+    @Override
+    public void endDTD() {
+        lexicalEventsReceived++;
+    }
+
+    @Override
+    public void startCDATA() {
+        lexicalEventsReceived++;
+    }
+
+    @Override
+    public void endCDATA() {
+        lexicalEventsReceived++;
+    }
+
+    public int getLexicalEventsReceived() {
+        return lexicalEventsReceived;
+    }
+}

Propchange: webservices/axiom/trunk/testing/jaxp-testsuite/src/main/java/org/apache/axiom/ts/jaxp/TestContentHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: webservices/axiom/trunk/testing/jaxp-testsuite/src/main/java/org/apache/axiom/ts/jaxp/XSLTImplementation.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/testing/jaxp-testsuite/src/main/java/org/apache/axiom/ts/jaxp/XSLTImplementation.java?rev=1797581&r1=1797580&r2=1797581&view=diff
==============================================================================
--- webservices/axiom/trunk/testing/jaxp-testsuite/src/main/java/org/apache/axiom/ts/jaxp/XSLTImplementation.java (original)
+++ webservices/axiom/trunk/testing/jaxp-testsuite/src/main/java/org/apache/axiom/ts/jaxp/XSLTImplementation.java Sun Jun  4 14:08:59 2017
@@ -18,6 +18,9 @@
  */
 package org.apache.axiom.ts.jaxp;
 
+import java.io.StringReader;
+
+import javax.xml.transform.TransformerException;
 import javax.xml.transform.TransformerFactory;
 import javax.xml.transform.sax.SAXResult;
 import javax.xml.transform.stream.StreamSource;
@@ -36,14 +39,14 @@ public abstract class XSLTImplementation
             "com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl",
     };
     
-    public static final XSLTImplementation XALAN = new XSLTImplementation("xalan", true) {
+    public static final XSLTImplementation XALAN = new XSLTImplementation("xalan") {
         @Override
         public TransformerFactory newTransformerFactory() {
             return new org.apache.xalan.processor.TransformerFactoryImpl();
         }
     };
     
-    public static final XSLTImplementation SAXON = new XSLTImplementation("saxon", false) {
+    public static final XSLTImplementation SAXON = new XSLTImplementation("saxon") {
         @Override
         public TransformerFactory newTransformerFactory() {
             TransformerFactory factory = new net.sf.saxon.TransformerFactoryImpl();
@@ -55,11 +58,10 @@ public abstract class XSLTImplementation
     };
     
     private final String name;
-    private final boolean supportsLexicalHandlerWithStreamSource;
+    private Boolean supportsLexicalHandlerWithStreamSource;
     
-    private XSLTImplementation(String name, boolean supportsLexicalHandlerWithStreamSource) {
+    private XSLTImplementation(String name) {
         this.name = name;
-        this.supportsLexicalHandlerWithStreamSource = supportsLexicalHandlerWithStreamSource;
     }
 
     @Instances
@@ -67,7 +69,7 @@ public abstract class XSLTImplementation
         for (String className : jreTransformerFactoryClassNames) {
             try {
                 final Class<? extends TransformerFactory> clazz = Class.forName(className).asSubclass(TransformerFactory.class);
-                XSLTImplementation implementation = new XSLTImplementation("jre", true) {
+                XSLTImplementation implementation = new XSLTImplementation("jre") {
                     @Override
                     public TransformerFactory newTransformerFactory() {
                         try {
@@ -98,7 +100,19 @@ public abstract class XSLTImplementation
      * @return <code>true</code> if the XSLT implementation will invoke the methods on the
      *         {@link LexicalHandler} set on the {@link SAXResult}, <code>false</code> otherwise
      */
-    public final boolean supportsLexicalHandlerWithStreamSource() {
+    public final synchronized boolean supportsLexicalHandlerWithStreamSource() {
+        if (supportsLexicalHandlerWithStreamSource == null) {
+            StreamSource source = new StreamSource(new StringReader("<!DOCTYPE root><root><![CDATA[test]]></root>"));
+            TestContentHandler handler = new TestContentHandler();
+            SAXResult result = new SAXResult(handler);
+            result.setLexicalHandler(handler);
+            try {
+                newTransformerFactory().newTransformer().transform(source, result);
+            } catch (TransformerException ex) {
+                throw new RuntimeException(ex);
+            }
+            supportsLexicalHandlerWithStreamSource = handler.getLexicalEventsReceived() == 4;
+        }
         return supportsLexicalHandlerWithStreamSource;
     }
 }

Added: webservices/axiom/trunk/testing/jaxp-testsuite/src/test/java/org/apache/axiom/ts/jaxp/XSLTImplementationTest.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/testing/jaxp-testsuite/src/test/java/org/apache/axiom/ts/jaxp/XSLTImplementationTest.java?rev=1797581&view=auto
==============================================================================
--- webservices/axiom/trunk/testing/jaxp-testsuite/src/test/java/org/apache/axiom/ts/jaxp/XSLTImplementationTest.java (added)
+++ webservices/axiom/trunk/testing/jaxp-testsuite/src/test/java/org/apache/axiom/ts/jaxp/XSLTImplementationTest.java Sun Jun  4 14:08:59 2017
@@ -0,0 +1,31 @@
+/*
+ * 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.axiom.ts.jaxp;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import org.junit.Test;
+
+public class XSLTImplementationTest {
+    @Test
+    public void testSupportsLexicalHandlerWithStreamSource() {
+        assertThat(XSLTImplementation.SAXON.supportsLexicalHandlerWithStreamSource()).isFalse();
+        assertThat(XSLTImplementation.XALAN.supportsLexicalHandlerWithStreamSource()).isTrue();
+    }
+}

Propchange: webservices/axiom/trunk/testing/jaxp-testsuite/src/test/java/org/apache/axiom/ts/jaxp/XSLTImplementationTest.java
------------------------------------------------------------------------------
    svn:eol-style = native