Example usage for org.w3c.dom.bootstrap DOMImplementationRegistry getDOMImplementation

List of usage examples for org.w3c.dom.bootstrap DOMImplementationRegistry getDOMImplementation

Introduction

In this page you can find the example usage for org.w3c.dom.bootstrap DOMImplementationRegistry getDOMImplementation.

Prototype

public DOMImplementation getDOMImplementation(final String features) 

Source Link

Document

Return the first implementation that has the desired features, or null if none is found.

Usage

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

private void loadContext(final Collection<String> routes) {
    try {//  ww  w  . j a v  a  2 s  . c om
        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.chiba.tools.schemabuilder.AbstractSchemaFormBuilder.java

private void loadSchema(String inputURI) throws java.lang.ClassNotFoundException,
        java.lang.InstantiationException, java.lang.IllegalAccessException {

    // Get DOM Implementation using DOM Registry
    System.setProperty(DOMImplementationRegistry.PROPERTY,
            "org.apache.xerces.dom.DOMXSImplementationSourceImpl");
    DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();
    Object o = registry.getDOMImplementation("XS-Loader");
    if (o instanceof XSImplementation) {
        XSImplementation impl = (XSImplementation) o;
        XSLoader schemaLoader = impl.createXSLoader(null);
        schema = schemaLoader.loadURI(inputURI);
    } else if (o != null) {
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("DOMImplementation is not a XSImplementation: " + o.getClass().getName());
        }/*w  w  w.  j a  va 2s  .c o m*/
        System.exit(1);
    }
}

From source file:org.chiba.xml.xforms.core.Model.java

private XSLoader getSchemaLoader()
        throws IllegalAccessException, InstantiationException, ClassNotFoundException {
    System.setProperty(DOMImplementationRegistry.PROPERTY,
            "org.apache.xerces.dom.DOMXSImplementationSourceImpl");
    DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();
    XSImplementation implementation = (XSImplementation) registry.getDOMImplementation("XS-Loader");
    XSLoader loader = implementation.createXSLoader(null);

    return loader;
}

From source file:org.deegree.tools.feature.gml.SchemaAnalyzer.java

/**
 * @param args/* www . j a  va2  s  .c o  m*/
 * @throws IllegalAccessException
 * @throws InstantiationException
 * @throws ClassNotFoundException
 * @throws ClassCastException
 * @throws IOException
 */
public static void main(String[] args) throws ClassCastException, ClassNotFoundException,
        InstantiationException, IllegalAccessException, IOException {

    Options options = initOptions();

    // for the moment, using the CLI API there is no way to respond to a help argument; see https://issues.apache.org/jira/browse/CLI-179
    if (args.length == 0 || (args.length > 0 && (args[0].contains("help") || args[0].contains("?")))) {
        printHelp(options);
    }

    try {
        new PosixParser().parse(options, args);

        String inputFileName = options.getOption(OPT_INPUT_FILE).getValue();
        String namespace = options.getOption(OPT_NAMESPACE).getValue();

        System.setProperty(DOMImplementationRegistry.PROPERTY,
                "org.apache.xerces.dom.DOMXSImplementationSourceImpl");
        DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();
        XSImplementation impl = (XSImplementation) registry.getDOMImplementation("XS-Loader");
        XSLoader schemaLoader = impl.createXSLoader(null);

        File inputFile = new File(inputFileName);
        System.out.println("Loading input schema: '" + inputFileName + "'");
        XSModel schema = schemaLoader.loadURI(inputFile.toURI().toURL().toString());
        SchemaAnalyzer analyzer = new SchemaAnalyzer(schema);

        // analyzer.printElementDeclarationSummary( "http://www.opengis.net/gml" );
        String s = analyzer.getElementDeclarationSummary(namespace);
        System.out.println(s);
    } catch (ParseException exp) {
        System.err.println("ERROR: Invalid command line: " + exp.getMessage());
    }
}

From source file:org.intellij.xquery.runner.rt.vendor.exist.ExistRunnerApp.java

private String prettyPrint(Element node, DOMImplementation domImplementation)
        throws InstantiationException, IllegalAccessException, ClassNotFoundException {
    DOMImplementationRegistry domImplementationRegistry = DOMImplementationRegistry.newInstance();
    DOMImplementationLS domImplementationLS = (DOMImplementationLS) domImplementationRegistry
            .getDOMImplementation("LS");
    LSOutput lsOutput = domImplementationLS.createLSOutput();
    LSSerializer lsSerializer = domImplementationLS.createLSSerializer();
    lsOutput.setEncoding("UTF-8");
    Writer stringWriter = new StringWriter();
    lsOutput.setCharacterStream(stringWriter);
    lsSerializer.write(node, lsOutput);//ww  w . j a  v  a  2 s  .  co  m
    String result = stringWriter.toString();
    return result;
}

From source file:org.jaggeryjs.modules.sso.common.util.Util.java

/**
 * Serializing a SAML2 object into a String
 *
 * @param xmlObject object that needs to serialized.
 * @return serialized object/*from  w  w  w.  j  a v a  2 s. co m*/
 * @throws Exception
 */
public static String marshall(XMLObject xmlObject) throws Exception {
    try {
        doBootstrap();
        System.setProperty("javax.xml.parsers.DocumentBuilderFactory",
                "org.apache.xerces.jaxp.DocumentBuilderFactoryImpl");

        MarshallerFactory marshallerFactory = org.opensaml.xml.Configuration.getMarshallerFactory();
        Marshaller marshaller = marshallerFactory.getMarshaller(xmlObject);
        Element element = marshaller.marshall(xmlObject);

        ByteArrayOutputStream byteArrayOutputStrm = new ByteArrayOutputStream();
        DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();
        DOMImplementationLS impl = (DOMImplementationLS) registry.getDOMImplementation("LS");
        LSSerializer writer = impl.createLSSerializer();
        LSOutput output = impl.createLSOutput();
        output.setByteStream(byteArrayOutputStrm);
        writer.write(element, output);
        return byteArrayOutputStrm.toString();
    } catch (Exception e) {
        throw new Exception("Error Serializing the SAML Response", e);
    }
}

From source file:org.mitre.eren.model.ModelManager.java

/**
 * Convert the message into a string and then parse it using the abdera parser.
 * Is there a simpler way to do this?/*from   w w  w  .j  av a  2s.c  o  m*/
 * @param edxl
 * @param outgoing
 */
private void attachMessage(EDXLDistribution edxl, Node outgoing) {

    try {
        DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();

        DOMImplementationLS impl = (DOMImplementationLS) registry.getDOMImplementation("LS");

        LSSerializer writer = impl.createLSSerializer();
        String str = writer.writeToString(outgoing);

        Abdera abdera = new Abdera();
        Parser parser = abdera.getParser();
        Document<Feed> feed_doc = parser.parse(new StringReader(str));
        ExtensibleElement content = feed_doc.getRoot();

        ContentObject co = edxl.addContentObject();
        XmlContent xc = co.setXmlContent();
        EmbeddedXMLContent exc = xc.addEmbeddedXMLContent();

        exc.addExtension(content);
    } catch (ClassCastException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (ClassNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (InstantiationException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}

From source file:org.sakaiproject.tool.assessment.qti.util.XmlStringBuffer.java

/**
 * string value of document// w w  w  .  j  a  va2s .  c o  m
 *
 * @return the string
 */
public final String stringValue() {
    if (log.isDebugEnabled()) {
        log.debug("stringValue()");
    }

    if (document == null) {
        return this.xml.toString();
    } else {
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        try {
            DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();
            DOMImplementationLS impl = (DOMImplementationLS) registry.getDOMImplementation("LS");
            LSSerializer writer = impl.createLSSerializer();
            writer.getDomConfig().setParameter("format-pretty-print", Boolean.TRUE);
            LSOutput output = impl.createLSOutput();
            output.setByteStream(out);
            writer.write(document, output);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
        return out.toString();
    }
}

From source file:org.sonar.plugins.xml.schemas.SchemaResolver.java

private static LSInput createLSInput(InputStream inputStream) {
    if (inputStream != null) {
        System.setProperty(DOMImplementationRegistry.PROPERTY,
                "org.apache.xerces.dom.DOMImplementationSourceImpl");

        try {/*  w ww . j a va 2  s  .co  m*/
            DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();
            DOMImplementation impl = registry.getDOMImplementation("XML 1.0 LS 3.0");
            DOMImplementationLS implls = (DOMImplementationLS) impl;
            LSInput lsInput = implls.createLSInput();
            lsInput.setByteStream(inputStream);
            return lsInput;
        } catch (ClassNotFoundException e) {
            throw new SonarException(e);
        } catch (InstantiationException e) {
            throw new SonarException(e);
        } catch (IllegalAccessException e) {
            throw new SonarException(e);
        }
    }
    return null;
}

From source file:org.wso2.appserver.webapp.security.utils.SSOUtils.java

/**
 * Serializes the specified SAML 2.0 based XML content representation to its corresponding actual XML syntax
 * representation./*from  www .ja  v  a  2 s .  co  m*/
 *
 * @param xmlObject the SAML 2.0 based XML content object
 * @return a {@link String} representation of the actual XML representation of the SAML 2.0 based XML content
 * representation
 * @throws SSOException if an error occurs during the marshalling process
 */
public static String marshall(XMLObject xmlObject) throws SSOException {
    try {
        Marshaller marshaller = XMLObjectProviderRegistrySupport.getMarshallerFactory()
                .getMarshaller(xmlObject);
        Element element = null;
        if (marshaller != null) {
            element = marshaller.marshall(xmlObject);
        }
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();
        DOMImplementationLS implementation = (DOMImplementationLS) registry.getDOMImplementation("LS");
        LSSerializer writer = implementation.createLSSerializer();
        LSOutput output = implementation.createLSOutput();
        output.setByteStream(byteArrayOutputStream);
        writer.write(element, output);
        return new String(byteArrayOutputStream.toByteArray(), StandardCharsets.UTF_8);
    } catch (ClassNotFoundException | InstantiationException | MarshallingException
            | IllegalAccessException e) {
        throw new SSOException("Error in marshalling SAML 2.0 Assertion", e);
    }
}