List of usage examples for org.jdom2.output Format getPrettyFormat
public static Format getPrettyFormat()
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 ww w .j a va 2 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 {/* w ww . j a v a 2 s.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.jumpmind.metl.core.runtime.component.XmlFormatter.java
License:Open Source License
private void createXml(ISendMessageCallback callback) { Document generatedXml = new Document(); Stack<DocElement> parentStack = new Stack<DocElement>(); ArrayList<String> outboundPayload = new ArrayList<String>(); for (Message msg : messagesToProcess) { processMsgEntities(parentStack, msg, generatedXml); }//from ww w . j a v a2s. c om XMLOutputter xmlOutputter = new XMLOutputter(); Format format = null; if (xmlFormat.equals(COMPACT_FORMAT)) { format = Format.getCompactFormat(); } else if (xmlFormat.equals(RAW_FORMAT)) { format = Format.getRawFormat(); } else { format = Format.getPrettyFormat(); } xmlOutputter.setFormat(format); outboundPayload.add(xmlOutputter.outputString(generatedXml)); callback.sendTextMessage(null, outboundPayload); }
From source file:org.jumpmind.metl.core.runtime.component.XsltProcessor.java
License:Open Source License
public static String getBatchXml(Model model, ArrayList<EntityData> inputRows, boolean outputAllAttributes) { SimpleDateFormat df = new SimpleDateFormat(DATE_FORMAT); Element root = new Element("batch"); Document doc = new Document(root); for (ModelEntity entity : getModelEntities(model, inputRows)) { Element entityElement = new Element("entity"); entityElement.setAttribute("name", entity.getName()); root.addContent(entityElement);/*w w w . j ava2 s . c o m*/ for (EntityData entityData : inputRows) { List<ModelAttribute> attributes = null; if (outputAllAttributes) { attributes = entity.getModelAttributes(); } else { attributes = getModelAttributes(model, entity.getId(), entityData.keySet()); } Element recordElement = new Element("record"); if (attributes.size() > 0) { entityElement.addContent(recordElement); } for (ModelAttribute attribute : attributes) { if (attribute != null && attribute.getEntityId().equals(entity.getId())) { Element attributeElement = new Element("attribute"); attributeElement.setAttribute("name", attribute.getName()); Object object = entityData.get(attribute.getId()); String value = null; DataType type = attribute.getDataType(); if (object != null) { if (type.isTimestamp() && object instanceof Date) { value = df.format(object); } else { value = object.toString(); } } attributeElement.setAttribute("value", value == null ? "" : value); recordElement.addContent(attributeElement); } } } } StringWriter writer = new StringWriter(); XMLOutputter xmlOutput = new XMLOutputter(); xmlOutput.setFormat(Format.getPrettyFormat()); try { xmlOutput.output(doc, writer); writer.close(); } catch (IOException e) { throw new RuntimeException(e); } return writer.toString(); }
From source file:org.jumpmind.metl.core.runtime.component.XsltProcessor.java
License:Open Source License
public static String getTransformedXml(String inputXml, String stylesheetXml, String xmlFormat, boolean omitXmlDeclaration) { StringWriter writer = new StringWriter(); SAXBuilder builder = new SAXBuilder(); builder.setXMLReaderFactory(XMLReaders.NONVALIDATING); builder.setFeature("http://xml.org/sax/features/validation", false); try {// ww w. ja v a 2 s . co m Document inputDoc = builder.build(new StringReader(inputXml)); StringReader reader = new StringReader(stylesheetXml); XSLTransformer transformer = new XSLTransformer(reader); Document outputDoc = transformer.transform(inputDoc); XMLOutputter xmlOutput = new XMLOutputter(); Format format = null; if (xmlFormat.equals(COMPACT_FORMAT)) { format = Format.getCompactFormat(); } else if (xmlFormat.equals(RAW_FORMAT)) { format = Format.getRawFormat(); } else { format = Format.getPrettyFormat(); } format.setOmitDeclaration(omitXmlDeclaration); xmlOutput.setFormat(format); xmlOutput.output(outputDoc, writer); writer.close(); } catch (Exception e) { throw new RuntimeException(e); } return writer.toString(); }
From source file:org.jwebsocket.config.xml.JWebSocketConfigHandler.java
License:Apache License
/** * * @param aDoc/* w w w .j ava2 s . c o m*/ * @param aPath * @throws IOException */ protected void saveChange(Document aDoc, String aPath) throws IOException { XMLOutputter lXmlOutput = new XMLOutputter(); lXmlOutput.setFormat(Format.getPrettyFormat()); lXmlOutput.output(aDoc, new FileWriter(aPath)); }
From source file:org.kdp.word.transformer.OPFTransformer.java
License:Apache License
private void writeOPFDocument(Context context, Document doc) { Options options = context.getOptions(); Path basedir = context.getBasedir(); Path filePath = options.getOpfTarget(); if (filePath == null) { String filename = context.getSource().getFileName().toString(); filename = filename.substring(0, filename.lastIndexOf('.')) + ".opf"; filePath = options.getBookDir().resolve(filename); }//www .jav a 2 s . c om try { log.info("Writing OPF: {}", filePath); File outfile = basedir.resolve(filePath).toFile(); outfile.getParentFile().mkdirs(); FileOutputStream fos = new FileOutputStream(outfile); XMLOutputter xo = new XMLOutputter(); Format format = Format.getPrettyFormat(); xo.setFormat(format.setOmitDeclaration(false)); format.setEncoding("UTF-8"); xo.output(doc, fos); fos.close(); } catch (IOException ex) { throw new IllegalStateException("Cannot write OPF file: " + filePath, ex); } }
From source file:org.kdp.word.utils.IOUtils.java
License:Apache License
public static void writeDocument(Context context, Document doc, OutputStream out) throws IOException { Parser parser = context.getParser(); String outputEncoding = parser.getProperty(Parser.PROPERTY_OUTPUT_ENCODING); outputEncoding = outputEncoding != null ? outputEncoding : "UTF-8"; String outputFormat = parser.getProperty(Parser.PROPERTY_OUTPUT_FORMAT); boolean pretty = Parser.OUTPUT_FORMAT_PRETTY.equals(outputFormat); XMLOutputter xo = new XMLOutputter(); Format format = pretty ? Format.getPrettyFormat() : Format.getCompactFormat(); format.setEncoding(outputEncoding);/*from w w w. jav a 2 s.c om*/ EscapeStrategy strategy = new OutputEscapeStrategy(context, format.getEscapeStrategy()); format.setEscapeStrategy(strategy); xo.setFormat(format.setOmitDeclaration(true)); xo.output(doc, out); }
From source file:org.kisst.cordys.caas.util.XmlNode.java
License:Open Source License
public String getPretty() { XMLOutputter out = new XMLOutputter(); out.setFormat(Format.getPrettyFormat()); String xml = out.outputString(element); return xml;/*from w ww . j a v a 2 s. com*/ }
From source file:org.kitodo.docket.ExportXmlLog.java
License:Open Source License
/** * This method exports the production metadata as xml to a given stream. * * @param docketData//from w ww.ja v a 2s. co m * the docket data to export * @param os * the OutputStream to write the contents to * @throws IOException * Throws IOException, when document creation fails. */ void startExport(DocketData docketData, OutputStream os) throws IOException { try { Document doc = createDocument(docketData, true); XMLOutputter outp = new XMLOutputter(); outp.setFormat(Format.getPrettyFormat()); outp.output(doc, os); os.close(); } catch (RuntimeException e) { logger.error("Document creation failed."); throw new IOException(e); } }