jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r659084 - in /jackrabbit/trunk/jackrabbit-webdav: ./ src/main/java/org/apache/jackrabbit/webdav/ src/main/java/org/apache/jackrabbit/webdav/client/methods/ src/main/java/org/apache/jackrabbit/webdav/xml/
Date Thu, 22 May 2008 11:51:37 GMT
Author: jukka
Date: Thu May 22 04:51:37 2008
New Revision: 659084

URL: http://svn.apache.org/viewvc?rev=659084&view=rev
Log:
JCR-1310: Webdav: Drop xerces dependency
    - Removed Xerces dependency from jackrabbit-webdav.
    - Using SerializingContentHandler from jackrabbit-jcr-commons (JCR-1350)

Modified:
    jackrabbit/trunk/jackrabbit-webdav/pom.xml
    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/pom.xml
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-webdav/pom.xml?rev=659084&r1=659083&r2=659084&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-webdav/pom.xml (original)
+++ jackrabbit/trunk/jackrabbit-webdav/pom.xml Thu May 22 04:51:37 2008
@@ -78,10 +78,6 @@
       <artifactId>slf4j-api</artifactId>
     </dependency>
     <dependency>
-      <groupId>xerces</groupId>
-      <artifactId>xercesImpl</artifactId>
-    </dependency>
-    <dependency>
       <groupId>javax.servlet</groupId>
       <artifactId>servlet-api</artifactId>
       <scope>provided</scope>

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=659084&r1=659083&r2=659084&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 May 22 04:51:37 2008
@@ -16,28 +16,33 @@
  */
 package org.apache.jackrabbit.webdav;
 
+import org.apache.jackrabbit.commons.xml.SerializingContentHandler;
+import org.apache.jackrabbit.webdav.header.CodedUrlHeader;
+import org.apache.jackrabbit.webdav.header.Header;
 import org.apache.jackrabbit.webdav.lock.ActiveLock;
 import org.apache.jackrabbit.webdav.lock.LockDiscovery;
 import org.apache.jackrabbit.webdav.observation.EventDiscovery;
+import org.apache.jackrabbit.webdav.observation.ObservationConstants;
 import org.apache.jackrabbit.webdav.observation.Subscription;
 import org.apache.jackrabbit.webdav.observation.SubscriptionDiscovery;
-import org.apache.jackrabbit.webdav.observation.ObservationConstants;
 import org.apache.jackrabbit.webdav.property.DavPropertySet;
-import org.apache.jackrabbit.webdav.xml.XmlSerializable;
 import org.apache.jackrabbit.webdav.xml.DomUtil;
-import org.apache.jackrabbit.webdav.header.CodedUrlHeader;
-import org.apache.jackrabbit.webdav.header.Header;
-import org.apache.xml.serialize.OutputFormat;
-import org.apache.xml.serialize.XMLSerializer;
+import org.apache.jackrabbit.webdav.xml.XmlSerializable;
 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.PrintWriter;
@@ -146,25 +151,33 @@
      */
     public void sendXmlResponse(XmlSerializable serializable, int status) throws IOException
{
         httpResponse.setStatus(status);
+
         if (serializable != null) {
             ByteArrayOutputStream out = new ByteArrayOutputStream();
             try {
                 Document doc = DomUtil.BUILDER_FACTORY.newDocumentBuilder().newDocument();
                 doc.appendChild(serializable.toXml(doc));
 
-                OutputFormat format = new OutputFormat("xml", "UTF-8", false);
-                XMLSerializer serializer = new XMLSerializer(out, format);
-                serializer.setNamespaces(true);
-                serializer.asDOMSerializer().serialize(doc);
-
-                byte[] bytes = out.toByteArray();
-                httpResponse.setContentType("text/xml; charset=UTF-8");
-                httpResponse.setContentLength(bytes.length);
-                httpResponse.getOutputStream().write(bytes);
-
+                ContentHandler handler =
+                    SerializingContentHandler.getSerializer(out);
+                TransformerFactory factory = TransformerFactory.newInstance();
+                Transformer transformer = factory.newTransformer();
+                transformer.transform(
+                        new DOMSource(doc), new SAXResult(handler));
+
+                // TODO: application/xml?
+                httpResponse.setContentType("text/xml");
+                httpResponse.setContentLength(out.size());
+                out.writeTo(httpResponse.getOutputStream());
             } catch (ParserConfigurationException e) {
                 log.error(e.getMessage());
                 throw new IOException(e.getMessage());
+            } catch (TransformerException e) {
+                log.error(e.getMessage());
+                throw new IOException(e.getMessage());
+            } catch (SAXException e) {
+                log.error(e.getMessage());
+                throw new IOException(e.getMessage());
             }
         }
     }

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=659084&r1=659083&r2=659084&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 May 22 04:51:37 2008
@@ -16,17 +16,23 @@
  */
 package org.apache.jackrabbit.webdav.client.methods;
 
+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.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.apache.commons.httpclient.methods.RequestEntity;
-import org.apache.commons.httpclient.methods.StringRequestEntity;
-import org.apache.xml.serialize.OutputFormat;
-import org.apache.xml.serialize.XMLSerializer;
 import org.w3c.dom.Document;
-
-import java.io.OutputStream;
-import java.io.IOException;
-import java.io.ByteArrayOutputStream;
+import org.xml.sax.ContentHandler;
+import org.xml.sax.SAXException;
 
 /**
  * <code>XmlRequestEntity</code>...
@@ -35,31 +41,39 @@
 
     private static Logger log = LoggerFactory.getLogger(XmlRequestEntity.class);
 
-    private final RequestEntity delegatee;
+    private final ByteArrayOutputStream xml = new ByteArrayOutputStream();
 
     public XmlRequestEntity(Document xmlDocument) throws IOException {
-        super();
-        ByteArrayOutputStream out = new ByteArrayOutputStream();
-        OutputFormat format = new OutputFormat("xml", "UTF-8", false);
-        XMLSerializer serializer = new XMLSerializer(out, format);
-        serializer.setNamespaces(true);
-        serializer.asDOMSerializer().serialize(xmlDocument);
-        delegatee = new StringRequestEntity(out.toString(), "text/xml", "UTF-8");
+        try {
+            ContentHandler handler =
+                SerializingContentHandler.getSerializer(xml);
+            TransformerFactory factory = TransformerFactory.newInstance();
+            Transformer transformer = factory.newTransformer();
+            transformer.transform(
+                    new DOMSource(xmlDocument), new SAXResult(handler));
+        } catch (TransformerException e) {
+            log.error(e.getMessage());
+            throw new IOException(e.getMessage());
+        } catch (SAXException e) {
+            log.error(e.getMessage());
+            throw new IOException(e.getMessage());
+        }
     }
 
     public boolean isRepeatable() {
-        return delegatee.isRepeatable();
+        return true;
     }
 
     public String getContentType() {
-        return delegatee.getContentType();
+        return "text/xml"; // TODO: Shouldn't this be application/xml?
     }
 
     public void writeRequest(OutputStream out) throws IOException {
-        delegatee.writeRequest(out);
+        xml.writeTo(out);
     }
 
     public long getContentLength() {
-        return delegatee.getContentLength();
+        return xml.size();
     }
+
 }
\ No newline at end of file

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=659084&r1=659083&r2=659084&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 May 22 04:51:37 2008
@@ -124,7 +124,8 @@
      *
      * @param element
      * @param defaultValue
-     * @return
+     * @return the text contained in the specified element or
+     * <code>defaultValue</code> if the element does not contain any text.
      */
     public static String getText(Element element, String defaultValue) {
         String txt = getText(element);
@@ -259,11 +260,12 @@
     }
 
     /**
-     * Return true if the given parent contains any child that is either an
-     * Element, Text or CDATA.
+     * Return <code>true</code> if the given parent contains any child that is
+     * either an Element, Text or CDATA.
      *
      * @param parent
-     * @return
+     * @return <code>true</code> if the given parent contains any child that
is
+     * either an Element, Text or CDATA.
      */
     public static boolean hasContent(Node parent) {
         if (parent != null) {
@@ -282,7 +284,7 @@
      * Return a list of all child nodes that are either Element, Text or CDATA.
      *
      * @param parent
-     * @return
+     * @return a list of all child nodes that are either Element, Text or CDATA.
      */
     public static List getContent(Node parent) {
         List content = new ArrayList();
@@ -301,7 +303,7 @@
     /**
      * Build a Namespace from the prefix and uri retrieved from the given element.
      *
-     * @return
+     * @return the <code>Namespace</code> of the given element.
      */
     public static Namespace getNamespace(Element element) {
         String uri = element.getNamespaceURI();
@@ -522,6 +524,15 @@
      * @param uri
      */
     public static void setNamespaceAttribute(Element element, String prefix, String uri)
{
+        if (Namespace.EMPTY_NAMESPACE.equals(Namespace.getNamespace(prefix, uri))) {
+            /**
+             * don't try to set the empty namespace which will fail
+             * see {@link org.w3c.dom.DOMException#NAMESPACE_ERR}
+             * TODO: correct?
+             */
+            log.debug("Empty namespace -> omit attribute setting.");
+            return;
+        }
         setAttribute(element, prefix, Namespace.XMLNS_NAMESPACE, uri);
     }
 
@@ -587,7 +598,9 @@
      *
      * @param localName
      * @param namespace
-     * @return
+     * @return the qualified name of a DOM node consisting of "{" + namespace uri + "}"
+     * + localName. If the specified namespace is <code>null</code> or represents
+     * the empty namespace, the local name is returned.
      */
     public static String getQualifiedName(String localName, Namespace namespace) {
         if (namespace == null || namespace.equals(Namespace.EMPTY_NAMESPACE)) {



Mime
View raw message