List of usage examples for org.dom4j DocumentFactory createDocument
public Document createDocument(Element rootElement)
From source file:com.arc.intro.CompilerSamplesProvider.java
License:Open Source License
public void init(IIntroContentProviderSite site) { if (samplesDoc == null) { File samplesXML = computeSampleXML(); Document doc = null;// w w w .j ava2s. c om if (samplesXML.exists()) { SAXReader reader = new SAXReader(); try { doc = reader.read(samplesXML); } catch (Exception e) { ToolchainPlugin.log("Error in reading " + samplesXML, e); } } if (doc == null) { // Create a makeshift version DocumentFactory f = DocumentFactory.getInstance(); Element root = f.createElement(SAMPLES_TAG); root.addAttribute(DEMOS_ATTR, DEFAULT_DEMOS_DIR); for (int i = 0; i < targetNames.length; i += 2) { Element target = root.addElement(TARGET_TAG); target.addAttribute(NAME_ATTR, targetNames[i]); target.addAttribute(DESC_ATTR, targetNames[i + 1]); } Element category = root.addElement(CATEGORY_TAG); category.addAttribute(TITLE_ATTR, "Compiler Samples"); category.addAttribute(WORKSPACE_ATTR, ".*mide_workspace"); category.addAttribute(ID_ATTR, "compiler"); doc = f.createDocument(root); } samplesDoc = doc; } }
From source file:com.liferay.portal.xml.SAXReaderImpl.java
License:Open Source License
public Document createDocument(String encoding) { DocumentFactory documentFactory = DocumentFactory.getInstance(); return new DocumentImpl(documentFactory.createDocument(encoding)); }
From source file:de.hasait.eclipse.common.xml.XDocument.java
License:Apache License
/** * /*from ww w .j a va 2s .c om*/ */ public XDocument(final String encoding, final String rootElementName) { super(); DocumentFactory df = DocumentFactory.getInstance(); _document = df.createDocument(encoding); _document.setRootElement(df.createElement(rootElementName)); }
From source file:fr.gouv.culture.vitam.writer.XmlWriter.java
License:Open Source License
/** * @param file/*from w w w . ja v a 2s .c o m*/ * @param rootname */ public XmlWriter(File file, String rootname) { this.file = file; this.rootname = rootname; DocumentFactory factory = DocumentFactory.getInstance(); document = factory.createDocument(StaticValues.CURRENT_OUTPUT_ENCODING); Element root = factory.createElement(rootname); document.setRootElement(root); }
From source file:fr.gouv.culture.vitam.writer.XmlWriter.java
License:Open Source License
public void write() throws IOException { FileOutputStream out = new FileOutputStream(file); OutputFormat format = OutputFormat.createPrettyPrint(); format.setEncoding(StaticValues.CURRENT_OUTPUT_ENCODING); XMLWriter writer = new XMLWriter(out, format); writer.write(document);/*from ww w .ja v a 2s. c o m*/ writer.close(); out.close(); document.clearContent(); document = null; DocumentFactory factory = DocumentFactory.getInstance(); document = factory.createDocument(StaticValues.CURRENT_OUTPUT_ENCODING); Element root = factory.createElement(rootname); document.setRootElement(root); StaticValues.freeMemory(); }
From source file:nc.noumea.mairie.organigramme.services.exportGraphML.impl.ExportGraphMLServiceOrgaEntitesImpl.java
License:Open Source License
private byte[] exportGraphML(EntiteDto entiteDto, FiltreStatut filtreStatut, Map<String, Boolean> mapIdLiOuvert) throws IOException { DocumentFactory factory = DocumentFactory.getInstance(); Element root = factory.createElement("graphml"); Document document = factory.createDocument(root); document.setXMLEncoding("utf-8"); Element graph = initRoot(root); initHeader(root);//from w w w.j a va2s. c om construitTableauStats(graph, entiteDto); buildGraphMlTree(graph, entiteDto, mapIdLiOuvert, filtreStatut); ajoutLogoMairie(graph); ByteArrayOutputStream os_writer = new ByteArrayOutputStream(); try { BufferedWriter wtr = new BufferedWriter(new OutputStreamWriter(os_writer, "UTF-8")); document.write(wtr); wtr.flush(); wtr.close(); } catch (Exception e) { throw new RuntimeException(e); } return os_writer.toByteArray(); }
From source file:nc.noumea.mairie.organigramme.services.exportGraphML.impl.ExportGraphMLServiceOrgaFichesPosteImpl.java
License:Open Source License
private byte[] exportGraphML(FichePosteTreeNodeDto node, boolean isAfficheAgent, Map<String, Boolean> mapIdLiOuvert) throws IOException { DocumentFactory factory = DocumentFactory.getInstance(); Element root = factory.createElement("graphml"); Document document = factory.createDocument(root); document.setXMLEncoding("utf-8"); Element graph = initRoot(root); initHeader(root);// w ww. j av a2 s.co m construitTableauStats(graph, this.entiteDto); mapFichesPosteSuperieureByService = EntityUtils.getFichesPosteChefDeService(node); buildGraphMlTree(graph, node, mapIdLiOuvert, isAfficheAgent, null); ByteArrayOutputStream os_writer = new ByteArrayOutputStream(); try { BufferedWriter wtr = new BufferedWriter(new OutputStreamWriter(os_writer, "UTF-8")); document.write(wtr); wtr.flush(); wtr.close(); } catch (Exception e) { throw new RuntimeException(e); } return os_writer.toByteArray(); }
From source file:nc.noumea.mairie.organigramme.services.impl.ExportGraphMLServiceImpl.java
License:Open Source License
private byte[] exportGraphML(EntiteDto entiteDto, Map<String, Boolean> mapIdLiOuvert) { DocumentFactory factory = DocumentFactory.getInstance(); Element root = factory.createElement("graphml"); Document document = factory.createDocument(root); document.setXMLEncoding("utf-8"); initHeader(root);/* w ww. j a v a2 s . c o m*/ Element graph = initRoot(root); buildGraphMlTree(graph, entiteDto, mapIdLiOuvert); ByteArrayOutputStream os_writer = new ByteArrayOutputStream(); try { BufferedWriter wtr = new BufferedWriter(new OutputStreamWriter(os_writer, "UTF-8")); document.write(wtr); wtr.flush(); wtr.close(); } catch (Exception e) { throw new RuntimeException(e); } return os_writer.toByteArray(); }
From source file:org.danann.cernunnos.xml.XslTransformTask.java
License:Apache License
public void perform(TaskRequest req, TaskResponse res) { final String contextLocation = (String) context.evaluate(req, res); final String stylesheetLocation = (String) stylesheet.evaluate(req, res); final Tuple<String, String> transformerKey = new Tuple<String, String>(contextLocation, stylesheetLocation); final Templates templates = this.transformerCache.getCachedObject(req, res, transformerKey, this.transformerFactory); Element srcElement = null;//w w w .j ava 2 s . com Node nodeReagentEvaluated = node != null ? (Node) node.evaluate(req, res) : null; if (nodeReagentEvaluated != null) { // Reading from the NODE reagent is preferred... srcElement = (Element) nodeReagentEvaluated; } else { // But read from LOCATION if NODE isn't set... final String locationStr = (String) location.evaluate(req, res); final URL loc; try { final URL ctx; try { ctx = new URL(contextLocation); } catch (MalformedURLException mue) { throw new RuntimeException("Failed to parse context '" + contextLocation + "' into URL", mue); } loc = new URL(ctx, locationStr); } catch (MalformedURLException mue) { throw new RuntimeException("Failed to parse location '" + locationStr + "' with context '" + contextLocation + "' into URL", mue); } // Use an EntityResolver if provided... SAXReader rdr = new SAXReader(); EntityResolver resolver = (EntityResolver) entityResolver.evaluate(req, res); if (resolver != null) { rdr.setEntityResolver(resolver); } final Document document; try { document = rdr.read(loc); } catch (DocumentException de) { throw new RuntimeException("Failed to read XML Document for XSLT from " + loc.toExternalForm(), de); } srcElement = document.getRootElement(); } DocumentFactory dfac = new DocumentFactory(); Document ddoc = dfac.createDocument((Element) srcElement.clone()); DOMWriter dwriter = new DOMWriter(); DocumentResult rslt = new DocumentResult(); final Transformer trans; try { trans = templates.newTransformer(); } catch (TransformerConfigurationException tce) { throw new RuntimeException("Failed to retrieve Transformer for XSLT", tce); } try { trans.transform(new DOMSource(dwriter.write(ddoc)), rslt); } catch (TransformerException te) { throw new RuntimeException("Failed to perform XSL transformation", te); } catch (DocumentException de) { throw new RuntimeException("Failed to translate JDOM Document to W3C Document", de); } final Element rootElement = rslt.getDocument().getRootElement(); if (to_file != null) { File f = new File((String) to_file.evaluate(req, res)); if (f.getParentFile() != null) { // Make sure the necessary directories are in place... f.getParentFile().mkdirs(); } final XMLWriter writer; try { writer = new XMLWriter(new FileOutputStream(f), new OutputFormat(" ", true)); } catch (UnsupportedEncodingException uee) { throw new RuntimeException("Failed to create XML writer", uee); } catch (FileNotFoundException fnfe) { throw new RuntimeException("Could not create file for XML output: " + f, fnfe); } try { writer.write(rootElement); } catch (IOException ioe) { throw new RuntimeException("Failed to write transformed XML document to: " + f, ioe); } } else { // default behavior... res.setAttribute(Attributes.NODE, rootElement); } super.performSubtasks(req, res); }
From source file:org.eclipse.birt.build.GenCaseResult.java
License:Open Source License
private void genReport(String path) { /*//from w w w .j av a 2 s. c om * Add genDate node to report */ DOMElement testElement = new DOMElement("ReportDate"); Calendar cal = Calendar.getInstance(); SimpleDateFormat currentDate = new SimpleDateFormat("yyyy-MM-dd"); String strDate = currentDate.format(cal.getTime()); testElement.setText(strDate); this.rootElement.add(testElement); DocumentFactory factory = new DocumentFactory(); Document doc = factory.createDocument(rootElement); OutputFormat format = OutputFormat.createPrettyPrint(); try { XMLWriter writer = new XMLWriter(new FileWriter(this.getReportPath(path)), format); writer.write(doc); writer.close(); } catch (Exception ex) { ex.printStackTrace(); } }