You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ws.apache.org by ve...@apache.org on 2012/07/22 10:58:24 UTC
svn commit: r1364239 - in /webservices/axiom/branches/AXIOM-437/modules:
axiom-api/src/main/java/org/apache/axiom/om/
axiom-api/src/main/java/org/apache/axiom/om/impl/jaxp/
axiom-api/src/main/java/org/apache/axiom/om/impl/serialize/
axiom-api/src/test/...
Author: veithen
Date: Sun Jul 22 08:58:24 2012
New Revision: 1364239
URL: http://svn.apache.org/viewvc?rev=1364239&view=rev
Log:
Added support for DTDs to getSAXSource.
Modified:
webservices/axiom/branches/AXIOM-437/modules/axiom-api/src/main/java/org/apache/axiom/om/OMContainer.java
webservices/axiom/branches/AXIOM-437/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/jaxp/OMSource.java
webservices/axiom/branches/AXIOM-437/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/serialize/OMXMLReader.java
webservices/axiom/branches/AXIOM-437/modules/axiom-api/src/test/java/org/apache/axiom/om/AbstractTestCase.java
webservices/axiom/branches/AXIOM-437/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/container/TestGetSAXSource.java
Modified: webservices/axiom/branches/AXIOM-437/modules/axiom-api/src/main/java/org/apache/axiom/om/OMContainer.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/AXIOM-437/modules/axiom-api/src/main/java/org/apache/axiom/om/OMContainer.java?rev=1364239&r1=1364238&r2=1364239&view=diff
==============================================================================
--- webservices/axiom/branches/AXIOM-437/modules/axiom-api/src/main/java/org/apache/axiom/om/OMContainer.java (original)
+++ webservices/axiom/branches/AXIOM-437/modules/axiom-api/src/main/java/org/apache/axiom/om/OMContainer.java Sun Jul 22 08:58:24 2012
@@ -26,6 +26,8 @@ import javax.xml.transform.Transformer;
import javax.xml.transform.sax.SAXSource;
import org.xml.sax.ContentHandler;
+import org.xml.sax.DTDHandler;
+import org.xml.sax.ext.DeclHandler;
import org.xml.sax.ext.LexicalHandler;
import java.io.OutputStream;
@@ -387,8 +389,7 @@ public interface OMContainer extends OMS
* used with the {@link Transformer} API.
* <p>
* The returned object supports all events defined by {@link ContentHandler} and
- * {@link LexicalHandler}, with the exception of DTD related events. {@link OMDocType} nodes
- * will be silently skipped.
+ * {@link LexicalHandler}. {@link DTDHandler} and {@link DeclHandler} are not supported.
* <p>
* If the node is an element and has a parent which is not a document, care is taken to properly
* generate {@link ContentHandler#startPrefixMapping(String, String)} and
Modified: webservices/axiom/branches/AXIOM-437/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/jaxp/OMSource.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/AXIOM-437/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/jaxp/OMSource.java?rev=1364239&r1=1364238&r2=1364239&view=diff
==============================================================================
--- webservices/axiom/branches/AXIOM-437/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/jaxp/OMSource.java (original)
+++ webservices/axiom/branches/AXIOM-437/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/jaxp/OMSource.java Sun Jul 22 08:58:24 2012
@@ -24,15 +24,19 @@ import javax.xml.transform.sax.SAXSource
import org.apache.axiom.om.OMContainer;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.impl.serialize.OMXMLReader;
+import org.xml.sax.ContentHandler;
+import org.xml.sax.DTDHandler;
import org.xml.sax.InputSource;
+import org.xml.sax.ext.DeclHandler;
+import org.xml.sax.ext.LexicalHandler;
/**
* Implementation of {@link javax.xml.transform.Source} for AXIOM.
* The implementation is based on {@link SAXSource} and directly transforms an AXIOM
* tree into a stream of SAX events using {@link OMXMLReader}.
* <p>
- * Note that {@link org.apache.axiom.om.OMDocType} nodes are not supported and will be
- * silently skipped.
+ * Note that this class only supports {@link ContentHandler} and {@link LexicalHandler}.
+ * {@link DTDHandler} and {@link DeclHandler} are not supported.
* <p>
* <b>NOTE: As of version 1.2.13, application code should use
* {@link OMContainer#getSAXSource(boolean)} instead of instantiating this class directly.</b>
Modified: webservices/axiom/branches/AXIOM-437/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/serialize/OMXMLReader.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/AXIOM-437/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/serialize/OMXMLReader.java?rev=1364239&r1=1364238&r2=1364239&view=diff
==============================================================================
--- webservices/axiom/branches/AXIOM-437/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/serialize/OMXMLReader.java (original)
+++ webservices/axiom/branches/AXIOM-437/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/serialize/OMXMLReader.java Sun Jul 22 08:58:24 2012
@@ -29,6 +29,7 @@ import java.util.Set;
import org.apache.axiom.om.OMAttribute;
import org.apache.axiom.om.OMComment;
import org.apache.axiom.om.OMContainer;
+import org.apache.axiom.om.OMDocType;
import org.apache.axiom.om.OMDocument;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMNamespace;
@@ -38,17 +39,20 @@ import org.apache.axiom.om.OMText;
import org.apache.axiom.util.sax.AbstractXMLReader;
import org.xml.sax.Attributes;
import org.xml.sax.ContentHandler;
+import org.xml.sax.DTDHandler;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
+import org.xml.sax.ext.DeclHandler;
+import org.xml.sax.ext.LexicalHandler;
/**
* SAX {@link XMLReader} implementation that traverses a given OM tree and invokes the
* callback methods on the configured {@link ContentHandler}. This can be used to
* serialize an Axiom tree to SAX.
* <p>
- * Note that this class doesn't support serializing {@link org.apache.axiom.om.OMDocType}
- * nodes. They will be silently skipped.
+ * Note that this class only supports {@link ContentHandler} and {@link LexicalHandler}.
+ * {@link DTDHandler} and {@link DeclHandler} are not supported.
* <p>
* This class can also generate SAX events for a subtree. This is the case if the
* element passed to the constructor is not the root element of the document. In this
@@ -177,6 +181,13 @@ public class OMXMLReader extends Abstrac
for (Iterator it = parent.getChildren(); it.hasNext(); ) {
OMNode node = (OMNode)it.next();
switch (node.getType()) {
+ case OMNode.DTD_NODE:
+ if (lexicalHandler != null) {
+ OMDocType doctype = (OMDocType)node;
+ lexicalHandler.startDTD(doctype.getRootName(), doctype.getPublicId(), doctype.getSystemId());
+ lexicalHandler.endDTD();
+ }
+ break;
case OMNode.ELEMENT_NODE:
generateEvents((OMElement)node);
break;
Modified: webservices/axiom/branches/AXIOM-437/modules/axiom-api/src/test/java/org/apache/axiom/om/AbstractTestCase.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/AXIOM-437/modules/axiom-api/src/test/java/org/apache/axiom/om/AbstractTestCase.java?rev=1364239&r1=1364238&r2=1364239&view=diff
==============================================================================
--- webservices/axiom/branches/AXIOM-437/modules/axiom-api/src/test/java/org/apache/axiom/om/AbstractTestCase.java (original)
+++ webservices/axiom/branches/AXIOM-437/modules/axiom-api/src/test/java/org/apache/axiom/om/AbstractTestCase.java Sun Jul 22 08:58:24 2012
@@ -24,11 +24,8 @@ import java.net.URL;
import javax.activation.DataSource;
import javax.activation.URLDataSource;
-import javax.xml.parsers.DocumentBuilderFactory;
import org.custommonkey.xmlunit.XMLTestCase;
-import org.w3c.dom.Document;
-import org.w3c.dom.DocumentType;
/** Abstract base class for test cases. */
public abstract class AbstractTestCase
@@ -76,14 +73,5 @@ public abstract class AbstractTestCase
public static OMElement getTestResourceAsElement(OMMetaFactory omMetaFactory, String relativePath) {
return OMXMLBuilderFactory.createOMBuilder(omMetaFactory.getOMFactory(), getTestResource(relativePath)).getDocumentElement();
}
-
- public static Document toDocumentWithoutDTD(InputStream in) throws Exception {
- Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(in);
- DocumentType docType = doc.getDoctype();
- if (docType != null) {
- doc.removeChild(docType);
- }
- return doc;
- }
}
Modified: webservices/axiom/branches/AXIOM-437/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/container/TestGetSAXSource.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/AXIOM-437/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/container/TestGetSAXSource.java?rev=1364239&r1=1364238&r2=1364239&view=diff
==============================================================================
--- webservices/axiom/branches/AXIOM-437/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/container/TestGetSAXSource.java (original)
+++ webservices/axiom/branches/AXIOM-437/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/container/TestGetSAXSource.java Sun Jul 22 08:58:24 2012
@@ -25,7 +25,6 @@ import java.io.InputStream;
import javax.xml.transform.sax.SAXSource;
import javax.xml.transform.stream.StreamResult;
-import org.apache.axiom.om.AbstractTestCase;
import org.apache.axiom.om.OMMetaFactory;
import org.apache.axiom.om.OMXMLBuilderFactory;
import org.apache.axiom.om.OMXMLParserWrapper;
@@ -35,6 +34,7 @@ import org.apache.axiom.ts.ConformanceTe
import org.apache.xalan.processor.TransformerFactoryImpl;
import org.custommonkey.xmlunit.XMLAssert;
import org.custommonkey.xmlunit.XMLUnit;
+import org.xml.sax.InputSource;
public class TestGetSAXSource extends ConformanceTestCase {
private final OMContainerFactory containerFactory;
@@ -61,7 +61,7 @@ public class TestGetSAXSource extends Co
in.close();
}
XMLAssert.assertXMLIdentical(XMLUnit.compareXML(
- AbstractTestCase.toDocumentWithoutDTD(getFileAsStream()),
- AbstractTestCase.toDocumentWithoutDTD(new ByteArrayInputStream(out.toByteArray()))), true);
+ containerFactory.getControl(getFileAsStream()),
+ new InputSource(new ByteArrayInputStream(out.toByteArray()))), true);
}
}