cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bimargul...@apache.org
Subject svn commit: r639325 - /incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/TunedDocumentLoader.java
Date Thu, 20 Mar 2008 15:46:49 GMT
Author: bimargulies
Date: Thu Mar 20 08:46:48 2008
New Revision: 639325

URL: http://svn.apache.org/viewvc?rev=639325&view=rev
Log:
Stax with a more compatible SAX interface, and very slightly speedier, to boot.

Modified:
    incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/TunedDocumentLoader.java

Modified: incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/TunedDocumentLoader.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/TunedDocumentLoader.java?rev=639325&r1=639324&r2=639325&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/TunedDocumentLoader.java
(original)
+++ incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/TunedDocumentLoader.java
Thu Mar 20 08:46:48 2008
@@ -21,12 +21,9 @@
 
 import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.stream.Location;
-import javax.xml.stream.XMLInputFactory;
-import javax.xml.stream.XMLReporter;
-import javax.xml.stream.XMLResolver;
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamReader;
+import javax.xml.parsers.SAXParser;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMResult;
 import javax.xml.transform.sax.SAXSource;
 
 import org.w3c.dom.Document;
@@ -34,92 +31,45 @@
 import org.xml.sax.EntityResolver;
 import org.xml.sax.ErrorHandler;
 import org.xml.sax.InputSource;
-import org.xml.sax.SAXException;
-import org.xml.sax.SAXParseException;
-import org.xml.sax.ext.EntityResolver2;
+import org.xml.sax.XMLReader;
 
-import org.apache.cxf.staxutils.StaxUtils;
-import org.apache.cxf.staxutils.W3CDOMStreamWriter;
+import com.ctc.wstx.sax.WstxSAXParserFactory;
+
+import org.apache.cxf.helpers.XMLUtils;
 import org.springframework.beans.factory.xml.DefaultDocumentLoader;
 import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
 
+
+
 /**
- * 
+ * A Spring DocumentLoader that uses WoodStox when we are not validating to speed up the
process. 
  */
-public class TunedDocumentLoader extends DefaultDocumentLoader {
+class TunedDocumentLoader extends DefaultDocumentLoader {
+    
+    private TransformerFactory transformerFactory;
+    
+    TunedDocumentLoader() {
+        transformerFactory = TransformerFactory.newInstance();
+    }
 
     @Override
     public Document loadDocument(InputSource inputSource, EntityResolver entityResolver,
                                  ErrorHandler errorHandler, int validationMode, boolean namespaceAware)
         throws Exception {
         if (validationMode == XmlBeanDefinitionReader.VALIDATION_NONE) {
-
-            final EntityResolver finalResolver = entityResolver;
-            final ErrorHandler finalHandler = errorHandler;
-
-            W3CDOMStreamWriter domStreamWriter = new W3CDOMStreamWriter();
-
-            final XMLInputFactory inputFactory = StaxUtils.createXMLInputFactory(namespaceAware);
-            inputFactory.setXMLReporter(new XMLReporter() {
-
-                public void report(String message, String errorType, Object relatedInformation,
-                                   Location location) throws XMLStreamException {
-                    final Location finalLocation = location;
-                    org.xml.sax.Locator saxLocator = new org.xml.sax.Locator() {
-
-                        public int getColumnNumber() {
-                            return finalLocation.getColumnNumber();
-                        }
-
-                        public int getLineNumber() {
-                            return finalLocation.getLineNumber();
-                        }
-
-                        public String getPublicId() {
-                            return finalLocation.getPublicId();
-                        }
-
-                        public String getSystemId() {
-                            return finalLocation.getSystemId();
-                        }
-                    };
-
-                    try {
-                        finalHandler.error(new SAXParseException(message, saxLocator));
-                    } catch (SAXException e) {
-                        // this is not what we want, but
-                        // I don't see how to get it right.
-                        throw new XMLStreamException(e);
-                    }
-                }
-            });
-
-            inputFactory.setXMLResolver(new XMLResolver() {
-
-                public Object resolveEntity(String publicID, 
-                                            String systemID, String baseURI, String namespace)
-                    throws XMLStreamException {
-                    try {
-                        if (finalResolver instanceof EntityResolver2) {
-                            EntityResolver2 er2 = (EntityResolver2)finalResolver;
-
-                            InputSource entitySource = er2
-                                .resolveEntity("[dtd]", publicID, baseURI, systemID);
-                            return inputFactory.createXMLStreamReader(new SAXSource(entitySource));
-                        } else {
-                            InputSource entitySource = finalResolver.resolveEntity(publicID,
systemID);
-                            return inputFactory.createXMLStreamReader(new SAXSource(entitySource));
-                        }
-                    } catch (Exception e) {
-                        throw new XMLStreamException(e);
-                    }
-                }
-            });
-
-            SAXSource saxSource = new SAXSource(inputSource);
-            XMLStreamReader reader = inputFactory.createXMLStreamReader(saxSource);
-            StaxUtils.copy(reader, domStreamWriter);
-            return domStreamWriter.getDocument();
+            WstxSAXParserFactory woodstoxParserFactory;
+            woodstoxParserFactory = new WstxSAXParserFactory();
+            woodstoxParserFactory.setFeature("http://xml.org/sax/features/namespace-prefixes",

+                                             namespaceAware);
+            SAXParser parser = woodstoxParserFactory.newSAXParser();
+            XMLReader reader = parser.getXMLReader();
+            reader.setEntityResolver(entityResolver);
+            reader.setErrorHandler(errorHandler);
+            SAXSource saxSource = new SAXSource(reader, inputSource);
+            Document document = XMLUtils.newDocument();
+            DOMResult domResult = new DOMResult(document, inputSource.getSystemId());
+            transformerFactory.newTransformer().transform(saxSource, domResult);
+            return document;
         } else {
             return super.loadDocument(inputSource, entityResolver, errorHandler, validationMode,
                                       namespaceAware);



Mime
View raw message