Search in sources :

Example 1 with OMDocType

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);
}
Also used : OMDocType(org.apache.axiom.om.OMDocType) XMLStreamWriter(javax.xml.stream.XMLStreamWriter)

Example 2 with OMDocType

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());
}
Also used : OMDocType(org.apache.axiom.om.OMDocType)

Example 3 with OMDocType

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");
    }
}
Also used : OMNamespace(org.apache.axiom.om.OMNamespace) AxiomDocType(org.apache.axiom.om.impl.intf.AxiomDocType) AxiomProcessingInstruction(org.apache.axiom.om.impl.intf.AxiomProcessingInstruction) AxiomEntityReference(org.apache.axiom.om.impl.intf.AxiomEntityReference) OMElement(org.apache.axiom.om.OMElement) AxiomNamespaceDeclaration(org.apache.axiom.om.impl.intf.AxiomNamespaceDeclaration) OMProcessingInstruction(org.apache.axiom.om.OMProcessingInstruction) OMDocType(org.apache.axiom.om.OMDocType) OMComment(org.apache.axiom.om.OMComment) AxiomComment(org.apache.axiom.om.impl.intf.AxiomComment) Iterator(java.util.Iterator) OMText(org.apache.axiom.om.OMText) AxiomElement(org.apache.axiom.om.impl.intf.AxiomElement) TextContent(org.apache.axiom.om.impl.intf.TextContent)

Example 4 with OMDocType

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);
}
Also used : OMNode(org.apache.axiom.om.OMNode) OMDocType(org.apache.axiom.om.OMDocType) InputStream(java.io.InputStream) OMElement(org.apache.axiom.om.OMElement) OMXMLParserWrapper(org.apache.axiom.om.OMXMLParserWrapper) OMDocument(org.apache.axiom.om.OMDocument)

Example 5 with OMDocType

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());
        }
    }
}
Also used : OMProcessingInstruction(org.apache.axiom.om.OMProcessingInstruction) OMNode(org.apache.axiom.om.OMNode) OMDocType(org.apache.axiom.om.OMDocType) Iterator(java.util.Iterator)

Aggregations

OMDocType (org.apache.axiom.om.OMDocType)6 Iterator (java.util.Iterator)2 OMDocument (org.apache.axiom.om.OMDocument)2 OMElement (org.apache.axiom.om.OMElement)2 OMNode (org.apache.axiom.om.OMNode)2 OMProcessingInstruction (org.apache.axiom.om.OMProcessingInstruction)2 InputStream (java.io.InputStream)1 StringReader (java.io.StringReader)1 XMLStreamWriter (javax.xml.stream.XMLStreamWriter)1 OMComment (org.apache.axiom.om.OMComment)1 OMNamespace (org.apache.axiom.om.OMNamespace)1 OMText (org.apache.axiom.om.OMText)1 OMXMLParserWrapper (org.apache.axiom.om.OMXMLParserWrapper)1 AxiomComment (org.apache.axiom.om.impl.intf.AxiomComment)1 AxiomDocType (org.apache.axiom.om.impl.intf.AxiomDocType)1 AxiomElement (org.apache.axiom.om.impl.intf.AxiomElement)1 AxiomEntityReference (org.apache.axiom.om.impl.intf.AxiomEntityReference)1 AxiomNamespaceDeclaration (org.apache.axiom.om.impl.intf.AxiomNamespaceDeclaration)1 AxiomProcessingInstruction (org.apache.axiom.om.impl.intf.AxiomProcessingInstruction)1 TextContent (org.apache.axiom.om.impl.intf.TextContent)1