Example usage for org.w3c.dom DocumentType getSystemId

List of usage examples for org.w3c.dom DocumentType getSystemId

Introduction

In this page you can find the example usage for org.w3c.dom DocumentType getSystemId.

Prototype

public String getSystemId();

Source Link

Document

The system identifier of the external subset.

Usage

From source file:com.gargoylesoftware.htmlunit.javascript.host.html.HTMLDocument.java

private boolean isQuirksDocType(final BrowserVersion browserVersion) {
    final DocumentType docType = getPage().getDoctype();
    if (docType != null) {
        final String systemId = docType.getSystemId();
        if (systemId != null) {
            if ("http://www.w3.org/TR/html4/strict.dtd".equals(systemId)) {
                return false;
            }/*w  w w.j  av a 2s.com*/

            if ("http://www.w3.org/TR/html4/loose.dtd".equals(systemId)) {
                final String publicId = docType.getPublicId();
                if ("-//W3C//DTD HTML 4.01 Transitional//EN".equals(publicId)) {
                    return false;
                }
            }

            if ("http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd".equals(systemId)
                    || "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd".equals(systemId)) {
                return false;
            }
        } else if (docType.getPublicId() == null) {
            if (docType.getName() != null) {
                return false;
            }
            return true;
        }
    }
    return true;
}

From source file:org.apache.stratos.load.balancer.conf.configurator.SynapseConfigurator.java

/**
 * Write xml document to file.//from   ww  w  .  j av  a 2s.  c  om
 *
 * @param document
 * @param outputFilePath
 * @throws IOException
 */
private static void write(Document document, String outputFilePath) throws IOException {
    try {
        Transformer transformer = TransformerFactory.newInstance().newTransformer();
        DocumentType documentType = document.getDoctype();
        if (documentType != null) {
            String publicId = documentType.getPublicId();
            if (publicId != null) {
                transformer.setOutputProperty(OutputKeys.DOCTYPE_PUBLIC, publicId);
            }
            transformer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, documentType.getSystemId());
        }
        transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
        transformer.setOutputProperty(OutputKeys.INDENT, "yes");
        transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
        Source source = new DOMSource(document);
        FileOutputStream outputStream = new FileOutputStream(outputFilePath);
        Result result = new StreamResult(outputStream);
        transformer.transform(source, result);
    } catch (Exception e) {
        throw new RuntimeException(String.format("Could not write xml file: s%", outputFilePath), e);
    }
}

From source file:org.cruxframework.crux.core.declarativeui.ViewParser.java

/**
 * @param cruxPageDocument//ww  w . j a  v a  2  s.  co  m
 * @return
 */
private Document createHTMLDocument(Document cruxPageDocument) {
    Document htmlDocument;
    DocumentType doctype = cruxPageDocument.getDoctype();

    if (doctype != null
            || Boolean.parseBoolean(ConfigurationFactory.getConfigurations().enableGenerateHTMLDoctype())) {
        String name = doctype != null ? doctype.getName() : "HTML";
        String publicId = doctype != null ? doctype.getPublicId() : null;
        String systemId = doctype != null ? doctype.getSystemId() : null;

        DocumentType newDoctype = documentBuilder.getDOMImplementation().createDocumentType(name, publicId,
                systemId);
        htmlDocument = documentBuilder.getDOMImplementation().createDocument(XHTML_NAMESPACE, "html",
                newDoctype);
    } else {
        htmlDocument = documentBuilder.newDocument();
        Element cruxPageElement = cruxPageDocument.getDocumentElement();
        Node htmlElement = htmlDocument.importNode(cruxPageElement, false);
        htmlDocument.appendChild(htmlElement);
    }

    String manifest = cruxPageDocument.getDocumentElement().getAttribute("manifest");
    if (!StringUtils.isEmpty(manifest)) {
        htmlDocument.getDocumentElement().setAttribute("manifest", manifest);
    }
    return htmlDocument;
}

From source file:org.dspace.installer_edm.InstallerEDMAskosi.java

/**
 * Modifica el archivo web.xml de Askosi para indicarle el directorio de datos de Askosi
 *
 * @param webXmlFile archivo web.xml de Askosi
 */// w ww .j ava2  s.c  om
private void changeWebXml(File webXmlFile, String webXmlFileName) {
    try {
        // se abre con DOM el archivo web.xml
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        factory.setNamespaceAware(true);
        DocumentBuilder builder = factory.newDocumentBuilder();
        Document doc = builder.parse(webXmlFile);
        XPath xpathInputForms = XPathFactory.newInstance().newXPath();

        // se busca el elemento SKOSdirectory
        NodeList results = (NodeList) xpathInputForms.evaluate("//*[contains(*,\"SKOSdirectory\")]", doc,
                XPathConstants.NODESET);
        if (results.getLength() > 0) {
            Element contextParam = (Element) results.item(0);

            // se busca el elemento context-param como hijo del anterior
            if (contextParam.getTagName().equals("context-param")) {

                // se busca el elemento param-value como hijo del anterior
                NodeList resultsParamValue = contextParam.getElementsByTagName("param-value");
                if (resultsParamValue.getLength() > 0) {

                    // se modifica con la ruta del directorio de datos de Askosi
                    Element valueParam = (Element) resultsParamValue.item(0);
                    Text text = doc.createTextNode(finalAskosiDataDestDirFile.getAbsolutePath());
                    valueParam.replaceChild(text, valueParam.getFirstChild());

                    // se guarda
                    TransformerFactory transformerFactory = TransformerFactory.newInstance();
                    Transformer transformer = transformerFactory.newTransformer();
                    transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no");
                    transformer.setOutputProperty(OutputKeys.METHOD, "xml");
                    transformer.setOutputProperty(OutputKeys.INDENT, "yes");
                    //transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
                    transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
                    DocumentType docType = doc.getDoctype();
                    if (docType != null) {
                        if (docType.getPublicId() != null)
                            transformer.setOutputProperty(OutputKeys.DOCTYPE_PUBLIC, docType.getPublicId());
                        transformer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, docType.getSystemId());
                    }
                    DOMSource source = new DOMSource(doc);
                    StreamResult result = (fileSeparator.equals("\\")) ? new StreamResult(webXmlFileName)
                            : new StreamResult(webXmlFile);
                    transformer.transform(source, result);
                }
            }
        } else
            installerEDMDisplay.showQuestion(currentStepGlobal, "changeWebXml.noSKOSdirectory",
                    new String[] { webXmlFile.getAbsolutePath() });
    } catch (ParserConfigurationException e) {
        showException(e);
    } catch (SAXException e) {
        showException(e);
    } catch (IOException e) {
        showException(e);
    } catch (XPathExpressionException e) {
        showException(e);
    } catch (TransformerConfigurationException e) {
        showException(e);
    } catch (TransformerException e) {
        showException(e);
    }

}

From source file:org.dspace.installer_edm.InstallerEDMConfEDMExport.java

/**
 * Aadimos el contenido del documento jdom como archivo web.xml al flujo de escritura del war
 *
 * @param jarOutputStream flujo de escritura del war
 * @throws TransformerException/*  w  w w  .  ja va2  s. c om*/
 * @throws IOException
 */
private void addNewWebXml(JarOutputStream jarOutputStream) throws TransformerException, IOException {
    TransformerFactory transformerFactory = TransformerFactory.newInstance();
    Transformer transformer = transformerFactory.newTransformer();
    transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no");
    transformer.setOutputProperty(OutputKeys.METHOD, "xml");
    transformer.setOutputProperty(OutputKeys.INDENT, "yes");
    //transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
    transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
    DocumentType docType = eDMExportDocument.getDoctype();
    if (docType != null) {
        if (docType.getPublicId() != null)
            transformer.setOutputProperty(OutputKeys.DOCTYPE_PUBLIC, docType.getPublicId());
        transformer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, docType.getSystemId());
    }
    StringWriter sw = new StringWriter();
    StreamResult result = new StreamResult(sw);
    DOMSource source = new DOMSource(eDMExportDocument);
    transformer.transform(source, result);
    String xmlString = sw.toString();
    jarOutputStream.putNextEntry(new JarEntry("WEB-INF/web.xml"));
    jarOutputStream.write(xmlString.getBytes());
    jarOutputStream.closeEntry();
}

From source file:org.josso.tooling.gshell.install.installer.VFSInstaller.java

protected Document readContentAsDom(FileObject file, boolean nameSpaceAware) throws Exception {
    InputStream is = null;/*w  w w.  j  av  a2 s.  c  om*/

    try {
        is = file.getContent().getInputStream();

        DocumentBuilderFactory parserFactory = DocumentBuilderFactory.newInstance();
        parserFactory.setValidating(false);
        parserFactory.setNamespaceAware(nameSpaceAware);
        parserFactory.setIgnoringElementContentWhitespace(false);
        parserFactory.setIgnoringComments(false);

        DocumentBuilder builder = parserFactory.newDocumentBuilder();

        boolean dtdNotFound = false;
        Document doc = null;
        try {
            doc = builder.parse(is);
        } catch (FileNotFoundException e) {
            dtdNotFound = true;
        }

        // if dtd doesn't exist parse the document again without trying to load dtd
        if (dtdNotFound) {
            is = file.getContent().getInputStream();
            // disable dtd loading
            parserFactory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
            builder = parserFactory.newDocumentBuilder();
            doc = builder.parse(is);
        }

        DocumentType docType = doc.getDoctype();

        if (log.isDebugEnabled() && docType != null) {
            log.debug("docType.getPublicId()=" + docType.getPublicId());
            log.debug("docType.getSystemId()=" + docType.getSystemId());
        }

        return doc;
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        throw e;
    } finally {
        if (is != null)
            try {
                is.close();
            } catch (IOException e) {
                /**/}
    }

}

From source file:org.jzkit.search.util.RecordModel.XMLRecord.java

public String getDocumentSchema() {
    // return getDocument().getDocumentElement().getNodeName();
    DocumentType doctype = getDocument().getDoctype();

    if (doctype != null) {
        return doctype.getSystemId(); // Or getPublicId()
    }//w  w w . j  av  a  2s.  c o  m

    return getDocument().getDocumentElement().getNodeName();
}

From source file:org.openmrs.util.OpenmrsUtil.java

/**
 * Save the given xml document to the given outfile
 * /*from w w  w . j a  va 2 s  .c  o  m*/
 * @param doc Document to be saved
 * @param outFile file pointer to the location the xml file is to be saved to
 */
public static void saveDocument(Document doc, File outFile) {
    OutputStream outStream = null;
    try {
        outStream = new FileOutputStream(outFile);
        TransformerFactory tFactory = TransformerFactory.newInstance();
        Transformer transformer = tFactory.newTransformer();
        transformer.setOutputProperty(OutputKeys.INDENT, "yes");

        DocumentType doctype = doc.getDoctype();
        if (doctype != null) {
            transformer.setOutputProperty(OutputKeys.DOCTYPE_PUBLIC, doctype.getPublicId());
            transformer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, doctype.getSystemId());
        }

        DOMSource source = new DOMSource(doc);
        StreamResult result = new StreamResult(outStream);
        transformer.transform(source, result);
    } catch (TransformerException e) {
        throw new ModuleException("Error while saving dwrmodulexml back to dwr-modules.xml", e);
    } catch (FileNotFoundException e) {
        throw new ModuleException(outFile.getAbsolutePath() + " file doesn't exist.", e);
    } finally {
        try {
            if (outStream != null) {
                outStream.close();
            }
        } catch (Exception e) {
            log.warn("Unable to close outstream", e);
        }
    }
}

From source file:tufts.vue.ds.XMLIngest.java

public static Schema ingestXML(XmlSchema schema, org.xml.sax.InputSource input, String itemKey) {
    final org.w3c.dom.Document doc = parseXML(input, false);

    //doc.normalizeDocument();
    if (DEBUG.DR) {
        try {//  w  w  w  .  j  a  va2  s  . c om
            errout("XML parsed, document built:");
            errout("org.w3c.dom.Document: " + Util.tags(doc));
            final org.w3c.dom.DocumentType type = doc.getDoctype();
            //errout("InputEncoding: " + doc.getInputEncoding()); // AbstractMethodError ?
            //errout("xmlEncoding: " + doc.getXmlEncoding()); // AbstractMethodError
            //errout("xmlVersion: " + doc.getXmlVersion()); // AbstractMethodError
            errout("docType: " + Util.tags(type));
            if (type != null) {
                errout("docType.name: " + Util.tags(type.getName()));
                errout("docType.entities: " + Util.tags(type.getEntities()));
                errout("docType.notations: " + Util.tags(type.getNotations()));
                errout("docType.publicId: " + Util.tags(type.getPublicId()));
                errout("docType.systemId: " + Util.tags(type.getSystemId()));
            }
            errout("impl: " + Util.tags(doc.getImplementation().getClass()));
            errout("docElement: " + Util.tags(doc.getDocumentElement().getClass())); // toString() can dump whole document!
        } catch (Throwable t) {
            Log.error("debug failure", t);
        }
    }
    //out("element: " + Util.tags(doc.getDocumentElement()));

    //outln("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>");
    //outln("<!-- created by RSSTest " + new Date() + " from " + src + " -->");

    if (schema == null)
        schema = new XmlSchema(tufts.vue.Resource.instance(input), itemKey);
    else
        schema.flushData();

    if (false)
        XPathExtract(schema, doc);
    else
        scanNode(schema, doc.getDocumentElement(), null, null);

    if (DEBUG.DR || DEBUG.SCHEMA)
        schema.dumpSchema(System.err);
    return schema;
}