use of javax.xml.transform.TransformerConfigurationException in project jackrabbit by apache.
the class DefaultItemResource method spoolMultiValued.
private void spoolMultiValued(OutputStream out) {
try {
Document doc = DomUtil.createDocument();
doc.appendChild(getProperty(JCR_VALUES).toXml(doc));
ContentHandler handler = SerializingContentHandler.getSerializer(out);
Transformer transformer = TransformerFactory.newInstance().newTransformer();
transformer.transform(new DOMSource(doc), new SAXResult(handler));
} catch (SAXException e) {
log.error("Failed to set up XML serializer for " + item, e);
} catch (TransformerConfigurationException e) {
log.error("Failed to set up XML transformer for " + item, e);
} catch (ParserConfigurationException e) {
log.error("Failed to set up XML document for " + item, e);
} catch (TransformerException e) {
log.error("Failed to serialize the values of " + item, e);
}
}
use of javax.xml.transform.TransformerConfigurationException in project jackrabbit by apache.
the class ClientSession method exportSystemView.
/**
* Exports the XML system view of the specified repository location
* to the given XML content handler. This method first requests the
* raw XML data from the remote session, and then uses an identity
* transformation to feed the data to the given XML content handler.
* Possible IO and transformer exceptions are thrown as SAXExceptions.
*
* {@inheritDoc}
*/
public void exportSystemView(String path, ContentHandler handler, boolean binaryAsLink, boolean noRecurse) throws SAXException, RepositoryException {
try {
byte[] xml = remote.exportSystemView(path, binaryAsLink, noRecurse);
Source source = new StreamSource(new ByteArrayInputStream(xml));
Result result = new SAXResult(handler);
TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer = factory.newTransformer();
transformer.transform(source, result);
} catch (RemoteException ex) {
throw new RemoteRepositoryException(ex);
} catch (IOException ex) {
throw new SAXException(ex);
} catch (TransformerConfigurationException ex) {
throw new SAXException(ex);
} catch (TransformerException ex) {
throw new SAXException(ex);
}
}
use of javax.xml.transform.TransformerConfigurationException in project jackrabbit-oak by apache.
the class HtmlRepresentation method startResponse.
private XHTMLContentHandler startResponse(HttpServletResponse response, String title) throws IOException {
try {
response.setContentType("text/html");
response.setCharacterEncoding("UTF-8");
SAXTransformerFactory factory = (SAXTransformerFactory) SAXTransformerFactory.newInstance();
TransformerHandler handler = factory.newTransformerHandler();
Transformer transformer = handler.getTransformer();
transformer.setOutputProperty(OutputKeys.METHOD, "html");
transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
handler.setResult(new StreamResult(response.getOutputStream()));
Metadata metadata = new Metadata();
metadata.set(Metadata.TITLE, title);
return new XHTMLContentHandler(handler, metadata);
} catch (TransformerConfigurationException e) {
throw new IOException(e);
}
}
use of javax.xml.transform.TransformerConfigurationException in project jackrabbit by apache.
the class SerializingContentHandler method getSerializer.
/**
* Creates a serializing content handler that writes to the given result.
*
* @param result serialization target
* @return serializing content handler
* @throws SAXException if the content handler could not be initialized
*/
public static DefaultHandler getSerializer(Result result) throws SAXException {
try {
TransformerHandler handler = FACTORY.newTransformerHandler();
handler.setResult(result);
// Specify the output properties to avoid surprises especially in
// character encoding or the output method (might be html for some
// documents!)
Transformer transformer = handler.getTransformer();
transformer.setOutputProperty(OutputKeys.METHOD, "xml");
transformer.setOutputProperty(OutputKeys.ENCODING, ENCODING);
transformer.setOutputProperty(OutputKeys.INDENT, "no");
if (NEEDS_XMLNS_ATTRIBUTES) {
// so we need to do it explicitly with this wrapper
return new SerializingContentHandler(handler);
} else {
return new DefaultContentHandler(handler);
}
} catch (TransformerConfigurationException e) {
throw new SAXException("Failed to initialize XML serializer", e);
}
}
use of javax.xml.transform.TransformerConfigurationException in project jackrabbit by apache.
the class ResultHelper method getResult.
/**
* In case the underlying XML library doesn't properly handle xmlns attributes
* this method creates new content handler dealing with the misbehavior and
* returns an new instance of SAXResult. Otherwise the passed result
* is returned back.
*
* @param result
* @return A instance of <code>Result</code> that properly handles xmlns attributes.
* @throws SAXException
*/
public static Result getResult(Result result) throws SAXException {
try {
TransformerHandler handler = FACTORY.newTransformerHandler();
handler.setResult(result);
// Specify the output properties to avoid surprises especially in
// character encoding or the output method (might be html for some
// documents!)
Transformer transformer = handler.getTransformer();
transformer.setOutputProperty(OutputKeys.METHOD, "xml");
transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
transformer.setOutputProperty(OutputKeys.INDENT, "no");
if (NEEDS_XMLNS_ATTRIBUTES) {
// so we need to do it explicitly with this wrapper
return new SAXResult(new SerializingContentHandler(handler));
} else {
return result;
}
} catch (TransformerConfigurationException e) {
throw new SAXException("Failed to initialize XML serializer", e);
}
}
Aggregations