use of org.apache.axiom.om.OMDocType in project webservices-axiom by apache.
the class TestSerialize method runTest.
@Override
protected void runTest() throws Throwable {
OMDocType doctype = metaFactory.getOMFactory().createOMDocType(null, "root", null, "my.dtd", null);
XMLStreamWriter writer = mock(XMLStreamWriter.class);
doctype.serialize(writer);
verify(writer).writeDTD("<!DOCTYPE root SYSTEM \"my.dtd\">");
verify(writer, atMost(1)).flush();
verifyNoMoreInteractions(writer);
}
use of org.apache.axiom.om.OMDocType in project webservices-axiom by apache.
the class TestCreateOMDocTypeWithoutParent method runTest.
@Override
protected void runTest() throws Throwable {
OMDocType dtd = metaFactory.getOMFactory().createOMDocType(null, "root", "publicId", "systemId", "internalSubset");
assertNull(dtd.getParent());
assertEquals("root", dtd.getRootName());
assertEquals("publicId", dtd.getPublicId());
assertEquals("systemId", dtd.getSystemId());
assertEquals("internalSubset", dtd.getInternalSubset());
}
use of org.apache.axiom.om.OMDocType in project webservices-axiom by apache.
the class OMFactoryImpl method importChildNode.
private AxiomChildNode importChildNode(OMNode child) {
int type = child.getType();
switch(type) {
case OMNode.ELEMENT_NODE:
{
OMElement element = (OMElement) child;
AxiomElement importedElement = createNode(AxiomElement.class);
copyName(element, importedElement);
for (Iterator<OMAttribute> it = element.getAllAttributes(); it.hasNext(); ) {
importedElement.coreAppendAttribute(importAttribute(it.next()));
}
for (Iterator<OMNamespace> it = element.getAllDeclaredNamespaces(); it.hasNext(); ) {
OMNamespace ns = it.next();
AxiomNamespaceDeclaration nsDecl = createNode(AxiomNamespaceDeclaration.class);
nsDecl.coreSetDeclaredNamespace(ns.getPrefix(), ns.getNamespaceURI());
importedElement.coreAppendAttribute(nsDecl);
}
importChildren(element, importedElement);
return importedElement;
}
case OMNode.TEXT_NODE:
case OMNode.SPACE_NODE:
case OMNode.CDATA_SECTION_NODE:
{
OMText text = (OMText) child;
Object content;
if (text.isBinary()) {
content = new TextContent(text.getContentID(), text.getDataHandler(), text.isOptimized());
} else {
content = text.getText();
}
return createAxiomText(null, content, type);
}
case OMNode.PI_NODE:
{
OMProcessingInstruction pi = (OMProcessingInstruction) child;
AxiomProcessingInstruction importedPI = createNode(AxiomProcessingInstruction.class);
importedPI.setTarget(pi.getTarget());
importedPI.setValue(pi.getValue());
return importedPI;
}
case OMNode.COMMENT_NODE:
{
OMComment comment = (OMComment) child;
AxiomComment importedComment = createNode(AxiomComment.class);
importedComment.setValue(comment.getValue());
return importedComment;
}
case OMNode.DTD_NODE:
{
OMDocType docType = (OMDocType) child;
AxiomDocType importedDocType = createNode(AxiomDocType.class);
importedDocType.coreSetRootName(docType.getRootName());
importedDocType.coreSetPublicId(docType.getPublicId());
importedDocType.coreSetSystemId(docType.getSystemId());
importedDocType.coreSetInternalSubset(docType.getInternalSubset());
return importedDocType;
}
case OMNode.ENTITY_REFERENCE_NODE:
AxiomEntityReference importedEntityRef = createNode(AxiomEntityReference.class);
importedEntityRef.coreSetName(((OMEntityReference) child).getName());
return importedEntityRef;
default:
throw new IllegalArgumentException("Unsupported node type");
}
}
use of org.apache.axiom.om.OMDocType in project webservices-axiom by apache.
the class TestStandaloneConfiguration method runTest.
@Override
protected void runTest() throws Throwable {
InputStream is = TestStandaloneConfiguration.class.getResourceAsStream("web_w_dtd2.xml");
OMXMLParserWrapper builder = OMXMLBuilderFactory.createOMBuilder(metaFactory.getOMFactory(), StAXParserConfiguration.STANDALONE, is);
OMElement root = builder.getDocumentElement();
assertTrue(root.getLocalName().equals("web-app"));
OMDocument document = builder.getDocument();
Iterator<OMNode> i = document.getChildren();
OMDocType docType = null;
while (docType == null && i.hasNext()) {
OMNode obj = i.next();
if (obj instanceof OMDocType) {
docType = (OMDocType) obj;
}
}
assertTrue(docType != null);
root.close(false);
}
use of org.apache.axiom.om.OMDocType in project webservices-axiom by apache.
the class OMXMLReader method generateEventsForChildren.
private void generateEventsForChildren(OMContainer parent) throws SAXException {
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;
case OMNode.TEXT_NODE:
generateEvents((OMText) node, false);
break;
case OMNode.SPACE_NODE:
generateEvents((OMText) node, true);
break;
case OMNode.CDATA_SECTION_NODE:
if (lexicalHandler != null) {
lexicalHandler.startCDATA();
}
generateEvents((OMText) node, false);
if (lexicalHandler != null) {
lexicalHandler.endCDATA();
}
break;
case OMNode.COMMENT_NODE:
if (lexicalHandler != null) {
char[] ch = ((OMComment) node).getValue().toCharArray();
lexicalHandler.comment(ch, 0, ch.length);
}
break;
case OMNode.PI_NODE:
OMProcessingInstruction pi = (OMProcessingInstruction) node;
contentHandler.processingInstruction(pi.getTarget(), pi.getValue());
break;
case OMNode.ENTITY_REFERENCE_NODE:
contentHandler.skippedEntity(((OMEntityReference) node).getName());
break;
default:
throw new IllegalStateException("Unrecognized node type " + node.getType());
}
}
}
Aggregations