jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r1071571 - in /jackrabbit/trunk/jackrabbit-webdav/src/main/java/org/apache/jackrabbit/webdav: WebdavResponseImpl.java client/methods/XmlRequestEntity.java xml/DomUtil.java
Date Thu, 17 Feb 2011 11:03:34 GMT
Author: angela
Date: Thu Feb 17 11:03:34 2011
New Revision: 1071571

URL: http://svn.apache.org/viewvc?rev=1071571&view=rev
Log:
JCR-2896 : WebdavResponseImpl should cache TransformerFactory

Modified:
    jackrabbit/trunk/jackrabbit-webdav/src/main/java/org/apache/jackrabbit/webdav/WebdavResponseImpl.java
    jackrabbit/trunk/jackrabbit-webdav/src/main/java/org/apache/jackrabbit/webdav/client/methods/XmlRequestEntity.java
    jackrabbit/trunk/jackrabbit-webdav/src/main/java/org/apache/jackrabbit/webdav/xml/DomUtil.java

Modified: jackrabbit/trunk/jackrabbit-webdav/src/main/java/org/apache/jackrabbit/webdav/WebdavResponseImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-webdav/src/main/java/org/apache/jackrabbit/webdav/WebdavResponseImpl.java?rev=1071571&r1=1071570&r2=1071571&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-webdav/src/main/java/org/apache/jackrabbit/webdav/WebdavResponseImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-webdav/src/main/java/org/apache/jackrabbit/webdav/WebdavResponseImpl.java
Thu Feb 17 11:03:34 2011
@@ -31,18 +31,13 @@ import org.apache.jackrabbit.webdav.xml.
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.w3c.dom.Document;
-import org.xml.sax.ContentHandler;
 import org.xml.sax.SAXException;
 
 import javax.servlet.ServletOutputStream;
 import javax.servlet.http.Cookie;
 import javax.servlet.http.HttpServletResponse;
 import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.transform.Transformer;
 import javax.xml.transform.TransformerException;
-import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.dom.DOMSource;
-import javax.xml.transform.sax.SAXResult;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.OutputStreamWriter;
@@ -147,14 +142,8 @@ public class WebdavResponseImpl implemen
                 // JCR-2636: Need to use an explicit OutputStreamWriter
                 // instead of relying on the built-in UTF-8 serialization
                 // to avoid problems with surrogate pairs on Sun JRE 1.5.
-                Writer writer = new OutputStreamWriter(
-                        out, SerializingContentHandler.ENCODING);
-                ContentHandler handler =
-                    SerializingContentHandler.getSerializer(writer);
-                TransformerFactory factory = TransformerFactory.newInstance();
-                Transformer transformer = factory.newTransformer();
-                transformer.transform(
-                        new DOMSource(doc), new SAXResult(handler));
+                Writer writer = new OutputStreamWriter(out, SerializingContentHandler.ENCODING);
+                DomUtil.transformDocument(doc, writer);
                 writer.flush();
 
                 // TODO: Should this be application/xml? See JCR-1621

Modified: jackrabbit/trunk/jackrabbit-webdav/src/main/java/org/apache/jackrabbit/webdav/client/methods/XmlRequestEntity.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-webdav/src/main/java/org/apache/jackrabbit/webdav/client/methods/XmlRequestEntity.java?rev=1071571&r1=1071570&r2=1071571&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-webdav/src/main/java/org/apache/jackrabbit/webdav/client/methods/XmlRequestEntity.java
(original)
+++ jackrabbit/trunk/jackrabbit-webdav/src/main/java/org/apache/jackrabbit/webdav/client/methods/XmlRequestEntity.java
Thu Feb 17 11:03:34 2011
@@ -20,18 +20,14 @@ import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.OutputStream;
 
-import javax.xml.transform.Transformer;
 import javax.xml.transform.TransformerException;
-import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.dom.DOMSource;
-import javax.xml.transform.sax.SAXResult;
 
 import org.apache.commons.httpclient.methods.RequestEntity;
 import org.apache.jackrabbit.commons.xml.SerializingContentHandler;
+import org.apache.jackrabbit.webdav.xml.DomUtil;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.w3c.dom.Document;
-import org.xml.sax.ContentHandler;
 import org.xml.sax.SAXException;
 
 /**
@@ -45,12 +41,7 @@ public class XmlRequestEntity implements
 
     public XmlRequestEntity(Document xmlDocument) throws IOException {
         try {
-            ContentHandler handler =
-                SerializingContentHandler.getSerializer(xml);
-            TransformerFactory factory = TransformerFactory.newInstance();
-            Transformer transformer = factory.newTransformer();
-            transformer.transform(
-                    new DOMSource(xmlDocument), new SAXResult(handler));
+            DomUtil.transformDocument(xmlDocument, xml);
         } catch (TransformerException e) {
             log.error(e.getMessage());
             throw new IOException(e.getMessage());

Modified: jackrabbit/trunk/jackrabbit-webdav/src/main/java/org/apache/jackrabbit/webdav/xml/DomUtil.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-webdav/src/main/java/org/apache/jackrabbit/webdav/xml/DomUtil.java?rev=1071571&r1=1071570&r2=1071571&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-webdav/src/main/java/org/apache/jackrabbit/webdav/xml/DomUtil.java
(original)
+++ jackrabbit/trunk/jackrabbit-webdav/src/main/java/org/apache/jackrabbit/webdav/xml/DomUtil.java
Thu Feb 17 11:03:34 2011
@@ -16,6 +16,7 @@
  */
 package org.apache.jackrabbit.webdav.xml;
 
+import org.apache.jackrabbit.commons.xml.SerializingContentHandler;
 import org.apache.jackrabbit.webdav.DavConstants;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -34,9 +35,19 @@ import javax.xml.XMLConstants;
 import javax.xml.parsers.DocumentBuilder;
 import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.Result;
+import javax.xml.transform.Source;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.sax.SAXResult;
+import javax.xml.transform.stream.StreamResult;
 
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.Writer;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -68,6 +79,11 @@ public class DomUtil {
     }
 
     /**
+     * Transformer factory
+     */
+    private static TransformerFactory TRANSFORMER_FACTORY = TransformerFactory.newInstance();
+
+    /**
      * Creates and returns a new empty DOM document.
      *
      * @return new DOM document
@@ -704,4 +720,47 @@ public class DomUtil {
         buf.append(localName);
         return buf.toString();
     }
+
+    /**
+     * Uses a new Transformer instance to transform the specified xml document
+     * to the specified writer output target.
+     *
+     * @param xmlDoc XML document to create the transformation
+     * <code>Source</code> for.
+     * @param writer The writer used to create a new transformation
+     * <code>Result </code>for.
+     * @throws TransformerException
+     */
+    public static void transformDocument(Document xmlDoc, Writer writer) throws TransformerException,
SAXException {
+        Transformer transformer = TRANSFORMER_FACTORY.newTransformer();
+        transformer.transform(new DOMSource(xmlDoc), new SAXResult(SerializingContentHandler.getSerializer(new
StreamResult(writer))));
+    }
+
+    /**
+     * Uses a new Transformer instance to transform the specified xml document
+     * to the specified writer output target.
+     *
+     * @param xmlDoc XML document to create the transformation
+     * <code>Source</code> for.
+     * @param out The stream used to create a new transformation
+     * <code>Result </code>for.
+     * @throws TransformerException
+     */
+    public static void transformDocument(Document xmlDoc, OutputStream out) throws TransformerException,
SAXException {
+        Transformer transformer = TRANSFORMER_FACTORY.newTransformer();
+        transformer.transform(new DOMSource(xmlDoc), new SAXResult(SerializingContentHandler.getSerializer(new
StreamResult(out))));
+    }
+
+    /**
+     * Uses a new Transformer instance to transform the given source to the
+     * specified result.
+     *
+     * @param source the transformation source.
+     * @param result the transformation result.
+     * @throws TransformerException
+     */
+    private static void transformDocument(Source source, Result result) throws TransformerException
{
+        Transformer transformer = TRANSFORMER_FACTORY.newTransformer();
+        transformer.transform(source, result);
+    }
 }



Mime
View raw message