use of javax.xml.transform.sax.SAXResult in project OpenAM by OpenRock.
the class MarshallerImpl method marshal.
public void marshal(Object obj, Result result) throws JAXBException {
//XMLSerializable so = Util.toXMLSerializable(obj);
XMLSerializable so = context.getGrammarInfo().castToXMLSerializable(obj);
if (so == null)
throw new MarshalException(Messages.format(Messages.NOT_MARSHALLABLE));
if (result instanceof SAXResult) {
write(so, ((SAXResult) result).getHandler());
return;
}
if (result instanceof DOMResult) {
Node node = ((DOMResult) result).getNode();
if (node == null) {
try {
DocumentBuilder db = XMLUtils.getSafeDocumentBuilder(false);
Document doc = db.newDocument();
((DOMResult) result).setNode(doc);
write(so, new SAX2DOMEx(doc));
} catch (ParserConfigurationException pce) {
throw new JAXBAssertionError(pce);
}
} else {
write(so, new SAX2DOMEx(node));
}
return;
}
if (result instanceof StreamResult) {
StreamResult sr = (StreamResult) result;
XMLWriter w = null;
if (sr.getWriter() != null)
w = createWriter(sr.getWriter());
else if (sr.getOutputStream() != null)
w = createWriter(sr.getOutputStream());
else if (sr.getSystemId() != null) {
String fileURL = sr.getSystemId();
if (fileURL.startsWith("file:///")) {
if (fileURL.substring(8).indexOf(":") > 0)
fileURL = fileURL.substring(8);
else
fileURL = fileURL.substring(7);
}
try {
w = createWriter(new FileOutputStream(fileURL));
} catch (IOException e) {
throw new MarshalException(e);
}
}
if (w == null)
throw new IllegalArgumentException();
write(so, w);
return;
}
// unsupported parameter type
throw new MarshalException(Messages.format(Messages.UNSUPPORTED_RESULT));
}
use of javax.xml.transform.sax.SAXResult in project OpenAM by OpenRock.
the class MarshallerImpl method marshal.
public void marshal(Object obj, Result result) throws JAXBException {
//XMLSerializable so = Util.toXMLSerializable(obj);
XMLSerializable so = context.getGrammarInfo().castToXMLSerializable(obj);
if (so == null)
throw new MarshalException(Messages.format(Messages.NOT_MARSHALLABLE));
if (result instanceof SAXResult) {
write(so, ((SAXResult) result).getHandler());
return;
}
if (result instanceof DOMResult) {
Node node = ((DOMResult) result).getNode();
if (node == null) {
try {
DocumentBuilder db = XMLUtils.getSafeDocumentBuilder(false);
Document doc = db.newDocument();
((DOMResult) result).setNode(doc);
write(so, new SAX2DOMEx(doc));
} catch (ParserConfigurationException pce) {
throw new JAXBAssertionError(pce);
}
} else {
write(so, new SAX2DOMEx(node));
}
return;
}
if (result instanceof StreamResult) {
StreamResult sr = (StreamResult) result;
XMLWriter w = null;
if (sr.getWriter() != null)
w = createWriter(sr.getWriter());
else if (sr.getOutputStream() != null)
w = createWriter(sr.getOutputStream());
else if (sr.getSystemId() != null) {
String fileURL = sr.getSystemId();
if (fileURL.startsWith("file:///")) {
if (fileURL.substring(8).indexOf(":") > 0)
fileURL = fileURL.substring(8);
else
fileURL = fileURL.substring(7);
}
try {
w = createWriter(new FileOutputStream(fileURL));
} catch (IOException e) {
throw new MarshalException(e);
}
}
if (w == null)
throw new IllegalArgumentException();
write(so, w);
return;
}
// unsupported parameter type
throw new MarshalException(Messages.format(Messages.UNSUPPORTED_RESULT));
}
use of javax.xml.transform.sax.SAXResult in project voltdb by VoltDB.
the class JDBCSQLXML method createSAXResult.
/**
* Retrieves a new SAXResult for setting the XML value designated by this
* SQLXML instance.
*
* @param resultClass The class of the result, or null.
* @throws java.sql.SQLException if there is an error processing the XML
* value
* @return for setting the XML value designated by this SQLXML instance.
*/
@SuppressWarnings("unchecked")
protected <T extends Result> T createSAXResult(Class<T> resultClass) throws SQLException {
SAXResult result = null;
try {
result = (resultClass == null) ? new SAXResult() : (SAXResult) resultClass.newInstance();
} catch (SecurityException ex) {
throw Exceptions.resultInstantiation(ex);
} catch (InstantiationException ex) {
throw Exceptions.resultInstantiation(ex);
} catch (IllegalAccessException ex) {
throw Exceptions.resultInstantiation(ex);
} catch (ClassCastException ex) {
throw Exceptions.resultInstantiation(ex);
}
StAXResult staxResult = createStAXResult(null);
XMLStreamWriter xmlWriter = staxResult.getXMLStreamWriter();
SAX2XMLStreamWriter handler = new SAX2XMLStreamWriter(xmlWriter);
result.setHandler(handler);
return (T) result;
}
use of javax.xml.transform.sax.SAXResult 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.sax.SAXResult 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);
}
}
Aggregations