Example usage for org.w3c.dom.ls DOMImplementationLS MODE_SYNCHRONOUS

List of usage examples for org.w3c.dom.ls DOMImplementationLS MODE_SYNCHRONOUS

Introduction

In this page you can find the example usage for org.w3c.dom.ls DOMImplementationLS MODE_SYNCHRONOUS.

Prototype

short MODE_SYNCHRONOUS

To view the source code for org.w3c.dom.ls DOMImplementationLS MODE_SYNCHRONOUS.

Click Source Link

Document

Create a synchronous LSParser.

Usage

From source file:org.apache.syncope.core.provisioning.camel.SyncopeCamelContext.java

private void loadContext(final Collection<String> routes) {
    try {/*from  w  w w . j  ava2s.c  o m*/
        DOMImplementationRegistry reg = DOMImplementationRegistry.newInstance();
        DOMImplementationLS domImpl = (DOMImplementationLS) reg.getDOMImplementation("LS");
        LSParser parser = domImpl.createLSParser(DOMImplementationLS.MODE_SYNCHRONOUS, null);

        JAXBContext jaxbContext = JAXBContext.newInstance(Constants.JAXB_CONTEXT_PACKAGES);
        Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
        List<RouteDefinition> routeDefs = new ArrayList<>();
        for (String route : routes) {
            try (InputStream input = IOUtils.toInputStream(route, StandardCharsets.UTF_8)) {
                LSInput lsinput = domImpl.createLSInput();
                lsinput.setByteStream(input);

                Node routeElement = parser.parse(lsinput).getDocumentElement();
                routeDefs.add(unmarshaller.unmarshal(routeElement, RouteDefinition.class).getValue());
            }
        }
        camelContext.addRouteDefinitions(routeDefs);
    } catch (Exception e) {
        LOG.error("While loading Camel context {}", e);
        throw new CamelException(e);
    }
}

From source file:org.xwiki.platform.patchservice.web.PatchServiceAction.java

private Document parseString(String content) {
    try {//from   w  w w  . j  a va2s  .  c  o m
        DOMImplementationLS lsImpl = (DOMImplementationLS) DOMImplementationRegistry.newInstance()
                .getDOMImplementation("LS 3.0");
        LSInput input = lsImpl.createLSInput();
        input.setCharacterStream(new StringReader(content));
        LSParser p = lsImpl.createLSParser(DOMImplementationLS.MODE_SYNCHRONOUS, null);
        return p.parse(input);
    } catch (Exception ex) {
        return null;
    }
}