List of usage examples for org.jdom2.output Format getPrettyFormat
public static Format getPrettyFormat()
From source file:com.khodev.oradiff.io.XmlSchemaWriter.java
License:Open Source License
public void write(Schema schema) { XMLOutputter output = new XMLOutputter(Format.getPrettyFormat()); XmlSchemaWriter writer = new XmlSchemaWriter(filename.replaceAll(".ini", "") + "_autosave.xml"); try {/*from w w w . j a va 2 s .c o m*/ output.output(getXml(schema), new FileOutputStream(filename)); } catch (IOException e) { e.printStackTrace(); } }
From source file:com.khodev.sc2.quiz.Quiz.java
License:Open Source License
private void writeUserData(OutputStream s) throws IOException { Element root = new Element("Catalog"); Document d = new Document(root); Element user = new Element("CUser").setAttribute("id", "QuizDictionary"); root.addContent(user);// ww w . j ava 2 s .c om user.addContent(new Element("Fields").setAttribute("EditorColumn", "1").setAttribute("Id", "Level") .setAttribute("Type", "Int")); user.addContent(new Element("Fields").setAttribute("EditorColumn", "2").setAttribute("Id", "Question") .setAttribute("Type", "Text")); user.addContent(new Element("Fields").setAttribute("EditorColumn", "3").setAttribute("Id", "Answer") .setAttribute("Type", "Text")); user.addContent(new Element("Instances").setAttribute("Id", "[Default]")); int i = 0; for (Question question : questions) { i++; Element instance = new Element("Instances").setAttribute("Id", "" + i); user.addContent(instance); Element q = new Element("Text").setAttribute("Text", "UserData/QuizDictionary/" + i + "_Question"); instance.addContent(q); q.addContent(new Element("Field").setAttribute("Id", "Question")); Element r = new Element("Text").setAttribute("Text", "UserData/QuizDictionary/" + i + "_Answer"); instance.addContent(r); r.addContent(new Element("Field").setAttribute("Id", "Answer")); } XMLOutputter xmlOutput = new XMLOutputter(); xmlOutput.setFormat(Format.getPrettyFormat()); xmlOutput.output(d, s); }
From source file:com.lapis.jsfexporter.xml.XMLExportType.java
License:Apache License
@Override public void writeExport(ExternalContext externalContext) throws Exception { externalContext.setResponseCharacterEncoding("UTF-8"); new XMLOutputter(Format.getPrettyFormat()).output(document, externalContext.getResponseOutputStream()); }
From source file:com.medvision360.medrecord.basex.AbstractXmlConverter.java
License:Creative Commons License
protected void outputDocument(Document d, OutputStream os, String encoding) throws IOException { Format format = Format.getPrettyFormat(); format.setTextMode(Format.TextMode.PRESERVE); // this is the default, set just to be very safe format.setEncoding(encoding);/* w w w .j a v a2 s .c o m*/ XMLOutputter output = new XMLOutputter(format); output.output(d, os); }
From source file:com.medvision360.medrecord.basex.MockLocatableSerializer.java
License:Creative Commons License
@Override public void serialize(Locatable locatable, OutputStream os, String encoding) throws IOException { String rmEntity = locatable.getArchetypeDetails().getArchetypeId().rmEntity(); Element root = new Element(rmEntity); root.setAttribute("archetype_node_id", locatable.getArchetypeNodeId()); set(root, "/uid/value", locatable.getUid().getValue()); set(root, "/archetype_id/value", locatable.getArchetypeDetails().getArchetypeId().getValue()); set(root, "/name/value", locatable.getName().getValue()); Document d = new Document(root); Format format = Format.getPrettyFormat(); format.setEncoding(encoding);/* w w w . j a v a 2 s . com*/ XMLOutputter output = new XMLOutputter(format); output.output(d, os); }
From source file:com.rometools.propono.atom.server.AtomServlet.java
License:Apache License
/** * Handles an Atom GET by calling handler and writing results to response. */// w w w.j a v a2 s .c om @Override protected void doGet(final HttpServletRequest req, final HttpServletResponse res) throws ServletException, IOException { LOG.debug("Entering"); final AtomHandler handler = createAtomRequestHandler(req, res); final String userName = handler.getAuthenticatedUsername(); if (userName != null) { final AtomRequest areq = new AtomRequestImpl(req); try { if (handler.isAtomServiceURI(areq)) { // return an Atom Service document final AtomService service = handler.getAtomService(areq); final Document doc = service.serviceToDocument(); res.setContentType("application/atomsvc+xml; charset=utf-8"); final Writer writer = res.getWriter(); final XMLOutputter outputter = new XMLOutputter(); outputter.setFormat(Format.getPrettyFormat()); outputter.output(doc, writer); writer.close(); res.setStatus(HttpServletResponse.SC_OK); } else if (handler.isCategoriesURI(areq)) { final Categories cats = handler.getCategories(areq); res.setContentType("application/xml"); final Writer writer = res.getWriter(); final Document catsDoc = new Document(); catsDoc.setRootElement(cats.categoriesToElement()); final XMLOutputter outputter = new XMLOutputter(); outputter.output(catsDoc, writer); writer.close(); res.setStatus(HttpServletResponse.SC_OK); } else if (handler.isCollectionURI(areq)) { // return a collection final Feed col = handler.getCollection(areq); col.setFeedType(FEED_TYPE); final WireFeedOutput wireFeedOutput = new WireFeedOutput(); final Document feedDoc = wireFeedOutput.outputJDom(col); res.setContentType("application/atom+xml; charset=utf-8"); final Writer writer = res.getWriter(); final XMLOutputter outputter = new XMLOutputter(); outputter.setFormat(Format.getPrettyFormat()); outputter.output(feedDoc, writer); writer.close(); res.setStatus(HttpServletResponse.SC_OK); } else if (handler.isEntryURI(areq)) { // return an entry final Entry entry = handler.getEntry(areq); if (entry != null) { res.setContentType("application/atom+xml; type=entry; charset=utf-8"); final Writer writer = res.getWriter(); Atom10Generator.serializeEntry(entry, writer); writer.close(); } else { res.setStatus(HttpServletResponse.SC_NOT_FOUND); } } else if (handler.isMediaEditURI(areq)) { final AtomMediaResource entry = handler.getMediaResource(areq); res.setContentType(entry.getContentType()); res.setContentLength((int) entry.getContentLength()); Utilities.copyInputToOutput(entry.getInputStream(), res.getOutputStream()); res.getOutputStream().flush(); res.getOutputStream().close(); } else { res.setStatus(HttpServletResponse.SC_NOT_FOUND); } } catch (final AtomException ae) { res.sendError(ae.getStatus(), ae.getMessage()); LOG.debug("An error occured while processing GET", ae); } catch (final Exception e) { res.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage()); LOG.debug("An error occured while processing GET", e); } } else { res.setHeader("WWW-Authenticate", "BASIC realm=\"AtomPub\""); res.sendError(HttpServletResponse.SC_UNAUTHORIZED); } LOG.debug("Exiting"); }
From source file:com.rometools.rome.io.WireFeedOutput.java
License:Open Source License
/** * Creates a String with the XML representation for the given WireFeed. * <p>/*from ww w . j a v a2 s. c om*/ * If the feed encoding is not NULL, it will be used in the XML prolog encoding attribute. It is * the responsibility of the developer to ensure that if the String is written to a character * stream the stream charset is the same as the feed encoding property. * <p> * NOTE: This method delages to the 'Document WireFeedOutput#outputJDom(WireFeed)'. * <p> * * @param feed Abstract feed to create XML representation from. The type of the WireFeed must * match the type given to the FeedOuptut constructor. * @param prettyPrint pretty-print XML (true) oder collapsed * @return a String with the XML representation for the given WireFeed. * @throws IllegalArgumentException thrown if the feed type of the WireFeedOutput and WireFeed * don't match. * @throws FeedException thrown if the XML representation for the feed could not be created. * */ public String outputString(final WireFeed feed, final boolean prettyPrint) throws IllegalArgumentException, FeedException { final Document doc = outputJDom(feed); final String encoding = feed.getEncoding(); Format format; if (prettyPrint) { format = Format.getPrettyFormat(); } else { format = Format.getCompactFormat(); } if (encoding != null) { format.setEncoding(encoding); } final XMLOutputter outputter = new XMLOutputter(format); return outputter.outputString(doc); }
From source file:com.rometools.rome.io.WireFeedOutput.java
License:Open Source License
/** * Writes to an Writer the XML representation for the given WireFeed. * <p>// w ww . j a v a2 s .c o m * If the feed encoding is not NULL, it will be used in the XML prolog encoding attribute. It is * the responsibility of the developer to ensure the Writer instance is using the same charset * encoding. * <p> * NOTE: This method delages to the 'Document WireFeedOutput#outputJDom(WireFeed)'. * <p> * * @param feed Abstract feed to create XML representation from. The type of the WireFeed must * match the type given to the FeedOuptut constructor. * @param writer Writer to write the XML representation for the given WireFeed. * @param prettyPrint pretty-print XML (true) oder collapsed * @throws IllegalArgumentException thrown if the feed type of the WireFeedOutput and WireFeed * don't match. * @throws IOException thrown if there was some problem writing to the Writer. * @throws FeedException thrown if the XML representation for the feed could not be created. * */ public void output(final WireFeed feed, final Writer writer, final boolean prettyPrint) throws IllegalArgumentException, IOException, FeedException { final Document doc = outputJDom(feed); final String encoding = feed.getEncoding(); Format format; if (prettyPrint) { format = Format.getPrettyFormat(); } else { format = Format.getCompactFormat(); } if (encoding != null) { format.setEncoding(encoding); } final XMLOutputter outputter = new XMLOutputter(format); outputter.output(doc, writer); }
From source file:com.soulgalore.web.pagesavings.reporters.XMLReporter.java
License:Apache License
public void report(Set<SiteResult> results, Map<String, DescriptiveStatistics> statistics) { Date reportDate = new Date(); DateFormat df = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss"); Element root = new Element("savings"); root.setAttribute("date", "" + reportDate); Element resultsXML = new Element("results"); root.addContent(resultsXML);//from w w w . j av a 2 s.c o m Double totalPw = 0D; Double totalUnique = 0D; for (SiteResult siteResult : results) { totalPw += siteResult.getTotalSavings() * siteResult.getSite().getPageViews(); totalUnique += siteResult.getTotalSavings() * siteResult.getSite().getUniqueBrowsers(); Element site = new Element("site"); Element url = new Element("url"); Element weight = new Element("total-page-weight"); Element savingsPerPage = new Element("savings-per-page"); Element savingsForPW = new Element("savings-for-page-view"); Element savingsForUnique = new Element("savings-for-unique-browsers"); Element savingsPercentage = new Element("savings-percentage"); url.addContent(new CDATA(siteResult.getSite().getUrl())); savingsPerPage.setAttribute(READABLE, humanReadableByteCount(Math.round(siteResult.getTotalSavings()), true)); savingsPerPage.setAttribute(KB, "" + Math.round(siteResult.getTotalSavings())); savingsForPW.setAttribute(READABLE, humanReadableByteCount( Math.round(siteResult.getTotalSavings() * siteResult.getSite().getPageViews()), true)); savingsForPW.setAttribute(KB, "" + Math.round(siteResult.getTotalSavings() * siteResult.getSite().getPageViews())); savingsForUnique.setAttribute(READABLE, humanReadableByteCount( Math.round(siteResult.getTotalSavings() * siteResult.getSite().getUniqueBrowsers()), true)); savingsForUnique.setAttribute(KB, "" + Math.round(siteResult.getTotalSavings() * siteResult.getSite().getUniqueBrowsers())); savingsPercentage.addContent("" + Math.round(siteResult.getSavingsPercentage() * 100) / 100.0d); weight.setAttribute(READABLE, humanReadableByteCount(siteResult.getTotalSizeBytes() / 1000, true)); weight.setAttribute(KB, "" + siteResult.getTotalSizeBytes() / 1000); Element rulesSavings = new Element("rule-savings"); for (RuleResult ruleResult : siteResult.getResults()) { Element rule = new Element(ruleResult.getRule()); rule.addContent("" + ruleResult.getSavings()); rulesSavings.addContent(rule); } site.addContent(url); site.addContent(weight); site.addContent(savingsPerPage); site.addContent(savingsForPW); site.addContent(savingsForUnique); site.addContent(savingsPercentage); site.addContent(rulesSavings); resultsXML.addContent(site); } Element summary = new Element("summary"); summary.setAttribute("nrofsites", "" + results.size()); Element totalPW = new Element("total-pw"); Element totalUniqueSummary = new Element("total-unique"); totalPW.setAttribute(READABLE, humanReadableByteCount(Math.round(totalPw), true)); totalPW.setAttribute(KB, "" + Math.round(totalPw)); totalUniqueSummary.setAttribute(READABLE, humanReadableByteCount(Math.round(totalUnique), true)); totalUniqueSummary.setAttribute(KB, "" + Math.round(totalUnique)); summary.addContent(totalPW); summary.addContent(totalUniqueSummary); for (String rule : statistics.keySet()) { DescriptiveStatistics stats = statistics.get(rule); Element ruleElement = new Element(rule); Element max = new Element("max"); Element median = new Element("median"); max.addContent("" + stats.getMax()); median.addContent("" + stats.getPercentile(50)); ruleElement.addContent(max); ruleElement.addContent(median); summary.addContent(ruleElement); } resultsXML.addContent(summary); Document doc = new Document(root); XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat()); try { FileWriter writer = new FileWriter("report-" + df.format(reportDate) + ".xml"); outputter.output(doc, writer); } catch (Exception e) { } }
From source file:com.sun.syndication.io.WireFeedOutput.java
License:Open Source License
/** * Creates a String with the XML representation for the given WireFeed. * <p>/* ww w .j a v a2s.c o m*/ * If the feed encoding is not NULL, it will be used in the XML prolog encoding attribute. It is the responsibility * of the developer to ensure that if the String is written to a character stream the stream charset is the same as * the feed encoding property. * <p> * NOTE: This method delages to the 'Document WireFeedOutput#outputJDom(WireFeed)'. * <p> * @param feed Abstract feed to create XML representation from. The type of the WireFeed must match * the type given to the FeedOuptut constructor. * @param prettyPrint pretty-print XML (true) oder collapsed * @return a String with the XML representation for the given WireFeed. * @throws IllegalArgumentException thrown if the feed type of the WireFeedOutput and WireFeed don't match. * @throws FeedException thrown if the XML representation for the feed could not be created. * */ public String outputString(WireFeed feed, boolean prettyPrint) throws IllegalArgumentException, FeedException { Document doc = outputJDom(feed); String encoding = feed.getEncoding(); Format format = prettyPrint ? Format.getPrettyFormat() : Format.getCompactFormat(); if (encoding != null) { format.setEncoding(encoding); } XMLOutputter outputter = new XMLOutputter(format); return outputter.outputString(doc); }