List of usage examples for org.dom4j.io OutputFormat createPrettyPrint
public static OutputFormat createPrettyPrint()
From source file:org.eclipse.birt.build.VersionUpdater.java
License:Open Source License
/** * @author /*from w ww. ja v a2 s. c o m*/ * @param folderPath * @param plug_id * @param lastDate * @param dayInpast */ private void genVersionLog(File folderPath, String plug_id, String lastDate, int dayInpast) { // gen the dest file path String parentPath = folderPath.getAbsolutePath(); String fileName = plug_id + "_DayInPast" + ".xml"; String fullName = parentPath + "/" + fileName; File dest = new File(fullName); System.out.println("dest file full path:\t" + fullName); try { //genarate document factory DocumentFactory factory = new DocumentFactory(); //create root element DOMElement rootElement = new DOMElement("plugin"); rootElement.setAttribute("id", plug_id); //add child:lastdate DOMElement dateElement = new DOMElement("LastDate"); dateElement.setText(lastDate); rootElement.add(dateElement); //add child:dayinpast DOMElement dayElement = new DOMElement("DayInPast"); dayElement.setText(Integer.toString(dayInpast)); rootElement.add(dayElement); //gen the doc Document doc = factory.createDocument(rootElement); //PrettyFormat OutputFormat format = OutputFormat.createPrettyPrint(); XMLWriter writer = new XMLWriter(new FileWriter(dest), format); writer.write(doc); writer.close(); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:org.eclipse.jubula.client.core.businessprocess.XmlResultReportWriter.java
License:Open Source License
/** * //from www. j a v a 2s . com * {@inheritDoc} */ public void write(Document document) { OutputFormat xmlFormat = OutputFormat.createPrettyPrint(); xmlFormat.setEncoding(m_writer.getEncoding()); XMLWriter xmlWriter = null; try { // write xml xmlWriter = new XMLWriter(m_writer, xmlFormat); xmlWriter.write(document); } catch (UnsupportedEncodingException e) { LOG.error(Messages.ErrorFileWriting + StringConstants.DOT, e); } catch (IOException e) { LOG.error(Messages.ErrorFileWriting + StringConstants.DOT, e); } }
From source file:org.eclipselabs.spray.releng.tools.ant.CompositeSiteTask.java
License:Open Source License
protected void modifyRepositoryDescriptorFile(File compositeXmlFile) { if (compositeXmlFile == null) return;/*from ww w.j a v a2 s . c om*/ try { log("Modifify " + compositeXmlFile.getPath()); SAXReader reader = new SAXReader(); Document doc = reader.read(compositeXmlFile); Element nodeTimestamp = (Element) doc.selectSingleNode("//property[@name='p2.timestamp']"); if (nodeTimestamp == null) { throw new IllegalStateException("Property p2.timestamp not found"); } nodeTimestamp.addAttribute("value", Long.toString(new Date().getTime())); Element nodeChildren = (Element) doc.selectSingleNode("/repository/children"); List<?> children = nodeChildren.elements("child"); int size = children.size(); Element child = nodeChildren.addElement("child"); child.addAttribute("location", versionToAdd); nodeChildren.addAttribute("size", Integer.toString(size + 1)); FileWriter fw = new FileWriter(compositeXmlFile); OutputFormat format = OutputFormat.createPrettyPrint(); XMLWriter writer = new XMLWriter(fw, format); writer.write(doc); fw.close(); } catch (Exception e) { throw new BuildException(e); } }
From source file:org.ecocean.servlet.ServletUtilities.java
License:Open Source License
public static synchronized void addRSSEntry(String title, String link, String description, File rssFile) { //File rssFile=new File("nofile.xml"); try {/* w ww .j ava 2s .c o m*/ System.out.println("Looking for RSS file: " + rssFile.getCanonicalPath()); if (rssFile.exists()) { SAXReader reader = new SAXReader(); Document document = reader.read(rssFile); Element root = document.getRootElement(); Element channel = root.element("channel"); List items = channel.elements("item"); int numItems = items.size(); items = null; if (numItems > 9) { Element removeThisItem = channel.element("item"); channel.remove(removeThisItem); } Element newItem = channel.addElement("item"); Element newTitle = newItem.addElement("title"); Element newLink = newItem.addElement("link"); Element newDescription = newItem.addElement("description"); newTitle.setText(title); newDescription.setText(description); newLink.setText(link); Element pubDate = channel.element("pubDate"); pubDate.setText((new java.util.Date()).toString()); //now save changes FileWriter mywriter = new FileWriter(rssFile); OutputFormat format = OutputFormat.createPrettyPrint(); format.setLineSeparator(System.getProperty("line.separator")); XMLWriter writer = new XMLWriter(mywriter, format); writer.write(document); writer.close(); } } catch (IOException ioe) { System.out.println("ERROR: Could not find the RSS file."); ioe.printStackTrace(); } catch (DocumentException de) { System.out.println("ERROR: Could not read the RSS file."); de.printStackTrace(); } catch (Exception e) { System.out.println("Unknown exception trying to add an entry to the RSS file."); e.printStackTrace(); } }
From source file:org.efaps.webdav4vfs.handler.LockHandler.java
License:Apache License
@Override protected void logXml(Node element) { ByteArrayOutputStream bos = new ByteArrayOutputStream(); try {/*from w w w . j av a 2 s. c o m*/ XMLWriter xmlWriter = new XMLWriter(bos, OutputFormat.createPrettyPrint()); xmlWriter.write(element); LOG.debug(bos.toString()); } catch (IOException e) { LOG.debug("ERROR writing XML log: " + e.getMessage()); } }
From source file:org.etudes.api.app.melete.util.XMLHelper.java
License:Apache License
/** * creates xml file for the give path//w w w . j ava 2s . c o m * @param url - path to create xml file * @throws IOException */ static public void generateXMLFile(String url, Document document) throws Exception { XMLWriter writer = null; FileOutputStream out = null; try { if (document == null) document = DocumentHelper.createDocument(); out = new FileOutputStream(new File(url)); OutputFormat outformat = OutputFormat.createPrettyPrint(); //outformat.setEncoding(aEncodingScheme); writer = new XMLWriter(out, outformat); writer.write(document); writer.flush(); } catch (IOException e1) { throw e1; } catch (Exception e) { throw e; } finally { try { if (writer != null) writer.close(); } catch (IOException e2) { } try { if (out != null) out.close(); } catch (IOException e3) { } } }
From source file:org.eurocarbdb.util.carbbank.CarbbankManager.java
License:Open Source License
/** * Exports a freshly parsed & loaded Carbbank as CSV to the * {@link OutputStream} given by {@link #getOutputStreamErrorSequences}. *//*from w ww .j a v a 2 s . c om*/ public int exportCarbbank() { assert false : "TODO"; //PrintWriter out = getOutputWriter(); OutputStream out = this.getOutputStreamErrorSequences(); assert out != null; Session s = null; EntityManager em = Eurocarb.getEntityManager(); if (em instanceof HibernateEntityManager) { s = ((HibernateEntityManager) em).getHibernateSession(); } else { throw new RuntimeException( "Only Hibernate-backed EntityManagers " + "support bulk exporting Carbbank data"); } assert s != null; Session dom4j = s.getSession(EntityMode.DOM4J); String contrib_name = getCarbbankContributor().getContributorName(); log.debug("query for all carbbank structures..."); /* List structures = dom4j.getNamedQuery( QUERY_GET_ALL_CARBBANK_STRUCTURES ) .setParameter("name", contrib_name ) .list(); if ( log.isDebugEnabled() ) log.debug( "found " + structures.size() + " carbbank structures..." ); Element e = (Element) structures.get(0); */ Element e = (Element) dom4j.load(Disease.class, 9538); try { log.debug("generating XML..."); OutputFormat format = OutputFormat.createPrettyPrint(); XMLWriter writer = new XMLWriter(out, format); writer.write(e); } catch (IOException ioex) { log.warn("Caught " + ioex.getClass().getName() + " while generating export XML", ioex); throw new RuntimeException(ioex); } return 1; }
From source file:org.fireflow.engine.modules.persistence.hibernate.VariableHeaderType.java
License:Open Source License
public static String map2XmlString(Properties arg0) { if (arg0 == null) return null; Properties map = arg0;//from www .j a v a2s .c o m Document document = documentFactory.createDocument(); Element root = documentFactory.createElement("map"); document.setRootElement(root); Iterator<Object> keys = map.keySet().iterator(); while (keys.hasNext()) { String key = (String) keys.next(); String value = (String) map.get(key); Element entry = documentFactory.createElement("entry"); root.add(entry); Element keyElm = documentFactory.createElement("key"); entry.add(keyElm); keyElm.setText(key); Element valueElm = documentFactory.createElement("value"); entry.add(valueElm); valueElm.add(documentFactory.createCDATA(value)); } try { StringWriter writer = new StringWriter(); OutputFormat format = OutputFormat.createPrettyPrint(); String jvmEncoding = Charset.defaultCharset().name(); format.setEncoding(jvmEncoding); XMLWriter xmlwriter = new XMLWriter(writer, format); xmlwriter.write(document); return writer.getBuffer().toString(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return document.toString(); }
From source file:org.foxbpm.engine.test.AbstractFoxBpmTestCase.java
License:Apache License
@Before public void annotationDeploymentSetUp() throws Exception { Method method = null;/*from w w w.j ava 2s . c om*/ try { method = this.getClass().getDeclaredMethod(name.getMethodName(), (Class<?>[]) null); } catch (Exception e) { throw new FoxBPMException("?!", e); } if (method.isAnnotationPresent(Clear.class)) { Clear clearAnnotation = method.getAnnotation(Clear.class); String[] tableNames = clearAnnotation.tables(); for (String tableName : tableNames) { jdbcTemplate.execute("delete from " + tableName); } } Deployment deploymentAnnotation = method.getAnnotation(Deployment.class); if (deploymentAnnotation != null) { String[] resources = deploymentAnnotation.resources(); if (resources.length == 0) { return; } DeploymentBuilder deploymentBuilder = null;// processEngine.getModelService().createDeployment().name("??"); // ????? BpmnXMLConverter bpmnXMLConverter = new BpmnXMLConverter(); BpmnModel bpmnModel = null; SAXReader reader = new SAXReader(); ByteArrayOutputStream out = null; OutputFormat format = null; for (String resource : resources) { bpmnModel = bpmnXMLConverter .convertToBpmnModel(reader.read(ReflectUtil.getResourceAsStream(resource))); deploymentBuilder = processEngine.getModelService().createDeployment().name("??"); // deploymentBuilder.addClasspathResource(resource); try { out = new ByteArrayOutputStream(); // ? format = OutputFormat.createPrettyPrint(); format.setEncoding("UTF-8"); XMLWriter xmlWriter = new XMLWriter(out, format); xmlWriter.setEscapeText(false); xmlWriter.write(bpmnXMLConverter.convertToXML(bpmnModel)); xmlWriter.close(); System.out.println(resource + "---------------" + out.toString()); deploymentBuilder.addInputStream(resource, new ByteArrayInputStream(out.toByteArray())); deploymentBuilder.deploy(); } catch (IOException e) { e.printStackTrace(); } } } }
From source file:org.frogx.service.maven.plugin.games.GenerateFrogxResourcesMojo.java
License:Open Source License
public void writeDocument(Document document, File file) throws IOException { PrintStream stream = new PrintStream(file); OutputFormat format = OutputFormat.createPrettyPrint(); XMLWriter writer = new XMLWriter(stream, format); writer.write(document);//w ww .ja v a2 s . c o m }