Search in sources :

Example 6 with QNameMap

use of com.thoughtworks.xstream.io.xml.QNameMap in project ddf by codice.

the class XstreamPathConverterTest 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 7 with QNameMap

use of com.thoughtworks.xstream.io.xml.QNameMap in project ddf by codice.

the class XstreamPathConverterTest 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 8 with QNameMap

use of com.thoughtworks.xstream.io.xml.QNameMap in project ddf by codice.

the class XstreamPathConverterTest method assertRepeatedElements.

private void assertRepeatedElements(String xml) throws XMLStreamException {
    Path path = new Path("/Polygon/B/C/D/E/F/G");
    Set<Path> paths = new LinkedHashSet<>();
    paths.add(path);
    argumentHolder.put(XstreamPathConverter.PATH_KEY, paths);
    XMLStreamReader streamReader = XMLInputFactory.newInstance().createXMLStreamReader(new StringReader(xml));
    HierarchicalStreamReader reader = new StaxReader(new QNameMap(), streamReader);
    XstreamPathValueTracker pathValueTracker = (XstreamPathValueTracker) xstream.unmarshal(reader, null, argumentHolder);
    assertThat(pathValueTracker.getAllValues(path), is(Arrays.asList("value1", "value2", "value3", "value4", "value5", "value6", "value7", "value8")));
}
Also used : Path(com.thoughtworks.xstream.io.path.Path) LinkedHashSet(java.util.LinkedHashSet) 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)

Example 9 with QNameMap

use of com.thoughtworks.xstream.io.xml.QNameMap in project camel by apache.

the class XStreamDataFormat method createHierarchicalStreamWriter.

protected HierarchicalStreamWriter createHierarchicalStreamWriter(Exchange exchange, Object body, OutputStream stream) throws XMLStreamException {
    updateCharactorEncodingInfo(exchange);
    if (getXstreamDriver() != null) {
        return getXstreamDriver().createWriter(stream);
    }
    XMLStreamWriter xmlWriter = getStaxConverter().createXMLStreamWriter(stream, exchange);
    return new StaxWriter(new QNameMap(), xmlWriter);
}
Also used : XMLStreamWriter(javax.xml.stream.XMLStreamWriter) StaxWriter(com.thoughtworks.xstream.io.xml.StaxWriter) QNameMap(com.thoughtworks.xstream.io.xml.QNameMap)

Example 10 with QNameMap

use of com.thoughtworks.xstream.io.xml.QNameMap in project ddf by codice.

the class TestXstreamPathConverter method setup.

@Before
public void setup() {
    QNameMap qmap = new QNameMap();
    qmap.setDefaultNamespace(GML_NAMESPACE);
    qmap.setDefaultPrefix("");
    StaxDriver staxDriver = new StaxDriver(qmap);
    xstream = new XStream(staxDriver);
    xstream.setClassLoader(this.getClass().getClassLoader());
    XstreamPathConverter converter = new XstreamPathConverter();
    xstream.registerConverter(converter);
    xstream.alias("Polygon", XstreamPathValueTracker.class);
    argumentHolder = xstream.newDataHolder();
    Set<Path> paths = new LinkedHashSet<>();
    paths.addAll(Arrays.asList(POLYGON_POS_PATH, BAD_PATH, POLYGON_GML_ID_PATH));
    argumentHolder.put(XstreamPathConverter.PATH_KEY, paths);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Path(com.thoughtworks.xstream.io.path.Path) StaxDriver(com.thoughtworks.xstream.io.xml.StaxDriver) XStream(com.thoughtworks.xstream.XStream) QNameMap(com.thoughtworks.xstream.io.xml.QNameMap) Before(org.junit.Before)

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