use of javax.xml.transform.Transformer in project voltdb by VoltDB.
the class JDBCSQLXML method createDOMSource.
/**
* Retrieves a new DOMSource for reading the XML value designated by this
* SQLXML instance. <p>
*
* @param sourceClass The class of the source
* @throws java.sql.SQLException if there is an error processing the XML
* value or if the given <tt>sourceClass</tt> is not supported.
* @return a new DOMSource for reading the XML value designated by this
* SQLXML instance
*/
@SuppressWarnings("unchecked")
protected <T extends Source> T createDOMSource(Class<T> sourceClass) throws SQLException {
DOMSource source = null;
try {
source = (sourceClass == null) ? new DOMSource() : (DOMSource) sourceClass.newInstance();
} catch (SecurityException ex) {
throw Exceptions.sourceInstantiation(ex);
} catch (IllegalAccessException ex) {
throw Exceptions.sourceInstantiation(ex);
} catch (InstantiationException ex) {
throw Exceptions.sourceInstantiation(ex);
} catch (ClassCastException ex) {
throw Exceptions.sourceInstantiation(ex);
}
Transformer transformer = JDBCSQLXML.getIdentityTransformer();
InputStream inputStream = this.getBinaryStreamImpl();
StreamSource streamSource = new StreamSource();
DOMResult domResult = new DOMResult();
streamSource.setInputStream(inputStream);
try {
transformer.transform(streamSource, domResult);
} catch (TransformerException ex) {
throw Exceptions.transformFailed(ex);
}
source.setNode(domResult.getNode());
return (T) source;
}
use of javax.xml.transform.Transformer 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.Transformer 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.Transformer in project intellij-community by JetBrains.
the class XsltDocumentationProvider method getDocumentation.
@Nullable
private String getDocumentation(String name, String type) {
try {
final Transformer transformer = getTemplate().newTransformer();
transformer.setParameter("element", name);
transformer.setParameter("type", type);
final StringWriter writer = new StringWriter();
transformer.transform(new JDOMSource(getDocumentationDocument()), new StreamResult(writer));
final String s = writer.toString();
final Matcher matcher = check.matcher(s);
if (matcher.find()) {
if (matcher.group(1).equals("true")) {
return s.replaceFirst("<META.+?>", "");
}
}
} catch (Exception e) {
Logger.getInstance(getClass().getName()).error(e);
}
return null;
}
use of javax.xml.transform.Transformer in project jangaroo-tools by CoreMedia.
the class PomConverter method writePom.
/**
* Serializes the given DOM document into a POM file within the given directory.
*/
private static void writePom(Document document, File projectBaseDir) throws MojoExecutionException {
try {
File pomFile = new File(projectBaseDir, "pom.xml");
// keep trailing whitespace because it's not reproduced by the transformer and we want to keep the diff small
String pom = readFileToString(pomFile);
String trailingWhitespace = pom.substring(pom.lastIndexOf('>') + 1);
PrintWriter pomWriter = new PrintWriter(pomFile);
try {
Transformer transformer = TransformerFactory.newInstance().newTransformer();
// the transformer does not reproduce the new line after the XML declaration, so we do it on our own
// see https://bugs.openjdk.java.net/browse/JDK-7150637
transformer.setOutputProperty(OMIT_XML_DECLARATION, "yes");
if (document.getXmlEncoding() != null) {
pomWriter.print("<?xml version=\"");
pomWriter.print(document.getXmlVersion());
pomWriter.print("\" encoding=\"");
pomWriter.print(document.getXmlEncoding());
pomWriter.println("\"?>");
}
transformer.transform(new DOMSource(document), new StreamResult(pomWriter));
pomWriter.write(trailingWhitespace);
} finally {
pomWriter.close();
}
} catch (IOException e) {
throw new MojoExecutionException("error while generating modified POM", e);
} catch (TransformerException e) {
throw new MojoExecutionException("error while generating modified POM", e);
}
}
Aggregations