Java Code Examples for org.jdom2.output.XMLOutputter#outputString()

The following examples show how to use org.jdom2.output.XMLOutputter#outputString() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SOAPKitScaffoldingAction.java    From mule-intellij-plugins with Apache License 2.0 6 votes vote down vote up
private void writeMuleXmlFile(Element element, VirtualFile muleConfig) {

        XMLOutputter xout = new XMLOutputter(Format.getPrettyFormat());
        InputStream inputStream = null;
        try {
            String outputString = xout.outputString(element);
            logger.debug("*** OUTPUT STRING IS " + outputString);
            OutputStreamWriter writer = new OutputStreamWriter(muleConfig.getOutputStream(this));
            writer.write(outputString);
            writer.flush();
            writer.close();
        } catch (Exception e) {
            logger.error("Unable to write file: " + e);
            e.printStackTrace();
        } finally {
            IOUtils.closeQuietly(inputStream);
        }
    }
 
Example 2
Source File: NcepHtmlScraper.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void writeParamTableXml(String filename, String title, String source, String tableName, List<Param> stuff)
    throws IOException {
  org.jdom2.Element rootElem = new org.jdom2.Element("parameterMap");
  org.jdom2.Document doc = new org.jdom2.Document(rootElem);
  rootElem.addContent(new org.jdom2.Element("table").setText(tableName));
  rootElem.addContent(new org.jdom2.Element("title").setText(title));
  rootElem.addContent(new org.jdom2.Element("source").setText(source));

  for (Param p : stuff) {
    org.jdom2.Element paramElem = new org.jdom2.Element("parameter");
    paramElem.setAttribute("code", Integer.toString(p.pnum));
    paramElem.addContent(new org.jdom2.Element("shortName").setText(p.name));
    paramElem.addContent(new org.jdom2.Element("description").setText(p.desc));
    paramElem.addContent(new org.jdom2.Element("units").setText(p.unit));
    rootElem.addContent(paramElem);
  }

  XMLOutputter fmt = new XMLOutputter(Format.getPrettyFormat());
  String x = fmt.outputString(doc);

  try (FileOutputStream fout = new FileOutputStream(dirOut + filename + ".xml")) {
    fout.write(x.getBytes(StandardCharsets.UTF_8));
  }

  if (show)
    System.out.printf("%s%n", x);
}
 
Example 3
Source File: XmlFormatter.java    From sndml3 with MIT License 5 votes vote down vote up
/**
 * Returns a JDOM Element formatted as an XML string with the option of raw or pretty.
 */
public static String format(Element element, boolean pretty) {
	if (element == null) return null;
	XMLOutputter formatter = pretty ? 
		prettyFormatter.get() : rawFormatter.get();
	return formatter.outputString(element);		
}
 
Example 4
Source File: XmlBuilder.java    From iaf with Apache License 2.0 5 votes vote down vote up
public String toXML(boolean xmlHeader) {
	Document document = new Document(element.detach());
	XMLOutputter xmlOutputter = new XMLOutputter();
	xmlOutputter.setFormat(
			Format.getPrettyFormat().setOmitDeclaration(!xmlHeader));
	return xmlOutputter.outputString(document);
}
 
Example 5
Source File: ConvertJsonToXmlService.java    From cs-actions with Apache License 2.0 5 votes vote down vote up
public String convertToXmlString(final ConvertJsonToXmlInputs inputs) {
    if (isBlank(inputs.getJson())) {
        return EMPTY;
    }
    final XMLOutputter xmlWriter = new XMLOutputter();
    xmlWriter.setFormat(getFormat(inputs.getPrettyPrint(), inputs.getShowXmlDeclaration()));
    if (inputs.getShowXmlDeclaration()) {
        return xmlWriter.outputString(convertJsonStringToXmlDocument(inputs.getJson(), inputs.getRootTagName()));
    }
    return getXmlFromElements(convertJsonStringToXmlElements(inputs.getJson(), inputs.getRootTagName()), xmlWriter);
}
 
Example 6
Source File: JDOMUtil.java    From yawl with GNU Lesser General Public License v3.0 5 votes vote down vote up
/****************************************************************************/

    public static String elementToString(Element e) {
        if (e == null) return null ;
        XMLOutputter out = new XMLOutputter(Format.getPrettyFormat());
        return out.outputString(e);
    }
 
Example 7
Source File: JDOMUtil.java    From yawl with GNU Lesser General Public License v3.0 5 votes vote down vote up
/****************************************************************************/

    public static String elementToStringDump(Element e) {
        if (e == null) return null ;
        XMLOutputter out = new XMLOutputter(Format.getCompactFormat());
        return out.outputString(e);
    }
 
Example 8
Source File: JDomUtils.java    From dsworkbench with Apache License 2.0 5 votes vote down vote up
public static String toShortString(Document pDoc) {
    XMLOutputter xmlOutput = new XMLOutputter();

    // display nice nice
    xmlOutput.setFormat(Format.getCompactFormat());
    return xmlOutput.outputString(pDoc);
}
 
Example 9
Source File: IbisXmlLayout.java    From iaf with Apache License 2.0 5 votes vote down vote up
@Override
public String toString() {
	Document document = new Document(element.detach());
	XMLOutputter xmlOutputter = new XMLOutputter();
	xmlOutputter.setFormat(Format.getPrettyFormat().setOmitDeclaration(true));
	return xmlOutputter.outputString(document);
}
 
Example 10
Source File: Atom10Parser.java    From rome with Apache License 2.0 5 votes vote down vote up
private String parseTextConstructToString(final Element e) {

        String type = getAttributeValue(e, "type");
        if (type == null) {
            type = Content.TEXT;
        }

        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;

    }
 
Example 11
Source File: JDOMUtil.java    From yawl with GNU Lesser General Public License v3.0 5 votes vote down vote up
/****************************************************************************/

    public static String documentToStringDump(Document doc) {
        if (doc == null) return null;
        XMLOutputter out = new XMLOutputter(Format.getCompactFormat());
        return out.outputString(doc);
    }
 
Example 12
Source File: StationObsDatasetInfo.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Write stationObsDataset XML document
 */
public String writeStationObsDatasetXML() {
  XMLOutputter fmt = new XMLOutputter(Format.getPrettyFormat());
  return fmt.outputString(makeStationObsDatasetDocument());
}
 
Example 13
Source File: TestFeatureDatasetCapabilitiesXML.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Test
public void doOne() throws IOException, JDOMException {
  FeatureDatasetCapabilitiesWriter capWriter;

  try (Formatter formatter = new Formatter()) {
    FeatureDatasetPoint fdp =
        (FeatureDatasetPoint) FeatureDatasetFactoryManager.open(FeatureType.ANY_POINT, location, null, formatter);
    // Calculates lat/lon bounding box and date range. If we skip this step, FeatureDatasetCapabilitiesWriter
    // will not include "TimeSpan" and "LatLonBox" in the document.
    fdp.calcBounds(formatter);

    logger.debug(formatter.toString());
    capWriter = new FeatureDatasetCapabilitiesWriter(fdp, path);
  }

  File f = tempFolder.newFile();
  try (FileOutputStream fos = new FileOutputStream(f)) {
    capWriter.getCapabilities(fos);
  }
  logger.debug("{} written", f.getPath());

  // round trip
  Document doc = capWriter.readCapabilitiesDocument(new FileInputStream(f));
  XMLOutputter fmt = new XMLOutputter(Format.getPrettyFormat());
  String xml = fmt.outputString(doc);
  logger.debug(xml);

  String altUnits = FeatureDatasetCapabilitiesWriter.getAltUnits(doc);
  if (hasAlt)
    logger.debug("altUnits={}", altUnits);
  Assert.assertEquals(hasAlt, altUnits != null);

  CalendarDateUnit cdu = FeatureDatasetCapabilitiesWriter.getTimeUnit(doc);
  Assert.assertNotNull("cdu", cdu);
  logger.debug("CalendarDateUnit= {}", cdu);
  logger.debug("Calendar= {}", cdu.getCalendar());

  CalendarDateRange cd = FeatureDatasetCapabilitiesWriter.getTimeSpan(doc); // Looks for "TimeSpan" in doc.
  Assert.assertNotNull("CalendarDateRange", cd);
  logger.debug("CalendarDateRange= {}", cd);

  LatLonRect bbox = FeatureDatasetCapabilitiesWriter.getSpatialExtent(doc); // Looks for "LatLonBox" in doc.
  Assert.assertNotNull("bbox", bbox);
  logger.debug("LatLonRect= {}", bbox);
}
 
Example 14
Source File: FeatureDatasetCapabilitiesWriter.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public String getCapabilities() {
  XMLOutputter fmt = new XMLOutputter(Format.getPrettyFormat());
  return fmt.outputString(getCapabilitiesDocument());
}
 
Example 15
Source File: FeatureDatasetCapabilitiesWriter.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public String getCapabilities() {
  XMLOutputter fmt = new XMLOutputter(Format.getPrettyFormat());
  return fmt.outputString(getCapabilitiesDocument());
}
 
Example 16
Source File: WireFeedOutput.java    From rome with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a String with the XML representation for the given WireFeed.
 * <p>
 * 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);
}
 
Example 17
Source File: StationObsDatasetInfo.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Write stationCollection XML document
 */
public String writeStationCollectionXML() throws IOException {
  XMLOutputter fmt = new XMLOutputter(Format.getPrettyFormat());
  return fmt.outputString(makeStationCollectionDocument());
}
 
Example 18
Source File: NetcdfDatasetInfo.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 2 votes vote down vote up
/**
 * Write the information as an XML document
 * 
 * @return String containing netcdfDatasetInfo XML
 */
public String writeXML() {
  XMLOutputter fmt = new XMLOutputter(Format.getPrettyFormat());
  return fmt.outputString(makeDocument());
}
 
Example 19
Source File: GridDatasetInfo.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 2 votes vote down vote up
/**
 * Write the information as an XML document
 *
 * @param doc write XML for this Document
 * @return String output
 */
public String writeXML(Document doc) {
  XMLOutputter fmt = new XMLOutputter(Format.getPrettyFormat());
  return fmt.outputString(doc);
}
 
Example 20
Source File: CoverageDatasetCapabilities.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 2 votes vote down vote up
/**
 * Write the information as an XML document
 *
 * @param doc write XML for this Document
 * @return String output
 */
public String writeXML(Document doc) {
  XMLOutputter fmt = new XMLOutputter(Format.getPrettyFormat());
  return fmt.outputString(doc);
}