Commonutil Class - VMware VCENTER CHARGEBACK 1.5 - API Manual

Vcenter chargeback api programming guide
Hide thumbs Also See for VCENTER CHARGEBACK 1.5 - API:
Table of Contents

Advertisement

vCenter Chargeback API Programming Guide

CommonUtil Class

The code examples use the following CommonUtil class.
public final class CommonUtil {
/**
* This method writes out a formatted XML document to the Writer out.
*
* @param doc
* @param out
* @throws IOException
*/
public static void printXML(Document doc, Writer out) throws IOException {
XMLOutputter o = new XMLOutputter();
Format newFormat = o.getFormat();
newFormat.setIndent("
o.setFormat(newFormat);
o.output(doc, out);
}
/**
* This method returns the XML document as a string object
*
* @param doc JDOM document representation of the XML
* @return String representation of the XML document
* @throws IOException
*/
public static String xmlAsString(Document doc) throws IOException {
Writer w = new StringWriter();
printXML(doc, w);
return w.toString();
}
/**
* This method reads the XML from a file and returns its representation as a
* JDOM document
*
* @param filePath path to the XML file
* @return JDOM document representation of the XML
* @throws IOException
* @throws JDOMException
*/
public static Document getXMLDocument(String filePath) throws IOException, JDOMException {
FileInputStream fis = null;
try {
fis = new FileInputStream(filePath);
return getXMLDocument(fis);
} finally {
if (fis != null) {
fis.close();
}
}
}
/**
* This method reads an XML document from the input Stream and returns its
* JDOM document representation
*
* @param is input stream that has the XML content
* @return jDOM document representation for the XML
* @throws IOException
* @throws JDOMException
*/
private static Document getXMLDocument(InputStream is) throws IOException, JDOMException {
Document xml = null;
SAXBuilder builder = new SAXBuilder();
xml = builder.build(is);
return xml;
}
}
24
");
VMware, Inc.

Advertisement

Table of Contents
loading

Table of Contents