Search in sources :

Example 6 with StaxDriver

use of com.thoughtworks.xstream.io.xml.StaxDriver in project jgnash by ccavanaugh.

the class XStreamFactory method getInstance.

static XStream getInstance() {
    final XStream xstream = new XStream(new StaxDriver());
    xstream.alias("Message", Message.class);
    xstream.alias("MessageProperty", MessageProperty.class);
    return xstream;
}
Also used : StaxDriver(com.thoughtworks.xstream.io.xml.StaxDriver) XStream(com.thoughtworks.xstream.XStream)

Example 7 with StaxDriver

use of com.thoughtworks.xstream.io.xml.StaxDriver in project jgnash by ccavanaugh.

the class CheckLayoutSerializationFactory method getStream.

private static XStream getStream() {
    XStream xstream = new XStream(new StaxDriver());
    xstream.alias("CheckLayout", CheckLayout.class);
    xstream.alias("CheckObject", CheckObject.class);
    /* Fix for printing on some Windows Systems.  Value and winID do not always serialize correctly
         * and do not have any apparent impact on restoring printing preferences */
    if (OS.isSystemWindows()) {
        try {
            Class<?> media = Class.forName("sun.print.Win32MediaTray");
            xstream.omitField(media, "value");
            xstream.omitField(media, "winID");
        } catch (ClassNotFoundException e) {
            logSevere(CheckLayoutSerializationFactory.class, e);
        }
    }
    return xstream;
}
Also used : StaxDriver(com.thoughtworks.xstream.io.xml.StaxDriver) XStream(com.thoughtworks.xstream.XStream)

Example 8 with StaxDriver

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

the class TestCswTransformProvider method testUnmarshalCopyPreservesNamespaces.

@Test
public void testUnmarshalCopyPreservesNamespaces() throws Exception {
    InputTransformer mockInputTransformer = mock(InputTransformer.class);
    when(mockInputManager.getTransformerBySchema(anyString())).thenReturn(mockInputTransformer);
    StaxDriver driver = new StaxDriver();
    driver.setRepairingNamespace(true);
    driver.getQnameMap().setDefaultNamespace(CswConstants.CSW_OUTPUT_SCHEMA);
    driver.getQnameMap().setDefaultPrefix(CswConstants.CSW_NAMESPACE_PREFIX);
    // Have to use XppReader in order to preserve the namespaces.
    HierarchicalStreamReader reader = new XppReader(new StringReader(getRecord()), XmlPullParserFactory.newInstance().newPullParser());
    CswTransformProvider provider = new CswTransformProvider(null, mockInputManager);
    UnmarshallingContext context = new TreeUnmarshaller(null, null, null, null);
    context.put(CswConstants.OUTPUT_SCHEMA_PARAMETER, "http://example.com/schema");
    ArgumentCaptor<InputStream> captor = ArgumentCaptor.forClass(InputStream.class);
    provider.unmarshal(reader, context);
    // Verify the context arguments were set correctly
    verify(mockInputTransformer, times(1)).transform(captor.capture());
    InputStream inStream = captor.getValue();
    String result = IOUtils.toString(inStream);
    XMLUnit.setIgnoreWhitespace(true);
    XMLAssert.assertXMLEqual(getRecord(), result);
}
Also used : StaxDriver(com.thoughtworks.xstream.io.xml.StaxDriver) XppReader(com.thoughtworks.xstream.io.xml.XppReader) InputStream(java.io.InputStream) StringReader(java.io.StringReader) HierarchicalStreamReader(com.thoughtworks.xstream.io.HierarchicalStreamReader) UnmarshallingContext(com.thoughtworks.xstream.converters.UnmarshallingContext) Matchers.anyString(org.mockito.Matchers.anyString) InputTransformer(ddf.catalog.transform.InputTransformer) TreeUnmarshaller(com.thoughtworks.xstream.core.TreeUnmarshaller) Test(org.junit.Test)

Example 9 with StaxDriver

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

the class TestGetRecordsResponseConverter method createXStream.

private XStream createXStream(final String elementName) {
    GetRecordsResponseConverter rrConverter = new GetRecordsResponseConverter(mockProvider);
    XStream xstream = new XStream(new StaxDriver(new NoNameCoder()));
    xstream.registerConverter(rrConverter);
    xstream.alias(CswConstants.CSW_NAMESPACE_PREFIX + CswConstants.NAMESPACE_DELIMITER + elementName, CswRecordCollection.class);
    return xstream;
}
Also used : StaxDriver(com.thoughtworks.xstream.io.xml.StaxDriver) XStream(com.thoughtworks.xstream.XStream) NoNameCoder(com.thoughtworks.xstream.io.naming.NoNameCoder)

Example 10 with StaxDriver

use of com.thoughtworks.xstream.io.xml.StaxDriver 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

StaxDriver (com.thoughtworks.xstream.io.xml.StaxDriver)10 XStream (com.thoughtworks.xstream.XStream)8 InputStream (java.io.InputStream)3 NoNameCoder (com.thoughtworks.xstream.io.naming.NoNameCoder)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 IOException (java.io.IOException)2 URL (java.net.URL)2 Matchers.anyString (org.mockito.Matchers.anyString)2 UnmarshallingContext (com.thoughtworks.xstream.converters.UnmarshallingContext)1 TreeUnmarshaller (com.thoughtworks.xstream.core.TreeUnmarshaller)1 HierarchicalStreamReader (com.thoughtworks.xstream.io.HierarchicalStreamReader)1 Path (com.thoughtworks.xstream.io.path.Path)1 CompactWriter (com.thoughtworks.xstream.io.xml.CompactWriter)1 QNameMap (com.thoughtworks.xstream.io.xml.QNameMap)1 WstxDriver (com.thoughtworks.xstream.io.xml.WstxDriver)1 XppReader (com.thoughtworks.xstream.io.xml.XppReader)1 InputTransformer (ddf.catalog.transform.InputTransformer)1 File (java.io.File)1 FileWriter (java.io.FileWriter)1 StringReader (java.io.StringReader)1