You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-commits@xmlgraphics.apache.org by vh...@apache.org on 2011/10/20 17:38:55 UTC

svn commit: r1186858 - in /xmlgraphics/fop/trunk: ./ build.xml test/java/org/apache/fop/intermediate/AbstractIFTestCase.java test/java/org/apache/fop/intermediate/XMLSchemaResolver.java

Author: vhennebert
Date: Thu Oct 20 15:38:54 2011
New Revision: 1186858

URL: http://svn.apache.org/viewvc?rev=1186858&view=rev
Log:
Cache the schema for the XML namespace to a local directory. This avoids downloading it from the W3C website every time the IF test cases are run.

Added:
    xmlgraphics/fop/trunk/test/java/org/apache/fop/intermediate/XMLSchemaResolver.java   (with props)
Modified:
    xmlgraphics/fop/trunk/   (props changed)
    xmlgraphics/fop/trunk/build.xml
    xmlgraphics/fop/trunk/test/java/org/apache/fop/intermediate/AbstractIFTestCase.java

Propchange: xmlgraphics/fop/trunk/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Thu Oct 20 15:38:54 2011
@@ -7,6 +7,7 @@ checkstyle-noframes.xsl
 .externalToolBuilders
 .checkstyle
 .settings
+.cache
 dist-bin
 dist-src
 work

Modified: xmlgraphics/fop/trunk/build.xml
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/build.xml?rev=1186858&r1=1186857&r2=1186858&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/build.xml (original)
+++ xmlgraphics/fop/trunk/build.xml Thu Oct 20 15:38:54 2011
@@ -836,11 +836,29 @@ list of possible build targets.
   <target name="junit-area-tree-xml-format" depends="junit-compile" description="Runs FOP's area tree XML format JUnit tests" if="xmlunit.present">
     <junit-run title="area tree XML format" testsuite="org.apache.fop.intermediate.AreaTreeXMLFormatTestSuite" outfile="TEST-area-tree-xml-format"/>
   </target>
-  <target name="junit-intermediate-layout" depends="junit-compile" if="xmlunit.present">
-    <junit-run title="intermediate format from layout tests" testsuite="org.apache.fop.intermediate.LayoutIFTestSuite" outfile="TEST-intermediate-format-from-layout"/>
+  <target name="junit-intermediate-layout" depends="junit-compile,setup-xml-schema" 
+    if="xmlunit.present">
+    <junit-run title="intermediate format from layout tests" 
+      testsuite="org.apache.fop.intermediate.LayoutIFTestSuite" 
+      outfile="TEST-intermediate-format-from-layout"/>
+  </target>
+  <target name="setup-xml-schema">
+    <local name="cache-dir"/>
+    <property name="cache-dir" value="${basedir}/.cache/junit/intermediate"/>
+    <mkdir dir="${cache-dir}"/>
+    <get src="http://www.w3.org/2001/xml.xsd"
+      dest="${cache-dir}/xml.xsd"
+      usetimestamp="true"/>
+    <copy file="${cache-dir}/xml.xsd" 
+      todir="${build.dir}/test-classes/org/apache/fop/intermediate"/>
   </target>
-  <target name="junit-intermediate-format" depends="junit-compile,junit-intermediate-layout" description="Runs FOP's intermediate format JUnit tests" if="xmlunit.present">
-    <junit-run title="intermediate format" testsuite="org.apache.fop.intermediate.IntermediateFormatTestSuite" outfile="TEST-intermediate-format"/>
+
+  <target name="junit-intermediate-format" 
+    depends="junit-compile,setup-xml-schema,junit-intermediate-layout"
+    description="Runs FOP's intermediate format JUnit tests" if="xmlunit.present">
+    <junit-run title="intermediate format" 
+      testsuite="org.apache.fop.intermediate.IntermediateFormatTestSuite" 
+      outfile="TEST-intermediate-format"/>
   </target>
   <target name="junit-events" depends="junit-compile" description="Runs FOP's event JUnit tests" if="junit.present">
     <junit-run title="event" basedir="test/events" testsuite="org.apache.fop.events.EventProcessingTestCase" outfile="TEST-events"/>

Modified: xmlgraphics/fop/trunk/test/java/org/apache/fop/intermediate/AbstractIFTestCase.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/test/java/org/apache/fop/intermediate/AbstractIFTestCase.java?rev=1186858&r1=1186857&r2=1186858&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/test/java/org/apache/fop/intermediate/AbstractIFTestCase.java (original)
+++ xmlgraphics/fop/trunk/test/java/org/apache/fop/intermediate/AbstractIFTestCase.java Thu Oct 20 15:38:54 2011
@@ -71,6 +71,7 @@ abstract class AbstractIFTestCase extend
                 }
 
             });
+            sFactory.setResourceResolver(XMLSchemaResolver.getInstance());
             File ifSchemaFile = new File(
                 "src/documentation/intermediate-format-ng/fop-intermediate-format-ng.xsd");
             ifSchema = sFactory.newSchema(ifSchemaFile);

Added: xmlgraphics/fop/trunk/test/java/org/apache/fop/intermediate/XMLSchemaResolver.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/test/java/org/apache/fop/intermediate/XMLSchemaResolver.java?rev=1186858&view=auto
==============================================================================
--- xmlgraphics/fop/trunk/test/java/org/apache/fop/intermediate/XMLSchemaResolver.java (added)
+++ xmlgraphics/fop/trunk/test/java/org/apache/fop/intermediate/XMLSchemaResolver.java Thu Oct 20 15:38:54 2011
@@ -0,0 +1,94 @@
+/*
+ * 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.fop.intermediate;
+
+import java.io.InputStream;
+import java.util.MissingResourceException;
+
+import javax.xml.XMLConstants;
+
+import org.w3c.dom.bootstrap.DOMImplementationRegistry;
+import org.w3c.dom.ls.DOMImplementationLS;
+import org.w3c.dom.ls.LSInput;
+import org.w3c.dom.ls.LSResourceResolver;
+
+/**
+ * A resource resolver that returns a cached instance of the XML Schema, that can normally
+ * be found at {@linkplain http://www.w3.org/2001/xml.xsd}. This can be used to avoid
+ * unnecessary connection to the W3C website.
+ */
+final class XMLSchemaResolver implements LSResourceResolver {
+
+    private static final String XML_SCHEMA_SYSTEM_ID = "http://www.w3.org/2001/xml.xsd";
+
+    private static final LSInput XML_SCHEMA_INPUT;
+
+    private static final XMLSchemaResolver INSTANCE = new XMLSchemaResolver();
+
+    private XMLSchemaResolver() { }
+
+    static {
+        DOMImplementationRegistry registry = getDOMImplementationRegistry();
+        DOMImplementationLS impl
+                = (DOMImplementationLS) registry.getDOMImplementation("LS 3.0");
+        XML_SCHEMA_INPUT = impl.createLSInput();
+        InputStream xmlSchema = loadXMLSchema();
+        XML_SCHEMA_INPUT.setByteStream(xmlSchema);
+    }
+
+    private static DOMImplementationRegistry getDOMImplementationRegistry() {
+        try {
+            return DOMImplementationRegistry.newInstance();
+        } catch (ClassCastException e) {
+            throw new ExceptionInInitializerError(e);
+        } catch (ClassNotFoundException e) {
+            throw new ExceptionInInitializerError(e);
+        } catch (InstantiationException e) {
+            throw new ExceptionInInitializerError(e);
+        } catch (IllegalAccessException e) {
+            throw new ExceptionInInitializerError(e);
+        }
+    }
+
+    private static InputStream loadXMLSchema() {
+        String xmlSchemaResource = "xml.xsd";
+        InputStream xmlSchema = XMLSchemaResolver.class.getResourceAsStream(xmlSchemaResource);
+        if (xmlSchema == null) {
+            throw new MissingResourceException("Schema for XML namespace not found."
+                    + " Did you run ant junit-intermediate-format?",
+                    XMLSchemaResolver.class.getName(), xmlSchemaResource);
+        }
+        return xmlSchema;
+    }
+
+    public static XMLSchemaResolver getInstance() {
+        return INSTANCE;
+    }
+
+    public LSInput resolveResource(String type, String namespaceURI, String publicId,
+            String systemId, String baseURI) {
+        if (XMLConstants.XML_NS_URI.equals(namespaceURI) && XML_SCHEMA_SYSTEM_ID.equals(systemId)) {
+            return XML_SCHEMA_INPUT;
+        } else {
+            return null;
+        }
+    }
+
+}

Propchange: xmlgraphics/fop/trunk/test/java/org/apache/fop/intermediate/XMLSchemaResolver.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: xmlgraphics/fop/trunk/test/java/org/apache/fop/intermediate/XMLSchemaResolver.java
------------------------------------------------------------------------------
    svn:keywords = Revision Id



---------------------------------------------------------------------
To unsubscribe, e-mail: fop-commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-commits-help@xmlgraphics.apache.org