use of javax.xml.transform.dom.DOMResult in project OpenClinica by OpenClinica.
the class SoapCreateSubject method createSubject.
public String createSubject(SubjectBean subjectBean, StudyBean studyBean, Date enrollmentDate, String secondaryId) {
Element requestElement = prepareRequest(subjectBean, studyBean);
DOMSource source = new DOMSource(requestElement);
DOMResult result = new DOMResult();
getWebServiceTemplate().sendSourceAndReceiveToResult(source, result);
return processResponse(result.getNode());
}
use of javax.xml.transform.dom.DOMResult 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.dom.DOMResult 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.dom.DOMResult 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.dom.DOMResult in project jackrabbit by apache.
the class ExportDocViewTest method readDocument.
/**
* Reads a DOM document from the given XML stream.
*
* @param xml XML stream
* @return DOM document
* @throws RepositoryException if the document could not be read
*/
private Document readDocument(InputStream xml) throws RepositoryException {
try {
StreamSource source = new StreamSource(xml);
DOMResult result = new DOMResult();
TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer = factory.newTransformer();
transformer.transform(source, result);
return (Document) result.getNode();
} catch (TransformerException e) {
throw new RepositoryException("Unable to read xml file", e);
}
}
Aggregations