Search in sources :

Example 16 with LSSerializer

use of org.w3c.dom.ls.LSSerializer in project CloudStack-archive by CloudStack-extras.

the class VsmCommand method serialize.

private static String serialize(DOMImplementation domImpl, Document document) {
    DOMImplementationLS ls = (DOMImplementationLS) domImpl;
    LSSerializer lss = ls.createLSSerializer();
    return lss.writeToString(document);
}
Also used : DOMImplementationLS(org.w3c.dom.ls.DOMImplementationLS) LSSerializer(org.w3c.dom.ls.LSSerializer)

Example 17 with LSSerializer

use of org.w3c.dom.ls.LSSerializer in project jackson-databind by FasterXML.

the class DOMSerializer method serialize.

@Override
public void serialize(Node value, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonGenerationException {
    if (_domImpl == null)
        throw new IllegalStateException("Could not find DOM LS");
    LSSerializer writer = _domImpl.createLSSerializer();
    jgen.writeString(writer.writeToString(value));
}
Also used : LSSerializer(org.w3c.dom.ls.LSSerializer)

Example 18 with LSSerializer

use of org.w3c.dom.ls.LSSerializer in project opennms by OpenNMS.

the class JaxbClassObjectAdapter method unmarshal.

@Override
public Object unmarshal(final Object from) throws Exception {
    LOG.trace("unmarshal: from = ({}){}", (from == null ? null : from.getClass()), from);
    if (from == null)
        return null;
    if (from instanceof Node) {
        final Node e = (Node) from;
        e.normalize();
        final String nodeName = e.getNodeName();
        final Class<?> clazz = getClassForElement(nodeName);
        LOG.trace("class type = {} (node name = {})", clazz, nodeName);
        if (clazz == null) {
            LOG.warn("Unable to determine object type for node name {}. Known elements include: {}", nodeName, m_knownElementClasses);
            return from;
        }
        final DOMImplementationLS lsImpl = (DOMImplementationLS) e.getOwnerDocument().getImplementation().getFeature("LS", "3.0");
        LSSerializer serializer = lsImpl.createLSSerializer();
        //by default its true, so set it to false to get String without xml-declaration
        serializer.getDomConfig().setParameter("xml-declaration", false);
        final String str = serializer.writeToString(e);
        return JaxbUtils.unmarshal(clazz, str);
    } else {
        LOG.error("Unsure how to determine which class to use for unmarshaling object type {}", from.getClass());
        throw new IllegalArgumentException("Unsure how to determine which class to use for unmarshaling object type " + from.getClass());
    }
}
Also used : Node(org.w3c.dom.Node) DOMImplementationLS(org.w3c.dom.ls.DOMImplementationLS) LSSerializer(org.w3c.dom.ls.LSSerializer)

Example 19 with LSSerializer

use of org.w3c.dom.ls.LSSerializer in project wildfly by wildfly.

the class UsernameTokenCallbackHandler method toString.

private String toString(Node node) {
    String str = null;
    if (node != null) {
        DOMImplementationLS lsImpl = (DOMImplementationLS) node.getOwnerDocument().getImplementation().getFeature("LS", "3.0");
        LSSerializer serializer = lsImpl.createLSSerializer();
        //by default its true, so set it to false to get String without xml-declaration
        serializer.getDomConfig().setParameter("xml-declaration", false);
        str = serializer.writeToString(node);
    }
    return str;
}
Also used : DOMImplementationLS(org.w3c.dom.ls.DOMImplementationLS) LSSerializer(org.w3c.dom.ls.LSSerializer)

Example 20 with LSSerializer

use of org.w3c.dom.ls.LSSerializer in project cloudstack by apache.

the class VsmCommand method serialize.

private static String serialize(DOMImplementation domImpl, Document document) {
    DOMImplementationLS ls = (DOMImplementationLS) domImpl;
    LSSerializer lss = ls.createLSSerializer();
    return lss.writeToString(document);
}
Also used : DOMImplementationLS(org.w3c.dom.ls.DOMImplementationLS) LSSerializer(org.w3c.dom.ls.LSSerializer)

Aggregations

LSSerializer (org.w3c.dom.ls.LSSerializer)25 DOMImplementationLS (org.w3c.dom.ls.DOMImplementationLS)18 DOMException (org.w3c.dom.DOMException)8 StringWriter (java.io.StringWriter)7 DocumentBuilder (javax.xml.parsers.DocumentBuilder)7 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)7 Document (org.w3c.dom.Document)7 LSException (org.w3c.dom.ls.LSException)7 UnsupportedEncodingException (java.io.UnsupportedEncodingException)6 DOM3Serializer (org.apache.xml.serializer.DOM3Serializer)6 Serializer (org.apache.xml.serializer.Serializer)6 LSOutput (org.w3c.dom.ls.LSOutput)5 FileOutputStream (java.io.FileOutputStream)4 IOException (java.io.IOException)4 OutputStream (java.io.OutputStream)4 HttpURLConnection (java.net.HttpURLConnection)4 URL (java.net.URL)4 URLConnection (java.net.URLConnection)4 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)4 Element (org.w3c.dom.Element)4