use of org.w3c.dom.bootstrap.DOMImplementationRegistry in project android by JetBrains.
the class ThemePreviewBuilder method printDebug.
private static void printDebug(@NotNull PrintStream out, @NotNull Document document) {
try {
DOMImplementationRegistry reg = DOMImplementationRegistry.newInstance();
DOMImplementationLS impl = (DOMImplementationLS) reg.getDOMImplementation("LS");
LSSerializer serializer = impl.createLSSerializer();
LSOutput lsOutput = impl.createLSOutput();
lsOutput.setEncoding("UTF-8");
lsOutput.setByteStream(out);
serializer.write(document, lsOutput);
} catch (ClassNotFoundException e) {
e.printStackTrace(out);
} catch (InstantiationException e) {
e.printStackTrace(out);
} catch (IllegalAccessException e) {
e.printStackTrace(out);
}
}
use of org.w3c.dom.bootstrap.DOMImplementationRegistry in project wildfly by wildfly.
the class DOMImplementationRegistryTestCase method testDOMImplementationRegistry.
@Test
@Ignore("[WFLY-4416] Cannot obtain DOMImplementationRegistry instance")
public void testDOMImplementationRegistry() throws Exception {
DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();
DOMImplementation domImpl = registry.getDOMImplementation("LS 3.0");
Assert.assertNotNull("DOMImplementation not null", domImpl);
}
use of org.w3c.dom.bootstrap.DOMImplementationRegistry in project intellij-community by JetBrains.
the class XSDModelLoader method loadSchema.
private XSModel loadSchema(File schemaFile, XMLEntityResolver resolver) throws Exception {
// get DOM Implementation using DOM Registry
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);
DOMConfiguration config = schemaLoader.getConfig();
// create Error Handler
DOMErrorHandler errorHandler = new DOMErrorHandler() {
public boolean handleError(DOMError domError) {
Util.log("DOMError: " + domError.getMessage());
Object relatedException = domError.getRelatedException();
if (relatedException != null) {
Util.log("DOMError: " + relatedException);
if (relatedException instanceof Throwable) {
((Throwable) relatedException).printStackTrace(System.out);
}
}
return false;
}
};
// set error handler
config.setParameter("error-handler", errorHandler);
// set validation feature
config.setParameter("validate", Boolean.TRUE);
// parse document
config.setParameter("error-handler", errorHandler);
config.setParameter("http://apache.org/xml/properties/internal/entity-resolver", resolver);
XSModel model = schemaLoader.loadURI(schemaFile.getAbsolutePath());
if (model == null)
return null;
XSNamedMap components = model.getComponents(XSConstants.ELEMENT_DECLARATION);
for (int i = 0; i < components.getLength(); i++) {
XSObject obj = components.item(i);
QName qname = new QName(obj.getNamespace(), obj.getName());
String file = this.model.qname2FileMap.get(qname);
this.model.qname2FileMap.put(qname, (file == null ? "" : file + ";") + schemaFile.getName());
}
components = model.getComponents(XSConstants.TYPE_DEFINITION);
for (int i = 0; i < components.getLength(); i++) {
XSObject obj = components.item(i);
QName qname = new QName(obj.getNamespace(), obj.getName());
String file = this.model.qname2FileMap.get(qname);
this.model.qname2FileMap.put(qname, (file == null ? "" : file) + ":" + schemaFile.getName() + ":");
}
return model;
}
use of org.w3c.dom.bootstrap.DOMImplementationRegistry in project ACS by ACS-Community.
the class HibernateWDALImpl method initializeParser.
private void initializeParser() throws RuntimeException {
try {
System.setProperty(DOMImplementationRegistry.PROPERTY, "org.apache.xerces.dom.DOMImplementationSourceImpl");
DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();
domImplementationLS = (DOMImplementationLS) registry.getDOMImplementation("LS");
parser = domImplementationLS.createLSParser(DOMImplementationLS.MODE_SYNCHRONOUS, "http://www.w3.org/2001/XMLSchema");
//parser.getDomConfig().setParameter("http://apache.org/xml/features/xinclude", Boolean.TRUE);
schemaResourceResolverLoader = new SchemaResourceResolverLoader(null, domImplementationLS, m_logger);
parser.getDomConfig().setParameter("resource-resolver", schemaResourceResolverLoader);
parser.getDomConfig().setParameter("http://apache.org/xml/features/validation/schema", Boolean.TRUE);
parser.getDomConfig().setParameter("error-handler", new DOMErrorHandler() {
public boolean handleError(DOMError error) {
//((Exception) error.getRelatedException()).printStackTrace();
throw new LSException(LSException.PARSE_ERR, error.getMessage());
}
});
input = domImplementationLS.createLSInput();
output = domImplementationLS.createLSOutput();
// SAX parser (non-validating)
SAXParserFactory factory = SAXParserFactory.newInstance();
saxParser = factory.newSAXParser();
} catch (Throwable th) {
throw new RuntimeException("Failed to initialize parser.", th);
}
}
use of org.w3c.dom.bootstrap.DOMImplementationRegistry in project jdk8u_jdk by JetBrains.
the class MergeStdCommentTest method main.
public static void main(String[] args) throws Exception {
String format = "javax_imageio_1.0";
BufferedImage img = new BufferedImage(16, 16, BufferedImage.TYPE_INT_RGB);
ImageWriter iw = ImageIO.getImageWritersByMIMEType("image/png").next();
IIOMetadata meta = iw.getDefaultImageMetadata(new ImageTypeSpecifier(img), null);
DOMImplementationRegistry registry;
registry = DOMImplementationRegistry.newInstance();
DOMImplementation impl = registry.getDOMImplementation("XML 3.0");
Document doc = impl.createDocument(null, format, null);
Element root, text, entry;
root = doc.getDocumentElement();
root.appendChild(text = doc.createElement("Text"));
text.appendChild(entry = doc.createElement("TextEntry"));
// keyword isn't #REQUIRED by the standard metadata format.
// However, it is required by the PNG format, so we include it here.
entry.setAttribute("keyword", "Comment");
entry.setAttribute("value", "Some demo comment");
meta.mergeTree(format, root);
}
Aggregations