Example usage for org.w3c.dom DocumentType getPublicId

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

Introduction

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

Prototype

public String getPublicId();

Source Link

Document

The public identifier of the external subset.

Usage

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/*from www.j  a v a 2s .  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;/*from w ww . java  2  s . c  o  m*/

    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.openmrs.util.OpenmrsUtil.java

/**
 * Save the given xml document to the given outfile
 * //from w w w  . j av a2  s .com
 * @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 {/*from   w  w w . ja  v a  2s.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;
}