Search in sources :

Example 1 with OMComment

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

the class OMElementTest method testAddLLOMTextChildToDOOM.

public void testAddLLOMTextChildToDOOM() throws XMLStreamException {
    OMFactory doomFactory = OMAbstractFactory.getMetaFactory(OMAbstractFactory.FEATURE_DOM).getOMFactory();
    OMFactory llomFactory = OMAbstractFactory.getOMFactory();
    String text = "This was a DOOM Text";
    OMElement doomRoot = doomFactory.createOMElement("root", null);
    OMText llomText = llomFactory.createOMText(text);
    OMComment comment = llomFactory.createOMComment(null, "comment");
    doomRoot.addChild(llomText);
    doomRoot.addChild(comment);
    OMElement newElement = (OMXMLBuilderFactory.createStAXOMBuilder(this.factory, doomRoot.getXMLStreamReader())).getDocumentElement();
    newElement.build();
    assertEquals(newElement.getText(), text);
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) OMComment(org.apache.axiom.om.OMComment) OMText(org.apache.axiom.om.OMText) OMElement(org.apache.axiom.om.OMElement)

Example 2 with OMComment

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

the class WriteCommentScenario method validate.

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

Example 3 with OMComment

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

the class TestGetDocumentElement method runTest.

@Override
protected void runTest() throws Throwable {
    OMXMLParserWrapper builder = builderFactory.getBuilder(metaFactory, new InputSource(new StringReader("<!--comment1--><root/><!--comment2-->")));
    OMElement element;
    if (discardDocument == null) {
        element = builder.getDocumentElement();
    } else {
        element = builder.getDocumentElement(discardDocument.booleanValue());
    }
    assertNotNull("Document element can not be null", element);
    assertEquals("Name of the document element is wrong", "root", element.getLocalName());
    if (Boolean.TRUE.equals(discardDocument)) {
        if (builderFactory.isDeferredParsing()) {
            assertFalse(element.isComplete());
        }
        assertNull(element.getParent());
        // Note: we can't test getNextOMSibling here because this would build the element
        assertNull(element.getPreviousOMSibling());
        OMElement newParent = element.getOMFactory().createOMElement("newParent", null);
        newParent.addChild(element);
        if (builderFactory.isDeferredParsing()) {
            assertFalse(element.isComplete());
            assertFalse(builder.isCompleted());
        }
        assertAbout(xml()).that(xml(OMElement.class, newParent)).hasSameContentAs("<newParent><root/></newParent>");
        assertTrue(element.isComplete());
        // Since we discarded the document, the nodes in the epilog will not be accessible.
        // Therefore we expect that when the document element changes its completion status,
        // the builder will consume the epilog and change its completion status as well.
        // This gives the underlying parser a chance to release some resources.
        assertTrue(builder.isCompleted());
    } else {
        // The getDocumentElement doesn't detach the document element from the document:
        assertSame(builder.getDocument(), element.getParent());
        assertSame(builder.getDocument().getOMDocumentElement(), element);
        assertTrue(element.getPreviousOMSibling() instanceof OMComment);
        assertTrue(element.getNextOMSibling() instanceof OMComment);
    }
}
Also used : InputSource(org.xml.sax.InputSource) OMComment(org.apache.axiom.om.OMComment) StringReader(java.io.StringReader) OMElement(org.apache.axiom.om.OMElement) OMXMLParserWrapper(org.apache.axiom.om.OMXMLParserWrapper)

Example 4 with OMComment

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

the class TestInsertSibling method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMElement parent = factory.createOMElement("parent", null);
    OMText child = factory.createOMText(parent, "test");
    OMComment orgSibling = altMetaFactory.getOMFactory().createOMComment(null, "test");
    if (before) {
        child.insertSiblingBefore(orgSibling);
    } else {
        child.insertSiblingAfter(orgSibling);
    }
    OMComment sibling = (OMComment) (before ? child.getPreviousOMSibling() : child.getNextOMSibling());
    assertThat(sibling).isNotSameAs(orgSibling);
    assertThat(sibling.getValue()).isEqualTo("test");
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) OMComment(org.apache.axiom.om.OMComment) OMText(org.apache.axiom.om.OMText) OMElement(org.apache.axiom.om.OMElement)

Example 5 with OMComment

use of org.apache.axiom.om.OMComment in project wso2-synapse by wso2.

the class SynapseXMLConfigurationFactory method getConfiguration.

public SynapseConfiguration getConfiguration(OMElement definitions, Properties properties) {
    if (!definitions.getQName().equals(XMLConfigConstants.DEFINITIONS_ELT)) {
        throw new SynapseException("Wrong QName for this configuration factory " + definitions.getQName());
    }
    SynapseConfiguration config = SynapseConfigUtils.newConfiguration();
    config.setDefaultQName(definitions.getQName());
    Iterator itr = definitions.getChildren();
    while (itr.hasNext()) {
        Object o = itr.next();
        if (o instanceof OMElement) {
            OMElement elt = (OMElement) o;
            if (XMLConfigConstants.SEQUENCE_ELT.equals(elt.getQName())) {
                String key = elt.getAttributeValue(new QName(XMLConfigConstants.NULL_NAMESPACE, "key"));
                // this could be a sequence def or a referred sequence
                if (key != null) {
                    handleException("Referred sequences are not allowed at the top level");
                } else {
                    defineSequence(config, elt, properties);
                }
            } else if (XMLConfigConstants.TEMPLATE_ELT.equals(elt.getQName())) {
                defineTemplate(config, elt, properties);
            } else if (XMLConfigConstants.IMPORT_ELT.equals(elt.getQName())) {
                defineImport(config, elt, properties);
            } else if (XMLConfigConstants.ENDPOINT_ELT.equals(elt.getQName())) {
                defineEndpoint(config, elt, properties);
            } else if (XMLConfigConstants.ENTRY_ELT.equals(elt.getQName())) {
                defineEntry(config, elt, properties);
            } else if (XMLConfigConstants.PROXY_ELT.equals(elt.getQName())) {
                defineProxy(config, elt, properties);
            } else if (XMLConfigConstants.REGISTRY_ELT.equals(elt.getQName())) {
                defineRegistry(config, elt, properties);
            } else if (XMLConfigConstants.EVENT_SOURCE_ELT.equals(elt.getQName())) {
                defineEventSource(config, elt, properties);
            } else if (XMLConfigConstants.EXECUTOR_ELT.equals(elt.getQName())) {
                defineExecutor(config, elt, properties);
            } else if (XMLConfigConstants.MESSAGE_STORE_ELT.equals(elt.getQName())) {
                defineMessageStore(config, elt, properties);
            } else if (XMLConfigConstants.TASK_MANAGER_ELT.equals(elt.getQName())) {
                defineTaskManager(config, elt, properties);
            } else if (XMLConfigConstants.MESSAGE_PROCESSOR_ELT.equals(elt.getQName())) {
                defineMessageProcessor(config, elt, properties);
            } else if (StartupFinder.getInstance().isStartup(elt.getQName())) {
                defineStartup(config, elt, properties);
            } else if (XMLConfigConstants.API_ELT.equals(elt.getQName())) {
                defineAPI(config, elt, properties);
            } else if (XMLConfigConstants.DESCRIPTION_ELT.equals(elt.getQName())) {
                config.setDescription(elt.getText());
            } else if (XMLConfigConstants.INBOUND_ENDPOINT_ELT.equals(elt.getQName())) {
                defineInboundEndpoint(config, elt, properties);
            } else {
                handleException("Invalid configuration element at the top level, one of \'sequence\', " + "\'endpoint\', \'proxy\', \'eventSource\', \'localEntry\', \'priorityExecutor\'" + ", \'registry\' or \'inboundEndpoint\' is expected");
            }
        } else if (o instanceof OMComment) {
            OMComment commentNode = (OMComment) o;
            defineComments(config, commentNode);
        }
    }
    return config;
}
Also used : SynapseException(org.apache.synapse.SynapseException) QName(javax.xml.namespace.QName) OMComment(org.apache.axiom.om.OMComment) Iterator(java.util.Iterator) OMElement(org.apache.axiom.om.OMElement) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration)

Aggregations

OMComment (org.apache.axiom.om.OMComment)19 OMElement (org.apache.axiom.om.OMElement)9 OMNode (org.apache.axiom.om.OMNode)8 OMFactory (org.apache.axiom.om.OMFactory)7 StringReader (java.io.StringReader)4 OMText (org.apache.axiom.om.OMText)4 Iterator (java.util.Iterator)3 OMContainer (org.apache.axiom.om.OMContainer)2 OMDocument (org.apache.axiom.om.OMDocument)2 OMProcessingInstruction (org.apache.axiom.om.OMProcessingInstruction)2 SynapseException (org.apache.synapse.SynapseException)2 SynapseConfiguration (org.apache.synapse.config.SynapseConfiguration)2 CommentMediator (org.apache.synapse.mediators.builtin.CommentMediator)2 QName (javax.xml.namespace.QName)1 XMLStreamWriter (javax.xml.stream.XMLStreamWriter)1 OMDocType (org.apache.axiom.om.OMDocType)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 AxiomEntityReference (org.apache.axiom.om.impl.intf.AxiomEntityReference)1