List of usage examples for org.jdom2.output Format getPrettyFormat
public static Format getPrettyFormat()
From source file:net.alegen.datpass.library.configure.XMLConfigurator.java
License:Open Source License
public XMLConfigurator(String configFileName) throws IOException, JDOMException { try {//from www .j av a2s . com this.configFileName = configFileName; File configFile = new File(configFileName); if (!configFile.exists()) { this.root = new Element(XmlConstants.DATPASS); Document doc = new Document(this.root); XMLOutputter xmlOutput = new XMLOutputter(); xmlOutput.setFormat(Format.getPrettyFormat()); FileWriter fileWriter = new FileWriter(configFileName); xmlOutput.output(doc, fileWriter); fileWriter.flush(); fileWriter.close(); } else this.root = new SAXBuilder().build(configFile).getRootElement(); } catch (JDOMException e) { log.error("The XML configuration file is not valid. Please check for syntax errors."); throw e; } catch (IOException e) { log.error("There was a problem when trying to read the XML configuration file."); throw e; } }
From source file:net.alegen.datpass.library.configure.XMLConfigurator.java
License:Open Source License
@Override public boolean saveConfig() { XMLOutputter xmlOutput = new XMLOutputter(); Format format = Format.getPrettyFormat(); format.setIndent(" "); xmlOutput.setFormat(format);/*from www .ja v a 2 s.com*/ try { xmlOutput.output(this.root.getDocument(), new FileOutputStream(configFileName)); return true; } catch (IOException e) { log.error("An IO exception occured while saving data."); return false; } }
From source file:net.alegen.easyhash.utils.Settings.java
License:Open Source License
public void save() { Element elemSettings = new Element("settings"); Document doc = new Document(elemSettings); Element elemAlgorithm = new Element("algorithm"); elemAlgorithm.addContent(this.algorithm); doc.getRootElement().addContent(elemAlgorithm); Element elemEcho = new Element("echo"); elemEcho.addContent(String.valueOf(this.echo)); doc.getRootElement().addContent(elemEcho); Element elemToClipboard = new Element("to-clipboard"); elemToClipboard.addContent(String.valueOf(this.tocb)); doc.getRootElement().addContent(elemToClipboard); Element elemCaps = new Element("caps"); elemCaps.addContent(String.valueOf(this.caps)); doc.getRootElement().addContent(elemCaps); Element elemChain = new Element("chain"); elemChain.addContent(String.valueOf(this.chain)); doc.getRootElement().addContent(elemChain); Element elemResetTime = new Element("reset-time"); elemResetTime.addContent(String.valueOf(this.resetTime)); doc.getRootElement().addContent(elemResetTime); Element elemSalt = new Element("salt"); elemSalt.addContent(this.salt); doc.getRootElement().addContent(elemSalt); XMLOutputter xmlOutput = new XMLOutputter(); xmlOutput.setFormat(Format.getPrettyFormat()); try {/*w w w. j a v a2 s.c om*/ xmlOutput.output(doc, new FileWriter("settings.eh.xml")); } catch (IOException ex) { System.out.println("eh > Could not save settings - " + ex.getMessage()); } }
From source file:net.instantcom.mm7.MM7Context.java
License:Open Source License
public Format getJdomFormat() { if (jdomFormat == null) { jdomFormat = Format.getPrettyFormat(); } return jdomFormat; }
From source file:net.instantcom.mm7.MM7Message.java
License:Open Source License
@Override public String toString() { XMLOutputter out = new XMLOutputter(Format.getPrettyFormat()); Document doc = new Document(toSOAP(new MM7Context())); StringWriter w = new StringWriter(); try {//w ww. j ava 2 s . co m out.output(doc, w); return w.toString(); } catch (IOException e) { return super.toString(); } }
From source file:net.osgiliath.helpers.cxf.exception.handling.jaxrs.mapper.ExceptionXmlMapper.java
License:Apache License
/** * Map the catched Exception to the response body (xml format). *///from w w w . jav a 2s.co m @Override public Response toResponse(Exception arg0) { // On cree une instance de SAXBuilder final Element root = new Element("Exception"); final Document doc = new Document(root); this.populateXML(arg0, root); final String res = new XMLOutputter(Format.getPrettyFormat()).outputString(doc); LOG.info("CXF exception thrown: " + res, arg0); return Response.status(Response.Status.FORBIDDEN).type(MediaType.APPLICATION_XML) .header(ExceptionMappingConstants.EXCEPTION_BODY_HEADER, res).build(); }
From source file:nl.colorize.util.xml.XMLHelper.java
License:Apache License
private static XMLOutputter getOutputter() { Format formatter = Format.getPrettyFormat(); formatter.setEncoding(Charsets.UTF_8.displayName()); formatter.setIndent(" "); formatter.setLineSeparator(Platform.getLineSeparator()); formatter.setExpandEmptyElements(false); formatter.setOmitDeclaration(false); formatter.setOmitEncoding(false);/* www . java2 s.c om*/ XMLOutputter outputter = new XMLOutputter(formatter); outputter.setFormat(formatter); return outputter; }
From source file:nl.nn.adapterframework.util.XmlBuilder.java
License:Apache License
public String toXML(boolean xmlHeader) { Document document = new Document(element.detach()); XMLOutputter xmlOutputter = new XMLOutputter(); xmlOutputter.setFormat(Format.getPrettyFormat().setOmitDeclaration(!xmlHeader)); return xmlOutputter.outputString(document); }
From source file:object2xml.JDOMXMLWriter.java
public void writeFileUsingJDOM(List<Pessoa> pessoaList, String fileName) throws IOException { Document doc = new Document(); doc.setRootElement(new Element("Pessoas", "")); for (Pessoa p : pessoaList) { System.out.println(p);// ww w .ja v a 2 s.co m Element pessoa = new Element("Pessoa"); pessoa.setAttribute("id", "" + p.getIdentidade()); pessoa.addContent(new Element("nome").setText(p.getNome())); pessoa.addContent(new Element("idade").setText("" + p.getIdade())); pessoa.addContent(new Element("peso").setText("" + p.getPeso())); Element celulares = new Element("Celulares"); for (Celular c : p.getCelulares()) { Element celular = new Element("Celular"); celular.setAttribute("id", "" + c.getIdCel()); celular.addContent(new Element("numero").setText("" + c.getNumero())); celular.addContent(new Element("operadora").setText("" + c.getOperadora())); celulares.addContent(celular); } pessoa.addContent(celulares); doc.getRootElement().addContent(pessoa); } //JDOM document is ready now, lets write it to file now XMLOutputter xmlOutputter = new XMLOutputter(Format.getPrettyFormat()); //output xml to console for debugging //xmlOutputter.output(doc, System.out); xmlOutputter.output(doc, new FileOutputStream(fileName)); }
From source file:odml.core.Writer.java
License:Open Source License
/** * Writes the dom tree to the given output stream. * * @param stream the output stream/*from w w w . j av a 2 s.c o m*/ * @return true if the dom tree was successfully written to the stream, false otherwise * */ private boolean writeToStream(OutputStream stream) { if (doc == null) { System.out.println("Writing to Stream failed, document is empty!"); return false; } try { org.jdom2.output.Format format = org.jdom2.output.Format.getPrettyFormat().setIndent(" "); XMLOutputter outputter = new XMLOutputter(); outputter.setFormat(Format.getPrettyFormat()); outputter.output(doc, stream); } catch (IOException ie) { System.out.println("Write to file failed: " + ie.getMessage()); return false; } System.out.println("Writing to file successful!"); return true; }