Search in sources :

Example 71 with OMFactory

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

the class TestGetNamespaceURI method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMNamespace ns = factory.createOMNamespace("http://www.w3.org/XML/1998/namespace", "xml");
    assertEquals("http://www.w3.org/XML/1998/namespace", ns.getNamespaceURI());
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) OMNamespace(org.apache.axiom.om.OMNamespace)

Example 72 with OMFactory

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

the class TestGetPrefix method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMNamespace ns = factory.createOMNamespace("http://www.w3.org/XML/1998/namespace", "xml");
    assertEquals("xml", ns.getPrefix());
    ns = factory.createOMNamespace("", null);
    assertNull(ns.getPrefix());
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) OMNamespace(org.apache.axiom.om.OMNamespace)

Example 73 with OMFactory

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

the class TestCloneOMElementNamespaceRepairing method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    // Create a root element on which we declare the namespaces
    OMElement root = factory.createOMElement("root", null);
    OMNamespace ns1 = root.declareNamespace("urn:ns1", "ns1");
    OMNamespace ns2 = root.declareNamespace("urn:ns2", "ns2");
    root.declareNamespace("urn:ns3", "ns3");
    // Create a child that uses these namespaces (in the element name and in the name of an attribute)
    OMElement child = factory.createOMElement("child", ns1, root);
    child.addAttribute("attr", "value", ns2);
    // Check that the child has no namespace declarations (to validate the correctness of the test)
    assertFalse(child.getAllDeclaredNamespaces().hasNext());
    // Clone the child and check that namespace declarations have been generated automatically
    OMElement clone = child.cloneOMElement();
    Set<OMNamespace> expectedNSDecls = new HashSet<>();
    expectedNSDecls.add(ns1);
    expectedNSDecls.add(ns2);
    Set<OMNamespace> actualNSDecls = new HashSet<>();
    for (Iterator<OMNamespace> it = clone.getAllDeclaredNamespaces(); it.hasNext(); ) {
        actualNSDecls.add(it.next());
    }
    assertEquals(expectedNSDecls, actualNSDecls);
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) OMNamespace(org.apache.axiom.om.OMNamespace) OMElement(org.apache.axiom.om.OMElement) HashSet(java.util.HashSet)

Example 74 with OMFactory

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

the class TestDeclareDefaultNamespaceConflict1 method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMElement element = factory.createOMElement("test", null);
    try {
        element.declareDefaultNamespace("urn:test");
        fail("Expected OMException");
    } catch (OMException ex) {
    // Expected
    }
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) OMElement(org.apache.axiom.om.OMElement) OMException(org.apache.axiom.om.OMException)

Example 75 with OMFactory

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

the class TestSetOMDocumentElementReplaceSame method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMDocument document = factory.createOMDocument();
    OMElement root = factory.createOMElement("root", null, document);
    document.setOMDocumentElement(root);
    assertThat(document.getOMDocumentElement()).isSameAs(root);
    assertThat(root.getPreviousOMSibling()).isNull();
    assertThat(root.getNextOMSibling()).isNull();
    assertThat(root.getParent()).isSameAs(document);
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) OMElement(org.apache.axiom.om.OMElement) OMDocument(org.apache.axiom.om.OMDocument)

Aggregations

OMFactory (org.apache.axiom.om.OMFactory)270 OMElement (org.apache.axiom.om.OMElement)202 OMNamespace (org.apache.axiom.om.OMNamespace)101 QName (javax.xml.namespace.QName)71 StringReader (java.io.StringReader)37 OMText (org.apache.axiom.om.OMText)35 OMSourcedElement (org.apache.axiom.om.OMSourcedElement)32 OMAttribute (org.apache.axiom.om.OMAttribute)31 PullOMDataSource (org.apache.axiom.ts.om.sourcedelement.util.PullOMDataSource)26 StringWriter (java.io.StringWriter)18 OMDocument (org.apache.axiom.om.OMDocument)18 DataHandler (javax.activation.DataHandler)14 XMLStreamReader (javax.xml.stream.XMLStreamReader)14 OMNode (org.apache.axiom.om.OMNode)14 OMException (org.apache.axiom.om.OMException)12 DataSource (javax.activation.DataSource)11 StringOMDataSource (org.apache.axiom.om.ds.StringOMDataSource)9 RandomDataSource (org.apache.axiom.testutils.activation.RandomDataSource)9 OMXMLParserWrapper (org.apache.axiom.om.OMXMLParserWrapper)8 Element (org.w3c.dom.Element)8