Search in sources :

Example 1 with DTDReader

use of org.apache.axiom.ext.stax.DTDReader in project webservices-axiom by apache.

the class StreamingOMSerializer method serializeDTD.

private void serializeDTD(XMLStreamReader reader, XMLStreamWriter writer) throws XMLStreamException {
    DTDReader dtdReader;
    try {
        dtdReader = (DTDReader) reader.getProperty(DTDReader.PROPERTY);
    } catch (IllegalArgumentException ex) {
        dtdReader = null;
    }
    if (dtdReader == null) {
        throw new XMLStreamException("Cannot serialize the DTD because the XMLStreamReader doesn't support the DTDReader extension");
    }
    XMLStreamWriterUtils.writeDTD(writer, dtdReader.getRootName(), dtdReader.getPublicId(), dtdReader.getSystemId(), reader.getText());
}
Also used : XMLStreamException(javax.xml.stream.XMLStreamException) DTDReader(org.apache.axiom.ext.stax.DTDReader)

Example 2 with DTDReader

use of org.apache.axiom.ext.stax.DTDReader in project webservices-axiom by apache.

the class StAXPullReader method processDTD.

private void processDTD() throws StreamException {
    DTDReader dtdReader;
    try {
        dtdReader = (DTDReader) parser.getProperty(DTDReader.PROPERTY);
    } catch (IllegalArgumentException ex) {
        dtdReader = null;
    }
    if (dtdReader == null) {
        throw new StreamException("Cannot process DTD events because the XMLStreamReader doesn't support the DTDReader extension");
    }
    String internalSubset = getDTDText();
    // Woodstox returns an empty string if there is no internal subset
    if (internalSubset != null && internalSubset.length() == 0) {
        internalSubset = null;
    }
    handler.processDocumentTypeDeclaration(dtdReader.getRootName(), dtdReader.getPublicId(), dtdReader.getSystemId(), internalSubset);
}
Also used : DTDReader(org.apache.axiom.ext.stax.DTDReader) StreamException(org.apache.axiom.core.stream.StreamException) XMLStreamException(javax.xml.stream.XMLStreamException)

Example 3 with DTDReader

use of org.apache.axiom.ext.stax.DTDReader in project webservices-axiom by apache.

the class TestDTDReader method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMDocument document = factory.createOMDocument();
    factory.createOMDocType(document, "root", "-//MY//DTD", "my.dtd", "<!ELEMENT root (#PCDATA)>");
    factory.createOMElement("root", null, document);
    XMLStreamReader reader = document.getXMLStreamReader();
    // Note that according to the specification of the DTDReader interface, it is
    // allowed to look up the extension before reaching the DTD event.
    DTDReader dtdReader = (DTDReader) reader.getProperty(DTDReader.PROPERTY);
    assertNotNull(dtdReader);
    assertEquals(XMLStreamReader.DTD, reader.next());
    assertEquals("root", dtdReader.getRootName());
    assertEquals("-//MY//DTD", dtdReader.getPublicId());
    assertEquals("my.dtd", dtdReader.getSystemId());
    assertEquals("<!ELEMENT root (#PCDATA)>", reader.getText());
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) XMLStreamReader(javax.xml.stream.XMLStreamReader) DTDReader(org.apache.axiom.ext.stax.DTDReader) OMDocument(org.apache.axiom.om.OMDocument)

Example 4 with DTDReader

use of org.apache.axiom.ext.stax.DTDReader in project webservices-axiom by apache.

the class TestDTDReader method runTest.

@Override
protected void runTest() throws Throwable {
    InputStream in = XMLSample.DTD_FULL.getInputStream();
    try {
        XMLStreamReader reader = staxImpl.newNormalizedXMLInputFactory().createXMLStreamReader(XMLSample.DTD_FULL.getUrl().toString(), in);
        while (reader.next() != XMLStreamReader.DTD) {
        // Just loop
        }
        DTDReader dtdReader = (DTDReader) reader.getProperty(DTDReader.PROPERTY);
        assertThat(dtdReader).isNotNull();
        assertThat(dtdReader.getRootName()).isEqualTo("root");
        assertThat(dtdReader.getSystemId()).isEqualTo("dtd-full.dtd");
        assertThat(dtdReader.getPublicId()).isEqualTo("-//TEST//Dummy DTD//EN");
        reader.close();
    } finally {
        in.close();
    }
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) DTDReader(org.apache.axiom.ext.stax.DTDReader) InputStream(java.io.InputStream)

Example 5 with DTDReader

use of org.apache.axiom.ext.stax.DTDReader in project webservices-axiom by apache.

the class TestDTDReaderFromParser method runTest.

@Override
protected void runTest() throws Throwable {
    OMDocument doc = OMXMLBuilderFactory.createOMBuilder(metaFactory.getOMFactory(), StAXParserConfiguration.STANDALONE, TestDTDReaderFromParser.class.getResourceAsStream("/web_w_dtd.xml")).getDocument();
    if (build) {
        doc.build();
    }
    XMLStreamReader reader = doc.getXMLStreamReader(cache);
    // Note that according to the specification of the DTDReader interface, it is
    // allowed to look up the extension before reaching the DTD event.
    DTDReader dtdReader = (DTDReader) reader.getProperty(DTDReader.PROPERTY);
    assertNotNull(dtdReader);
    while (reader.next() != XMLStreamReader.DTD) {
    // Just loop
    }
    assertEquals("web-app", dtdReader.getRootName());
    assertEquals("-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN", dtdReader.getPublicId());
    assertEquals("http://java.sun.com/dtd/web-app_2_3.dtd", dtdReader.getSystemId());
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) DTDReader(org.apache.axiom.ext.stax.DTDReader) OMDocument(org.apache.axiom.om.OMDocument)

Aggregations

DTDReader (org.apache.axiom.ext.stax.DTDReader)5 XMLStreamReader (javax.xml.stream.XMLStreamReader)3 XMLStreamException (javax.xml.stream.XMLStreamException)2 OMDocument (org.apache.axiom.om.OMDocument)2 InputStream (java.io.InputStream)1 StreamException (org.apache.axiom.core.stream.StreamException)1 OMFactory (org.apache.axiom.om.OMFactory)1