List of usage examples for org.jdom2.output XMLOutputter XMLOutputter
public XMLOutputter(XMLOutputProcessor processor)
XMLOutputter
with the specified XMLOutputProcessor. From source file:de.knowwe.visualization.dot.DOTRenderer.java
License:Open Source License
/** * Adds the target-tag to every URL in the svg-file * * @created 01.08.2012/*from w ww . j av a2 s. c om*/ */ private static void augmentSVG(File svg) throws IOException { Log.finest("Starting to augment SVG: " + svg.getAbsolutePath()); try { // check if svg file is closed, otherwise wait timeout second long start = System.currentTimeMillis(); while (!Utils.isFileClosed(svg)) { if ((System.currentTimeMillis() - start) > TIMEOUT) { Log.warning("Exceded timeout while waiting for SVG file to be closed."); return; } } Document doc = SAXBuilderSingleton.getInstance().build(svg); Element root = doc.getRootElement(); if (root == null) return; findAndAugmentElements(root); XMLOutputter xmlOutputter = new XMLOutputter(Format.getPrettyFormat()); xmlOutputter.output(doc, new FileWriter(svg)); Log.finest("Finished augmenting SVG: " + svg.getAbsolutePath()); } catch (JDOMException e) { Log.warning("Exception while augmenting SVG " + svg.getAbsolutePath(), e); } }
From source file:de.nava.informa.exporters.RSS_0_91_Exporter.java
License:Open Source License
public void write(ChannelIF channel) throws IOException { if (writer == null) { throw new RuntimeException("No writer has been initialized."); }//from ww w . j av a 2 s. c o m // create XML outputter with indent: 2 spaces, print new lines. Format format = Format.getPrettyFormat(); format.setEncoding(encoding); XMLOutputter outputter = new XMLOutputter(format); // ---- Element rootElem = new Element("rss"); rootElem.setAttribute("version", RSS_VERSION); Element channelElem = new Element("channel"); channelElem.addContent(new Element("title").setText(channel.getTitle())); channelElem.addContent(new Element("description").setText(channel.getDescription())); if (channel.getSite() != null) { channelElem.addContent(new Element("link").setText(channel.getSite().toString())); } if (channel.getLanguage() != null) { channelElem.addContent(new Element("language").setText(channel.getLanguage())); } Collection items = channel.getItems(); Iterator it = items.iterator(); while (it.hasNext()) { channelElem.addContent(getItemElement((ItemIF) it.next())); } // export channel image if (channel.getImage() != null) { Element imgElem = new Element("image"); imgElem.addContent(new Element("title").setText(channel.getImage().getTitle())); imgElem.addContent(new Element("url").setText(channel.getImage().getLocation().toString())); imgElem.addContent(new Element("link").setText(channel.getImage().getLink().toString())); imgElem.addContent(new Element("height").setText("" + channel.getImage().getHeight())); imgElem.addContent(new Element("width").setText("" + channel.getImage().getWidth())); imgElem.addContent(new Element("description").setText(channel.getImage().getDescription())); channelElem.addContent(imgElem); } // TODO: add exporting textinput field // if (channel.getTextInput() != null) { // channelElem.addContent(channel.getTextInput().getElement()); // } if (channel.getCopyright() != null) { channelElem.addContent(new Element("copyright").setText(channel.getCopyright())); } // we have all together for the channel definition rootElem.addContent(channelElem); // --- DocType docType = new DocType("rss", PUBLIC_ID, SYSTEM_ID); Document doc = new Document(rootElem, docType); outputter.output(doc, writer); }
From source file:de.nava.informa.exporters.RSS_1_0_Exporter.java
License:Open Source License
public void write(ChannelIF channel) throws IOException { if (writer == null) { throw new RuntimeException("No writer has been initialized."); }/*from w w w . j a v a 2 s . c o m*/ Element rootElem = new Element("RDF", NS_RDF); rootElem.addNamespaceDeclaration(NS_DEFAULT); // TODO rootElem.addNamespaceDeclaration(NS_DC); rootElem.addNamespaceDeclaration(NS_SY); // rootElem.setAttribute("version"); Element channelElem = new Element("channel", NS_DEFAULT); if (channel.getLocation() != null) { channelElem.setAttribute("about", channel.getLocation().toString(), NS_RDF); } channelElem.addContent(new Element("title", NS_DEFAULT).setText(channel.getTitle())); if (channel.getSite() != null) { channelElem.addContent(new Element("link", NS_DEFAULT).setText(channel.getSite().toString())); channelElem.addContent( new Element("source", NS_DC).setAttribute("resource", channel.getSite().toString())); } channelElem.addContent(new Element("description", NS_DEFAULT).setText(channel.getDescription())); if (channel.getLanguage() != null) { channelElem.addContent(new Element("language", NS_DC).setText(channel.getLanguage())); } if (channel.getCopyright() != null) { channelElem.addContent(new Element("copyright", NS_DC).setText(channel.getCopyright())); } if (channel.getUpdateBase() != null) { channelElem.addContent(new Element("updateBase", NS_SY).setText(df.format(channel.getUpdateBase()))); } if (channel.getUpdatePeriod() != null) { // don't put out frequency without specifying period channelElem.addContent(new Element("updateFrequency", NS_SY) .setText((new Integer(channel.getUpdateFrequency())).toString())); channelElem .addContent(new Element("updatePeriod", NS_SY).setText(channel.getUpdatePeriod().toString())); } // export channel image if (channel.getImage() != null) { Element imgElem = new Element("image", NS_DEFAULT); imgElem.addContent(new Element("title", NS_DEFAULT).setText(channel.getImage().getTitle())); imgElem.addContent(new Element("url", NS_DEFAULT).setText(channel.getImage().getLocation().toString())); imgElem.addContent(new Element("link", NS_DEFAULT).setText(channel.getImage().getLink().toString())); imgElem.addContent(new Element("height", NS_DEFAULT).setText("" + channel.getImage().getHeight())); imgElem.addContent(new Element("width", NS_DEFAULT).setText("" + channel.getImage().getWidth())); imgElem.addContent(new Element("description", NS_DEFAULT).setText(channel.getImage().getDescription())); channelElem.addContent(imgElem); } // TODO: add exporting textinput field // if (channel.getTextInput() != null) { // channelElem.addContent(channel.getTextInput().getElement()); // } // =========================================== Element itemsElem = new Element("items", NS_DEFAULT); Element seqElem = new Element("Seq", NS_RDF); Collection items = channel.getItems(); Iterator it = items.iterator(); while (it.hasNext()) { ItemIF item = (ItemIF) it.next(); Element itemElem = new Element("li", NS_RDF); if (item.getLink() != null) { itemElem.setAttribute("resource", item.getLink().toString()); } seqElem.addContent(itemElem); } itemsElem.addContent(seqElem); channelElem.addContent(itemsElem); rootElem.addContent(channelElem); // item-by-item en detail items = channel.getItems(); it = items.iterator(); while (it.hasNext()) { rootElem.addContent(getItemElement((ItemIF) it.next())); } // create XML outputter with indent: 2 spaces, print new lines. Format format = Format.getPrettyFormat(); format.setEncoding(encoding); XMLOutputter outputter = new XMLOutputter(format); // write DOM to file Document doc = new Document(rootElem); outputter.output(doc, writer); writer.close(); }
From source file:de.nava.informa.exporters.RSS_2_0_Exporter.java
License:Open Source License
public void write(ChannelIF channel) throws IOException { if (writer == null) { throw new RuntimeException("No writer has been initialized."); }// ww w . j av a 2 s . co m // create XML outputter with indent: 2 spaces, print new lines. Format format = Format.getPrettyFormat(); format.setEncoding(encoding); XMLOutputter outputter = new XMLOutputter(format); Namespace dcNs = Namespace.getNamespace("dc", NS_DC); Namespace syNs = Namespace.getNamespace("sy", NS_SY); Namespace adminNs = Namespace.getNamespace("admin", NS_ADMIN); //Namespace rdfNs = Namespace.getNamespace("rdf", NS_RDF); Element rootElem = new Element("rss"); rootElem.addNamespaceDeclaration(dcNs); rootElem.addNamespaceDeclaration(syNs); rootElem.addNamespaceDeclaration(adminNs); rootElem.setAttribute("version", RSS_VERSION); Element channelElem = new Element("channel"); // rootElem.setAttribute("version"); channelElem.addContent(new Element("title").setText(channel.getTitle())); if (channel.getSite() != null) { channelElem.addContent(new Element("link").setText(channel.getSite().toString())); } channelElem.addContent(new Element("description").setText(channel.getDescription())); if (channel.getLanguage() != null) { channelElem.addContent(new Element("language", dcNs).setText(channel.getLanguage())); } if (channel.getCopyright() != null) { channelElem.addContent(new Element("copyright", dcNs).setText(channel.getCopyright())); } if (channel.getPubDate() != null) { channelElem.addContent(new Element("pubDate").setText(ParserUtils.formatDate(channel.getPubDate()))); } if (channel.getCategories() != null) { Collection categories = channel.getCategories(); for (Object category : categories) { CategoryIF cat = (CategoryIF) category; channelElem = getCategoryElements(channelElem, cat, null); } } if (channel.getUpdateBase() != null) { channelElem.addContent(new Element("updateBase", syNs).setText(df.format(channel.getUpdateBase()))); } if (channel.getUpdatePeriod() != null) { // don't put out frequency without specifying period channelElem.addContent(new Element("updateFrequency", syNs) .setText((new Integer(channel.getUpdateFrequency())).toString())); channelElem.addContent(new Element("updatePeriod", syNs).setText(channel.getUpdatePeriod().toString())); } // export channel image if (channel.getImage() != null) { Element imgElem = new Element("image"); imgElem.addContent(new Element("title").setText(channel.getImage().getTitle())); imgElem.addContent(new Element("url").setText(channel.getImage().getLocation().toString())); imgElem.addContent(new Element("link").setText(channel.getImage().getLink().toString())); imgElem.addContent(new Element("height").setText("" + channel.getImage().getHeight())); imgElem.addContent(new Element("width").setText("" + channel.getImage().getWidth())); imgElem.addContent(new Element("description").setText(channel.getImage().getDescription())); channelElem.addContent(imgElem); } // TODO: add exporting textinput field // if (channel.getTextInput() != null) { // channelElem.addContent(channel.getTextInput().getElement()); // } Collection items = channel.getItems(); for (Object item : items) { channelElem.addContent(getItemElement((ItemIF) item)); } rootElem.addContent(channelElem); // --- Document doc = new Document(rootElem); outputter.output(doc, writer); // --- writer.close(); }
From source file:de.relaunch64.popelganda.database.CustomScripts.java
License:Open Source License
/** * Saves the scripts to xml-file/*from w w w . j av a2 s .c o m*/ */ public void saveScripts() { // if file exists, go on... if (filepath != null) { OutputStream dest = null; try { XMLOutputter out = new XMLOutputter(Format.getPrettyFormat()); dest = new FileOutputStream(filepath); out.output(scriptFile, dest); } catch (IOException ex) { ConstantsR64.r64logger.log(Level.WARNING, ex.getLocalizedMessage()); } finally { if (dest != null) { try { dest.close(); } catch (IOException ex) { ConstantsR64.r64logger.log(Level.WARNING, ex.getLocalizedMessage()); } } } } }
From source file:de.relaunch64.popelganda.database.Settings.java
License:Open Source License
/** * Loads the settings file/*from ww w.ja v a 2s .c o m*/ */ public void saveSettings() { // if file exists, go on... if (filepath != null) { OutputStream dest = null; try { XMLOutputter out = new XMLOutputter(Format.getPrettyFormat()); dest = new FileOutputStream(filepath); out.output(settingsFile, dest); } catch (IOException ex) { ConstantsR64.r64logger.log(Level.WARNING, ex.getLocalizedMessage()); } finally { if (dest != null) { try { dest.close(); } catch (IOException ex) { ConstantsR64.r64logger.log(Level.WARNING, ex.getLocalizedMessage()); } } } } }
From source file:de.sixtyfourktec.mirrorhub.modules.NationalRailModule.java
License:Open Source License
private NationalRailModule() { /* Create the soap envelope document */ Document doc = new Document(); Namespace soap = Namespace.getNamespace("soap", "http://schemas.xmlsoap.org/soap/envelope/"); Namespace ldb = Namespace.getNamespace("ldb", "http://thalesgroup.com/RTTI/2014-02-20/ldb/"); Namespace typ = Namespace.getNamespace("typ", "http://thalesgroup.com/RTTI/2010-11-01/ldb/commontypes"); Element env = new Element("Envelope", soap); /* Header *//*from w ww. ja v a 2 s . co m*/ env.addContent(new Element("Header", soap).addContent(new Element("AccessToken", typ) .addContent(new Element("TokenValue", typ).addContent(BuildConfig.NATIONALRAIL_API_KEY)))); /* Body */ Element dep_request = new Element("GetDepartureBoardRequest", ldb) .addContent(new Element("crs", ldb).addContent(BuildConfig.NATIONALRAIL_CRS)) .addContent(new Element("numRows", ldb).addContent("5")); if (!BuildConfig.NATIONALRAIL_FILTER_CRS.isEmpty()) { dep_request.addContent(new Element("filterCrs", ldb).addContent(BuildConfig.NATIONALRAIL_FILTER_CRS)) .addContent(new Element("filterType", ldb).addContent(BuildConfig.NATIONALRAIL_FILTER_TYPE)); } env.addContent(new Element("Body", soap).addContent(dep_request)); doc.setContent(env); String xml = new XMLOutputter(Format.getPrettyFormat()).outputString(doc); if (showXml) { Log.i(TAG, xml); } /* Create a static request object we can reuse */ RequestBody body = RequestBody.create(MediaType.parse("text/xml; charset=utf-8"), xml); request = new Request.Builder().url("https://lite.realtime.nationalrail.co.uk/OpenLDBWS/ldb6.asmx") .post(body).build(); }
From source file:de.smartics.maven.plugin.jboss.modules.parser.ModulesDescriptorBuilder.java
License:Apache License
private void parseApply(final Builder builder, final Element dependenciesElement) { final Element applyElement = dependenciesElement.getChild("apply", NS); if (applyElement == null) { return;/*ww w. j a v a 2s . c o m*/ } final String slot = applyElement.getChildText("slot", NS); final String skip = applyElement.getChildText("skip", NS); final String export = applyElement.getChildText("export", NS); final String services = applyElement.getChildText("services", NS); final String optional = applyElement.getChildText("optional", NS); builder.withSlot(slot); builder.withSkip(skip); builder.withExport(export); builder.withServices(services); builder.withOptional(optional); final XMLOutputter outputter = new XMLOutputter(Format.getCompactFormat()); final Element importElement = applyElement.getChild("imports", NS); if (importElement != null) { adjustNamespaces(importElement); final String imports = outputter.outputString(importElement); builder.withImportsXml(imports); } final Element exportElement = applyElement.getChild("exports", NS); if (exportElement != null) { adjustNamespaces(exportElement); final String exports = outputter.outputString(exportElement); builder.withExportsXml(exports); } }
From source file:de.smartics.maven.plugin.jboss.modules.parser.ModulesDescriptorBuilder.java
License:Apache License
private void parseApplyToModule(final Element applyToModuleElement) { if (applyToModuleElement == null) { return;/* w w w . j ava2 s . c o m*/ } final ApplyToModule.Builder mBuilder = new ApplyToModule.Builder(); adjustNamespaces(applyToModuleElement); final XMLOutputter outputter = new XMLOutputter(Format.getCompactFormat()); for (final Element child : applyToModuleElement.getChildren()) { handleChild(mBuilder, outputter, child); } builder.with(mBuilder.build()); }
From source file:de.smartics.maven.plugin.jboss.modules.parser.ModulesDescriptorBuilderV2.java
License:Apache License
private void parseApply(final Builder builder, final Element dependenciesElement) { if (dependenciesElement == null) { return;/* w ww.j a v a2 s .c o m*/ } final String slot = dependenciesElement.getAttributeValue("slot"); final String skip = dependenciesElement.getAttributeValue("skip"); final String export = dependenciesElement.getAttributeValue("export"); final String services = dependenciesElement.getAttributeValue("services"); final String optional = dependenciesElement.getAttributeValue("optional"); builder.withSlot(slot); builder.withSkip(skip); builder.withExport(export); builder.withServices(services); builder.withOptional(optional); final XMLOutputter outputter = new XMLOutputter(Format.getCompactFormat()); final Element importElement = dependenciesElement.getChild("imports", NS); if (importElement != null) { adjustNamespaces(importElement); final String imports = outputter.outputString(importElement); builder.withImportsXml(imports); } final Element exportElement = dependenciesElement.getChild("exports", NS); if (exportElement != null) { adjustNamespaces(exportElement); final String exports = outputter.outputString(exportElement); builder.withExportsXml(exports); } }