Search in sources :

Example 6 with OMProcessingInstruction

use of org.apache.axiom.om.OMProcessingInstruction in project webservices-axiom by apache.

the class TestGetDescendants method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMContainer root = containerFactory.create(factory);
    OMElement child1 = factory.createOMElement("child", null, root);
    OMProcessingInstruction child2 = factory.createOMProcessingInstruction(root, "test", "data");
    OMText grandchild1 = factory.createOMText(child1, "text");
    OMComment grandchild2 = factory.createOMComment(child1, "text");
    Iterator<? extends OMSerializable> it = root.getDescendants(includeSelf);
    if (includeSelf) {
        assertThat(it.hasNext()).isTrue();
        assertThat(it.next()).isEqualTo(root);
    }
    assertThat(it.hasNext()).isTrue();
    assertThat(it.next()).isEqualTo(child1);
    assertThat(it.hasNext()).isTrue();
    assertThat(it.next()).isEqualTo(grandchild1);
    assertThat(it.hasNext()).isTrue();
    assertThat(it.next()).isEqualTo(grandchild2);
    assertThat(it.hasNext()).isTrue();
    assertThat(it.next()).isEqualTo(child2);
    assertThat(it.hasNext()).isFalse();
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) OMProcessingInstruction(org.apache.axiom.om.OMProcessingInstruction) OMComment(org.apache.axiom.om.OMComment) OMText(org.apache.axiom.om.OMText) OMElement(org.apache.axiom.om.OMElement) OMContainer(org.apache.axiom.om.OMContainer)

Example 7 with OMProcessingInstruction

use of org.apache.axiom.om.OMProcessingInstruction in project webservices-axiom by apache.

the class WriteProcessingInstruction2Scenario method validate.

@Override
public void validate(OMElement element, boolean dataHandlersPreserved) throws Throwable {
    OMNode child = element.getFirstOMChild();
    Assert.assertTrue(child instanceof OMProcessingInstruction);
    OMProcessingInstruction pi = (OMProcessingInstruction) child;
    Assert.assertEquals("target", pi.getTarget());
    Assert.assertEquals("data", pi.getValue());
}
Also used : OMProcessingInstruction(org.apache.axiom.om.OMProcessingInstruction) OMNode(org.apache.axiom.om.OMNode)

Example 8 with OMProcessingInstruction

use of org.apache.axiom.om.OMProcessingInstruction in project webservices-axiom by apache.

the class WriteProcessingInstruction1Scenario method validate.

@Override
public void validate(OMElement element, boolean dataHandlersPreserved) throws Throwable {
    OMNode child = element.getFirstOMChild();
    Assert.assertTrue(child instanceof OMProcessingInstruction);
    OMProcessingInstruction pi = (OMProcessingInstruction) child;
    Assert.assertEquals("target", pi.getTarget());
    Assert.assertEquals("", pi.getValue());
}
Also used : OMProcessingInstruction(org.apache.axiom.om.OMProcessingInstruction) OMNode(org.apache.axiom.om.OMNode)

Example 9 with OMProcessingInstruction

use of org.apache.axiom.om.OMProcessingInstruction 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

OMProcessingInstruction (org.apache.axiom.om.OMProcessingInstruction)9 OMElement (org.apache.axiom.om.OMElement)4 OMNode (org.apache.axiom.om.OMNode)4 OMText (org.apache.axiom.om.OMText)3 Iterator (java.util.Iterator)2 OMComment (org.apache.axiom.om.OMComment)2 OMDocType (org.apache.axiom.om.OMDocType)2 OMFactory (org.apache.axiom.om.OMFactory)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 DataOutputStream (java.io.DataOutputStream)1 IOException (java.io.IOException)1 StringReader (java.io.StringReader)1 MessageDigest (java.security.MessageDigest)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 XMLStreamWriter (javax.xml.stream.XMLStreamWriter)1 OMAttribute (org.apache.axiom.om.OMAttribute)1 OMContainer (org.apache.axiom.om.OMContainer)1 OMDocument (org.apache.axiom.om.OMDocument)1 OMException (org.apache.axiom.om.OMException)1 OMNamespace (org.apache.axiom.om.OMNamespace)1