use of javax.xml.transform.TransformerFactory in project poi by apache.
the class WordToHtmlConverter method main.
/**
* Java main() interface to interact with {@link WordToHtmlConverter}<p>
*
* Usage: WordToHtmlConverter infile outfile<p>
*
* Where infile is an input .doc file ( Word 95-2007) which will be rendered
* as HTML into outfile
*/
public static void main(String[] args) throws IOException, ParserConfigurationException, TransformerException {
if (args.length < 2) {
System.err.println("Usage: WordToHtmlConverter <inputFile.doc> <saveTo.html>");
return;
}
System.out.println("Converting " + args[0]);
System.out.println("Saving output to " + args[1]);
Document doc = WordToHtmlConverter.process(new File(args[0]));
DOMSource domSource = new DOMSource(doc);
StreamResult streamResult = new StreamResult(new File(args[1]));
TransformerFactory tf = TransformerFactory.newInstance();
Transformer serializer = tf.newTransformer();
// TODO set encoding from a command argument
serializer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
serializer.setOutputProperty(OutputKeys.INDENT, "yes");
serializer.setOutputProperty(OutputKeys.METHOD, "html");
serializer.transform(domSource, streamResult);
}
use of javax.xml.transform.TransformerFactory in project poi by apache.
the class WordToTextConverter method getText.
public String getText() throws Exception {
StringWriter stringWriter = new StringWriter();
DOMSource domSource = new DOMSource(getDocument());
StreamResult streamResult = new StreamResult(stringWriter);
TransformerFactory tf = TransformerFactory.newInstance();
Transformer serializer = tf.newTransformer();
// TODO set encoding from a command argument
serializer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
serializer.setOutputProperty(OutputKeys.INDENT, "no");
serializer.setOutputProperty(OutputKeys.METHOD, "text");
serializer.transform(domSource, streamResult);
return stringWriter.toString();
}
use of javax.xml.transform.TransformerFactory in project poi by apache.
the class WordToFoConverter method main.
/**
* Java main() interface to interact with {@link WordToFoConverter}
*
* <p>
* Usage: WordToFoConverter infile outfile
* </p>
* Where infile is an input .doc file ( Word 97-2007) which will be rendered
* as XSL-FO into outfile
*/
public static void main(String[] args) throws Exception {
if (args.length < 2) {
System.err.println("Usage: WordToFoConverter <inputFile.doc> <saveTo.fo>");
return;
}
System.out.println("Converting " + args[0]);
System.out.println("Saving output to " + args[1]);
Document doc = WordToFoConverter.process(new File(args[0]));
DOMSource domSource = new DOMSource(doc);
StreamResult streamResult = new StreamResult(new File(args[1]));
TransformerFactory tf = TransformerFactory.newInstance();
Transformer serializer = tf.newTransformer();
// TODO set encoding from a command argument
serializer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
serializer.setOutputProperty(OutputKeys.INDENT, "yes");
serializer.transform(domSource, streamResult);
}
use of javax.xml.transform.TransformerFactory in project poi by apache.
the class PkiTestUtils method toString.
static String toString(Node dom) throws TransformerException {
Source source = new DOMSource(dom);
StringWriter stringWriter = new StringWriter();
Result result = new StreamResult(stringWriter);
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
/*
* We have to omit the ?xml declaration if we want to embed the
* document.
*/
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
transformer.transform(source, result);
return stringWriter.getBuffer().toString();
}
use of javax.xml.transform.TransformerFactory in project cloudstack by apache.
the class PaloAltoResource method prettyFormat.
// pretty printing of xml strings
private String prettyFormat(String input) {
int indent = 4;
try {
Source xmlInput = new StreamSource(new StringReader(input));
StringWriter stringWriter = new StringWriter();
StreamResult xmlOutput = new StreamResult(stringWriter);
TransformerFactory transformerFactory = TransformerFactory.newInstance();
transformerFactory.setAttribute("indent-number", indent);
Transformer transformer = transformerFactory.newTransformer();
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
transformer.transform(xmlInput, xmlOutput);
return xmlOutput.getWriter().toString();
} catch (Throwable e) {
try {
Source xmlInput = new StreamSource(new StringReader(input));
StringWriter stringWriter = new StringWriter();
StreamResult xmlOutput = new StreamResult(stringWriter);
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", String.valueOf(indent));
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
transformer.transform(xmlInput, xmlOutput);
return xmlOutput.getWriter().toString();
} catch (Throwable t) {
return input;
}
}
}
Aggregations