jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r616076 - in /jackrabbit/trunk/jackrabbit-jcr-commons/src: main/java/org/apache/jackrabbit/commons/xml/ test/java/org/apache/jackrabbit/commons/xml/
Date Mon, 28 Jan 2008 22:00:22 GMT
Author: jukka
Date: Mon Jan 28 14:00:20 2008
New Revision: 616076

URL: http://svn.apache.org/viewvc?rev=616076&view=rev
Log:
JCR-1350: Add a serializing content handler
    - Added utility methods to SerializingContentHandler

Modified:
    jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/xml/SerializingContentHandler.java
    jackrabbit/trunk/jackrabbit-jcr-commons/src/test/java/org/apache/jackrabbit/commons/xml/ParsingContentHandlerTest.java
    jackrabbit/trunk/jackrabbit-jcr-commons/src/test/java/org/apache/jackrabbit/commons/xml/SerializingContentHandlerTest.java

Modified: jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/xml/SerializingContentHandler.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/xml/SerializingContentHandler.java?rev=616076&r1=616075&r2=616076&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/xml/SerializingContentHandler.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/xml/SerializingContentHandler.java
Mon Jan 28 14:00:20 2008
@@ -16,7 +16,9 @@
  */
 package org.apache.jackrabbit.commons.xml;
 
+import java.io.OutputStream;
 import java.io.StringWriter;
+import java.io.Writer;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
@@ -55,6 +57,30 @@
 
     /** The URI for xml namespaces */
     private static final String XML = "http://www.w3.org/XML/1998/namespace";
+
+    /**
+     * Creates a serializing content handler that writes to the given stream.
+     *
+     * @param stream serialization target
+     * @return serializing content handler
+     * @throws SAXException if the content handler could not be initialized
+     */
+    public static DefaultHandler getSerializer(OutputStream output)
+            throws SAXException {
+        return getSerializer(new StreamResult(output));
+    }
+
+    /**
+     * Creates a serializing content handler that writes to the given writer.
+     *
+     * @param writer serialization target
+     * @return serializing content handler
+     * @throws SAXException if the content handler could not be initialized
+     */
+    public static DefaultHandler getSerializer(Writer writer)
+            throws SAXException {
+        return getSerializer(new StreamResult(writer));
+    }
 
     /**
      * Creates a serializing content handler that writes to the given result.

Modified: jackrabbit/trunk/jackrabbit-jcr-commons/src/test/java/org/apache/jackrabbit/commons/xml/ParsingContentHandlerTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-commons/src/test/java/org/apache/jackrabbit/commons/xml/ParsingContentHandlerTest.java?rev=616076&r1=616075&r2=616076&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-commons/src/test/java/org/apache/jackrabbit/commons/xml/ParsingContentHandlerTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-commons/src/test/java/org/apache/jackrabbit/commons/xml/ParsingContentHandlerTest.java
Mon Jan 28 14:00:20 2008
@@ -19,8 +19,6 @@
 import java.io.ByteArrayInputStream;
 import java.io.StringWriter;
 
-import javax.xml.transform.stream.StreamResult;
-
 import junit.framework.TestCase;
 
 import org.xml.sax.ContentHandler;
@@ -33,7 +31,7 @@
         StringWriter writer = new StringWriter();
 
         ContentHandler handler =
-            SerializingContentHandler.getSerializer(new StreamResult(writer));
+            SerializingContentHandler.getSerializer(writer);
         new ParsingContentHandler(handler).parse(
                 new ByteArrayInputStream(source.getBytes("UTF-8")));
 

Modified: jackrabbit/trunk/jackrabbit-jcr-commons/src/test/java/org/apache/jackrabbit/commons/xml/SerializingContentHandlerTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-commons/src/test/java/org/apache/jackrabbit/commons/xml/SerializingContentHandlerTest.java?rev=616076&r1=616075&r2=616076&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-commons/src/test/java/org/apache/jackrabbit/commons/xml/SerializingContentHandlerTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-commons/src/test/java/org/apache/jackrabbit/commons/xml/SerializingContentHandlerTest.java
Mon Jan 28 14:00:20 2008
@@ -18,20 +18,18 @@
 
 import java.io.StringWriter;
 
-import javax.xml.transform.stream.StreamResult;
+import junit.framework.TestCase;
 
 import org.xml.sax.ContentHandler;
 import org.xml.sax.helpers.AttributesImpl;
 
-import junit.framework.TestCase;
-
 public class SerializingContentHandlerTest extends TestCase {
 
     public void testSerializingContentHandler() throws Exception {
         StringWriter writer = new StringWriter();
 
         ContentHandler handler =
-            SerializingContentHandler.getSerializer(new StreamResult(writer));
+            SerializingContentHandler.getSerializer(writer);
         handler.startDocument();
         handler.startPrefixMapping("p", "uri");
         handler.startElement("uri", "a", "p:a", new AttributesImpl());



Mime
View raw message