use of org.w3c.dom.DOMImplementation in project cxf by apache.
the class ImportRepairTest method tryToParseSchemas.
private void tryToParseSchemas() throws Exception {
// Get DOM Implementation using DOM Registry
final List<DOMLSInput> inputs = new ArrayList<>();
final Map<String, LSInput> resolverMap = new HashMap<>();
for (XmlSchema schema : collection.getXmlSchemas()) {
if (XMLConstants.W3C_XML_SCHEMA_NS_URI.equals(schema.getTargetNamespace())) {
continue;
}
Document document = new XmlSchemaSerializer().serializeSchema(schema, false)[0];
DOMLSInput input = new DOMLSInput(document, schema.getTargetNamespace());
dumpSchema(document);
resolverMap.put(schema.getTargetNamespace(), input);
inputs.add(input);
}
DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();
DOMImplementation impl = registry.getDOMImplementation("XS-Loader");
try {
Object schemaLoader = findMethod(impl, "createXSLoader").invoke(impl, new Object[1]);
DOMConfiguration config = (DOMConfiguration) findMethod(schemaLoader, "getConfig").invoke(schemaLoader);
config.setParameter("validate", Boolean.TRUE);
try {
// bug in the JDK doesn't set this, but accesses it
config.setParameter("http://www.oracle.com/xml/jaxp/properties/xmlSecurityPropertyManager", Class.forName("com.sun.org.apache.xerces.internal.utils.XMLSecurityPropertyManager").newInstance());
config.setParameter("http://apache.org/xml/properties/security-manager", Class.forName("com.sun.org.apache.xerces.internal.utils.XMLSecurityManager").newInstance());
} catch (Throwable t) {
// ignore
}
config.setParameter("error-handler", new DOMErrorHandler() {
public boolean handleError(DOMError error) {
LOG.info("Schema parsing error: " + error.getMessage() + " " + error.getType() + " " + error.getLocation().getUri() + " " + error.getLocation().getLineNumber() + ":" + error.getLocation().getColumnNumber());
throw new DOMErrorException(error);
}
});
config.setParameter("resource-resolver", new LSResourceResolver() {
public LSInput resolveResource(String type, String namespaceURI, String publicId, String systemId, String baseURI) {
return resolverMap.get(namespaceURI);
}
});
Method m = findMethod(schemaLoader, "loadInputList");
String name = m.getParameterTypes()[0].getName() + "Impl";
name = name.replace("xs.LS", "impl.xs.util.LS");
Class<?> c = Class.forName(name);
Object inputList = c.getConstructor(LSInput[].class, Integer.TYPE).newInstance(inputs.toArray(new LSInput[inputs.size()]), inputs.size());
findMethod(schemaLoader, "loadInputList").invoke(schemaLoader, inputList);
} catch (InvocationTargetException ite) {
throw (Exception) ite.getTargetException();
}
}
use of org.w3c.dom.DOMImplementation in project cxf by apache.
the class HWStreamSourcePayloadProvider method getSOAPBodyStream.
private InputStream getSOAPBodyStream(Document doc) throws Exception {
// Try to get the DOMImplementation from the doc before
// defaulting to the sun implementation class (which uses
// sun internal xerces classes not found in the ibm jdk).
DOMImplementationLS impl = null;
DOMImplementation docImpl = doc.getImplementation();
if (docImpl != null && docImpl.hasFeature("LS", "3.0")) {
impl = (DOMImplementationLS) docImpl.getFeature("LS", "3.0");
} else {
System.setProperty(DOMImplementationRegistry.PROPERTY, "com.sun.org.apache.xerces.internal.dom.DOMImplementationSourceImpl");
DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();
impl = (DOMImplementationLS) registry.getDOMImplementation("LS");
}
LSOutput output = impl.createLSOutput();
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
output.setByteStream(byteArrayOutputStream);
LSSerializer writer = impl.createLSSerializer();
writer.write(doc, output);
byte[] buf = byteArrayOutputStream.toByteArray();
return new ByteArrayInputStream(buf);
}
use of org.w3c.dom.DOMImplementation in project Payara by payara.
the class DeveloperContentHandler method writeXML.
private synchronized void writeXML(final Node node, final Writer writer) throws ClassNotFoundException, InstantiationException, IllegalAccessException {
if (lsSerializer == null) {
final DOMImplementation domImpl = DOMImplementationRegistry.newInstance().getDOMImplementation("");
final DOMImplementationLS domLS = (DOMImplementationLS) domImpl.getFeature("LS", "3.0");
lsOutput = domLS.createLSOutput();
lsOutput.setEncoding("UTF-8");
lsSerializer = domLS.createLSSerializer();
}
lsOutput.setCharacterStream(writer);
lsSerializer.write(node, lsOutput);
}
use of org.w3c.dom.DOMImplementation in project Payara by payara.
the class J2EEDocumentBuilder method newDocument.
/**
* Creates and Return a new DOM document based on the current
* configuration
*
* @return the new DOM Document object
*/
public static Document newDocument() {
try {
// always use system default, see IT 8229
ClassLoader currentLoader = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(J2EEDocumentBuilder.class.getClassLoader());
DocumentBuilderFactory factory = null;
try {
factory = DocumentBuilderFactory.newInstance();
} finally {
Thread.currentThread().setContextClassLoader(currentLoader);
}
DocumentBuilder builder = factory.newDocumentBuilder();
DOMImplementation domImplementation = builder.getDOMImplementation();
Document document = builder.newDocument();
return document;
} catch (Exception e) {
DOLUtils.getDefaultLogger().log(Level.SEVERE, "enterprise.deployment.backend.saxParserError", new Object[] { "JAXP configuration error" });
DOLUtils.getDefaultLogger().log(Level.WARNING, "Error occurred", e);
}
return null;
}
use of org.w3c.dom.DOMImplementation in project yamcs-studio by yamcs.
the class SVGHandler method createWrapper.
private Document createWrapper(final SVGDocument doc) {
// creation of the SVG document
String svgNamespace = SVGDOMImplementation.SVG_NAMESPACE_URI;
DOMImplementation impl = SVGDOMImplementation.getDOMImplementation();
final Document newDocument = impl.createDocument(svgNamespace, "svg", null);
// get the root element
svgRootNode = newDocument.getDocumentElement();
mainGraphicNode = newDocument.createElementNS(svgNamespace, "g");
// attach the root of original doc to transform to the root
Node copiedRoot = newDocument.importNode(doc.getDocumentElement(), true);
mainGraphicNode.appendChild(copiedRoot);
svgRootNode.appendChild(mainGraphicNode);
updateMatrix();
return newDocument;
}
Aggregations