List of usage examples for org.jdom2.input DOMBuilder DOMBuilder
public DOMBuilder()
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()); }// w w w . ja v a 2 s. c om } } 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 w w w . ja v a 2 s . c om @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//from w w w. java2s. 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]); }//from w w w .ja va 2s .c o 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>/* w w w .j a v a 2 s .co 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>//w ww .j ava2 s .com * 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);//from w ww. ja v a 2 s. c o m writer.close(); }
From source file:de.unigoettingen.sub.search.opac.ConfigOpacCatalogue.java
License:Open Source License
public Node executeBeautifier(Node myHitlist) { /* Ausgabe des Opac-Ergebnissen in Datei */ // if (!ConfigurationHelper.getInstance().getDebugFolder().equals("") && Files.isWritable(Paths.get(ConfigurationHelper.getInstance().getDebugFolder()))) { // debugMyNode(myHitlist, ConfigurationHelper.getInstance().getDebugFolder() + "/opacBeautifyBefore.xml"); // }/* w w w . ja v a 2 s. co m*/ /* * --------------------- aus dem Dom-Node ein JDom-Object machen ------------------- */ Document doc = new DOMBuilder().build(myHitlist.getOwnerDocument()); /* * --------------------- Im JDom-Object alle Felder durchlaufen und die notwendigen Ersetzungen vornehmen ------------------- */ /* alle Records durchlaufen */ List<Element> elements = doc.getRootElement().getChildren(); for (Element el : elements) { // Element el = (Element) it.next(); /* in jedem Record den Beautifier anwenden */ executeBeautifierForElement(el); } /* * --------------------- aus dem JDom-Object wieder ein Dom-Node machen ------------------- */ DOMOutputter doutputter = new DOMOutputter(); try { myHitlist = doutputter.output(doc); myHitlist = myHitlist.getFirstChild(); } catch (JDOMException e) { logger.error("JDOMException in executeBeautifier(Node)", e); } /* Ausgabe des berarbeiteten Opac-Ergebnisses */ if (!ConfigurationHelper.getInstance().getDebugFolder().equals("") && StorageProvider.getInstance() .isWritable(Paths.get(ConfigurationHelper.getInstance().getDebugFolder()))) { debugMyNode(myHitlist, ConfigurationHelper.getInstance().getDebugFolder() + "/opacBeautifyAfter.xml"); } return myHitlist; }
From source file:de.unigoettingen.sub.search.opac.ConfigOpacCatalogue.java
License:Open Source License
/** * Print given DomNode to defined File ================================================================ *//*from w w w .j a v a 2s . c o m*/ private void debugMyNode(Node inNode, String fileName) { try { XMLOutputter outputter = new XMLOutputter(); Document tempDoc = new DOMBuilder().build(inNode.getOwnerDocument()); FileOutputStream output = new FileOutputStream(fileName); outputter.output(tempDoc.getRootElement(), output); } catch (FileNotFoundException e) { logger.error("debugMyNode(Node, String)", e); } catch (IOException e) { logger.error("debugMyNode(Node, String)", e); } }
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 {// www . j a v a2s . 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; } }