use of javax.xml.transform.Transformer in project rhino by PLOS.
the class AbstractXpathReader method recoverXml.
private static String recoverXml(Node node) {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
try {
Transformer transformer = TransformerFactory.newInstance().newTransformer();
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
transformer.transform(new DOMSource(node), new StreamResult(outputStream));
} catch (TransformerException e) {
throw new RuntimeException(e);
}
// TODO: Encoding?
return new String(outputStream.toByteArray());
}
use of javax.xml.transform.Transformer in project rhino by PLOS.
the class AuthorsXmlExtractor method getAsXMLString.
private static String getAsXMLString(Node node) throws TransformerException {
final Transformer tf = TransformerFactory.newInstance().newTransformer();
final StringWriter stringWriter = new StringWriter();
tf.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
tf.transform(new DOMSource(node), new StreamResult(stringWriter));
return stringWriter.toString();
}
use of javax.xml.transform.Transformer 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.Transformer 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);
}
use of javax.xml.transform.Transformer in project zaproxy by zaproxy.
the class ReportGenerator method stringToHtml.
public static String stringToHtml(String inxml, String infilexsl) {
Document doc = null;
// factory.setNamespaceAware(true);
// factory.setValidating(true);
File stylesheet = null;
StringReader inReader = new StringReader(inxml);
StringWriter writer = new StringWriter();
try {
stylesheet = new File(infilexsl);
DocumentBuilder builder = XmlUtils.newXxeDisabledDocumentBuilderFactory().newDocumentBuilder();
doc = builder.parse(new InputSource(inReader));
// Use a Transformer for output
TransformerFactory tFactory = TransformerFactory.newInstance();
StreamSource stylesource = new StreamSource(stylesheet);
Transformer transformer = tFactory.newTransformer(stylesource);
DOMSource source = new DOMSource(doc);
StreamResult result = new StreamResult(writer);
transformer.transform(source, result);
} catch (TransformerException | SAXException | ParserConfigurationException | IOException e) {
showDialogForGUI();
logger.error(e.getMessage(), e);
} finally {
}
// we should really adopt something other than XSLT ;)
return writer.toString().replace("<p>", "<p>").replace("</p>", "</p>");
}
Aggregations