List of usage examples for org.w3c.dom.bootstrap DOMImplementationRegistry newInstance
public static DOMImplementationRegistry newInstance() throws ClassNotFoundException, InstantiationException, IllegalAccessException, ClassCastException
DOMImplementationRegistry
. 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// w ww . j av a 2 s .co 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);/*from w ww . j a v a 2s .c o 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// ww w . j av a 2 s. c o 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 ww w . j a v a2 s . com*/ * @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.phenotips.tools.PropertyDisplayerTest.java
/** Instantiates the {@link #domls DOM parser}. */ public PropertyDisplayerTest() throws ClassNotFoundException, InstantiationException, IllegalAccessException { this.domls = (DOMImplementationLS) DOMImplementationRegistry.newInstance().getDOMImplementation("LS 3.0"); }
From source file:org.sakaiproject.tool.assessment.qti.util.XmlStringBuffer.java
/** * string value of document//from w ww.j a v a 2 s . co 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 w w . j av a 2 s . c o 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 w ww . j a v a2 s .c o 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); } }
From source file:org.wso2.carbon.identity.application.authenticator.samlsso.util.SSOUtils.java
/** * Serializing a SAML2 object into a String * * @param xmlObject object that needs to serialized. * @return serialized object// w w w . j ava 2 s .c o m * @throws SAMLSSOException */ public static String marshall(XMLObject xmlObject) throws SAMLSSOException { try { 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) { log.error("Error Serializing the SAML Response"); throw new SAMLSSOException("Error Serializing the SAML Response", e); } }