Search in sources :

Example 1 with TransformerProperties

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);
    }
}
Also used : StreamResult(javax.xml.transform.stream.StreamResult) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Node(org.w3c.dom.Node) TransformerProperties(org.codice.ddf.platform.util.TransformerProperties) ArrayList(java.util.ArrayList) CswException(org.codice.ddf.spatial.ogc.csw.catalog.common.CswException) CatalogTransformerException(ddf.catalog.transform.CatalogTransformerException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) InputTransformer(ddf.catalog.transform.InputTransformer) Metacard(ddf.catalog.data.Metacard) ByteArrayInputStream(java.io.ByteArrayInputStream)

Example 2 with TransformerProperties

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));
    }
}
Also used : TransformerProperties(org.codice.ddf.platform.util.TransformerProperties)

Example 3 with 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;
}
Also used : InputSource(org.xml.sax.InputSource) TransformerProperties(org.codice.ddf.platform.util.TransformerProperties) StreamSource(javax.xml.transform.stream.StreamSource) IOException(java.io.IOException) Document(org.w3c.dom.Document) SignatureException(org.opensaml.xmlsec.signature.support.SignatureException) MarshallingException(org.opensaml.core.xml.io.MarshallingException) IOException(java.io.IOException) UnmarshallingException(org.opensaml.core.xml.io.UnmarshallingException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException) SAXException(org.xml.sax.SAXException) DocumentBuilder(javax.xml.parsers.DocumentBuilder) StringReader(java.io.StringReader) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Aggregations

TransformerProperties (org.codice.ddf.platform.util.TransformerProperties)3 IOException (java.io.IOException)2 Metacard (ddf.catalog.data.Metacard)1 CatalogTransformerException (ddf.catalog.transform.CatalogTransformerException)1 InputTransformer (ddf.catalog.transform.InputTransformer)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 InputStream (java.io.InputStream)1 StringReader (java.io.StringReader)1 ArrayList (java.util.ArrayList)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 StreamResult (javax.xml.transform.stream.StreamResult)1 StreamSource (javax.xml.transform.stream.StreamSource)1 CswException (org.codice.ddf.spatial.ogc.csw.catalog.common.CswException)1 MarshallingException (org.opensaml.core.xml.io.MarshallingException)1 UnmarshallingException (org.opensaml.core.xml.io.UnmarshallingException)1 SignatureException (org.opensaml.xmlsec.signature.support.SignatureException)1 Document (org.w3c.dom.Document)1 Node (org.w3c.dom.Node)1