use of org.codice.ddf.platform.util.TransformerProperties in project ddf by codice.
the class CswSubscriptionEndpoint method getMetacards.
private List<Metacard> getMetacards(GetRecordsResponseType recordsResponse) throws CswException {
try {
InputTransformer transformer = inputTransformerManager.getTransformerBySchema(recordsResponse.getSearchResults().getRecordSchema());
List<Metacard> metacards = new ArrayList<>();
for (Object result : recordsResponse.getSearchResults().getAny()) {
if (result instanceof Node) {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
XML_UTILS.transform((Node) result, new TransformerProperties(), new StreamResult(outputStream));
InputStream is = new ByteArrayInputStream(outputStream.toByteArray());
metacards.add(transformer.transform(is));
}
}
return metacards;
} catch (IOException | CatalogTransformerException e) {
String msg = "Could not parse SearchResults in getRecordsResponse";
LOGGER.debug(msg, e);
throw new CswException(msg, e);
}
}
use of org.codice.ddf.platform.util.TransformerProperties in project ddf by codice.
the class AttributeQueryClient method printXML.
/**
* Prints the given XML.
*
* @param xmlNode Node to transform.
* @param message Message to display.
*/
private void printXML(String message, Node xmlNode) {
TransformerProperties transformerProperties = new TransformerProperties();
transformerProperties.addOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
if (LOGGER.isTraceEnabled()) {
LOGGER.trace(message, XML_UTILS.format(xmlNode, transformerProperties));
}
}
use of org.codice.ddf.platform.util.TransformerProperties in project ddf by codice.
the class AttributeQueryClient method sendRequest.
/**
* Sends the request to the external attribute store via a Dispatch client.
*
* @param requestDocument of the request.
* @return Document of the response or null if the response is empty.
* @throws AttributeQueryException
*/
protected Document sendRequest(Document requestDocument) {
TransformerProperties transformerProperties = new TransformerProperties();
transformerProperties.addOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
String request = XML_UTILS.format(requestDocument, transformerProperties);
StreamSource streamSource;
try {
streamSource = dispatch.invoke(new StreamSource(new StringReader(request)));
} catch (Exception e) {
throw new AttributeQueryException(String.format("Could not connect to: %s", this.externalAttributeStoreUrl), e);
}
String response = XML_UTILS.format(streamSource, transformerProperties);
if (StringUtils.isBlank(response)) {
LOGGER.debug("Response is empty.");
return null;
}
DocumentBuilder documentBuilder;
Document responseDoc;
try {
documentBuilder = XML_UTILS.getSecureDocumentBuilder(true);
responseDoc = documentBuilder.parse(new InputSource(new StringReader(response)));
} catch (ParserConfigurationException | SAXException | IOException e) {
throw new AttributeQueryException("Unable to parse response string into an XML document.", e);
}
return responseDoc;
}
Aggregations