List of usage examples for org.jdom2.output XMLOutputter XMLOutputter
public XMLOutputter(XMLOutputProcessor processor)
XMLOutputter
with the specified XMLOutputProcessor. From source file:org.goobi.production.export.ExportXmlLog.java
License:Open Source License
/** * This method transforms the xml log using a xslt file and opens a new window with the output file * // w w w. j ava 2s . c om * @param out ServletOutputStream * @param doc the xml document to transform * @param filename the filename of the xslt * @throws XSLTransformException * @throws IOException */ public void XmlTransformation(OutputStream out, Document doc, String filename) throws XSLTransformException, IOException { Document docTrans = new Document(); if (filename != null && filename.equals("")) { XSLTransformer transformer; transformer = new XSLTransformer(filename); docTrans = transformer.transform(doc); } else { docTrans = doc; } Format format = Format.getPrettyFormat(); format.setEncoding("utf-8"); XMLOutputter xmlOut = new XMLOutputter(format); xmlOut.output(docTrans, out); }
From source file:org.helm.notation2.MonomerFactory.java
License:Open Source License
private static String buildMonomerDbXMLFromCache(MonomerCache cache) throws MonomerException { XMLOutputter outputer = new XMLOutputter(Format.getPrettyFormat()); StringBuilder sb = new StringBuilder(); sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + System.getProperty("line.separator") + "<MonomerDB xmlns=\"lmr\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">" + System.getProperty("line.separator")); Map<String, Map<String, Monomer>> mDB = cache.getMonomerDB(); Element polymerListElement = new Element(POLYMER_LIST_ELEMENT); Set<String> polymerTypeSet = mDB.keySet(); for (Iterator i = polymerTypeSet.iterator(); i.hasNext();) { String polymerType = (String) i.next(); Element polymerElement = new Element(POLYMER_ELEMENT); Attribute att = new Attribute(POLYMER_TYPE_ATTRIBUTE, polymerType); polymerElement.setAttribute(att); polymerListElement.getChildren().add(polymerElement); Map<String, Monomer> monomerMap = mDB.get(polymerType); Set<String> monomerSet = monomerMap.keySet(); for (Iterator it = monomerSet.iterator(); it.hasNext();) { String monomerID = (String) it.next(); Monomer m = monomerMap.get(monomerID); Element monomerElement = MonomerParser.getMonomerElement(m); polymerElement.getChildren().add(monomerElement); }/*w w w . j a v a2 s .c o m*/ } String polymerListString = outputer.outputString(polymerListElement); sb.append(polymerListString + System.getProperty("line.separator")); Map<String, Attachment> aDB = cache.getAttachmentDB(); Element attachmentListElement = new Element(ATTACHMENT_LIST_ELEMENT); Set<String> attachmentSet = aDB.keySet(); for (Iterator itr = attachmentSet.iterator(); itr.hasNext();) { String attachmentID = (String) itr.next(); Attachment attachment = aDB.get(attachmentID); Element attachmentElement = MonomerParser.getAttachementElement(attachment); attachmentListElement.getChildren().add(attachmentElement); } String attachmentListString = outputer.outputString(attachmentListElement); sb.append(attachmentListString); sb.append(System.getProperty("line.separator") + "</MonomerDB>" + System.getProperty("line.separator")); return sb.toString(); }
From source file:org.helm.notation2.tools.NucleotideParser.java
License:Open Source License
public static String getNucleotideTemplatesXML(Map<String, Map<String, String>> templates) { XMLOutputter outputer = new XMLOutputter(Format.getPrettyFormat()); StringBuilder sb = new StringBuilder(); sb.append(//from w w w .ja v a2 s . c o m "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<NUCLEOTIDE_TEMPLATES xsi:schemaLocation=\"lmr NucleotideTemplateSchema.xsd\" xmlns=\"lmr\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n"); Set<String> templateSet = templates.keySet(); for (Iterator i = templateSet.iterator(); i.hasNext();) { String template = (String) i.next(); Element templateElement = new Element(TEMPLATE_ELEMENT); Attribute att = new Attribute(TEMPLATE_NOTATION_SOURCE_ATTRIBUTE, template); templateElement.setAttribute(att); Map<String, String> nucMap = templates.get(template); Set<String> nucleotideSet = nucMap.keySet(); for (Iterator it = nucleotideSet.iterator(); it.hasNext();) { Element nucleotideElement = new Element(NUCLEOTIDE_ELEMENT); templateElement.getChildren().add(nucleotideElement); String symbol = (String) it.next(); Element symbolElement = new Element(NUCLEOTIDE_SYMBOL_ELEMENT); symbolElement.setText(symbol); nucleotideElement.getChildren().add(symbolElement); String notation = nucMap.get(symbol); Element notationElement = new Element(NUCLEOTIDE_MONOMER_NOTATION_ELEMENT); notationElement.setText(notation); nucleotideElement.getChildren().add(notationElement); } String templateString = outputer.outputString(templateElement); sb.append(templateString); } sb.append("\n</NUCLEOTIDE_TEMPLATES>"); return sb.toString(); }
From source file:org.humsat.demo.gssw.sensorlocator.kml.SimpleKMLWriter.java
License:Open Source License
/** * Writes the current KML tree to the given output stream. * //from www .j av a 2 s . c om * @param os The output stream where the KML tree is to be written. * @throws IOException In case an IO error occurs. */ public void writeXML(OutputStream os) throws IOException { XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat()); outputter.output(this.kmlDocument, os); }
From source file:org.jboss.hal.processor.mbui.XmlHelper.java
License:Apache License
static String xmlAsString(org.jdom2.Element element) { String asString;/* w ww .ja va 2s . c om*/ StringWriter writer = new StringWriter(); try { new XMLOutputter(Format.getCompactFormat()).output(element, writer); asString = writer.toString(); } catch (IOException e) { asString = "<" + element + "/>"; } return asString; }
From source file:org.jls.toolbox.util.xml.XMLParser.java
License:Open Source License
/** * Permet partir d'un document XML gnr par JDom de rcuprer la chane * formate en XML.//ww w .j a v a 2s. c o m * * @param xmlDocument * Fichier XML gnr avec JDom. * @return Chane formate en XML. */ public static String getStream(Document xmlDocument) { Format format = Format.getPrettyFormat(); format.setIndent("\t"); XMLOutputter output = new XMLOutputter(format); return output.outputString(xmlDocument); }
From source file:org.jls.toolbox.util.xml.XMLParser.java
License:Open Source License
/** * Permet d'exporter un {@link Document} vers un fichier XML. * /* ww w .j ava 2 s.co m*/ * @param doc * Document exporter dans un fichier. * @param file * Fichier vers lequel exporter le fichier. * @throws FileNotFoundException * Le fichier est cr donc on s'en fout. * @throws IOException * Si une erreur survient pendant l'criture, une exception est * leve. */ public static void exportToFile(final Document doc, final File file) throws FileNotFoundException, IOException { if (doc != null && file != null) { try (FileOutputStream os = new FileOutputStream(file)) { XMLOutputter out = new XMLOutputter(Format.getPrettyFormat()); out.output(doc, os); } } else { throw new NullPointerException(); } }
From source file:org.jpos.transaction.Context.java
License:Open Source License
protected void dumpEntry(PrintStream p, String indent, Map.Entry<String, Object> entry) { String key = entry.getKey();//from www. jav a2 s. co m if (key.startsWith(".") || key.startsWith("*")) return; // see jPOS-63 p.printf("%s%s%s: ", indent, key, pmap != null && pmap.containsKey(key) ? "(P)" : ""); Object value = entry.getValue(); if (value instanceof Loggeable) { p.println(""); ((Loggeable) value).dump(p, indent + " "); p.print(indent); } else if (value instanceof Element) { p.println(""); p.println(indent + "<![CDATA["); XMLOutputter out = new XMLOutputter(Format.getPrettyFormat()); out.getFormat().setLineSeparator(System.lineSeparator()); try { out.output((Element) value, p); } catch (IOException ex) { ex.printStackTrace(p); } p.println(""); p.println(indent + "]]>"); } else if (value instanceof byte[]) { byte[] b = (byte[]) value; p.println(""); p.println(ISOUtil.hexdump(b)); p.print(indent); } else if (value instanceof LogEvent) { ((LogEvent) value).dump(p, indent); p.print(indent); } else if (value != null) { try { p.print(ISOUtil.normalize(value.toString(), true)); } catch (Exception e) { p.println(e.getMessage()); p.print(indent); } } p.println(); }
From source file:org.jpos.util.LogEvent.java
License:Open Source License
public void dump(PrintStream p, String outer) { String indent = dumpHeader(p, outer); if (payLoad.isEmpty()) { if (tag != null) p.println(indent + "<" + tag + "/>"); } else {//from w w w. j a va2s . c om String newIndent; if (tag != null) { p.println(indent + "<" + tag + ">"); newIndent = indent + " "; } else newIndent = ""; synchronized (payLoad) { for (Object o : payLoad) { if (o instanceof Loggeable) ((Loggeable) o).dump(p, newIndent); else if (o instanceof SQLException) { SQLException e = (SQLException) o; p.println(newIndent + "<SQLException>" + e.getMessage() + "</SQLException>"); p.println(newIndent + "<SQLState>" + e.getSQLState() + "</SQLState>"); p.println(newIndent + "<VendorError>" + e.getErrorCode() + "</VendorError>"); ((Throwable) o).printStackTrace(p); } else if (o instanceof Throwable) { p.println(newIndent + "<exception name=\"" + ((Throwable) o).getMessage() + "\">"); p.print(newIndent); ((Throwable) o).printStackTrace(p); p.println(newIndent + "</exception>"); } else if (o instanceof Object[]) { Object[] oa = (Object[]) o; p.print(newIndent + "["); for (int j = 0; j < oa.length; j++) { if (j > 0) p.print(","); p.print(oa[j].toString()); } p.println("]"); } else if (o instanceof Element) { p.println(""); p.println(newIndent + "<![CDATA["); XMLOutputter out = new XMLOutputter(Format.getPrettyFormat()); out.getFormat().setLineSeparator("\n"); try { out.output((Element) o, p); } catch (IOException ex) { ex.printStackTrace(p); } p.println(""); p.println(newIndent + "]]>"); } else if (o != null) { p.println(newIndent + o.toString()); } else { p.println(newIndent + "null"); } } } if (tag != null) p.println(indent + "</" + tag + ">"); } dumpTrailer(p, outer); }
From source file:org.kisst.cordys.caas.util.XmlNode.java
License:Open Source License
public String compact() { XMLOutputter out = new XMLOutputter(Format.getCompactFormat()); return out.outputString(element); }