Author: veithen Date: Wed Jul 18 18:44:08 2012 New Revision: 1363040 URL: http://svn.apache.org/viewvc?rev=1363040&view=rev Log: More unfinished code.
Modified: webservices/axiom/branches/AXIOM-435/modules/axiom-api/src/main/java/org/apache/axiom/om/OMMetaFactory.java webservices/axiom/branches/AXIOM-435/modules/axiom-api/src/main/java/org/apache/axiom/om/OMXMLBuilderFactory.java webservices/axiom/branches/AXIOM-435/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/SAXOMBuilder.java webservices/axiom/branches/AXIOM-435/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/factory/AbstractOMMetaFactory.java webservices/axiom/branches/AXIOM-435/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java webservices/axiom/branches/AXIOM-435/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/TestCreateOMBuilderFromSAXSource.java Modified: webservices/axiom/branches/AXIOM-435/modules/axiom-api/src/main/java/org/apache/axiom/om/OMMetaFactory.java URL: http://svn.apache.org/viewvc/webservices/axiom/branches/AXIOM-435/modules/axiom-api/src/main/java/org/apache/axiom/om/OMMetaFactory.java?rev=1363040&r1=1363039&r2=1363040&view=diff ============================================================================== --- webservices/axiom/branches/AXIOM-435/modules/axiom-api/src/main/java/org/apache/axiom/om/OMMetaFactory.java (original) +++ webservices/axiom/branches/AXIOM-435/modules/axiom-api/src/main/java/org/apache/axiom/om/OMMetaFactory.java Wed Jul 18 18:44:08 2012 @@ -22,6 +22,7 @@ package org.apache.axiom.om; import javax.xml.stream.XMLStreamReader; import javax.xml.transform.Source; import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.sax.SAXSource; import org.apache.axiom.om.util.StAXParserConfiguration; import org.apache.axiom.soap.SOAPFactory; @@ -29,6 +30,7 @@ import org.apache.axiom.soap.SOAPModelBu import org.apache.axiom.util.stax.xop.MimePartProvider; import org.w3c.dom.EntityReference; import org.xml.sax.InputSource; +import org.xml.sax.ext.LexicalHandler; /** * Object model meta factory. This interface encapsulates a particular Axiom implementation and @@ -139,6 +141,35 @@ public interface OMMetaFactory { OMXMLParserWrapper createOMBuilder(OMFactory omFactory, DOMSource source, boolean expandEntityReferences); /** + * Create an object model builder for plain XML that gets its input from a {@link SAXSource}. + * + * @param omFactory + * The object model factory to use. This factory must be obtained from the same + * {@link OMMetaFactory} instance as the one used to invoke this method. In general + * the factory will be retrieved from {@link #getOMFactory()}), but in some cases it + * may be necessary to pass a {@link SOAPFactory} instance, although this method will + * never produce a SOAP infoset. + * @param expandEntityReferences + * Determines how entity references (i.e. {@link LexicalHandler#startEntity(String)} + * and {@link LexicalHandler#endEntity(String)} events) are handled: + * <ul> + * <li>If the parameter is <code>false</code> then a single {@link OMEntityReference} + * will be created for each pair of {@link LexicalHandler#startEntity(String)} and + * {@link LexicalHandler#endEntity(String)} events. Other events reported between + * these two events are not taken into account. + * <li>If the parameter is <code>true</code> then no {@link OMEntityReference} nodes + * are created and {@link LexicalHandler#startEntity(String)} and + * {@link LexicalHandler#endEntity(String)} events are ignored. However, events + * between {@link LexicalHandler#startEntity(String)} and + * {@link LexicalHandler#endEntity(String)} are processed normally. + * </ul> + * @param source + * the source of the XML document + * @return the builder + */ + OMXMLParserWrapper createOMBuilder(OMFactory omFactory, SAXSource source, boolean expandEntityReferences); + + /** * Create an XOP aware object model builder. * * @param configuration Modified: webservices/axiom/branches/AXIOM-435/modules/axiom-api/src/main/java/org/apache/axiom/om/OMXMLBuilderFactory.java URL: http://svn.apache.org/viewvc/webservices/axiom/branches/AXIOM-435/modules/axiom-api/src/main/java/org/apache/axiom/om/OMXMLBuilderFactory.java?rev=1363040&r1=1363039&r2=1363040&view=diff ============================================================================== --- webservices/axiom/branches/AXIOM-435/modules/axiom-api/src/main/java/org/apache/axiom/om/OMXMLBuilderFactory.java (original) +++ webservices/axiom/branches/AXIOM-435/modules/axiom-api/src/main/java/org/apache/axiom/om/OMXMLBuilderFactory.java Wed Jul 18 18:44:08 2012 @@ -27,6 +27,7 @@ import javax.xml.stream.XMLStreamConstan import javax.xml.stream.XMLStreamReader; import javax.xml.transform.Source; import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.sax.SAXSource; import org.apache.axiom.attachments.Attachments; import org.apache.axiom.om.impl.builder.OMAttachmentAccessorMimePartProvider; @@ -35,6 +36,7 @@ import org.apache.axiom.soap.SOAPFactory import org.apache.axiom.soap.SOAPModelBuilder; import org.w3c.dom.EntityReference; import org.xml.sax.InputSource; +import org.xml.sax.ext.LexicalHandler; /** * Provides static factory methods to create various kinds of object model builders from different @@ -318,6 +320,33 @@ public class OMXMLBuilderFactory { } /** + * Create an object model builder that reads a plain XML document from the provided + * {@link SAXSource}. + * + * @param source + * the source of the XML document + * @param expandEntityReferences + * Determines how entity references (i.e. {@link LexicalHandler#startEntity(String)} + * and {@link LexicalHandler#endEntity(String)} events) are handled: + * <ul> + * <li>If the parameter is <code>false</code> then a single {@link OMEntityReference} + * will be created for each pair of {@link LexicalHandler#startEntity(String)} and + * {@link LexicalHandler#endEntity(String)} events. Other events reported between + * these two events are not taken into account. + * <li>If the parameter is <code>true</code> then no {@link OMEntityReference} nodes + * are created and {@link LexicalHandler#startEntity(String)} and + * {@link LexicalHandler#endEntity(String)} events are ignored. However, events + * between {@link LexicalHandler#startEntity(String)} and + * {@link LexicalHandler#endEntity(String)} are processed normally. + * </ul> + * @return the builder + */ + public static OMXMLParserWrapper createOMBuilder(SAXSource source, boolean expandEntityReferences) { + OMMetaFactory metaFactory = OMAbstractFactory.getMetaFactory(); + return metaFactory.createOMBuilder(metaFactory.getOMFactory(), source, expandEntityReferences); + } + + /** * Create an object model builder that reads an XML document from the provided {@link Source} * using a specified object model factory. * @@ -358,6 +387,34 @@ public class OMXMLBuilderFactory { } /** + * Create an object model builder that reads an XML document from the provided {@link SAXSource} + * using a specified object model factory. + * + * @param omFactory + * the object model factory to use + * @param source + * the source of the XML document + * @param expandEntityReferences + * Determines how entity references (i.e. {@link LexicalHandler#startEntity(String)} + * and {@link LexicalHandler#endEntity(String)} events) are handled: + * <ul> + * <li>If the parameter is <code>false</code> then a single {@link OMEntityReference} + * will be created for each pair of {@link LexicalHandler#startEntity(String)} and + * {@link LexicalHandler#endEntity(String)} events. Other events reported between + * these two events are not taken into account. + * <li>If the parameter is <code>true</code> then no {@link OMEntityReference} nodes + * are created and {@link LexicalHandler#startEntity(String)} and + * {@link LexicalHandler#endEntity(String)} events are ignored. However, events + * between {@link LexicalHandler#startEntity(String)} and + * {@link LexicalHandler#endEntity(String)} are processed normally. + * </ul> + * @return the builder + */ + public static OMXMLParserWrapper createOMBuilder(OMFactory omFactory, SAXSource source, boolean expandEntityReferences) { + return omFactory.getMetaFactory().createOMBuilder(omFactory, source, expandEntityReferences); + } + + /** * Create an XOP aware model builder from the provided {@link Attachments} object and with a * given parser configuration. * Modified: webservices/axiom/branches/AXIOM-435/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/SAXOMBuilder.java URL: http://svn.apache.org/viewvc/webservices/axiom/branches/AXIOM-435/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/SAXOMBuilder.java?rev=1363040&r1=1363039&r2=1363040&view=diff ============================================================================== --- webservices/axiom/branches/AXIOM-435/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/SAXOMBuilder.java (original) +++ webservices/axiom/branches/AXIOM-435/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/SAXOMBuilder.java Wed Jul 18 18:44:08 2012 @@ -44,6 +44,8 @@ import java.util.List; import javax.xml.XMLConstants; public class SAXOMBuilder extends DefaultHandler implements LexicalHandler, OMXMLParserWrapper { + private final boolean expandEntityReferences; + private OMDocument document; OMElement root = null; @@ -58,8 +60,13 @@ public class SAXOMBuilder extends Defaul int textNodeType = OMNode.TEXT_NODE; - public SAXOMBuilder(OMFactory factory) { + public SAXOMBuilder(OMFactory factory, boolean expandEntityReferences) { this.factory = (OMFactoryEx)factory; + this.expandEntityReferences = expandEntityReferences; + } + + public SAXOMBuilder(OMFactory factory) { + this(factory, true); } public SAXOMBuilder() { Modified: webservices/axiom/branches/AXIOM-435/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/factory/AbstractOMMetaFactory.java URL: http://svn.apache.org/viewvc/webservices/axiom/branches/AXIOM-435/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/factory/AbstractOMMetaFactory.java?rev=1363040&r1=1363039&r2=1363040&view=diff ============================================================================== --- webservices/axiom/branches/AXIOM-435/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/factory/AbstractOMMetaFactory.java (original) +++ webservices/axiom/branches/AXIOM-435/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/factory/AbstractOMMetaFactory.java Wed Jul 18 18:44:08 2012 @@ -99,7 +99,7 @@ public abstract class AbstractOMMetaFact public OMXMLParserWrapper createOMBuilder(OMFactory omFactory, Source source) { if (source instanceof SAXSource) { - return new SAXOMXMLParserWrapper(omFactory, (SAXSource)source); + return createOMBuilder(omFactory, (SAXSource)source, true); } else if (source instanceof DOMSource) { return createOMBuilder(omFactory, (DOMSource)source, true); } else { @@ -116,6 +116,11 @@ public abstract class AbstractOMMetaFact return new StAXOMBuilder(omFactory, new DOMXMLStreamReader(((DOMSource)source).getNode(), expandEntityReferences)); } + public OMXMLParserWrapper createOMBuilder(OMFactory omFactory, SAXSource source, + boolean expandEntityReferences) { + return new SAXOMXMLParserWrapper(omFactory, (SAXSource)source); + } + public OMXMLParserWrapper createOMBuilder(StAXParserConfiguration configuration, OMFactory omFactory, InputSource rootPart, MimePartProvider mimePartProvider) { XOPAwareStAXOMBuilder builder = new XOPAwareStAXOMBuilder(omFactory, createXMLStreamReader( Modified: webservices/axiom/branches/AXIOM-435/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java URL: http://svn.apache.org/viewvc/webservices/axiom/branches/AXIOM-435/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java?rev=1363040&r1=1363039&r2=1363040&view=diff ============================================================================== --- webservices/axiom/branches/AXIOM-435/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java (original) +++ webservices/axiom/branches/AXIOM-435/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java Wed Jul 18 18:44:08 2012 @@ -79,10 +79,12 @@ public class OMTestSuiteBuilder extends if (file.hasEntityReferences()) { addTest(new org.apache.axiom.ts.om.builder.TestCreateOMBuilderFromDOMSource(metaFactory, file, Boolean.TRUE)); addTest(new org.apache.axiom.ts.om.builder.TestCreateOMBuilderFromDOMSource(metaFactory, file, Boolean.FALSE)); + addTest(new org.apache.axiom.ts.om.builder.TestCreateOMBuilderFromSAXSource(metaFactory, file, Boolean.TRUE)); + addTest(new org.apache.axiom.ts.om.builder.TestCreateOMBuilderFromSAXSource(metaFactory, file, Boolean.FALSE)); } else { addTest(new org.apache.axiom.ts.om.builder.TestCreateOMBuilderFromDOMSource(metaFactory, file, null)); + addTest(new org.apache.axiom.ts.om.builder.TestCreateOMBuilderFromSAXSource(metaFactory, file, null)); } - addTest(new org.apache.axiom.ts.om.builder.TestCreateOMBuilderFromSAXSource(metaFactory, file)); } addTest(new org.apache.axiom.ts.om.builder.TestCreateStAXOMBuilderFromFragment(metaFactory)); addTest(new org.apache.axiom.ts.om.builder.TestCreateStAXOMBuilderIncorrectState(metaFactory)); Modified: webservices/axiom/branches/AXIOM-435/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/TestCreateOMBuilderFromSAXSource.java URL: http://svn.apache.org/viewvc/webservices/axiom/branches/AXIOM-435/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/TestCreateOMBuilderFromSAXSource.java?rev=1363040&r1=1363039&r2=1363040&view=diff ============================================================================== --- webservices/axiom/branches/AXIOM-435/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/TestCreateOMBuilderFromSAXSource.java (original) +++ webservices/axiom/branches/AXIOM-435/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/TestCreateOMBuilderFromSAXSource.java Wed Jul 18 18:44:08 2012 @@ -37,8 +37,15 @@ import org.custommonkey.xmlunit.XMLUnit; import org.xml.sax.InputSource; public class TestCreateOMBuilderFromSAXSource extends ConformanceTestCase { - public TestCreateOMBuilderFromSAXSource(OMMetaFactory metaFactory, ConformanceTestFile file) { + private final Boolean expandEntityReferences; + + public TestCreateOMBuilderFromSAXSource(OMMetaFactory metaFactory, ConformanceTestFile file, + Boolean expandEntityReferences) { super(metaFactory, file); + this.expandEntityReferences = expandEntityReferences; + if (expandEntityReferences != null) { + addTestProperty("expandEntityReferences", expandEntityReferences.toString()); + } } protected void runTest() throws Throwable { @@ -49,11 +56,18 @@ public class TestCreateOMBuilderFromSAXS InputStream in = getFileAsStream(); try { SAXSource source = new SAXSource(parser.getXMLReader(), new InputSource(in)); - OMXMLParserWrapper builder = OMXMLBuilderFactory.createOMBuilder(metaFactory.getOMFactory(), source); + OMXMLParserWrapper builder; + if (expandEntityReferences == null) { + builder = OMXMLBuilderFactory.createOMBuilder(metaFactory.getOMFactory(), source); + } else { + builder = OMXMLBuilderFactory.createOMBuilder(metaFactory.getOMFactory(), source, + expandEntityReferences.booleanValue()); + } ByteArrayOutputStream baos = new ByteArrayOutputStream(); builder.getDocument().serialize(baos); XMLAssert.assertXMLIdentical(XMLUnit.compareXML( - AbstractTestCase.toDocumentWithoutDTD(getFileAsStream()), + AbstractTestCase.toDocumentWithoutDTD(getFileAsStream(), + expandEntityReferences == null ? true : expandEntityReferences.booleanValue()), AbstractTestCase.toDocumentWithoutDTD(new ByteArrayInputStream(baos.toByteArray()))), true); } finally { in.close();