Search in sources :

Example 1 with XstreamPathValueTracker

use of org.codice.ddf.spatial.ogc.csw.catalog.converter.XstreamPathValueTracker in project ddf by codice.

the class GmdTransformer method handleTransform.

private Metacard handleTransform(InputStream inputStream, String id) throws CatalogTransformerException {
    String xml;
    XstreamPathValueTracker pathValueTracker;
    try (TemporaryFileBackedOutputStream temporaryFileBackedOutputStream = new TemporaryFileBackedOutputStream()) {
        IOUtils.copy(inputStream, temporaryFileBackedOutputStream);
        byteArray = temporaryFileBackedOutputStream.asByteSource();
        try (InputStream xmlSourceInputStream = getSourceInputStream()) {
            xml = IOUtils.toString(xmlSourceInputStream);
        }
        argumentHolder.put(XstreamPathConverter.PATH_KEY, buildPaths());
        XMLStreamReader streamReader = xmlFactory.createXMLStreamReader(new StringReader(xml));
        HierarchicalStreamReader reader = new StaxReader(new QNameMap(), streamReader);
        pathValueTracker = (XstreamPathValueTracker) xstream.unmarshal(reader, null, argumentHolder);
        Metacard metacard = toMetacard(pathValueTracker, id);
        metacard.setAttribute(new AttributeImpl(Core.METADATA, xml));
        return metacard;
    } catch (XStreamException | XMLStreamException | IOException e) {
        throw new CatalogTransformerException(TRANSFORM_EXCEPTION_MSG, e);
    } finally {
        IOUtils.closeQuietly(inputStream);
    }
}
Also used : StaxReader(com.thoughtworks.xstream.io.xml.StaxReader) XMLStreamReader(javax.xml.stream.XMLStreamReader) TemporaryFileBackedOutputStream(org.codice.ddf.platform.util.TemporaryFileBackedOutputStream) InputStream(java.io.InputStream) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) XstreamPathValueTracker(org.codice.ddf.spatial.ogc.csw.catalog.converter.XstreamPathValueTracker) CatalogTransformerException(ddf.catalog.transform.CatalogTransformerException) IOException(java.io.IOException) Metacard(ddf.catalog.data.Metacard) XStreamException(com.thoughtworks.xstream.XStreamException) XMLStreamException(javax.xml.stream.XMLStreamException) StringReader(java.io.StringReader) HierarchicalStreamReader(com.thoughtworks.xstream.io.HierarchicalStreamReader) QNameMap(com.thoughtworks.xstream.io.xml.QNameMap)

Aggregations

XStreamException (com.thoughtworks.xstream.XStreamException)1 HierarchicalStreamReader (com.thoughtworks.xstream.io.HierarchicalStreamReader)1 QNameMap (com.thoughtworks.xstream.io.xml.QNameMap)1 StaxReader (com.thoughtworks.xstream.io.xml.StaxReader)1 Metacard (ddf.catalog.data.Metacard)1 AttributeImpl (ddf.catalog.data.impl.AttributeImpl)1 CatalogTransformerException (ddf.catalog.transform.CatalogTransformerException)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 StringReader (java.io.StringReader)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 XMLStreamReader (javax.xml.stream.XMLStreamReader)1 TemporaryFileBackedOutputStream (org.codice.ddf.platform.util.TemporaryFileBackedOutputStream)1 XstreamPathValueTracker (org.codice.ddf.spatial.ogc.csw.catalog.converter.XstreamPathValueTracker)1