Example usage for javax.xml.parsers DocumentBuilder newDocument

List of usage examples for javax.xml.parsers DocumentBuilder newDocument

Introduction

In this page you can find the example usage for javax.xml.parsers DocumentBuilder newDocument.

Prototype


public abstract Document newDocument();

Source Link

Document

Obtain a new instance of a DOM Document object to build a DOM tree with.

Usage

From source file:net.sf.jabref.logic.exporter.OOCalcDatabase.java

public Document getDOMrepresentation() {
    Document result = null;/*from  ww  w  .  j a  v a  2  s .  c  o  m*/
    try {
        DocumentBuilder dbuild = DocumentBuilderFactory.newInstance().newDocumentBuilder();
        result = dbuild.newDocument();
        Element collection = result.createElement("office:document-content");
        //collection.setAttribute("xmlns", "http://openoffice.org/2000/office");
        collection.setAttribute("xmlns:office", "http://openoffice.org/2000/office");
        collection.setAttribute("xmlns:style", "http://openoffice.org/2000/style");
        collection.setAttribute("xmlns:text", "http://openoffice.org/2000/text");
        collection.setAttribute("xmlns:table", "http://openoffice.org/2000/table");
        collection.setAttribute("xmlns:office:class", "spreadsheet");
        collection.setAttribute("xmlns:office:version", "1.0");
        collection.setAttribute("xmlns:fo", "http://www.w3.org/1999/XSL/Format");
        Element el = result.createElement("office:script");
        collection.appendChild(el);

        el = result.createElement("office:automatic-styles");
        Element el2 = result.createElement("style:style");
        el2.setAttribute("style:name", "ro1");
        el2.setAttribute("style:family", "table-row");
        Element el3 = result.createElement("style.properties");
        el3.setAttribute("style:row-height", "0.1681inch");
        el3.setAttribute("fo:break-before", "auto");
        el3.setAttribute("style:use-optimal-row-height", "true");
        el2.appendChild(el3);
        el.appendChild(el2);
        el2 = result.createElement("style:style");
        el2.setAttribute("style:name", "ta1");
        el2.setAttribute("style:family", "table");
        el2.setAttribute("style:master-page-name", "Default");
        el3 = result.createElement("style:properties");
        el3.setAttribute("table:display", "true");
        el2.appendChild(el3);
        el.appendChild(el2);
        collection.appendChild(el);

        Element body = result.createElement("office:body");
        Element table = result.createElement("table:table");
        table.setAttribute("table:name", "biblio");
        table.setAttribute("table.style-name", "ta1");

        Element row = result.createElement("table:table-row");
        row.setAttribute("table.style-name", "ro1");
        addTableCell(result, row, "Type");
        addTableCell(result, row, "ISBN");
        addTableCell(result, row, "Identifier");
        addTableCell(result, row, "Author");
        addTableCell(result, row, "Title");
        addTableCell(result, row, "Journal");
        addTableCell(result, row, "Volume");
        addTableCell(result, row, "Number");
        addTableCell(result, row, "Month");
        addTableCell(result, row, "Pages");
        addTableCell(result, row, "Year");
        addTableCell(result, row, "Address");
        addTableCell(result, row, "Note");
        addTableCell(result, row, "URL");
        addTableCell(result, row, "Booktitle");
        addTableCell(result, row, "Chapter");
        addTableCell(result, row, "Edition");
        addTableCell(result, row, "Series");
        addTableCell(result, row, "Editor");
        addTableCell(result, row, "Publisher");
        addTableCell(result, row, "ReportType");
        addTableCell(result, row, "Howpublished");
        addTableCell(result, row, "Institution");
        addTableCell(result, row, "Organization");
        addTableCell(result, row, "School");
        addTableCell(result, row, "Annote");
        addTableCell(result, row, "Assignee");
        addTableCell(result, row, "Day");
        addTableCell(result, row, "Dayfiled");
        addTableCell(result, row, "Monthfiled");
        addTableCell(result, row, "Yearfiled");
        addTableCell(result, row, "Language");
        addTableCell(result, row, "Nationality");
        addTableCell(result, row, "Revision");
        addTableCell(result, row, "Custom1");
        addTableCell(result, row, "Custom2");
        addTableCell(result, row, "Custom3");
        addTableCell(result, row, "Custom4");
        addTableCell(result, row, "Custom5");
        table.appendChild(row);

        for (BibEntry e : entries) {
            row = result.createElement("table:table-row");
            addTableCell(result, row, new GetOpenOfficeType().format(e.getType()));
            addTableCell(result, row, getField(e, FieldName.ISBN));
            addTableCell(result, row, getField(e, BibEntry.KEY_FIELD));
            addTableCell(result, row, getField(e, FieldName.AUTHOR));//new AuthorLastFirst().format(getField(e, FieldName.AUTHOR_FIELD)));
            addTableCell(result, row,
                    new RemoveWhitespace().format(new RemoveBrackets().format(getField(e, FieldName.TITLE))));
            addTableCell(result, row, getField(e, FieldName.JOURNAL));
            addTableCell(result, row, getField(e, FieldName.VOLUME));
            addTableCell(result, row, getField(e, FieldName.NUMBER));
            addTableCell(result, row, getField(e, FieldName.MONTH));
            addTableCell(result, row, getField(e, FieldName.PAGES));
            addTableCell(result, row, getField(e, FieldName.YEAR));
            addTableCell(result, row, getField(e, "address"));
            addTableCell(result, row, getField(e, "note"));
            addTableCell(result, row, getField(e, FieldName.URL));
            addTableCell(result, row, getField(e, "booktitle"));
            addTableCell(result, row, getField(e, "chapter"));
            addTableCell(result, row, getField(e, "edition"));
            addTableCell(result, row, getField(e, "series"));
            addTableCell(result, row, getField(e, FieldName.EDITOR));//new AuthorLastFirst().format(getField(e, FieldName.EDITOR_FIELD)));
            addTableCell(result, row, getField(e, FieldName.PUBLISHER));
            addTableCell(result, row, getField(e, "reporttype"));
            addTableCell(result, row, getField(e, "howpublished"));
            addTableCell(result, row, getField(e, "institution"));
            addTableCell(result, row, getField(e, "organization"));
            addTableCell(result, row, getField(e, "school"));
            addTableCell(result, row, getField(e, "annote"));
            addTableCell(result, row, getField(e, "assignee"));
            addTableCell(result, row, getField(e, "day"));
            addTableCell(result, row, getField(e, "dayfiled"));
            addTableCell(result, row, getField(e, "monthfiled"));
            addTableCell(result, row, getField(e, "yearfiled"));
            addTableCell(result, row, getField(e, "language"));
            addTableCell(result, row, getField(e, "nationality"));
            addTableCell(result, row, getField(e, "revision"));
            addTableCell(result, row, "");
            addTableCell(result, row, "");
            addTableCell(result, row, "");
            addTableCell(result, row, "");
            addTableCell(result, row, "");
            table.appendChild(row);
        }

        body.appendChild(table);
        collection.appendChild(body);

        result.appendChild(collection);
    } catch (Exception e) {
        LOGGER.warn("Exception caught...", e);
    }
    return result;
}

From source file:org.bigtester.ate.model.data.TestDatabaseInitializer.java

/**
 * Combine init xml files./*from w  w w.j a v  a2  s. c  o m*/
 *
 * @return the input stream
 */
private InputStream combineInitXmlFiles() {
    if (getInitXmlFiles().isEmpty()) {
        throw GlobalUtils.createNotInitializedException("xml data files are not populated");
    } else {
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        dbf.setValidating(false);
        DocumentBuilder dbuilder;
        try {
            dbuilder = dbf.newDocumentBuilder();

            Document retDoc = dbuilder.newDocument();
            Document doc0;

            doc0 = dbuilder.parse(getInitXmlFiles().get(0));

            Node firstDataset = retDoc.importNode(doc0.getFirstChild(), true);
            retDoc.appendChild(firstDataset);
            for (int i = 1; i < getInitXmlFiles().size(); i++) {
                Document doc2 = dbuilder.parse(getInitXmlFiles().get(i));
                Node root = doc2.getFirstChild();
                NodeList list = root.getChildNodes();
                for (int index = 0; index < list.getLength(); index++) {
                    Node copiedNode = retDoc.importNode(list.item(index), true);
                    retDoc.getDocumentElement().appendChild(copiedNode);
                }
            }

            DOMSource source = new DOMSource(retDoc);
            StringWriter xmlAsWriter = new StringWriter();

            StreamResult result = new StreamResult(xmlAsWriter);

            TransformerFactory.newInstance().newTransformer().transform(source, result);

            // write changes
            return new ByteArrayInputStream(xmlAsWriter.toString().getBytes("UTF-8"));

        } catch (SAXException | IOException | ParserConfigurationException e) {
            throw GlobalUtils.createNotInitializedException("xml data files are not correctly populated", e);
        } catch (TransformerException | TransformerFactoryConfigurationError transE) {
            throw GlobalUtils.createInternalError("xml transformer error!", transE);
        }

    }
}

From source file:net.sourceforge.fullsync.fs.connection.SyncFileBufferedConnection.java

public void saveToBuffer() throws IOException {
    File fsRoot = fs.getRoot();// w  w  w . ja v  a 2 s  . c om
    File node = fsRoot.getChild(BUFFER_FILENAME);
    if ((null == node) || !node.exists()) {
        node = root.createChild(BUFFER_FILENAME, false);
    }

    try {
        DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
        Document doc = docBuilder.newDocument();

        Element e = doc.createElement(ELEMENT_SYNC_FILES);
        e.appendChild(serializeFile(root, doc));
        doc.appendChild(e);
        TransformerFactory fac = TransformerFactory.newInstance();
        fac.setAttribute("indent-number", 2); //$NON-NLS-1$
        Transformer tf = fac.newTransformer();
        tf.setOutputProperty(OutputKeys.METHOD, "xml"); //$NON-NLS-1$
        tf.setOutputProperty(OutputKeys.VERSION, "1.0"); //$NON-NLS-1$
        tf.setOutputProperty(OutputKeys.INDENT, "yes"); //$NON-NLS-1$
        tf.setOutputProperty(OutputKeys.STANDALONE, "no"); //$NON-NLS-1$
        DOMSource source = new DOMSource(doc);

        try (OutputStreamWriter osw = new OutputStreamWriter(new GZIPOutputStream(node.getOutputStream()),
                StandardCharsets.UTF_8)) {
            tf.transform(source, new StreamResult(osw));
            osw.flush();
        }
    } catch (IOException | ParserConfigurationException | FactoryConfigurationError | TransformerException e) {
        ExceptionHandler.reportException(e);
    }
}

From source file:net.sf.jabref.exporter.OpenDocumentRepresentation.java

public Document getDOMrepresentation() {
    Document result = null;//  w w  w  .  ja  va 2 s .  c o  m
    try {
        DocumentBuilder dbuild = DocumentBuilderFactory.newInstance().newDocumentBuilder();
        result = dbuild.newDocument();
        Element collection = result.createElement("office:document-content");
        //collection.setAttribute("xmlns", "http://openoffice.org/2000/office");
        collection.setAttribute("xmlns:office", "urn:oasis:names:tc:opendocument:xmlns:office:1.0");
        collection.setAttribute("xmlns:style", "urn:oasis:names:tc:opendocument:xmlns:style:1.0");
        collection.setAttribute("xmlns:text", "urn:oasis:names:tc:opendocument:xmlns:text:1.0");
        collection.setAttribute("xmlns:table", "urn:oasis:names:tc:opendocument:xmlns:table:1.0");
        collection.setAttribute("xmlns:meta", "urn:oasis:names:tc:opendocument:xmlns:meta:1.0");
        collection.setAttribute("office:version", "1.0");
        collection.setAttribute("xmlns:fo", "urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0");
        collection.setAttribute("xmlns:xlink", "http://www.w3.org/1999/xlink");
        Element el = result.createElement("office:scripts");
        collection.appendChild(el);

        el = result.createElement("office:automatic-styles");
        Element el2 = result.createElement("style:style");
        el2.setAttribute("style:name", "ro1");
        el2.setAttribute("style:family", "table-row");
        Element el3 = result.createElement("style.table-row-properties");
        el3.setAttribute("style:row-height", "0.1681inch");
        el3.setAttribute("fo:break-before", "auto");
        el3.setAttribute("style:use-optimal-row-height", "true");
        el2.appendChild(el3);
        el.appendChild(el2);
        el2 = result.createElement("style:style");
        el2.setAttribute("style:name", "ta1");
        el2.setAttribute("style:family", "table");
        el2.setAttribute("style:master-page-name", "Default");
        el3 = result.createElement("style:properties");
        el3.setAttribute("table:display", "true");
        el2.appendChild(el3);
        el.appendChild(el2);
        collection.appendChild(el);

        Element body = result.createElement("office:body");
        Element spreadsheet = result.createElement("office:spreadsheet");
        Element table = result.createElement("table:table");
        table.setAttribute("table:name", "biblio");
        table.setAttribute("table.style-name", "ta1");

        Element row = result.createElement("table:table-row");
        row.setAttribute("table.style-name", "ro1");
        addTableCell(result, row, "Identifier");
        addTableCell(result, row, "Type");
        addTableCell(result, row, "Address");
        addTableCell(result, row, "Assignee");
        addTableCell(result, row, "Annote");
        addTableCell(result, row, "Author");
        addTableCell(result, row, "Booktitle");
        addTableCell(result, row, "Chapter");
        addTableCell(result, row, "Day");
        addTableCell(result, row, "Dayfiled");
        addTableCell(result, row, "Edition");
        addTableCell(result, row, "Editor");
        addTableCell(result, row, "Howpublish");
        addTableCell(result, row, "Institution");
        addTableCell(result, row, "Journal");
        addTableCell(result, row, "Language");
        addTableCell(result, row, "Month");
        addTableCell(result, row, "Monthfiled");
        addTableCell(result, row, "Nationality");
        addTableCell(result, row, "Note");
        addTableCell(result, row, "Number");
        addTableCell(result, row, "Organization");
        addTableCell(result, row, "Pages");
        addTableCell(result, row, "Publisher");
        addTableCell(result, row, "Revision");
        addTableCell(result, row, "School");
        addTableCell(result, row, "Series");
        addTableCell(result, row, "Title");
        addTableCell(result, row, "RepType");
        addTableCell(result, row, "Volume");
        addTableCell(result, row, "Year");
        addTableCell(result, row, "Yearfiled");
        addTableCell(result, row, "URL");
        addTableCell(result, row, "Custom1");
        addTableCell(result, row, "Custom2");
        addTableCell(result, row, "Custom3");
        addTableCell(result, row, "Custom4");
        addTableCell(result, row, "Custom5");
        addTableCell(result, row, "ISBN");
        table.appendChild(row);

        for (BibEntry e : entries) {
            row = result.createElement("table:table-row");
            addTableCell(result, row, getField(e, BibEntry.KEY_FIELD));
            addTableCell(result, row, new GetOpenOfficeType().format(e.getType()));
            addTableCell(result, row, getField(e, "address"));
            addTableCell(result, row, getField(e, "assignee"));
            addTableCell(result, row, getField(e, "annote"));
            addTableCell(result, row, getField(e, "author"));//new AuthorLastFirst().format(getField(e, "author")));
            addTableCell(result, row, getField(e, "booktitle"));
            addTableCell(result, row, getField(e, "chapter"));
            addTableCell(result, row, getField(e, "day"));
            addTableCell(result, row, getField(e, "dayfiled"));
            addTableCell(result, row, getField(e, "edition"));
            addTableCell(result, row, getField(e, "editor"));//new AuthorLastFirst().format(getField(e, "editor")));
            addTableCell(result, row, getField(e, "howpublished"));
            addTableCell(result, row, getField(e, "institution"));
            addTableCell(result, row, getField(e, "journal"));
            addTableCell(result, row, getField(e, "language"));
            addTableCell(result, row, getField(e, "month"));
            addTableCell(result, row, getField(e, "monthfiled"));
            addTableCell(result, row, getField(e, "nationality"));
            addTableCell(result, row, getField(e, "note"));
            addTableCell(result, row, getField(e, "number"));
            addTableCell(result, row, getField(e, "organization"));
            addTableCell(result, row, getField(e, "pages"));
            addTableCell(result, row, getField(e, "publisher"));
            addTableCell(result, row, getField(e, "revision"));
            addTableCell(result, row, getField(e, "school"));
            addTableCell(result, row, getField(e, "series"));
            addTableCell(result, row,
                    new RemoveWhitespace().format(new RemoveBrackets().format(getField(e, "title"))));
            addTableCell(result, row, getField(e, "reporttype"));
            addTableCell(result, row, getField(e, "volume"));
            addTableCell(result, row, getField(e, "year"));
            addTableCell(result, row, getField(e, "yearfiled"));
            addTableCell(result, row, getField(e, "url"));
            addTableCell(result, row, "");
            addTableCell(result, row, "");
            addTableCell(result, row, "");
            addTableCell(result, row, "");
            addTableCell(result, row, "");
            addTableCell(result, row, getField(e, "isbn"));
            table.appendChild(row);
        }

        spreadsheet.appendChild(table);
        body.appendChild(spreadsheet);
        collection.appendChild(body);

        result.appendChild(collection);
    } catch (Exception e) {
        LOGGER.warn("Exception caught...", e);
    }
    return result;
}

From source file:net.sf.jabref.logic.exporter.OpenDocumentRepresentation.java

public Document getDOMrepresentation() {
    Document result = null;/*  w ww  . j av  a 2  s.  c  o m*/
    try {
        DocumentBuilder dbuild = DocumentBuilderFactory.newInstance().newDocumentBuilder();
        result = dbuild.newDocument();
        Element collection = result.createElement("office:document-content");
        //collection.setAttribute("xmlns", "http://openoffice.org/2000/office");
        collection.setAttribute("xmlns:office", "urn:oasis:names:tc:opendocument:xmlns:office:1.0");
        collection.setAttribute("xmlns:style", "urn:oasis:names:tc:opendocument:xmlns:style:1.0");
        collection.setAttribute("xmlns:text", "urn:oasis:names:tc:opendocument:xmlns:text:1.0");
        collection.setAttribute("xmlns:table", "urn:oasis:names:tc:opendocument:xmlns:table:1.0");
        collection.setAttribute("xmlns:meta", "urn:oasis:names:tc:opendocument:xmlns:meta:1.0");
        collection.setAttribute("office:version", "1.0");
        collection.setAttribute("xmlns:fo", "urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0");
        collection.setAttribute("xmlns:xlink", "http://www.w3.org/1999/xlink");
        Element el = result.createElement("office:scripts");
        collection.appendChild(el);

        el = result.createElement("office:automatic-styles");
        Element el2 = result.createElement("style:style");
        el2.setAttribute("style:name", "ro1");
        el2.setAttribute("style:family", "table-row");
        Element el3 = result.createElement("style.table-row-properties");
        el3.setAttribute("style:row-height", "0.1681inch");
        el3.setAttribute("fo:break-before", "auto");
        el3.setAttribute("style:use-optimal-row-height", "true");
        el2.appendChild(el3);
        el.appendChild(el2);
        el2 = result.createElement("style:style");
        el2.setAttribute("style:name", "ta1");
        el2.setAttribute("style:family", "table");
        el2.setAttribute("style:master-page-name", "Default");
        el3 = result.createElement("style:properties");
        el3.setAttribute("table:display", "true");
        el2.appendChild(el3);
        el.appendChild(el2);
        collection.appendChild(el);

        Element body = result.createElement("office:body");
        Element spreadsheet = result.createElement("office:spreadsheet");
        Element table = result.createElement("table:table");
        table.setAttribute("table:name", "biblio");
        table.setAttribute("table.style-name", "ta1");

        Element row = result.createElement("table:table-row");
        row.setAttribute("table.style-name", "ro1");
        addTableCell(result, row, "Identifier");
        addTableCell(result, row, "Type");
        addTableCell(result, row, "Address");
        addTableCell(result, row, "Assignee");
        addTableCell(result, row, "Annote");
        addTableCell(result, row, "Author");
        addTableCell(result, row, "Booktitle");
        addTableCell(result, row, "Chapter");
        addTableCell(result, row, "Day");
        addTableCell(result, row, "Dayfiled");
        addTableCell(result, row, "Edition");
        addTableCell(result, row, "Editor");
        addTableCell(result, row, "Howpublish");
        addTableCell(result, row, "Institution");
        addTableCell(result, row, "Journal");
        addTableCell(result, row, "Language");
        addTableCell(result, row, "Month");
        addTableCell(result, row, "Monthfiled");
        addTableCell(result, row, "Nationality");
        addTableCell(result, row, "Note");
        addTableCell(result, row, "Number");
        addTableCell(result, row, "Organization");
        addTableCell(result, row, "Pages");
        addTableCell(result, row, "Publisher");
        addTableCell(result, row, "Revision");
        addTableCell(result, row, "School");
        addTableCell(result, row, "Series");
        addTableCell(result, row, "Title");
        addTableCell(result, row, "RepType");
        addTableCell(result, row, "Volume");
        addTableCell(result, row, "Year");
        addTableCell(result, row, "Yearfiled");
        addTableCell(result, row, "URL");
        addTableCell(result, row, "Custom1");
        addTableCell(result, row, "Custom2");
        addTableCell(result, row, "Custom3");
        addTableCell(result, row, "Custom4");
        addTableCell(result, row, "Custom5");
        addTableCell(result, row, "ISBN");
        table.appendChild(row);

        for (BibEntry e : entries) {
            row = result.createElement("table:table-row");
            addTableCell(result, row, getField(e, BibEntry.KEY_FIELD));
            addTableCell(result, row, new GetOpenOfficeType().format(e.getType()));
            addTableCell(result, row, getField(e, "address"));
            addTableCell(result, row, getField(e, "assignee"));
            addTableCell(result, row, getField(e, "annote"));
            addTableCell(result, row, getField(e, FieldName.AUTHOR));//new AuthorLastFirst().format(getField(e, FieldName.AUTHOR_FIELD)));
            addTableCell(result, row, getField(e, "booktitle"));
            addTableCell(result, row, getField(e, "chapter"));
            addTableCell(result, row, getField(e, "day"));
            addTableCell(result, row, getField(e, "dayfiled"));
            addTableCell(result, row, getField(e, "edition"));
            addTableCell(result, row, getField(e, FieldName.EDITOR));//new AuthorLastFirst().format(getField(e, FieldName.EDITOR_FIELD)));
            addTableCell(result, row, getField(e, "howpublished"));
            addTableCell(result, row, getField(e, "institution"));
            addTableCell(result, row, getField(e, FieldName.JOURNAL));
            addTableCell(result, row, getField(e, "language"));
            addTableCell(result, row, getField(e, FieldName.MONTH));
            addTableCell(result, row, getField(e, "monthfiled"));
            addTableCell(result, row, getField(e, "nationality"));
            addTableCell(result, row, getField(e, "note"));
            addTableCell(result, row, getField(e, FieldName.NUMBER));
            addTableCell(result, row, getField(e, "organization"));
            addTableCell(result, row, getField(e, FieldName.PAGES));
            addTableCell(result, row, getField(e, FieldName.PUBLISHER));
            addTableCell(result, row, getField(e, "revision"));
            addTableCell(result, row, getField(e, "school"));
            addTableCell(result, row, getField(e, "series"));
            addTableCell(result, row,
                    new RemoveWhitespace().format(new RemoveBrackets().format(getField(e, FieldName.TITLE))));
            addTableCell(result, row, getField(e, "reporttype"));
            addTableCell(result, row, getField(e, FieldName.VOLUME));
            addTableCell(result, row, getField(e, FieldName.YEAR));
            addTableCell(result, row, getField(e, "yearfiled"));
            addTableCell(result, row, getField(e, FieldName.URL));
            addTableCell(result, row, "");
            addTableCell(result, row, "");
            addTableCell(result, row, "");
            addTableCell(result, row, "");
            addTableCell(result, row, "");
            addTableCell(result, row, getField(e, FieldName.ISBN));
            table.appendChild(row);
        }

        spreadsheet.appendChild(table);
        body.appendChild(spreadsheet);
        collection.appendChild(body);

        result.appendChild(collection);
    } catch (Exception e) {
        LOGGER.warn("Exception caught...", e);
    }
    return result;
}

From source file:com.cladonia.security.signature.SignatureGenerator.java

private Document getDom() throws Exception {
    // create a new dom to hold the signature   
    javax.xml.parsers.DocumentBuilderFactory dbf = javax.xml.parsers.DocumentBuilderFactory.newInstance();

    // XML Signature needs to be namespace aware
    dbf.setNamespaceAware(true);/*from   w  ww  . j a v  a2 s  .  c  om*/

    javax.xml.parsers.DocumentBuilder db = dbf.newDocumentBuilder();
    org.w3c.dom.Document docNew = db.newDocument();

    return docNew;
}

From source file:be.fedict.eid.applet.service.signer.ooxml.AbstractOOXMLSignatureService.java

private void addOriginSigsRels(String signatureZipEntryName, ZipOutputStream zipOutputStream)
        throws ParserConfigurationException, IOException, TransformerConfigurationException,
        TransformerFactoryConfigurationError, TransformerException {
    DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
    documentBuilderFactory.setNamespaceAware(true);
    DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
    Document originSignRelsDocument = documentBuilder.newDocument();

    Element relationshipsElement = originSignRelsDocument
            .createElementNS("http://schemas.openxmlformats.org/package/2006/relationships", "Relationships");
    relationshipsElement.setAttributeNS(Constants.NamespaceSpecNS, "xmlns",
            "http://schemas.openxmlformats.org/package/2006/relationships");
    originSignRelsDocument.appendChild(relationshipsElement);

    Element relationshipElement = originSignRelsDocument
            .createElementNS("http://schemas.openxmlformats.org/package/2006/relationships", "Relationship");
    String relationshipId = "rel-" + UUID.randomUUID().toString();
    relationshipElement.setAttribute("Id", relationshipId);
    relationshipElement.setAttribute("Type",
            "http://schemas.openxmlformats.org/package/2006/relationships/digital-signature/signature");
    String target = FilenameUtils.getName(signatureZipEntryName);
    LOG.debug("target: " + target);
    relationshipElement.setAttribute("Target", target);
    relationshipsElement.appendChild(relationshipElement);

    zipOutputStream.putNextEntry(new ZipEntry("_xmlsignatures/_rels/origin.sigs.rels"));
    writeDocumentNoClosing(originSignRelsDocument, zipOutputStream, false);
}

From source file:com.hydroLibCreator.action.Creator.java

private void buildDrumKitXML() {

    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    try {/*ww  w  .  ja  v  a2s .c  o m*/
        DocumentBuilder builder = factory.newDocumentBuilder();
        document = builder.newDocument();
    } catch (ParserConfigurationException parserException) {
        parserException.printStackTrace();
    }

    Element drumkit_info = document.createElement("drumkit_info");
    document.appendChild(drumkit_info);

    Attr xmlns = document.createAttribute("xmlns");
    xmlns.setValue("http://www.hydrogen-music.org/drumkit");

    Attr xmlns_xsi = document.createAttribute("xmlns:xsi");
    xmlns_xsi.setValue("http://www.w3.org/2001/XMLSchema-instance");

    drumkit_info.setAttributeNode(xmlns);
    drumkit_info.setAttributeNode(xmlns_xsi);

    Node nameNode = createNameNode(document);
    drumkit_info.appendChild(nameNode);

    Node authorNode = createAuthorNode(document);
    drumkit_info.appendChild(authorNode);

    Node infoNode = createInfoNode(document);
    drumkit_info.appendChild(infoNode);

    Node licenseNode = createLicenseNode(document);
    drumkit_info.appendChild(licenseNode);

    Node instrumentListNode = createInstrumentListNode(document);
    drumkit_info.appendChild(instrumentListNode);

    // write the XML document to disk
    try {

        // create DOMSource for source XML document
        Source xmlSource = new DOMSource(document);

        // create StreamResult for transformation result
        Result result = new StreamResult(new FileOutputStream(destinationPath + "/drumkit.xml"));

        // create TransformerFactory
        TransformerFactory transformerFactory = TransformerFactory.newInstance();

        // create Transformer for transformation
        Transformer transformer = transformerFactory.newTransformer();

        transformer.setOutputProperty(OutputKeys.INDENT, "yes");
        transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");

        // transform and deliver content to client
        transformer.transform(xmlSource, result);
    }

    // handle exception creating TransformerFactory
    catch (TransformerFactoryConfigurationError factoryError) {
        System.err.println("Error creating " + "TransformerFactory");
        factoryError.printStackTrace();
    } catch (TransformerException transformerError) {
        System.err.println("Error transforming document");
        transformerError.printStackTrace();
    } catch (IOException ioException) {
        ioException.printStackTrace();
    }

}

From source file:ee.ria.xroad.common.hashchain.HashChainVerifier.java

/** Downloads data from the URI and runs transforms on it. */
private InputStream performTransforms(String uri, TransformsType transforms) throws Exception {
    LOG.trace("performTransforms({}, {})", uri, transforms);

    JAXBElement<TransformsType> transformsElement = new ObjectFactory().createTransforms(transforms);

    // Create the Document
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    DocumentBuilder db = dbf.newDocumentBuilder();
    Document document = db.newDocument();

    Marshaller marshaller = jaxbCtx.createMarshaller();
    marshaller.marshal(transformsElement, document);

    Transforms tr = new Transforms(document.getDocumentElement(), null);

    XMLSignatureInput before = new XMLSignatureInput(referenceResolver.resolve(uri));

    XMLSignatureInput after = tr.performTransforms(before);

    return after.getOctetStream();
}

From source file:com.adr.mimame.PlatformList.java

private boolean saveList(List<GamesItem> games, File f) {

    try {//from   w  w  w . j a v a  2 s .  c o m
        FileUtils.forceMkdir(f);

        DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
        Document doc = docBuilder.newDocument();
        Element root = doc.createElement("gameslist");
        doc.appendChild(root);

        for (GamesItem g : games) {
            Element e = doc.createElement("game");
            root.appendChild(e);
            g.toElement(e);
        }

        // write the content into xml file
        TransformerFactory transformerFactory = TransformerFactory.newInstance();
        Transformer transformer = transformerFactory.newTransformer();
        transformer.setOutputProperty(OutputKeys.INDENT, "yes");
        DOMSource source = new DOMSource(doc);
        StreamResult result = new StreamResult(new File(f, "games.xml"));
        transformer.transform(source, result);
        return true;
    } catch (IOException ex) {
        logger.log(Level.SEVERE, null, ex);
    } catch (ParserConfigurationException ex) {
        Logger.getLogger(PlatformList.class.getName()).log(Level.SEVERE, null, ex);
    } catch (TransformerConfigurationException ex) {
        Logger.getLogger(PlatformList.class.getName()).log(Level.SEVERE, null, ex);
    } catch (TransformerException ex) {
        Logger.getLogger(PlatformList.class.getName()).log(Level.SEVERE, null, ex);
    }
    return false;
}