List of usage examples for org.jdom2.output XMLOutputter outputString
public final String outputString(EntityRef entity)
From source file:com.rometools.modules.content.io.ContentModuleParser.java
License:Open Source License
protected String getXmlInnerText(final Element e) { final StringBuffer sb = new StringBuffer(); final XMLOutputter xo = new XMLOutputter(); final List<Content> children = e.getContent(); sb.append(xo.outputString(children)); return sb.toString(); }
From source file:com.rometools.modules.itunes.io.ITunesParser.java
License:Open Source License
protected String getXmlInnerText(final Element e) { final StringBuffer sb = new StringBuffer(); final XMLOutputter xo = new XMLOutputter(); final List<Content> children = e.getContent(); sb.append(xo.outputString(children)); return sb.toString(); }
From source file:com.rometools.rome.io.impl.Atom03Parser.java
License:Open Source License
private Content parseContent(final Element e) { String value = null;/* ww w. ja va 2s .co m*/ String type = getAttributeValue(e, "type"); if (type == null) { type = "text/plain"; } String mode = getAttributeValue(e, "mode"); if (mode == null) { mode = Content.XML; // default to xml content } if (mode.equals(Content.ESCAPED)) { // do nothing XML Parser took care of this value = e.getText(); } else if (mode.equals(Content.BASE64)) { value = Base64.decode(e.getText()); } else if (mode.equals(Content.XML)) { final XMLOutputter outputter = new XMLOutputter(); final List<org.jdom2.Content> contents = e.getContent(); for (final org.jdom2.Content content : contents) { if (content instanceof Element) { final Element element = (Element) content; if (element.getNamespace().equals(getAtomNamespace())) { element.setNamespace(Namespace.NO_NAMESPACE); } } } value = outputter.outputString(contents); } final Content content = new Content(); content.setType(type); content.setMode(mode); content.setValue(value); return content; }
From source file:com.rometools.rome.io.impl.Atom10Parser.java
License:Open Source License
private String parseTextConstructToString(final Element e) { String type = getAttributeValue(e, "type"); if (type == null) { type = Content.TEXT;// w w w.j a v a2 s . c om } String value = null; if (type.equals(Content.XHTML) || type.indexOf("/xml") != -1 || type.indexOf("+xml") != -1) { // XHTML content needs special handling final XMLOutputter outputter = new XMLOutputter(); final List<org.jdom2.Content> contents = e.getContent(); for (final org.jdom2.Content content : contents) { if (content instanceof Element) { final Element element = (Element) content; if (element.getNamespace().equals(getAtomNamespace())) { element.setNamespace(Namespace.NO_NAMESPACE); } } } value = outputter.outputString(contents); } else { // Everything else comes in verbatim value = e.getText(); } return value; }
From source file:com.rometools.rome.io.impl.RSS092Parser.java
License:Open Source License
@Override protected Description parseItemDescription(final Element rssRoot, final Element eDesc) { final Description desc = new Description(); final StringBuilder sb = new StringBuilder(); final XMLOutputter xmlOut = new XMLOutputter(); for (final Content c : eDesc.getContent()) { switch (c.getCType()) { case Text: case CDATA: sb.append(c.getValue());//from ww w . j a v a 2s.c o m break; case EntityRef: LOG.debug("Entity: {}", c.getValue()); sb.append(c.getValue()); break; case Element: sb.append(xmlOut.outputString((Element) c)); break; default: // ignore break; } } desc.setValue(sb.toString()); String att = eDesc.getAttributeValue("type"); if (att == null) { att = "text/html"; } desc.setType(att); return desc; }
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 www . ja v a 2 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 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.sun.syndication.io.impl.Atom03Parser.java
License:Open Source License
private Content parseContent(Element e) { String value = null;// ww w . ja v a 2s. co m String type = getAttributeValue(e, "type"); type = (type != null) ? type : "text/plain"; String mode = getAttributeValue(e, "mode"); if (mode == null) { mode = Content.XML; // default to xml content } if (mode.equals(Content.ESCAPED)) { // do nothing XML Parser took care of this value = e.getText(); } else if (mode.equals(Content.BASE64)) { value = Base64.decode(e.getText()); } else if (mode.equals(Content.XML)) { XMLOutputter outputter = new XMLOutputter(); List eContent = e.getContent(); Iterator i = eContent.iterator(); while (i.hasNext()) { org.jdom2.Content c = (org.jdom2.Content) i.next(); if (c instanceof Element) { Element eC = (Element) c; if (eC.getNamespace().equals(getAtomNamespace())) { ((Element) c).setNamespace(Namespace.NO_NAMESPACE); } } } value = outputter.outputString(eContent); } Content content = new Content(); content.setType(type); content.setMode(mode); content.setValue(value); return content; }
From source file:com.sun.syndication.io.impl.Atom10Parser.java
License:Open Source License
private String parseTextConstructToString(Element e) { String value = null;//from www . j a v a 2 s .c o m String type = getAttributeValue(e, "type"); type = (type != null) ? type : Content.TEXT; if (type.equals(Content.XHTML) || (type.indexOf("/xml")) != -1 || (type.indexOf("+xml")) != -1) { // XHTML content needs special handling XMLOutputter outputter = new XMLOutputter(); List eContent = e.getContent(); Iterator i = eContent.iterator(); while (i.hasNext()) { org.jdom2.Content c = (org.jdom2.Content) i.next(); if (c instanceof Element) { Element eC = (Element) c; if (eC.getNamespace().equals(getAtomNamespace())) { ((Element) c).setNamespace(Namespace.NO_NAMESPACE); } } } value = outputter.outputString(eContent); } else { // Everything else comes in verbatim value = e.getText(); } return value; }
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>/* w w w .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 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); }
From source file:com.webfront.model.Config.java
public void setConfig() { FileWriter writer = null;//from w w w .j ava2 s .c o m File defaultStartupFile = new File(home + fileSep + defaultConfigFileName); try (FileWriter defaultWriter = new FileWriter(defaultStartupFile)) { defaultWriter.write(installDir); } catch (IOException ex) { Logger.getLogger(Config.class.getName()).log(Level.SEVERE, null, ex); } try { xmlDoc = new Document(); Element rootElement = new Element(root); Element systemNode = new Element("system"); systemNode.addContent(new Element("installDir").addContent(getInstallDir())); // systemNode.addContent(new Element("tmpDir").addContent(tmpDir)); String tmp = tmpDir; tmp.replaceAll("/", "\\/"); systemNode.addContent(new Element("tmpDir").addContent(tmp)); rootElement.addContent(systemNode); xmlDoc.setRootElement(rootElement); writer = new FileWriter(getInstallDir() + getFileSep() + configFileName); XMLOutputter xml = new XMLOutputter(); xml.setFormat(Format.getPrettyFormat()); writer.write(xml.outputString(xmlDoc)); } catch (IOException ex) { Logger.getLogger(Config.class.getName()).log(Level.SEVERE, null, ex); } finally { try { if (writer != null) { writer.close(); } } catch (IOException ex) { Logger.getLogger(Config.class.getName()).log(Level.SEVERE, null, ex); } } }