use of javax.xml.transform.TransformerConfigurationException in project CFLint by cflint.
the class HTMLOutput method output.
/**
* Output bug list in HTML format.
*/
public void output(final BugList bugList, final Writer writer, final CFLintStats stats) throws IOException, TransformerException {
// 1. Instantiate a TransformerFactory.
final javax.xml.transform.TransformerFactory tFactory = javax.xml.transform.TransformerFactory.newInstance();
// 2. Use the TransformerFactory to process the stylesheet Source and
// generate a Transformer.
javax.xml.transform.Transformer transformer;
try {
final InputStream is = getClass().getResourceAsStream("/findbugs/" + htmlStyle);
transformer = tFactory.newTransformer(new StreamSource(is));
} catch (final TransformerConfigurationException e) {
final InputStream is = getClass().getResourceAsStream("/" + htmlStyle);
transformer = tFactory.newTransformer(new StreamSource(is));
}
final StringWriter sw = new StringWriter();
new XMLOutput().outputFindBugs(bugList, sw, stats);
// 3. Use the Transformer to transform an XML Source and send the
// output to a Result object.
transformer.transform(new StreamSource(new StringReader(sw.toString())), new StreamResult(writer));
writer.close();
}
use of javax.xml.transform.TransformerConfigurationException in project gocd by gocd.
the class XmlRelaxng method getSchema.
private Schema getSchema(Source source, ThreadContext context) {
InputStream is = null;
VerifierFactory factory = new com.thaiopensource.relaxng.jarv.VerifierFactoryImpl();
if (source instanceof StreamSource) {
StreamSource ss = (StreamSource) source;
is = ss.getInputStream();
} else {
// if (this.source instanceof DOMSource)
DOMSource ds = (DOMSource) source;
StringWriter xmlAsWriter = new StringWriter();
StreamResult result = new StreamResult(xmlAsWriter);
try {
TransformerFactory.newInstance().newTransformer().transform(ds, result);
} catch (TransformerConfigurationException ex) {
throw context.getRuntime().newRuntimeError("Could not parse document: " + ex.getMessage());
} catch (TransformerException ex) {
throw context.getRuntime().newRuntimeError("Could not parse document: " + ex.getMessage());
}
try {
is = new ByteArrayInputStream(xmlAsWriter.toString().getBytes("UTF-8"));
} catch (UnsupportedEncodingException ex) {
throw context.getRuntime().newRuntimeError("Could not parse document: " + ex.getMessage());
}
}
try {
return factory.compileSchema(is);
} catch (VerifierConfigurationException ex) {
throw context.getRuntime().newRuntimeError("Could not parse document: " + ex.getMessage());
} catch (SAXException ex) {
throw context.getRuntime().newRuntimeError("Could not parse document: " + ex.getMessage());
} catch (IOException ex) {
throw context.getRuntime().newIOError(ex.getMessage());
}
}
use of javax.xml.transform.TransformerConfigurationException in project knime-core by knime.
the class PMMLContentHandler method addPMMLModel.
/**
* @param fragment the document fragment to add the model to
* @param spec the pmml port object spec
* @throws SAXException if the model cannot be added
*/
public final void addPMMLModel(final DocumentFragment fragment, final PMMLPortObjectSpec spec) throws SAXException {
ByteArrayOutputStream out = new ByteArrayOutputStream();
SAXTransformerFactory fac = (SAXTransformerFactory) TransformerFactory.newInstance();
TransformerHandler handler;
try {
handler = fac.newTransformerHandler();
} catch (TransformerConfigurationException e) {
throw new SAXException(e);
}
Transformer t = handler.getTransformer();
t.setOutputProperty(OutputKeys.METHOD, "xml");
t.setOutputProperty(OutputKeys.INDENT, "yes");
handler.setResult(new StreamResult(out));
handler.startDocument();
/* Here the subclasses can insert the content by overriding the
* addModelContent method.*/
addPMMLModelContent(handler, spec);
handler.endDocument();
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
SAXSource s = new SAXSource(new InputSource(in));
DOMResult r = new DOMResult(fragment);
try {
t.transform(s, r);
in.close();
out.close();
} catch (Exception e) {
throw new SAXException(e);
}
}
use of javax.xml.transform.TransformerConfigurationException in project cxf by apache.
the class JsXMLHttpRequest method domToUtf8.
private byte[] domToUtf8(JsSimpleDomNode xml) {
Node node = xml.getWrappedNode();
// entire document.
// if that's an issue, we could code something more complex.
ByteArrayOutputStream baos = new ByteArrayOutputStream();
StreamResult result = new StreamResult(baos);
DOMSource source = new DOMSource(node);
try {
TransformerFactory transformerFactory = TransformerFactory.newInstance();
transformerFactory.setFeature(javax.xml.XMLConstants.FEATURE_SECURE_PROCESSING, true);
transformerFactory.newTransformer().transform(source, result);
} catch (TransformerConfigurationException e) {
throw new RuntimeException(e);
} catch (TransformerException e) {
throw new RuntimeException(e);
} catch (TransformerFactoryConfigurationError e) {
throw new RuntimeException(e);
}
return baos.toByteArray();
}
use of javax.xml.transform.TransformerConfigurationException in project HongsCORE by ihongs.
the class Form method saveDocument.
private void saveDocument(String path, Document docm) throws HongsException {
File file = new File(path);
File fold = file.getParentFile();
if (!fold.exists()) {
fold.mkdirs();
}
TransformerFactory tf = TransformerFactory.newInstance();
try {
Transformer tr = tf.newTransformer();
DOMSource ds = new DOMSource(docm);
StreamResult sr = new StreamResult(new OutputStreamWriter(new FileOutputStream(file), "utf-8"));
tr.setOutputProperty(OutputKeys.ENCODING, "utf-8");
tr.setOutputProperty(OutputKeys.METHOD, "xml");
tr.setOutputProperty(OutputKeys.INDENT, "yes");
tr.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
tr.transform(ds, sr);
} catch (TransformerConfigurationException e) {
throw new HongsException.Common(e);
} catch (IllegalArgumentException e) {
throw new HongsException.Common(e);
} catch (TransformerException e) {
throw new HongsException.Common(e);
} catch (FileNotFoundException e) {
throw new HongsException.Common(e);
} catch (UnsupportedEncodingException e) {
throw new HongsException.Common(e);
}
}
Aggregations