use of javax.xml.transform.TransformerFactory in project opennms by OpenNMS.
the class OnmsPdfViewResolver method resolveView.
@Override
public void resolveView(ServletRequest request, ServletResponse response, Preferences preferences, Object viewData) throws Exception {
InputStream is = new ByteArrayInputStream(((String) viewData).getBytes(StandardCharsets.UTF_8));
ByteArrayOutputStream out = new ByteArrayOutputStream();
FopFactory fopFactory = FopFactory.newInstance();
fopFactory.setStrictValidation(false);
FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, foUserAgent, out);
TransformerFactory tfact = TransformerFactory.newInstance();
Transformer transformer = tfact.newTransformer();
Source src = new StreamSource(is);
Result res = new SAXResult(fop.getDefaultHandler());
transformer.transform(src, res);
byte[] contents = out.toByteArray();
response.setContentLength(contents.length);
response.getOutputStream().write(contents);
}
use of javax.xml.transform.TransformerFactory in project zm-mailbox by Zimbra.
the class QuotedTextUtil method getHtml.
/**
* Convert the DOM document back to HTML string
*
* @param document
* @return String the String representation of the DOM document
*/
private String getHtml(Document document) {
try {
StringWriter writer = new StringWriter();
StreamResult result = new StreamResult(writer);
TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer = factory.newTransformer();
transformer.transform(new DOMSource(document), result);
return writer.toString();
} catch (TransformerException e) {
ZimbraLog.soap.warn("Exception in converting DOM to html", e);
}
return null;
}
use of javax.xml.transform.TransformerFactory in project zm-mailbox by Zimbra.
the class XsdCleaner method getTranformer.
public static Transformer getTranformer() {
try {
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
return transformer;
} catch (TransformerFactoryConfigurationError | TransformerException e) {
LOG.error("XsdCleaner:Problem getting XML Transformer", e);
}
return null;
}
use of javax.xml.transform.TransformerFactory in project ACS by ACS-Community.
the class ExtraDataFeatureUtil method getExtraDataMap.
public String getExtraDataMap(DAOOperations dao, String path, Set<String> expectedAttributes, Set<String> expectedElements) throws CDBFieldDoesNotExistEx, WrongCDBDataTypeEx, ParserConfigurationException, TransformerException {
Document xmldoc;
DocumentBuilder builder = documentBuilderObjectPool.borrowObject();
try {
DOMImplementation impl = builder.getDOMImplementation();
xmldoc = impl.createDocument(null, "data", null);
} finally {
documentBuilderObjectPool.returnObject(builder);
}
Element root = xmldoc.getDocumentElement();
if (getExtraDataMap(root, dao, path, expectedAttributes, expectedElements)) {
StringWriter stringWriter = new StringWriter();
StreamResult streamResult = new StreamResult(stringWriter);
TransformerFactory tf = TransformerFactory.newInstance();
Transformer serializer = tf.newTransformer();
serializer.setOutputProperty(OutputKeys.INDENT, "yes");
serializer.transform(new DOMSource(xmldoc), streamResult);
String ret = stringWriter.toString();
// Oracle XMLTYPE attributes don't like empty XML, thus we convert it to null
if (ret != null && ret.trim().isEmpty()) {
ret = null;
}
return ret;
} else {
return null;
}
}
use of javax.xml.transform.TransformerFactory in project ACS by ACS-Community.
the class DumpXML method main.
/**
* @param args
*/
public static void main(String[] args) throws Throwable {
if (args.length != 1) {
System.err.println("Usage: java " + DumpXML.class.getName() + " <xml file>");
System.exit(1);
}
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
// XercesJ 2.9.1 rejects this, it supports it by default
//factory.setXIncludeAware(true);
DocumentBuilder builder = factory.newDocumentBuilder();
Document xmldoc = builder.parse(new InputSource(new FileReader(args[0])));
Source src = new DOMSource(xmldoc);
Result dest = new StreamResult(System.out);
TransformerFactory tranFactory = TransformerFactory.newInstance();
Transformer transformer = tranFactory.newTransformer();
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.transform(src, dest);
}
Aggregations