Example usage for org.jdom2.output Format getCompactFormat

List of usage examples for org.jdom2.output Format getCompactFormat

Introduction

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

Prototype

public static Format getCompactFormat() 

Source Link

Document

Returns a new Format object that performs whitespace normalization, uses the UTF-8 encoding, doesn't expand empty elements, includes the declaration and encoding, and uses the default entity escape strategy.

Usage

From source file:AIR.Common.xml.XmlElement.java

License:Open Source License

public String getOuterXml() {
    XMLOutputter outp = new XMLOutputter();
    outp.setFormat(Format.getCompactFormat());
    String returnString = "";
    try (StringWriter sw = new StringWriter()) {
        if (_element instanceof Element)
            outp.output((Element) _element, sw);
        else {/*w  w w  .j av  a2s.c  o  m*/
            // TODO: What to do for other types of Content?
            // Note: Document is not derived from Content.
        }
        returnString = sw.getBuffer().toString();
    } catch (IOException e1) {
        e1.printStackTrace();
    }
    return returnString;
}

From source file:AIR.Common.xml.XmlElement.java

License:Open Source License

public String getInnerXml() {
    XMLOutputter outp = new XMLOutputter();

    outp.setFormat(Format.getCompactFormat());
    try (StringWriter sw = new StringWriter()) {
        if (_element instanceof Element)
            outp.outputElementContent((Element) _element, sw);
        else {/*from   ww  w  . ja va 2 s  .  co m*/
            // TODO: What to do for other types of Content?
        }

        return sw.toString();
    } catch (IOException e1) {
        e1.printStackTrace();
        throw new XmlReaderException(e1);
    }
}

From source file:ca.nrc.cadc.vodml.VOModelWriter.java

License:Open Source License

public void write(Document doc, Writer out) throws IOException {
    XMLOutputter outputter = new XMLOutputter();
    if (prettyPrint) {
        outputter.setFormat(Format.getPrettyFormat());
    } else {/* ww w .  j  av a 2 s.c om*/
        outputter.setFormat(Format.getCompactFormat());
    }
    outputter.output(doc, out);
}

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>//w w  w  . jav 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.rometools.rome.io.WireFeedOutput.java

License:Open Source License

/**
 * Writes to an Writer the XML representation for the given WireFeed.
 * <p>/*  ww w. ja va2 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.sun.syndication.io.WireFeedOutput.java

License:Open Source License

/**
 * Creates a String with the XML representation for the given WireFeed.
 * <p>//from ww  w  .  ja  v  a  2s .co 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.sun.syndication.io.WireFeedOutput.java

License:Open Source License

/**
 * Writes to an Writer the XML representation for the given WireFeed.
 * <p>/*from ww  w .j av 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 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(WireFeed feed, Writer writer, boolean prettyPrint)
        throws IllegalArgumentException, IOException, 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);
    outputter.output(doc, writer);
}

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 . com*/
    }

    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;/*from  w w w  .j  a va2s  . 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;/*from w w  w  .  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);
    }
}