Search in sources :

Example 41 with DocumentFragment

use of org.w3c.dom.DocumentFragment in project webservices-axiom by apache.

the class TestLookupPrefix method runTest.

protected void runTest() throws Throwable {
    Document document = dbf.newDocumentBuilder().newDocument();
    DocumentFragment fragment = document.createDocumentFragment();
    Element element = document.createElementNS("urn:test", "ns:root");
    element.setAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, "xmlns:ns", "urn:test");
    fragment.appendChild(element);
    assertNull(fragment.lookupPrefix("urn:test"));
}
Also used : Element(org.w3c.dom.Element) Document(org.w3c.dom.Document) DocumentFragment(org.w3c.dom.DocumentFragment)

Example 42 with DocumentFragment

use of org.w3c.dom.DocumentFragment in project webservices-axiom by apache.

the class TestReplaceChildFirstWithDocumentFragment method runTest.

protected void runTest() throws Throwable {
    Document document = dbf.newDocumentBuilder().newDocument();
    DocumentFragment fragment = document.createDocumentFragment();
    Element x = document.createElementNS(null, "x");
    Element y = document.createElementNS(null, "y");
    fragment.appendChild(x);
    fragment.appendChild(y);
    Element element = document.createElementNS(null, "parent");
    Element a = document.createElementNS(null, "a");
    Element b = document.createElementNS(null, "b");
    element.appendChild(a);
    element.appendChild(b);
    element.replaceChild(fragment, a);
    NodeList children = element.getChildNodes();
    assertEquals(3, children.getLength());
    assertSame(x, children.item(0));
    assertSame(y, children.item(1));
    assertSame(b, children.item(2));
    assertSame(element, x.getParentNode());
    assertSame(element, y.getParentNode());
    assertNull(fragment.getFirstChild());
    assertNull(fragment.getLastChild());
    assertEquals(0, fragment.getChildNodes().getLength());
    assertSame(x, element.getFirstChild());
    assertSame(b, element.getLastChild());
}
Also used : Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) Document(org.w3c.dom.Document) DocumentFragment(org.w3c.dom.DocumentFragment)

Example 43 with DocumentFragment

use of org.w3c.dom.DocumentFragment in project webservices-axiom by apache.

the class TestReplaceChildMiddleWithDocumentFragment method runTest.

protected void runTest() throws Throwable {
    Document document = dbf.newDocumentBuilder().newDocument();
    DocumentFragment fragment = document.createDocumentFragment();
    Element x = document.createElementNS(null, "x");
    Element y = document.createElementNS(null, "y");
    fragment.appendChild(x);
    fragment.appendChild(y);
    Element element = document.createElementNS(null, "parent");
    Element a = document.createElementNS(null, "a");
    Element b = document.createElementNS(null, "b");
    Element c = document.createElementNS(null, "c");
    element.appendChild(a);
    element.appendChild(b);
    element.appendChild(c);
    element.replaceChild(fragment, b);
    NodeList children = element.getChildNodes();
    assertEquals(4, children.getLength());
    assertSame(a, children.item(0));
    assertSame(x, children.item(1));
    assertSame(y, children.item(2));
    assertSame(c, children.item(3));
    assertSame(element, x.getParentNode());
    assertSame(element, y.getParentNode());
    assertNull(fragment.getFirstChild());
    assertNull(fragment.getLastChild());
    assertEquals(0, fragment.getChildNodes().getLength());
    assertSame(a, element.getFirstChild());
    assertSame(c, element.getLastChild());
}
Also used : Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) Document(org.w3c.dom.Document) DocumentFragment(org.w3c.dom.DocumentFragment)

Example 44 with DocumentFragment

use of org.w3c.dom.DocumentFragment in project cxf by apache.

the class ProviderImpl method convertToInternal.

/**
 * Convert from EndpointReference to CXF internal 2005/08 EndpointReferenceType
 *
 * @param external the javax.xml.ws.EndpointReference
 * @return CXF internal 2005/08 EndpointReferenceType
 */
public static EndpointReferenceType convertToInternal(EndpointReference external) {
    if (external instanceof W3CEndpointReference) {
        Unmarshaller um = null;
        try {
            DocumentFragment frag = DOMUtils.getEmptyDocument().createDocumentFragment();
            DOMResult result = new DOMResult(frag);
            external.writeTo(result);
            W3CDOMStreamReader reader = new W3CDOMStreamReader(frag);
            // CXF internal 2005/08 EndpointReferenceType should be
            // compatible with W3CEndpointReference
            // jaxContext = ContextUtils.getJAXBContext();
            JAXBContext context = JAXBContext.newInstance(new Class[] { org.apache.cxf.ws.addressing.ObjectFactory.class });
            um = context.createUnmarshaller();
            return um.unmarshal(reader, EndpointReferenceType.class).getValue();
        } catch (JAXBException e) {
            throw new IllegalArgumentException("Could not unmarshal EndpointReference", e);
        } finally {
            JAXBUtils.closeUnmarshaller(um);
        }
    }
    return null;
}
Also used : DOMResult(javax.xml.transform.dom.DOMResult) EndpointReferenceType(org.apache.cxf.ws.addressing.EndpointReferenceType) W3CDOMStreamReader(org.apache.cxf.staxutils.W3CDOMStreamReader) W3CEndpointReference(javax.xml.ws.wsaddressing.W3CEndpointReference) JAXBException(javax.xml.bind.JAXBException) JAXBContext(javax.xml.bind.JAXBContext) Unmarshaller(javax.xml.bind.Unmarshaller) DocumentFragment(org.w3c.dom.DocumentFragment)

Example 45 with DocumentFragment

use of org.w3c.dom.DocumentFragment in project cxf by apache.

the class LogicalMessageImpl method getPayload.

public Object getPayload(JAXBContext arg0) {
    try {
        Source s = getPayload();
        if (s instanceof DOMSource) {
            DOMSource ds = (DOMSource) s;
            ds.setNode(org.apache.cxf.helpers.DOMUtils.getDomElement(ds.getNode()));
            Node parent = ds.getNode().getParentNode();
            Node next = ds.getNode().getNextSibling();
            if (parent instanceof DocumentFragment) {
                parent.removeChild(ds.getNode());
            }
            try {
                return JAXBUtils.unmarshall(arg0, ds);
            } finally {
                if (parent instanceof DocumentFragment) {
                    parent.insertBefore(ds.getNode(), next);
                }
            }
        }
        return JAXBUtils.unmarshall(arg0, getPayload());
    } catch (JAXBException e) {
        throw new WebServiceException(e);
    }
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) WebServiceException(javax.xml.ws.WebServiceException) Node(org.w3c.dom.Node) JAXBException(javax.xml.bind.JAXBException) DOMSource(javax.xml.transform.dom.DOMSource) StreamSource(javax.xml.transform.stream.StreamSource) Source(javax.xml.transform.Source) DataSource(javax.activation.DataSource) DocumentFragment(org.w3c.dom.DocumentFragment)

Aggregations

DocumentFragment (org.w3c.dom.DocumentFragment)57 Document (org.w3c.dom.Document)27 Element (org.w3c.dom.Element)24 Node (org.w3c.dom.Node)20 NodeList (org.w3c.dom.NodeList)17 JAXBElement (javax.xml.bind.JAXBElement)8 Marshaller (javax.xml.bind.Marshaller)6 IOException (java.io.IOException)5 ArrayList (java.util.ArrayList)5 XMLStreamException (javax.xml.stream.XMLStreamException)5 DOMException (org.w3c.dom.DOMException)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 JAXBException (javax.xml.bind.JAXBException)4 DOMFragmentParser (org.cyberneko.html.parsers.DOMFragmentParser)4 Text (org.w3c.dom.Text)4 SAXException (org.xml.sax.SAXException)4 MalformedURLException (java.net.MalformedURLException)3 LinkedHashMap (java.util.LinkedHashMap)3 DocumentBuilder (javax.xml.parsers.DocumentBuilder)3 XMLStreamReader (javax.xml.stream.XMLStreamReader)3