use of com.thoughtworks.xstream.io.xml.QNameMap 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.QNameMap 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.QNameMap 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.QNameMap 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.QNameMap in project ddf by codice.
the class GetRecordsMessageBodyReader method unmarshalWithStaxReader.
private CswRecordCollection unmarshalWithStaxReader(String originalInputStream) throws IOException {
CswRecordCollection cswRecords;
XMLInputFactory xmlInputFactory = XMLInputFactory.newFactory();
xmlInputFactory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false);
xmlInputFactory.setProperty(XMLInputFactory.SUPPORT_DTD, false);
xmlInputFactory.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, true);
InputStream inStream = new ByteArrayInputStream(originalInputStream.getBytes("UTF-8"));
XMLStreamReader xmlStreamReader = null;
try (InputStreamReader inputStreamReader = new InputStreamReader(inStream, StandardCharsets.UTF_8)) {
xmlStreamReader = xmlInputFactory.createXMLStreamReader(inputStreamReader);
HierarchicalStreamReader reader = new StaxReader(new QNameMap(), xmlStreamReader);
cswRecords = (CswRecordCollection) xstream.unmarshal(reader, null, argumentHolder);
} catch (XMLStreamException | XStreamException e) {
// to a CswException, and logs.
throw new WebApplicationException(e, createResponse(originalInputStream));
} finally {
IOUtils.closeQuietly(inStream);
try {
if (xmlStreamReader != null) {
xmlStreamReader.close();
}
} catch (XMLStreamException e) {
// ignore
}
}
return cswRecords;
}
Aggregations