use of com.thoughtworks.xstream.io.xml.StaxReader in project camel by apache.
the class XStreamDataFormat method createHierarchicalStreamReader.
protected HierarchicalStreamReader createHierarchicalStreamReader(Exchange exchange, InputStream stream) throws XMLStreamException {
updateCharactorEncodingInfo(exchange);
if (getXstreamDriver() != null) {
return getXstreamDriver().createReader(stream);
}
XMLStreamReader xmlReader = getStaxConverter().createXMLStreamReader(stream, exchange);
return new StaxReader(new QNameMap(), xmlReader);
}
use of com.thoughtworks.xstream.io.xml.StaxReader in project ddf by codice.
the class TestXstreamPathConverter method testAttributeValid.
@Test
public void testAttributeValid() throws XMLStreamException {
XMLStreamReader streamReader = XMLInputFactory.newInstance().createXMLStreamReader(new StringReader(GML_XML));
HierarchicalStreamReader reader = new StaxReader(new QNameMap(), streamReader);
XstreamPathValueTracker pathValueTracker = (XstreamPathValueTracker) xstream.unmarshal(reader, null, argumentHolder);
assertThat(pathValueTracker.getFirstValue(POLYGON_GML_ID_PATH), is("p1"));
}
use of com.thoughtworks.xstream.io.xml.StaxReader in project ddf by codice.
the class TestXstreamPathConverter method testGetFirstNodeValue.
@Test
public void testGetFirstNodeValue() throws XMLStreamException {
XMLStreamReader streamReader = XMLInputFactory.newInstance().createXMLStreamReader(new StringReader(GML_XML));
HierarchicalStreamReader reader = new StaxReader(new QNameMap(), streamReader);
XstreamPathValueTracker pathValueTracker = (XstreamPathValueTracker) xstream.unmarshal(reader, null, argumentHolder);
assertThat(pathValueTracker.getFirstValue(POLYGON_POS_PATH), is("-180.000000 90.000000"));
}
use of com.thoughtworks.xstream.io.xml.StaxReader in project ddf by codice.
the class TestXstreamPathConverter method testBadPath.
@Test
public void testBadPath() throws XMLStreamException {
XMLStreamReader streamReader = XMLInputFactory.newInstance().createXMLStreamReader(new StringReader(GML_XML));
HierarchicalStreamReader reader = new StaxReader(new QNameMap(), streamReader);
XstreamPathValueTracker pathValueTracker = (XstreamPathValueTracker) xstream.unmarshal(reader, null, argumentHolder);
assertThat(pathValueTracker.getFirstValue(BAD_PATH), nullValue());
}
use of com.thoughtworks.xstream.io.xml.StaxReader 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);
}
}
Aggregations