Search in sources :

Example 31 with DOMImplementation

use of org.w3c.dom.DOMImplementation in project robovm by robovm.

the class DOMImplementationCreateDocument method testCreateDocument4.

public void testCreateDocument4() throws Throwable {
    Document doc;
    DOMImplementation domImpl;
    String namespaceURI = null;
    String qualifiedName = "dom:root";
    DocumentType docType = null;
    doc = (Document) load("staffNS", builder);
    domImpl = doc.getImplementation();
    {
        boolean success = false;
        try {
            domImpl.createDocument(namespaceURI, qualifiedName, docType);
        } catch (DOMException ex) {
            success = (ex.code == DOMException.NAMESPACE_ERR);
        }
        assertTrue("domimplementationcreatedocument04", success);
    }
}
Also used : DOMException(org.w3c.dom.DOMException) DOMImplementation(org.w3c.dom.DOMImplementation) DocumentType(org.w3c.dom.DocumentType) Document(org.w3c.dom.Document)

Example 32 with DOMImplementation

use of org.w3c.dom.DOMImplementation in project robovm by robovm.

the class DocumentTypePublicId method testGetPublicId.

/**
    * Runs the test case.
    * @throws Throwable Any uncaught exception causes test to fail
    */
public void testGetPublicId() throws Throwable {
    Document doc;
    DocumentType docType;
    DOMImplementation domImpl;
    String publicId;
    String nullNS = null;
    doc = (Document) load("staffNS", builder);
    domImpl = doc.getImplementation();
    docType = domImpl.createDocumentType("l2:root", "PUB", nullNS);
    publicId = docType.getPublicId();
    assertEquals("documenttypepublicid01", "PUB", publicId);
}
Also used : DocumentType(org.w3c.dom.DocumentType) DOMImplementation(org.w3c.dom.DOMImplementation) Document(org.w3c.dom.Document)

Example 33 with DOMImplementation

use of org.w3c.dom.DOMImplementation in project robovm by robovm.

the class DocumentTypeSystemId method testGetSystemId.

/**
    * Runs the test case.
    * @throws Throwable Any uncaught exception causes test to fail
    */
public void testGetSystemId() throws Throwable {
    Document doc;
    DocumentType docType;
    DOMImplementation domImpl;
    String publicId;
    String systemId;
    doc = (Document) load("staffNS", builder);
    domImpl = doc.getImplementation();
    docType = domImpl.createDocumentType("l2:root", "PUB", "SYS");
    publicId = docType.getPublicId();
    systemId = docType.getSystemId();
    assertEquals("documenttypepublicid01", "PUB", publicId);
    assertEquals("documenttypesystemid01", "SYS", systemId);
}
Also used : DocumentType(org.w3c.dom.DocumentType) DOMImplementation(org.w3c.dom.DOMImplementation) Document(org.w3c.dom.Document)

Example 34 with DOMImplementation

use of org.w3c.dom.DOMImplementation in project ddf by codice.

the class AbstractStsRealm method getFormattedXml.

/**
     * Transform into formatted XML.
     */
private String getFormattedXml(Node node) {
    Document document = node.getOwnerDocument().getImplementation().createDocument("", "fake", null);
    Element copy = (Element) document.importNode(node, true);
    document.importNode(node, false);
    document.removeChild(document.getDocumentElement());
    document.appendChild(copy);
    DOMImplementation domImpl = document.getImplementation();
    DOMImplementationLS domImplLs = (DOMImplementationLS) domImpl.getFeature("LS", "3.0");
    if (null != domImplLs) {
        LSSerializer serializer = domImplLs.createLSSerializer();
        serializer.getDomConfig().setParameter("format-pretty-print", true);
        return serializer.writeToString(document);
    } else {
        return "";
    }
}
Also used : Element(org.w3c.dom.Element) DOMImplementationLS(org.w3c.dom.ls.DOMImplementationLS) DOMImplementation(org.w3c.dom.DOMImplementation) LSSerializer(org.w3c.dom.ls.LSSerializer) Document(org.w3c.dom.Document)

Example 35 with DOMImplementation

use of org.w3c.dom.DOMImplementation in project JGroups by belaban.

the class XMLSchemaGenerator method main.

public static void main(String[] args) {
    String outputDir = "./";
    for (int i = 0; i < args.length; i++) {
        String arg = args[i];
        if ("-o".equals(arg)) {
            outputDir = args[++i];
        } else {
            System.out.println("XMLSchemaGenerator -o <path to newly created xsd schema file>");
            return;
        }
    }
    String version = Version.major + "." + Version.minor;
    File f = new File(outputDir, "jgroups-" + version + ".xsd");
    try {
        FileWriter fw = new FileWriter(f, false);
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder = factory.newDocumentBuilder();
        DOMImplementation impl = builder.getDOMImplementation();
        Document xmldoc = impl.createDocument("http://www.w3.org/2001/XMLSchema", "xs:schema", null);
        xmldoc.getDocumentElement().setAttribute("targetNamespace", "urn:org:jgroups");
        xmldoc.getDocumentElement().setAttribute("elementFormDefault", "qualified");
        xmldoc.getDocumentElement().setAttribute("attributeFormDefault", "qualified");
        xmldoc.getDocumentElement().setAttribute("version", version);
        Element complexType = xmldoc.createElement("xs:complexType");
        complexType.setAttribute("name", "ConfigType");
        xmldoc.getDocumentElement().appendChild(complexType);
        Element allType = xmldoc.createElement("xs:choice");
        allType.setAttribute("maxOccurs", "unbounded");
        complexType.appendChild(allType);
        generateProtocolSchema(xmldoc, allType, PACKAGES);
        Element xsElement = xmldoc.createElement("xs:element");
        xsElement.setAttribute("name", "config");
        xsElement.setAttribute("type", "ConfigType");
        xmldoc.getDocumentElement().appendChild(xsElement);
        DOMSource domSource = new DOMSource(xmldoc);
        StreamResult streamResult = new StreamResult(fw);
        TransformerFactory tf = TransformerFactory.newInstance();
        Transformer serializer = tf.newTransformer();
        serializer.setOutputProperty(OutputKeys.METHOD, "xml");
        serializer.setOutputProperty(OutputKeys.INDENT, "yes");
        serializer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
        serializer.transform(domSource, streamResult);
        fw.flush();
        fw.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) TransformerFactory(javax.xml.transform.TransformerFactory) Transformer(javax.xml.transform.Transformer) StreamResult(javax.xml.transform.stream.StreamResult) FileWriter(java.io.FileWriter) Element(org.w3c.dom.Element) XmlElement(org.jgroups.annotations.XmlElement) DOMImplementation(org.w3c.dom.DOMImplementation) Document(org.w3c.dom.Document) IOException(java.io.IOException) DocumentBuilder(javax.xml.parsers.DocumentBuilder) File(java.io.File)

Aggregations

DOMImplementation (org.w3c.dom.DOMImplementation)82 Document (org.w3c.dom.Document)67 DOMException (org.w3c.dom.DOMException)35 Element (org.w3c.dom.Element)34 DocumentType (org.w3c.dom.DocumentType)28 DocumentBuilder (javax.xml.parsers.DocumentBuilder)25 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)22 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)22 ArrayList (java.util.ArrayList)8 TransformerException (javax.xml.transform.TransformerException)6 DOMImplementationRegistry (org.w3c.dom.bootstrap.DOMImplementationRegistry)6 DOMImplementationLS (org.w3c.dom.ls.DOMImplementationLS)6 IOException (java.io.IOException)5 Transformer (javax.xml.transform.Transformer)5 DOMSource (javax.xml.transform.dom.DOMSource)5 StreamResult (javax.xml.transform.stream.StreamResult)5 Node (org.w3c.dom.Node)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 NodeList (org.w3c.dom.NodeList)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3