use of javax.xml.transform.Result in project jackrabbit by apache.
the class AbstractImportXmlTest method serialize.
public void serialize(Document document) throws IOException {
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file));
try {
// disable pretty printing/default line wrapping!
Transformer t = TransformerFactory.newInstance().newTransformer();
t.setOutputProperty(OutputKeys.METHOD, "xml");
t.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
t.setOutputProperty(OutputKeys.INDENT, "no");
Source s = new DOMSource(document);
Result r = new StreamResult(bos);
t.transform(s, r);
} catch (TransformerException te) {
throw (IOException) new IOException(te.getMessage()).initCause(te);
} finally {
bos.close();
}
}
use of javax.xml.transform.Result in project karaf by apache.
the class SpringTransformer method analyze.
public static Set<String> analyze(Source source) throws Exception {
Set<String> refers = new TreeSet<>();
ByteArrayOutputStream bout = new ByteArrayOutputStream();
Result r = new StreamResult(bout);
XmlUtils.transform(new StreamSource(SpringTransformer.class.getResourceAsStream("extract.xsl")), source, r);
ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
bout.close();
BufferedReader br = new BufferedReader(new InputStreamReader(bin));
String line = br.readLine();
while (line != null) {
line = line.trim();
if (line.length() > 0) {
String[] parts = line.split("\\s*,\\s*");
for (String part : parts) {
int n = part.lastIndexOf('.');
if (n > 0) {
String pkg = part.substring(0, n);
if (!pkg.startsWith("java.")) {
refers.add(part.substring(0, n));
}
}
}
}
line = br.readLine();
}
br.close();
return refers;
}
use of javax.xml.transform.Result in project karaf by apache.
the class BlueprintTransformer method analyze.
public static Set<String> analyze(Source source) throws Exception {
Set<String> refers = new TreeSet<String>();
ByteArrayOutputStream bout = new ByteArrayOutputStream();
Result r = new StreamResult(bout);
XmlUtils.transform(new StreamSource(BlueprintTransformer.class.getResourceAsStream("extract.xsl")), source, r);
ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
bout.close();
BufferedReader br = new BufferedReader(new InputStreamReader(bin));
String line = br.readLine();
while (line != null) {
line = line.trim();
if (line.length() > 0) {
String[] parts = line.split("\\s*,\\s*");
for (String part : parts) {
int n = part.lastIndexOf('.');
if (n > 0) {
String pkg = part.substring(0, n);
if (!pkg.startsWith("java.")) {
refers.add(pkg);
}
}
}
}
line = br.readLine();
}
br.close();
return refers;
}
use of javax.xml.transform.Result in project poi by apache.
the class RecordGenerator method transform.
/**
* <p>Executes an XSL transformation. This process transforms an XML input
* file into a text output file controlled by an XSLT specification.</p>
*
* @param in the XML input file
* @param out the text output file
* @param xslt the XSLT specification, i.e. an XSL style sheet
* @throws FileNotFoundException
* @throws TransformerException
*/
private static void transform(final File in, final File out, final File xslt) throws FileNotFoundException, TransformerException {
final StreamSource ss = new StreamSource(xslt);
final TransformerFactory tf = TransformerFactory.newInstance();
final Transformer t;
try {
t = tf.newTransformer(ss);
} catch (TransformerException ex) {
System.err.println("Error compiling XSL style sheet " + xslt);
throw ex;
}
final Properties p = new Properties();
p.setProperty(OutputKeys.METHOD, "text");
t.setOutputProperties(p);
final Result result = new StreamResult(out);
t.transform(new StreamSource(in), result);
}
use of javax.xml.transform.Result in project poi by apache.
the class OOXMLPrettyPrint method pretty.
private static void pretty(Document document, OutputStream outputStream, int indent) throws TransformerException {
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
if (indent > 0) {
// set properties to indent the resulting XML nicely
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", Integer.toString(indent));
}
Result result = new StreamResult(outputStream);
Source source = new DOMSource(document);
transformer.transform(source, result);
}
Aggregations