jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r997955 - in /jackrabbit/trunk: jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/ jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/version/report/ jackrabbit-jcr-server/src/main/java/org/apache/jackra...
Date Thu, 16 Sep 2010 23:59:38 GMT
Author: jukka
Date: Thu Sep 16 23:59:38 2010
New Revision: 997955

URL: http://svn.apache.org/viewvc?rev=997955&view=rev
Log:
JCR-2638: Litmus locks test failures

Consolidate duplicate code to the new DomUtil.createDocument() and .parseDocument() methods,
and use an explicit error handler instance to prevent system out prints by parser libraries
like Xerces.

Modified:
    jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/DefaultItemCollection.java
    jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/DefaultItemResource.java
    jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/version/report/ExportViewReport.java
    jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/simple/ResourceConfig.java
    jackrabbit/trunk/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/ExceptionConverter.java
    jackrabbit/trunk/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/RepositoryServiceImpl.java
    jackrabbit/trunk/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2davex/QValueFactoryImpl.java
    jackrabbit/trunk/jackrabbit-webdav/src/main/java/org/apache/jackrabbit/webdav/WebdavRequestImpl.java
    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/BaselineControlMethod.java
    jackrabbit/trunk/jackrabbit-webdav/src/main/java/org/apache/jackrabbit/webdav/client/methods/DavMethodBase.java
    jackrabbit/trunk/jackrabbit-webdav/src/main/java/org/apache/jackrabbit/webdav/client/methods/PropFindMethod.java
    jackrabbit/trunk/jackrabbit-webdav/src/main/java/org/apache/jackrabbit/webdav/client/methods/PropPatchMethod.java
    jackrabbit/trunk/jackrabbit-webdav/src/main/java/org/apache/jackrabbit/webdav/xml/DomUtil.java
    jackrabbit/trunk/jackrabbit-webdav/src/test/java/org/apache/jackrabbit/webdav/lock/ActiveLockTest.java

Modified: jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/DefaultItemCollection.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/DefaultItemCollection.java?rev=997955&r1=997954&r2=997955&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/DefaultItemCollection.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/DefaultItemCollection.java
Thu Sep 16 23:59:38 2010
@@ -1000,7 +1000,7 @@ public class DefaultItemCollection exten
     private ValuesProperty buildValuesProperty(InputStream in) {
         String errorMsg = "Cannot parse stream into a 'ValuesProperty'.";
         try {
-            Document reqBody = DomUtil.BUILDER_FACTORY.newDocumentBuilder().parse(in);
+            Document reqBody = DomUtil.parseDocument(in);
             DavProperty<?> defaultProp = DefaultDavProperty.createFromXml(reqBody.getDocumentElement());
             ValuesProperty vp = new ValuesProperty(defaultProp, PropertyType.STRING, getRepositorySession().getValueFactory());
             return vp;

Modified: jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/DefaultItemResource.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/DefaultItemResource.java?rev=997955&r1=997954&r2=997955&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/DefaultItemResource.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/DefaultItemResource.java
Thu Sep 16 23:59:38 2010
@@ -136,8 +136,7 @@ public class DefaultItemResource extends
 
     private void spoolMultiValued(OutputStream out) {
         try {
-            Document doc =
-                DomUtil.BUILDER_FACTORY.newDocumentBuilder().newDocument();
+            Document doc = DomUtil.createDocument();
             doc.appendChild(getProperty(JCR_VALUES).toXml(doc));
 
             ContentHandler handler =

Modified: jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/version/report/ExportViewReport.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/version/report/ExportViewReport.java?rev=997955&r1=997954&r2=997955&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/version/report/ExportViewReport.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/version/report/ExportViewReport.java
Thu Sep 16 23:59:38 2010
@@ -138,8 +138,8 @@ public class ExportViewReport extends Ab
             }
             out.close();
 
-            InputStream in = new FileInputStream(tmpfile);
-            Document tmpDoc = DomUtil.BUILDER_FACTORY.newDocumentBuilder().parse(in);
+            Document tmpDoc =
+                DomUtil.parseDocument(new FileInputStream(tmpfile));
 
             // import the root node of the generated xml to the given document.
             Element rootElem = (Element)document.importNode(tmpDoc.getDocumentElement(),
true);

Modified: jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/simple/ResourceConfig.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/simple/ResourceConfig.java?rev=997955&r1=997954&r2=997955&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/simple/ResourceConfig.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/simple/ResourceConfig.java
Thu Sep 16 23:59:38 2010
@@ -25,7 +25,6 @@ import java.util.List;
 import javax.jcr.Item;
 import javax.jcr.Node;
 import javax.jcr.RepositoryException;
-import javax.xml.parsers.DocumentBuilder;
 import javax.xml.parsers.ParserConfigurationException;
 
 import org.apache.jackrabbit.server.io.DefaultIOManager;
@@ -39,7 +38,6 @@ import org.apache.jackrabbit.webdav.xml.
 import org.apache.tika.detect.Detector;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.xml.sax.SAXException;
 
@@ -105,9 +103,7 @@ public class ResourceConfig {
     public void parse(URL configURL) {
         try {
             InputStream in = configURL.openStream();
-            DocumentBuilder builder = DomUtil.BUILDER_FACTORY.newDocumentBuilder();
-            Document document = builder.parse(in);
-            Element config = document.getDocumentElement();
+            Element config = DomUtil.parseDocument(in).getDocumentElement();
 
             if (config == null) {
                 log.warn("Resource configuration: mandatory 'config' element is missing.");

Modified: jackrabbit/trunk/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/ExceptionConverter.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/ExceptionConverter.java?rev=997955&r1=997954&r2=997955&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/ExceptionConverter.java
(original)
+++ jackrabbit/trunk/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/ExceptionConverter.java
Thu Sep 16 23:59:38 2010
@@ -55,7 +55,7 @@ public class ExceptionConverter {
         String msg = davExc.getMessage();
         if (davExc.hasErrorCondition()) {
             try {
-                Element error = davExc.toXml(DomUtil.BUILDER_FACTORY.newDocumentBuilder().newDocument());
+                Element error = davExc.toXml(DomUtil.createDocument());
                 if (DomUtil.matches(error, DavException.XML_ERROR, DavConstants.NAMESPACE))
{
                     if (DomUtil.hasChildElement(error, "exception", null)) {
                         Element exc = DomUtil.getChildElement(error, "exception", null);

Modified: jackrabbit/trunk/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/RepositoryServiceImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/RepositoryServiceImpl.java?rev=997955&r1=997954&r2=997955&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/RepositoryServiceImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/RepositoryServiceImpl.java
Thu Sep 16 23:59:38 2010
@@ -53,7 +53,6 @@ import javax.jcr.nodetype.NoSuchNodeType
 import javax.jcr.nodetype.NodeTypeExistsException;
 import javax.jcr.query.InvalidQueryException;
 import javax.jcr.version.VersionException;
-import javax.xml.parsers.DocumentBuilder;
 import javax.xml.parsers.ParserConfigurationException;
 
 import org.apache.commons.httpclient.Header;
@@ -256,7 +255,7 @@ public class RepositoryServiceImpl imple
         this.itemInfoCacheSize = itemInfoCacheSize;
 
         try {
-            domFactory = DomUtil.BUILDER_FACTORY.newDocumentBuilder().newDocument();
+            domFactory = DomUtil.createDocument();
         } catch (ParserConfigurationException e) {
             throw new RepositoryException(e);
         }
@@ -1157,8 +1156,7 @@ public class RepositoryServiceImpl imple
 
     private QValue[] getValues(InputStream response, NamePathResolver resolver, ItemId id)
throws RepositoryException {
         try {
-            DocumentBuilder db = DomUtil.BUILDER_FACTORY.newDocumentBuilder();
-            Document doc = db.parse(response);
+            Document doc = DomUtil.parseDocument(response);
             Element prop = DomUtil.getChildElement(doc, ItemResourceConstants.JCR_VALUES.getName(),
ItemResourceConstants.JCR_VALUES.getNamespace());
             if (prop == null) {
                 // no jcr-values present in the response body -> apparently
@@ -2421,7 +2419,7 @@ public class RepositoryServiceImpl imple
                 MkColMethod method = new MkColMethod(uri);
 
                 // build 'sys-view' for the node to create and append it as request body
-                Document body = DomUtil.BUILDER_FACTORY.newDocumentBuilder().newDocument();
+                Document body = DomUtil.createDocument();
                 Element nodeElement = DomUtil.addChildElement(body, NODE_ELEMENT, SV_NAMESPACE);
                 String nameAttr = resolver.getJCRName(nodeName);
                 DomUtil.setAttribute(nodeElement, NAME_ATTRIBUTE, SV_NAMESPACE, nameAttr);

Modified: jackrabbit/trunk/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2davex/QValueFactoryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2davex/QValueFactoryImpl.java?rev=997955&r1=997954&r2=997955&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2davex/QValueFactoryImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2davex/QValueFactoryImpl.java
Thu Sep 16 23:59:38 2010
@@ -16,7 +16,6 @@
  */
 package org.apache.jackrabbit.spi2davex;
 
-
 import static org.apache.jackrabbit.webdav.DavConstants.HEADER_ETAG;
 import static org.apache.jackrabbit.webdav.DavConstants.HEADER_LAST_MODIFIED;
 
@@ -41,7 +40,6 @@ import javax.jcr.PropertyType;
 import javax.jcr.RepositoryException;
 import javax.jcr.Value;
 import javax.jcr.ValueFactory;
-import javax.xml.parsers.DocumentBuilder;
 import javax.xml.parsers.ParserConfigurationException;
 
 import java.io.ByteArrayInputStream;
@@ -550,8 +548,7 @@ class QValueFactoryImpl extends org.apac
             } else {
                 // TODO: improve. jcr-server sends XML for multivalued properties
                 try {
-                    DocumentBuilder db = DomUtil.BUILDER_FACTORY.newDocumentBuilder();
-                    Document doc = db.parse(in);
+                    Document doc = DomUtil.parseDocument(in);
                     Element prop = DomUtil.getChildElement(doc, ItemResourceConstants.JCR_VALUES.getName(),
ItemResourceConstants.JCR_VALUES.getNamespace());
                     DavProperty<?> p = DefaultDavProperty.createFromXml(prop);
                     ValuesProperty vp = new ValuesProperty(p, PropertyType.BINARY, vf);

Modified: jackrabbit/trunk/jackrabbit-webdav/src/main/java/org/apache/jackrabbit/webdav/WebdavRequestImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-webdav/src/main/java/org/apache/jackrabbit/webdav/WebdavRequestImpl.java?rev=997955&r1=997954&r2=997955&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-webdav/src/main/java/org/apache/jackrabbit/webdav/WebdavRequestImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-webdav/src/main/java/org/apache/jackrabbit/webdav/WebdavRequestImpl.java
Thu Sep 16 23:59:38 2010
@@ -36,7 +36,6 @@ import javax.servlet.ServletInputStream;
 import javax.servlet.http.Cookie;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpSession;
-import javax.xml.parsers.DocumentBuilder;
 import javax.xml.parsers.ParserConfigurationException;
 
 import org.apache.jackrabbit.webdav.bind.BindInfo;
@@ -300,8 +299,7 @@ public class WebdavRequestImpl implement
                 boolean isEmpty = -1 == bin.read();
                 bin.reset();
                 if (!isEmpty) {
-                    DocumentBuilder docBuilder = DomUtil.BUILDER_FACTORY.newDocumentBuilder();
-                    requestDocument = docBuilder.parse(bin);
+                    requestDocument = DomUtil.parseDocument(bin);
                 }
             }
         } catch (IOException e) {

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=997955&r1=997954&r2=997955&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 Sep 16 23:59:38 2010
@@ -141,11 +141,11 @@ public class WebdavResponseImpl implemen
         if (serializable != null) {
             ByteArrayOutputStream out = new ByteArrayOutputStream();
             try {
-                Document doc = DomUtil.BUILDER_FACTORY.newDocumentBuilder().newDocument();
+                Document doc = DomUtil.createDocument();
                 doc.appendChild(serializable.toXml(doc));
 
                 // JCR-2636: Need to use an explicit OutputStreamWriter
-                // instead of relying on the built-in UTF-8 serialisation
+                // 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);

Modified: jackrabbit/trunk/jackrabbit-webdav/src/main/java/org/apache/jackrabbit/webdav/client/methods/BaselineControlMethod.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-webdav/src/main/java/org/apache/jackrabbit/webdav/client/methods/BaselineControlMethod.java?rev=997955&r1=997954&r2=997955&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-webdav/src/main/java/org/apache/jackrabbit/webdav/client/methods/BaselineControlMethod.java
(original)
+++ jackrabbit/trunk/jackrabbit-webdav/src/main/java/org/apache/jackrabbit/webdav/client/methods/BaselineControlMethod.java
Thu Sep 16 23:59:38 2010
@@ -45,7 +45,7 @@ public class BaselineControlMethod exten
             // build the request body
             try {
                 // create the document and attach the root element
-                Document document = BUILDER_FACTORY.newDocumentBuilder().newDocument();
+                Document document = DomUtil.createDocument();
                 Element el = DomUtil.addChildElement(document, "baseline-control", DeltaVConstants.NAMESPACE);
                 el.appendChild(DomUtil.hrefToXml(baselineHref, document));
                 // set the request body

Modified: jackrabbit/trunk/jackrabbit-webdav/src/main/java/org/apache/jackrabbit/webdav/client/methods/DavMethodBase.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-webdav/src/main/java/org/apache/jackrabbit/webdav/client/methods/DavMethodBase.java?rev=997955&r1=997954&r2=997955&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-webdav/src/main/java/org/apache/jackrabbit/webdav/client/methods/DavMethodBase.java
(original)
+++ jackrabbit/trunk/jackrabbit-webdav/src/main/java/org/apache/jackrabbit/webdav/client/methods/DavMethodBase.java
Thu Sep 16 23:59:38 2010
@@ -34,10 +34,7 @@ import org.slf4j.LoggerFactory;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.xml.sax.SAXException;
-import org.xml.sax.helpers.DefaultHandler;
 
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.parsers.ParserConfigurationException;
 import java.io.IOException;
 import java.io.InputStream;
@@ -49,8 +46,6 @@ public abstract class DavMethodBase exte
 
     private static Logger log = LoggerFactory.getLogger(DavMethodBase.class);
 
-    static final DocumentBuilderFactory BUILDER_FACTORY = DomUtil.BUILDER_FACTORY;
-
     private boolean success;
     private Document responseDocument;
     private MultiStatus multiStatus;
@@ -115,10 +110,7 @@ public abstract class DavMethodBase exte
         if (in != null) {
             // read response and try to build a xml document
             try {
-                DocumentBuilder docBuilder = BUILDER_FACTORY.newDocumentBuilder();
-                docBuilder.setErrorHandler(new DefaultHandler());
-                responseDocument = docBuilder.parse(in);
-                return responseDocument;
+                return DomUtil.parseDocument(in);
             } catch (ParserConfigurationException e) {
                 IOException exception =
                     new IOException("XML parser configuration error");
@@ -208,7 +200,7 @@ public abstract class DavMethodBase exte
      */
     public void setRequestBody(XmlSerializable requestBody) throws IOException {
         try {
-            Document doc = BUILDER_FACTORY.newDocumentBuilder().newDocument();
+            Document doc = DomUtil.createDocument();
             doc.appendChild(requestBody.toXml(doc));
             setRequestBody(doc);
         } catch (ParserConfigurationException e) {

Modified: jackrabbit/trunk/jackrabbit-webdav/src/main/java/org/apache/jackrabbit/webdav/client/methods/PropFindMethod.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-webdav/src/main/java/org/apache/jackrabbit/webdav/client/methods/PropFindMethod.java?rev=997955&r1=997954&r2=997955&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-webdav/src/main/java/org/apache/jackrabbit/webdav/client/methods/PropFindMethod.java
(original)
+++ jackrabbit/trunk/jackrabbit-webdav/src/main/java/org/apache/jackrabbit/webdav/client/methods/PropFindMethod.java
Thu Sep 16 23:59:38 2010
@@ -79,7 +79,7 @@ public class PropFindMethod extends DavM
         // build the request body
         try {
             // create the document and attach the root element
-            Document document = BUILDER_FACTORY.newDocumentBuilder().newDocument();
+            Document document = DomUtil.createDocument();
             Element propfind = DomUtil.createElement(document, XML_PROPFIND, NAMESPACE);
             document.appendChild(propfind);
 

Modified: jackrabbit/trunk/jackrabbit-webdav/src/main/java/org/apache/jackrabbit/webdav/client/methods/PropPatchMethod.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-webdav/src/main/java/org/apache/jackrabbit/webdav/client/methods/PropPatchMethod.java?rev=997955&r1=997954&r2=997955&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-webdav/src/main/java/org/apache/jackrabbit/webdav/client/methods/PropPatchMethod.java
(original)
+++ jackrabbit/trunk/jackrabbit-webdav/src/main/java/org/apache/jackrabbit/webdav/client/methods/PropPatchMethod.java
Thu Sep 16 23:59:38 2010
@@ -65,7 +65,7 @@ public class PropPatchMethod extends Dav
             throw new IllegalArgumentException("PROPPATCH cannot be executed without properties
to be set or removed.");
         }
         try {
-            Document document = BUILDER_FACTORY.newDocumentBuilder().newDocument();
+            Document document = DomUtil.createDocument();
             Element propUpdateElement = DomUtil.addChildElement(document, XML_PROPERTYUPDATE,
NAMESPACE);
 
             Element propElement = null;
@@ -115,7 +115,7 @@ public class PropPatchMethod extends Dav
         }
 
         try {
-            Document document = BUILDER_FACTORY.newDocumentBuilder().newDocument();
+            Document document = DomUtil.createDocument();
             Element propupdate = DomUtil.addChildElement(document, XML_PROPERTYUPDATE, NAMESPACE);
             // DAV:set
             if (!setProperties.isEmpty()) {

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=997955&r1=997954&r2=997955&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 Sep 16 23:59:38 2010
@@ -27,8 +27,16 @@ import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
 import org.w3c.dom.Text;
 import org.w3c.dom.NamedNodeMap;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.DefaultHandler;
 
+import javax.xml.XMLConstants;
+import javax.xml.parsers.DocumentBuilder;
 import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+import java.io.IOException;
+import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -41,14 +49,53 @@ public class DomUtil {
 
     /**
      * Constant for <code>DocumentBuilderFactory</code> which is used
-     * widely to create new <code>Document</code>s
+     * to create and parse DOM documents.
+     */
+    private static DocumentBuilderFactory BUILDER_FACTORY = createFactory();
+
+    private static DocumentBuilderFactory createFactory() {
+        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+        factory.setNamespaceAware(true);
+        factory.setIgnoringComments(true);
+        factory.setIgnoringElementContentWhitespace(true);
+        factory.setCoalescing(true);
+        try {
+            factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
+        } catch (ParserConfigurationException e) {
+            log.warn("Secure XML processing is not supported", e);
+        }
+        return factory;
+    }
+
+    /**
+     * Creates and returns a new empty DOM document.
+     *
+     * @return new DOM document
+     * @throws ParserConfigurationException if the document can not be created
      */
-    public static DocumentBuilderFactory BUILDER_FACTORY = DocumentBuilderFactory.newInstance();
-    static {
-        BUILDER_FACTORY.setNamespaceAware(true);
-        BUILDER_FACTORY.setIgnoringComments(true);
-        BUILDER_FACTORY.setIgnoringElementContentWhitespace(true);
-        BUILDER_FACTORY.setCoalescing(true);
+    public static Document createDocument()
+            throws ParserConfigurationException {
+        return BUILDER_FACTORY.newDocumentBuilder().newDocument();
+    }
+
+    /**
+     * Parses the given input stream and returns the resulting DOM document.
+     *
+     * @param input XML input stream
+     * @return parsed DOM document
+     * @throws ParserConfigurationException if the document can not be created
+     * @throws SAXException if the document can not be parsed
+     * @throws IOException if the input stream can not be read
+     */
+    public static Document parseDocument(InputStream stream)
+            throws ParserConfigurationException, SAXException, IOException {
+        DocumentBuilder docBuilder = BUILDER_FACTORY.newDocumentBuilder();
+
+        // Set an error handler to prevent parsers like Xerces
+        // from printing error messages to standard output!
+        docBuilder.setErrorHandler(new DefaultHandler());
+
+        return docBuilder.parse(stream);
     }
 
     /**

Modified: jackrabbit/trunk/jackrabbit-webdav/src/test/java/org/apache/jackrabbit/webdav/lock/ActiveLockTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-webdav/src/test/java/org/apache/jackrabbit/webdav/lock/ActiveLockTest.java?rev=997955&r1=997954&r2=997955&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-webdav/src/test/java/org/apache/jackrabbit/webdav/lock/ActiveLockTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-webdav/src/test/java/org/apache/jackrabbit/webdav/lock/ActiveLockTest.java
Thu Sep 16 23:59:38 2010
@@ -43,7 +43,7 @@ public class ActiveLockTest extends Test
     }
 
     public void testParsing() throws ParserConfigurationException {
-        Document doc = DomUtil.BUILDER_FACTORY.newDocumentBuilder().newDocument();
+        Document doc = DomUtil.createDocument();
 
         ActiveLock lock = new DefaultActiveLock();
         lock.setLockroot("lockroot");



Mime
View raw message