use of javax.xml.transform.Transformer in project voltdb by VoltDB.
the class JDBCSQLXML method init.
/**
* Initializes this object's SQLXML value from the given Source
* object. <p>
*
* @param source the Source representing the SQLXML value
* @throws SQLException if the argument does not represent a
* valid SQLXML value
*/
protected void init(Source source) throws SQLException {
if (source == null) {
throw Util.nullArgument("source");
}
Transformer transformer = JDBCSQLXML.getIdentityTransformer();
StreamResult result = new StreamResult();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
GZIPOutputStream gzos;
try {
gzos = new GZIPOutputStream(baos);
} catch (IOException ex) {
throw Exceptions.transformFailed(ex);
}
result.setOutputStream(gzos);
try {
transformer.transform(source, result);
} catch (TransformerException ex) {
throw Exceptions.transformFailed(ex);
}
try {
gzos.close();
} catch (IOException ex) {
throw Exceptions.transformFailed(ex);
}
byte[] data = baos.toByteArray();
setGZipData(data);
setReadable(true);
setWritable(false);
}
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 pcgen by PCGen.
the class FopTask method run.
/**
* Run the FO to PDF/AWT conversion. This automatically closes any provided OutputStream for
* this FopTask.
*/
@Override
public void run() {
try (OutputStream out = outputStream) {
userAgent.setProducer("PC Gen Character Generator");
userAgent.setAuthor(System.getProperty("user.name"));
userAgent.setCreationDate(new Date());
userAgent.getEventBroadcaster().addEventListener(new FOPEventListener());
String mimeType;
if (renderer != null) {
userAgent.setKeywords("PCGEN FOP PREVIEW");
mimeType = MimeConstants.MIME_FOP_AWT_PREVIEW;
} else {
userAgent.setKeywords("PCGEN FOP PDF");
mimeType = MimeConstants.MIME_PDF;
}
Fop fop;
if (out != null) {
fop = FOP_FACTORY.newFop(mimeType, userAgent, out);
} else {
fop = FOP_FACTORY.newFop(mimeType, userAgent);
}
Transformer transformer;
if (xsltSource != null) {
transformer = TRANS_FACTORY.newTransformer(xsltSource);
} else {
// identity transformer
transformer = TRANS_FACTORY.newTransformer();
}
transformer.setErrorListener(new FOPErrorListener());
transformer.transform(inputSource, new SAXResult(fop.getDefaultHandler()));
} catch (TransformerException | FOPException | IOException e) {
errorBuilder.append(e.getMessage()).append(Constants.LINE_SEPARATOR);
Logging.errorPrint("Exception in FopTask:run", e);
} catch (RuntimeException ex) {
errorBuilder.append(ex.getMessage()).append(Constants.LINE_SEPARATOR);
Logging.errorPrint("Unexpected exception in FopTask:run: ", ex);
}
}
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();
}
Aggregations