Example usage for org.jdom2.input DOMBuilder build

List of usage examples for org.jdom2.input DOMBuilder build

Introduction

In this page you can find the example usage for org.jdom2.input DOMBuilder build.

Prototype

public org.jdom2.DocType build(org.w3c.dom.DocumentType doctype) 

Source Link

Document

This will build a JDOM Element from an existing DOM Element

Usage

From source file:com.bc.ceres.site.util.ExclusionListBuilder.java

License:Open Source License

static void addPomToExclusionList(File exclusionList, URL pom) throws Exception {
    try (BufferedWriter writer = new BufferedWriter(new FileWriter(exclusionList, true))) {
        final DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
        final Document w3cDoc = builder.parse(pom.openStream());
        final DOMBuilder domBuilder = new DOMBuilder();
        final org.jdom2.Document doc = domBuilder.build(w3cDoc);
        final Element root = doc.getRootElement();
        final Namespace namespace = root.getNamespace();
        final List<Element> modules = root.getChildren(MODULES_NODE, namespace);
        if (modules != null) {
            // hard-coded index 0 is ok because xml-schema allows only one <modules>-node
            final Element modulesNode = modules.get(0);
            final List<Element> modulesList = modulesNode.getChildren(MODULE_NAME, namespace);
            for (Element module : modulesList) {
                addModuleToExclusionList(exclusionList, writer, module.getText());
            }/*from w ww  . j a v a2s  .  c o m*/
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

}

From source file:com.c4om.autoconf.ulysses.configanalyzer.objectivesextractor.JSchematronValidatorBasedExtractor.java

License:Apache License

/**
 * This implementation is based on JSchematronValidator
 * @see com.c4om.autoconf.ulysses.interfaces.configanalyzer.objectivesextractor.SchematronBasedExtractor#performSchematronValidation(org.jdom2.Document, org.jdom2.Document, java.io.File)
 *//*from www .  j  a v  a2 s .com*/
@Override
protected Document performSchematronValidation(Document schematronSchema, Document inputCandidate,
        File workingDirectory) throws SchematronObjectivesExtractionException {
    try {
        DOMOutputter domOutputter = new DOMOutputter();
        org.w3c.dom.Document schematronSchemaW3C = domOutputter.output(schematronSchema);
        org.w3c.dom.Document inputCandidateW3C = domOutputter.output(inputCandidate);
        //We set the working directory to the provided one
        String userDirBackup = System.getProperty("user.dir");
        System.setProperty("user.dir", workingDirectory.getAbsolutePath()); //this is equivalent to a 'cd' console command
        org.w3c.dom.Document resultSVRLW3C = validator.performValidation(inputCandidateW3C,
                schematronSchemaW3C);
        System.setProperty("user.dir", userDirBackup); //We restore the original path
        DOMBuilder domBuilder = new DOMBuilder();
        Document resultSVRL = domBuilder.build(resultSVRLW3C);
        return resultSVRL;
    } catch (SchematronValidationException | JDOMException e) {
        throw new SchematronObjectivesExtractionException(e);
    }
}

From source file:com.c4om.utils.xmlutils.XMLLibsShortcuts.java

License:Apache License

/**
 * This method takes an input JDOM2 {@link Document} and a XSLT (as a JDOM2 {@link Document}) 
 * and applies the sheet to the document. The result is returned as a JDOM2 {@link Document}. 
 * @param inputDocument the input document
 * @param xslt the XSLT sheet/*w  ww.j  a va2  s.c  o m*/
 * @return the result of applying the sheet to the document
 * @throws JDOMException if there are problems at JDOM2 parsing
 * @throws SaxonApiException if there are problems related to JDOM2 documents
 * @throws ParserConfigurationException if there are problems at building internal {@link org.w3c.dom.Document} objects used to interact with Saxon API.
 */
public static Document performXSLT(Document inputDocument, Document xslt)
        throws JDOMException, SaxonApiException, ParserConfigurationException {
    //First, we convert JDOM2 documents to org.w3c.dom.Document
    DOMOutputter domOutputter = new DOMOutputter();
    org.w3c.dom.Document w3cXSLT = domOutputter.output(xslt);
    org.w3c.dom.Document w3cInput = domOutputter.output(inputDocument);
    Processor processor = new Processor(false);

    DocumentBuilderFactory w3cDocumentBuilderFactory = DocumentBuilderFactory.newInstance();
    w3cDocumentBuilderFactory.setNamespaceAware(true);
    DocumentBuilder documentBuilder = w3cDocumentBuilderFactory.newDocumentBuilder();
    org.w3c.dom.Document w3cDestinationDocument = documentBuilder.newDocument();

    Source w3cXSLTSource = new DOMSource(w3cXSLT);
    Source w3cInputSource = new DOMSource(w3cInput);
    Destination destination = new DOMDestination(w3cDestinationDocument);

    XsltCompiler comp = processor.newXsltCompiler();
    XsltExecutable executable = comp.compile(w3cXSLTSource);
    XsltTransformer transformer = executable.load();
    XdmNode xdmInput = processor.newDocumentBuilder().build(w3cInputSource);
    transformer.setInitialContextNode(xdmInput);
    transformer.setDestination(destination);
    transformer.transform();

    DOMBuilder domBuilder = new DOMBuilder();
    Document destinationDocument = domBuilder.build(w3cDestinationDocument);

    return destinationDocument;
}

From source file:com.izforge.izpack.util.xmlmerge.merge.DefaultXmlMerge.java

License:Open Source License

@Override
public org.w3c.dom.Document merge(org.w3c.dom.Document[] sources) throws AbstractXmlMergeException {
    DOMBuilder domb = new DOMBuilder();

    // to save all XML files as JDOM objects
    Document[] docs = new Document[sources.length];

    for (int i = 0; i < sources.length; i++) {
        // ask JDOM to parse the given inputStream
        docs[i] = domb.build(sources[i]);
    }/*www.j  a va  2 s  .co m*/

    Document result = doMerge(docs);

    DOMOutputter outputter = new DOMOutputter();

    try {
        return outputter.output(result);
    } catch (JDOMException e) {
        throw new DocumentException(result, e);
    }
}

From source file:com.rometools.rome.io.WireFeedInput.java

License:Open Source License

/**
 * Builds an WireFeed (RSS or Atom) from an W3C DOM document.
 * <p>/*from ww  w. j a  va  2 s  .c o  m*/
 * NOTE: This method delages to the 'AsbtractFeed WireFeedInput#build(org.jdom2.Document)'.
 * <p>
 *
 * @param document W3C DOM document to read to create the WireFeed.
 * @return the WireFeed read from the W3C DOM document.
 * @throws IllegalArgumentException thrown if feed type could not be understood by any of the
 *             underlying parsers.
 * @throws FeedException if the feed could not be parsed
 *
 */
public WireFeed build(final org.w3c.dom.Document document) throws IllegalArgumentException, FeedException {
    final DOMBuilder domBuilder = new DOMBuilder();
    try {
        final Document jdomDoc = domBuilder.build(document);
        return this.build(jdomDoc);
    } catch (final IllegalArgumentException ex) {
        throw ex;
    } catch (final Exception ex) {
        throw new ParsingFeedException("Invalid XML", ex);
    }
}

From source file:com.sun.syndication.io.WireFeedInput.java

License:Open Source License

/**
 * Builds an WireFeed (RSS or Atom) from an W3C DOM document.
 * <p>//from  ww  w. ja v  a2s  .c  o  m
 * NOTE: This method delages to the 'AsbtractFeed WireFeedInput#build(org.jdom2.Document)'.
 * <p>
 * @param document W3C DOM document to read to create the WireFeed.
 * @return the WireFeed read from the W3C DOM document.
 * @throws IllegalArgumentException thrown if feed type could not be understood by any of the underlying parsers.
 * @throws FeedException if the feed could not be parsed
 *
 */
public WireFeed build(org.w3c.dom.Document document) throws IllegalArgumentException, FeedException {
    DOMBuilder domBuilder = new DOMBuilder();
    try {
        Document jdomDoc = domBuilder.build(document);
        return build(jdomDoc);
    } catch (IllegalArgumentException ex) {
        throw ex;
    } catch (Exception ex) {
        throw new ParsingFeedException("Invalid XML", ex);
    }
}

From source file:de.kay_muench.reqif10.reqifparser.ToolExRemover.java

License:Open Source License

private void output(final Document document, final File tmp) throws IOException {
    DOMBuilder domBuilder = new DOMBuilder();
    org.jdom2.Document doc = domBuilder.build(document);
    XMLOutputter out = new XMLOutputter();

    Writer w = new OutputStreamWriter(new FileOutputStream(tmp), "UTF8");
    BufferedWriter writer = new BufferedWriter(w);
    out.output(doc, writer);/* ww w .j  a va 2 s.  c om*/
    writer.close();
}

From source file:eu.himeros.cophi.ocr.proofreader.controller.pojo.HocrDocumentExistLoader.java

License:Open Source License

@Override
public Document load(Map<String, Object> origin) {
    try {/*from  w  w  w. j  a v  a  2  s  .  c om*/
        //String library = origin.get("library");
        //String book = library + "/" + origin.get("book");
        //String page = origin.get("page");
        //String login = origin.get("login");
        //String password = origin.get("password");
        //Database database = (Database) (Class.forName("org.exist.xmldb.DatabaseImpl").newInstance());
        //DatabaseManager.registerDatabase(database);
        //Collection col = DatabaseManager.getCollection(book, login, password);
        Collection libCol = (Collection) origin.get("library");
        Collection bookCol = libCol.getChildCollection((String) origin.get("book"));
        XMLResource res = (XMLResource) bookCol.getResource((String) origin.get("page"));
        DOMBuilder domBuilder = new DOMBuilder();
        Document doc = domBuilder.build((org.w3c.dom.Document) res.getContentAsDOM());
        System.err.println(doc.toString());
        System.err.println("nothing");
        //col.close();
        return doc;
    } catch (Exception ex) {
        return null;
    }
}

From source file:eu.himeros.cophi.ocr.proofreader.controller.pojo.LibraryExistDescriptor.java

License:Open Source License

public Document load(Map<String, String> origin) {
    try {/*from   w w w .  jav a2s .  co  m*/
        String library = origin.get("library");
        String book = library + "/" + origin.get("book");
        String page = origin.get("page");
        String login = origin.get("login");
        String password = origin.get("password");
        Database database = (Database) (Class.forName("org.exist.xmldb.DatabaseImpl").newInstance());
        DatabaseManager.registerDatabase(database);
        Collection col = DatabaseManager.getCollection(book, login, password);
        XMLResource res = (XMLResource) col.getResource(page);
        DOMBuilder domBuilder = new DOMBuilder();
        Document doc = domBuilder.build((org.w3c.dom.Document) res.getContentAsDOM());
        col.close();
        return doc;
    } catch (Exception ex) {
        ex.printStackTrace(System.err);
        return null;
    }
}

From source file:facturacion.controller.FacturaController.java

public void crearArchivo() {

    try {//from w  w  w.j  ava  2s .c o m
        DOMBuilder builder = new DOMBuilder();
        org.jdom2.Document jdom = builder.build((new DOMOutputter()).output(facturaXml.getDoc()));
        XMLOutputter xmlOutput = new XMLOutputter();
        xmlOutput.setFormat(Format.getPrettyFormat());
        FileWriter a = new FileWriter("C:\\tributasoft\\prueba\\filePrueba" + this.factura.getPunto_emision()
                + this.factura.getNumero_factura() + ".xml");
        xmlOutput.output(jdom, a);
        a.close();
        facturaXml.getClaveAcceso();
        System.out.println("----> firmar factura +++ 16==" + facturaXml.getClaveAcceso());
    } catch (JDOMException e) {
        // TODO Auto-generated catch block
        System.out.println("----> firmar factura +++ 1");

        e.printStackTrace();

    } catch (NullPointerException e) {
        // TODO Auto-generated catch block
        System.out.println("----> firmar factura +++ 2");
        e.printStackTrace();

    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}