Search in sources :

Example 51 with OMElement

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

the class TestHasNameWithNamespace method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    String localName = "TestLocalName";
    String namespace = "http://ws.apache.org/axis2/ns";
    String prefix = "axis2";
    OMElement element = factory.createOMElement(localName, namespace, prefix);
    assertTrue(element.hasName(new QName(namespace, localName, prefix)));
    assertTrue(element.hasName(new QName(namespace, localName, "otherPrefix")));
    assertFalse(element.hasName(new QName("http://some.other.org/", localName, prefix)));
    assertFalse(element.hasName(new QName(namespace, "otherName", prefix)));
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) QName(javax.xml.namespace.QName) OMElement(org.apache.axiom.om.OMElement)

Example 52 with OMElement

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

the class TestGetXMLStreamReaderWithoutCachingPartiallyBuiltModified method runTest.

@Override
protected void runTest() throws Throwable {
    OMElement root = OMXMLBuilderFactory.createOMBuilder(metaFactory.getOMFactory(), new StringReader("<root><a/><b/><c/></root>")).getDocumentElement();
    OMElement b = root.getFirstChildWithName(new QName("b"));
    b.addAttribute("att", "value", null);
    assertFalse(b.isComplete());
    XMLStreamReader reader = root.getXMLStreamReaderWithoutCaching();
    // Skip to the START_ELEMENT event corresponding to b
    for (int i = 0; i < 4; i++) {
        reader.next();
    }
    assertEquals(XMLStreamReader.START_ELEMENT, reader.getEventType());
    assertEquals("b", reader.getLocalName());
    // The previously added attribute must be visible
    assertEquals(1, reader.getAttributeCount());
    assertEquals("att", reader.getAttributeLocalName(0));
    assertEquals("value", reader.getAttributeValue(0));
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) QName(javax.xml.namespace.QName) StringReader(java.io.StringReader) OMElement(org.apache.axiom.om.OMElement)

Example 53 with OMElement

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

the class TestGetQNameWithNamespace method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    String localName = "TestLocalName";
    String namespace = "http://ws.apache.org/axis2/ns";
    String prefix = "axis2";
    OMElement elem = factory.createOMElement(localName, namespace, prefix);
    QName qname = elem.getQName();
    assertEquals("Localname mismatch", localName, qname.getLocalPart());
    assertEquals("Namespace mismatch", namespace, qname.getNamespaceURI());
    assertEquals("namespace prefix mismatch", prefix, qname.getPrefix());
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) QName(javax.xml.namespace.QName) OMElement(org.apache.axiom.om.OMElement)

Example 54 with OMElement

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

the class TestGetSAXResultWithDTD method runTest.

@Override
protected void runTest() throws Throwable {
    OMElement root = metaFactory.getOMFactory().createOMElement("root", null);
    SAXResult result = root.getSAXResult();
    LexicalHandler lexicalHandler = result.getLexicalHandler();
    ContentHandler contentHandler = result.getHandler();
    contentHandler.startDocument();
    lexicalHandler.startDTD("test", null, "my.dtd");
    lexicalHandler.endDTD();
    contentHandler.startElement("", "test", "test", new AttributesImpl());
    contentHandler.endElement("", "test", "test");
    contentHandler.endDocument();
    OMNode child = root.getFirstOMChild();
    assertTrue(child instanceof OMElement);
    assertEquals("test", ((OMElement) child).getLocalName());
}
Also used : OMNode(org.apache.axiom.om.OMNode) AttributesImpl(org.xml.sax.helpers.AttributesImpl) SAXResult(javax.xml.transform.sax.SAXResult) LexicalHandler(org.xml.sax.ext.LexicalHandler) OMElement(org.apache.axiom.om.OMElement) ContentHandler(org.xml.sax.ContentHandler)

Example 55 with OMElement

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

the class TestGetSAXSourceIdentityTransformOnFragment method runTest.

@Override
protected void runTest() throws Throwable {
    Transformer transformer = xsltImplementation.newTransformerFactory().newTransformer();
    OMFactory factory = metaFactory.getOMFactory();
    OMElement element = OMXMLBuilderFactory.createOMBuilder(factory, getInput()).getDocumentElement().getFirstElement();
    OMDocument outputDocument = factory.createOMDocument();
    transformer.transform(element.getSAXSource(cache), outputDocument.getSAXResult());
    OMNamespace ns = outputDocument.getOMDocumentElement().findNamespaceURI("p");
    assertNotNull(ns);
    assertEquals("urn:some:namespace", ns.getNamespaceURI());
    element.close(false);
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) OMNamespace(org.apache.axiom.om.OMNamespace) Transformer(javax.xml.transform.Transformer) OMElement(org.apache.axiom.om.OMElement) OMDocument(org.apache.axiom.om.OMDocument)

Aggregations

OMElement (org.apache.axiom.om.OMElement)414 OMFactory (org.apache.axiom.om.OMFactory)202 OMNamespace (org.apache.axiom.om.OMNamespace)108 QName (javax.xml.namespace.QName)97 StringReader (java.io.StringReader)63 OMNode (org.apache.axiom.om.OMNode)43 OMText (org.apache.axiom.om.OMText)41 XMLStreamReader (javax.xml.stream.XMLStreamReader)37 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)32 OMAttribute (org.apache.axiom.om.OMAttribute)26 StringWriter (java.io.StringWriter)24 OMXMLParserWrapper (org.apache.axiom.om.OMXMLParserWrapper)21 DataHandler (javax.activation.DataHandler)20 OMDocument (org.apache.axiom.om.OMDocument)19 PullOMDataSource (org.apache.axiom.ts.om.sourcedelement.util.PullOMDataSource)18 Element (org.w3c.dom.Element)18 InputStream (java.io.InputStream)16 OMSourcedElement (org.apache.axiom.om.OMSourcedElement)16 ByteArrayInputStream (java.io.ByteArrayInputStream)13 OMException (org.apache.axiom.om.OMException)13