Search in sources :

Example 6 with DOMImplementationRegistry

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);
    }
}
Also used : DOMImplementationLS(org.w3c.dom.ls.DOMImplementationLS) DOMImplementationRegistry(org.w3c.dom.bootstrap.DOMImplementationRegistry) LSSerializer(org.w3c.dom.ls.LSSerializer) LSOutput(org.w3c.dom.ls.LSOutput)

Example 7 with DOMImplementationRegistry

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);
}
Also used : DOMImplementationRegistry(org.w3c.dom.bootstrap.DOMImplementationRegistry) DOMImplementation(org.w3c.dom.DOMImplementation) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 8 with DOMImplementationRegistry

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;
}
Also used : DOMErrorHandler(org.w3c.dom.DOMErrorHandler) DOMError(org.w3c.dom.DOMError) QName(javax.xml.namespace.QName) DOMConfiguration(org.w3c.dom.DOMConfiguration) DOMImplementationRegistry(org.w3c.dom.bootstrap.DOMImplementationRegistry)

Example 9 with DOMImplementationRegistry

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);
    }
}
Also used : DOMErrorHandler(org.w3c.dom.DOMErrorHandler) DOMError(org.w3c.dom.DOMError) DOMImplementationRegistry(org.w3c.dom.bootstrap.DOMImplementationRegistry) LSException(org.w3c.dom.ls.LSException) SAXParserFactory(javax.xml.parsers.SAXParserFactory)

Example 10 with DOMImplementationRegistry

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);
}
Also used : IIOMetadata(javax.imageio.metadata.IIOMetadata) Element(org.w3c.dom.Element) ImageWriter(javax.imageio.ImageWriter) DOMImplementationRegistry(org.w3c.dom.bootstrap.DOMImplementationRegistry) DOMImplementation(org.w3c.dom.DOMImplementation) Document(org.w3c.dom.Document) BufferedImage(java.awt.image.BufferedImage) ImageTypeSpecifier(javax.imageio.ImageTypeSpecifier)

Aggregations

DOMImplementationRegistry (org.w3c.dom.bootstrap.DOMImplementationRegistry)11 DOMImplementationLS (org.w3c.dom.ls.DOMImplementationLS)6 DOMImplementation (org.w3c.dom.DOMImplementation)4 Document (org.w3c.dom.Document)4 LSSerializer (org.w3c.dom.ls.LSSerializer)4 Element (org.w3c.dom.Element)3 LSOutput (org.w3c.dom.ls.LSOutput)3 BufferedImage (java.awt.image.BufferedImage)2 ImageTypeSpecifier (javax.imageio.ImageTypeSpecifier)2 ImageWriter (javax.imageio.ImageWriter)2 IIOMetadata (javax.imageio.metadata.IIOMetadata)2 DocumentBuilder (javax.xml.parsers.DocumentBuilder)2 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)2 DOMError (org.w3c.dom.DOMError)2 DOMErrorHandler (org.w3c.dom.DOMErrorHandler)2 Node (org.w3c.dom.Node)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 StringReader (java.io.StringReader)1