Example usage for org.jdom2.output XMLOutputter XMLOutputter

List of usage examples for org.jdom2.output XMLOutputter XMLOutputter

Introduction

In this page you can find the example usage for org.jdom2.output XMLOutputter XMLOutputter.

Prototype

public XMLOutputter() 

Source Link

Document

This will create an XMLOutputter with a default Format and XMLOutputProcessor .

Usage

From source file:com.rometools.rome.io.impl.Atom10Generator.java

License:Open Source License

/**
 * Utility method to serialize an entry to writer.
 *//*from   w w  w. java  2  s  .c  om*/
public static void serializeEntry(final Entry entry, final Writer writer)
        throws IllegalArgumentException, FeedException, IOException {

    // Build a feed containing only the entry
    final List<Entry> entries = new ArrayList<Entry>();
    entries.add(entry);
    final Feed feed1 = new Feed();
    feed1.setFeedType("atom_1.0");
    feed1.setEntries(entries);

    // Get Rome to output feed as a JDOM document
    final WireFeedOutput wireFeedOutput = new WireFeedOutput();
    final Document feedDoc = wireFeedOutput.outputJDom(feed1);

    // Grab entry element from feed and get JDOM to serialize it
    final Element entryElement = feedDoc.getRootElement().getChildren().get(0);

    final XMLOutputter outputter = new XMLOutputter();
    outputter.output(entryElement, writer);
}

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;//from  w  ww. j  a va 2 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 w w 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.sun.syndication.io.impl.Atom03Parser.java

License:Open Source License

private Content parseContent(Element e) {
    String value = null;/*  www.  j a  v  a 2 s.c o 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.Atom10Generator.java

License:Open Source License

/**
 * Utility method to serialize an entry to writer.
 *//*from w  ww . j a v  a  2  s.com*/
public static void serializeEntry(Entry entry, Writer writer)
        throws IllegalArgumentException, FeedException, IOException {

    // Build a feed containing only the entry
    List entries = new ArrayList();
    entries.add(entry);
    Feed feed1 = new Feed();
    feed1.setFeedType("atom_1.0");
    feed1.setEntries(entries);

    // Get Rome to output feed as a JDOM document
    WireFeedOutput wireFeedOutput = new WireFeedOutput();
    Document feedDoc = wireFeedOutput.outputJDom(feed1);

    // Grab entry element from feed and get JDOM to serialize it
    Element entryElement = (Element) feedDoc.getRootElement().getChildren().get(0);

    XMLOutputter outputter = new XMLOutputter();
    outputter.output(entryElement, writer);
}

From source file:com.sun.syndication.io.impl.Atom10Parser.java

License:Open Source License

private String parseTextConstructToString(Element e) {
    String value = null;//w ww . jav  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.tactfactory.harmony.utils.XMLUtils.java

License:Open Source License

/**
 * Write an XML Document to the given file.
 * @param doc The XML document to write//from  w ww.java 2  s .c o  m
 * @param xmlFileName The name of the file
 */
public static void writeXMLToFile(final Document doc, final String xmlFileName) {
    try {
        final File xmlFile = TactFileUtils.makeFile(xmlFileName);
        final XMLOutputter xmlOutput = new XMLOutputter();

        // Write to File
        // Make beautiful file with indent !!!
        xmlOutput.setFormat(Format.getPrettyFormat().setIndent("\t"));
        xmlOutput.setXMLOutputProcessor(new TactXMLOutputter());
        FileOutputStream fos = new FileOutputStream(xmlFile.getAbsoluteFile());

        xmlOutput.output(doc, new OutputStreamWriter(fos, TactFileUtils.DEFAULT_ENCODING));

        fos.close();
    } catch (IOException e) {
        ConsoleUtils.displayError(e);
    }
}

From source file:com.thoughtworks.go.domain.activity.ProjectStatus.java

License:Apache License

public String xmlRepresentation() {
    if (cachedXmlRepresentation == null) {
        cachedXmlRepresentation = new XMLOutputter().outputString(ccTrayXmlElement(SITE_URL_PREFIX));
    }/*from   ww  w.  jav  a2s  . co  m*/
    return cachedXmlRepresentation;
}

From source file:com.thoughtworks.go.util.ConfigUtil.java

License:Apache License

public String elementOutput(Element e) {
    return "\n\t" + new XMLOutputter().outputString(e);
}

From source file:com.webfront.model.Config.java

public void setConfig() {
    FileWriter writer = null;//from w  w w .j av a  2s  .  c  om
    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);
        }
    }
}