jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r516427 - in /jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api: AbstractImportXmlTest.java SerializationTest.java
Date Fri, 09 Mar 2007 15:15:15 GMT
Author: mreutegg
Date: Fri Mar  9 07:15:14 2007
New Revision: 516427

URL: http://svn.apache.org/viewvc?view=rev&rev=516427
Log:
JCR-783: TCK: SerializationTest.helpTestSaxException casts ContentHandler to DefaultHandler

Modified:
    jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/AbstractImportXmlTest.java
    jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/SerializationTest.java

Modified: jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/AbstractImportXmlTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/AbstractImportXmlTest.java?view=diff&rev=516427&r1=516426&r2=516427
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/AbstractImportXmlTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/AbstractImportXmlTest.java
Fri Mar  9 07:15:14 2007
@@ -24,7 +24,8 @@
 import org.xml.sax.ContentHandler;
 import org.xml.sax.SAXException;
 import org.xml.sax.InputSource;
-import org.xml.sax.helpers.DefaultHandler;
+import org.xml.sax.XMLReader;
+import org.xml.sax.helpers.XMLReaderFactory;
 
 import javax.jcr.nodetype.NodeTypeManager;
 import javax.jcr.nodetype.NoSuchNodeTypeException;
@@ -37,9 +38,6 @@
 import javax.jcr.PathNotFoundException;
 import javax.xml.parsers.DocumentBuilder;
 import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.parsers.SAXParser;
-import javax.xml.parsers.SAXParserFactory;
 import javax.xml.transform.OutputKeys;
 import javax.xml.transform.Result;
 import javax.xml.transform.Source;
@@ -259,13 +257,12 @@
             handler = session.getImportContentHandler(absPath, uuidBehaviour);
         }
 
-        SAXParserFactory factory = SAXParserFactory.newInstance();
-        factory.setNamespaceAware(true);
-        factory.setFeature(
-                "http://xml.org/sax/features/namespace-prefixes", false);
+        XMLReader reader = XMLReaderFactory.createXMLReader();
+        reader.setFeature("http://xml.org/sax/features/namespaces", true);
+        reader.setFeature("http://xml.org/sax/features/namespace-prefixes", false);
 
-        SAXParser parser = factory.newSAXParser();
-        parser.parse(new InputSource(bin), (DefaultHandler) handler);
+        reader.setContentHandler(handler);
+        reader.parse(new InputSource(bin));
 
         if (!withWorkspace) {
             session.save();

Modified: jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/SerializationTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/SerializationTest.java?view=diff&rev=516427&r1=516426&r2=516427
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/SerializationTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/SerializationTest.java
Fri Mar  9 07:15:14 2007
@@ -21,7 +21,8 @@
 import org.xml.sax.ContentHandler;
 import org.xml.sax.InputSource;
 import org.xml.sax.SAXException;
-import org.xml.sax.helpers.DefaultHandler;
+import org.xml.sax.XMLReader;
+import org.xml.sax.helpers.XMLReaderFactory;
 
 import javax.jcr.ImportUUIDBehavior;
 import javax.jcr.InvalidSerializedDataException;
@@ -36,8 +37,6 @@
 import javax.jcr.lock.LockException;
 import javax.jcr.version.VersionException;
 import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.parsers.SAXParser;
-import javax.xml.parsers.SAXParserFactory;
 
 import java.io.ByteArrayInputStream;
 import java.io.File;
@@ -191,7 +190,6 @@
      */
     public void doTestLockException(boolean useWorkspace, boolean useHandler)
             throws Exception {
-        Repository repository = session.getRepository();
         exportRepository(SKIPBINARY, RECURSE);
         if (isSupported(Repository.OPTION_LOCKING_SUPPORTED)) {
             //A LockException is thrown if a lock prevents the addition of the subtree.
@@ -262,15 +260,9 @@
      * @param in
      */
     private void helpTestSaxException(ContentHandler ih, Reader in, String mode)
-            throws IOException, ParserConfigurationException {
+            throws IOException {
         try {
-            SAXParserFactory factory = SAXParserFactory.newInstance();
-            factory.setNamespaceAware(true);
-            factory.setFeature(
-                    "http://xml.org/sax/features/namespace-prefixes", false);
-
-            SAXParser parser = factory.newSAXParser();
-            parser.parse(new InputSource(in), (DefaultHandler) ih);
+            createXMLReader(ih).parse(new InputSource(in));
             fail("Parsing an invalid XML file with via " + mode + " ContentHandler did not
throw a SAXException.");
         } catch (SAXException e) {
             // success
@@ -556,18 +548,12 @@
     public void doImport(String absPath, FileInputStream in, boolean useWorkspace, boolean
useHandler)
             throws Exception {
         if (useHandler) {
-            SAXParserFactory factory = SAXParserFactory.newInstance();
-            factory.setNamespaceAware(true);
-            factory.setFeature(
-                    "http://xml.org/sax/features/namespace-prefixes", false);
-
-            SAXParser parser = factory.newSAXParser();
             if (useWorkspace) {
                 ContentHandler ih = workspace.getImportContentHandler(absPath, 0);
-                parser.parse(new InputSource(in), (DefaultHandler) ih);
+                createXMLReader(ih).parse(new InputSource(in));
             } else {
                 ContentHandler ih = session.getImportContentHandler(absPath, 0);
-                parser.parse(new InputSource(in), (DefaultHandler) ih);
+                createXMLReader(ih).parse(new InputSource(in));
                 session.save();
             }
         } else {
@@ -583,14 +569,8 @@
     public void doImportNoSave(String absPath, FileInputStream in, boolean useHandler)
             throws Exception {
         if (useHandler) {
-            SAXParserFactory factory = SAXParserFactory.newInstance();
-            factory.setNamespaceAware(true);
-            factory.setFeature(
-                    "http://xml.org/sax/features/namespace-prefixes", false);
-
-            SAXParser parser = factory.newSAXParser();
             ContentHandler ih = session.getImportContentHandler(absPath, 0);
-            parser.parse(new InputSource(in), (DefaultHandler) ih);
+            createXMLReader(ih).parse(new InputSource(in));
         } else {
             session.importXML(absPath, in, ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW);
         }
@@ -715,19 +695,13 @@
         FileInputStream in = new FileInputStream(file);
         try {
             if (useHandler) {
-                SAXParserFactory factory = SAXParserFactory.newInstance();
-                factory.setNamespaceAware(true);
-                factory.setFeature(
-                        "http://xml.org/sax/features/namespace-prefixes", false);
-
-                SAXParser parser = factory.newSAXParser();
                 if (workspace) {
                     ContentHandler ih = this.workspace.getImportContentHandler(treeComparator.targetFolder,
0);
-                    parser.parse(new InputSource(in), (DefaultHandler) ih);
+                    createXMLReader(ih).parse(new InputSource(in));
                 } else {
                     ContentHandler ih = session.getImportContentHandler(treeComparator.targetFolder,
                             ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW);
-                    parser.parse(new InputSource(in), (DefaultHandler) ih);
+                    createXMLReader(ih).parse(new InputSource(in));
                     session.save();
                 }
             } else {
@@ -744,5 +718,20 @@
         } finally {
             in.close();
         }
+    }
+
+    /**
+     * Creates an XMLReader for the given content handler.
+     *
+     * @param handler the content handler.
+     * @return an XMLReader for the given content handler.
+     * @throws SAXException if the reader cannot be created.
+     */
+    private XMLReader createXMLReader(ContentHandler handler) throws SAXException {
+        XMLReader reader = XMLReaderFactory.createXMLReader();
+        reader.setFeature("http://xml.org/sax/features/namespaces", true);
+        reader.setFeature("http://xml.org/sax/features/namespace-prefixes", false);
+        reader.setContentHandler(handler);
+        return reader;
     }
 }



Mime
View raw message