use of javax.xml.transform.TransformerFactory in project geode by apache.
the class Installer method streamXML.
private void streamXML(final Document doc, final OutputStream out) {
try {
// Use a Transformer for output
final TransformerFactory tFactory = TransformerFactory.newInstance();
final Transformer transformer = tFactory.newTransformer();
if (doc.getDoctype() != null) {
final String systemId = doc.getDoctype().getSystemId();
final String publicId = doc.getDoctype().getPublicId();
transformer.setOutputProperty(OutputKeys.DOCTYPE_PUBLIC, publicId);
transformer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, systemId);
}
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
final DOMSource source = new DOMSource(doc);
final StreamResult result = new StreamResult(out);
transformer.transform(source, result);
} catch (final Exception e) {
e.printStackTrace();
}
}
use of javax.xml.transform.TransformerFactory in project spring-framework by spring-projects.
the class StaxSourceTests method setUp.
@Before
public void setUp() throws Exception {
TransformerFactory transformerFactory = TransformerFactory.newInstance();
transformer = transformerFactory.newTransformer();
inputFactory = XMLInputFactory.newInstance();
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
documentBuilderFactory.setNamespaceAware(true);
documentBuilder = documentBuilderFactory.newDocumentBuilder();
}
use of javax.xml.transform.TransformerFactory in project amos-ss17-alexa by c-i-ber.
the class XMLParser method xmlToString.
public static String xmlToString(Document doc) {
try {
StringWriter sw = new StringWriter();
TransformerFactory tf = TransformerFactory.newInstance();
Transformer transformer = tf.newTransformer();
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no");
transformer.setOutputProperty(OutputKeys.METHOD, "xml");
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
transformer.transform(new DOMSource(doc), new StreamResult(sw));
return sw.toString();
} catch (Exception ex) {
throw new RuntimeException("Error converting to String", ex);
}
}
use of javax.xml.transform.TransformerFactory in project midpoint by Evolveum.
the class CsvAccountTests method updateCsvFilePath.
/**
* Update icfccsvfile:filePath tag value, set the correct
* path to midpoint-flatfile.csv file
*/
public void updateCsvFilePath() {
try {
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
Document doc = docBuilder.parse(CSV_RESOURCE_XML_PATH);
// Get the CSV filePath element by tag name directly
Node filePathNode = doc.getElementsByTagName("icfccsvfile:filePath").item(0);
filePathNode.setTextContent(System.getProperty("user.dir") + "/src/test/resources/mp-resources/midpoint-flatfile.csv");
// write the content into xml file
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
DOMSource source = new DOMSource(doc);
StreamResult result = new StreamResult(new File(CSV_RESOURCE_XML_PATH));
transformer.transform(source, result);
} catch (ParserConfigurationException pce) {
pce.printStackTrace();
} catch (TransformerException tfe) {
tfe.printStackTrace();
} catch (IOException ioe) {
ioe.printStackTrace();
} catch (SAXException sae) {
sae.printStackTrace();
}
}
use of javax.xml.transform.TransformerFactory in project uPortal by Jasig.
the class ILFBuilder method printNodeToDebug.
private static void printNodeToDebug(Node n, String name) throws TransformerFactoryConfigurationError {
if (!LOG.isDebugEnabled()) {
return;
}
final StringWriter writer = new StringWriter();
try {
final TransformerFactory transFactory = TransformerFactory.newInstance();
final Transformer trans = transFactory.newTransformer();
final Source xmlSource = new DOMSource(n);
final Result transResult = new StreamResult(writer);
trans.transform(xmlSource, transResult);
final String xmlStr = writer.toString();
LOG.debug(name + " DOM Tree:\n\n" + xmlStr);
} catch (Exception e) {
LOG.error("Error printing out " + name + " DOM Tree", e);
final String xmlStr = writer.toString();
LOG.debug("Partial " + name + " DOM Tree:\n\n" + xmlStr);
}
}
Aggregations