Search in sources :

Example 1 with QNameMap

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);
}
Also used : StaxReader(com.thoughtworks.xstream.io.xml.StaxReader) XMLStreamReader(javax.xml.stream.XMLStreamReader) QNameMap(com.thoughtworks.xstream.io.xml.QNameMap)

Example 2 with QNameMap

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"));
}
Also used : StaxReader(com.thoughtworks.xstream.io.xml.StaxReader) XMLStreamReader(javax.xml.stream.XMLStreamReader) StringReader(java.io.StringReader) HierarchicalStreamReader(com.thoughtworks.xstream.io.HierarchicalStreamReader) QNameMap(com.thoughtworks.xstream.io.xml.QNameMap) Test(org.junit.Test)

Example 3 with QNameMap

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"));
}
Also used : StaxReader(com.thoughtworks.xstream.io.xml.StaxReader) XMLStreamReader(javax.xml.stream.XMLStreamReader) StringReader(java.io.StringReader) HierarchicalStreamReader(com.thoughtworks.xstream.io.HierarchicalStreamReader) QNameMap(com.thoughtworks.xstream.io.xml.QNameMap) Test(org.junit.Test)

Example 4 with QNameMap

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());
}
Also used : StaxReader(com.thoughtworks.xstream.io.xml.StaxReader) XMLStreamReader(javax.xml.stream.XMLStreamReader) StringReader(java.io.StringReader) HierarchicalStreamReader(com.thoughtworks.xstream.io.HierarchicalStreamReader) QNameMap(com.thoughtworks.xstream.io.xml.QNameMap) Test(org.junit.Test)

Example 5 with QNameMap

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;
}
Also used : StaxReader(com.thoughtworks.xstream.io.xml.StaxReader) XMLStreamReader(javax.xml.stream.XMLStreamReader) InputStreamReader(java.io.InputStreamReader) WebApplicationException(javax.ws.rs.WebApplicationException) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) XStreamException(com.thoughtworks.xstream.XStreamException) XMLStreamException(javax.xml.stream.XMLStreamException) ByteArrayInputStream(java.io.ByteArrayInputStream) CswRecordCollection(org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection) HierarchicalStreamReader(com.thoughtworks.xstream.io.HierarchicalStreamReader) QNameMap(com.thoughtworks.xstream.io.xml.QNameMap) XMLInputFactory(javax.xml.stream.XMLInputFactory)

Aggregations

QNameMap (com.thoughtworks.xstream.io.xml.QNameMap)17 StaxReader (com.thoughtworks.xstream.io.xml.StaxReader)13 XMLStreamReader (javax.xml.stream.XMLStreamReader)13 HierarchicalStreamReader (com.thoughtworks.xstream.io.HierarchicalStreamReader)12 StringReader (java.io.StringReader)10 Test (org.junit.Test)8 StaxDriver (com.thoughtworks.xstream.io.xml.StaxDriver)4 XStream (com.thoughtworks.xstream.XStream)3 Path (com.thoughtworks.xstream.io.path.Path)3 InputStream (java.io.InputStream)3 LinkedHashSet (java.util.LinkedHashSet)3 XMLStreamException (javax.xml.stream.XMLStreamException)3 XStreamException (com.thoughtworks.xstream.XStreamException)2 IOException (java.io.IOException)2 InputStreamReader (java.io.InputStreamReader)2 XMLInputFactory (javax.xml.stream.XMLInputFactory)2 XMLStreamWriter (javax.xml.stream.XMLStreamWriter)2 Before (org.junit.Before)2 StaxWriter (com.thoughtworks.xstream.io.xml.StaxWriter)1 XStream11NameCoder (com.thoughtworks.xstream.io.xml.XStream11NameCoder)1