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());
}
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);
}
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());
}
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();
}
}
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());
}
Aggregations