Search in sources :

Example 11 with XppDriver

use of com.thoughtworks.xstream.io.xml.XppDriver in project jmeter by apache.

the class SaveService method loadTestResults.

/**
 * Read results from JTL file.
 *
 * @param reader of the file
 * @param resultCollectorHelper helper class to enable TestResultWrapperConverter to deliver the samples
 * @throws IOException if an I/O error occurs
 */
public static void loadTestResults(InputStream reader, ResultCollectorHelper resultCollectorHelper) throws IOException {
    // Get the InputReader to use
    InputStreamReader inputStreamReader = getInputStreamReader(reader);
    DataHolder dh = JTLSAVER.newDataHolder();
    // Allow TestResultWrapper to feed back the samples
    dh.put(RESULTCOLLECTOR_HELPER_OBJECT, resultCollectorHelper);
    // This is effectively the same as saver.fromXML(InputStream) except we get to provide the DataHolder
    // Don't know why there is no method for this in the XStream class
    JTLSAVER.unmarshal(new XppDriver().createReader(reader), null, dh);
    inputStreamReader.close();
}
Also used : InputStreamReader(java.io.InputStreamReader) XppDriver(com.thoughtworks.xstream.io.xml.XppDriver) DataHolder(com.thoughtworks.xstream.converters.DataHolder)

Example 12 with XppDriver

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

the class CswRecordConverterTest method testUnmarshalNoNamespaceDeclaration.

@Test
public void testUnmarshalNoNamespaceDeclaration() throws Exception {
    XStream xstream = createXstream(new XppDriver());
    xstream.registerConverter(converter);
    xstream.alias("Record", MetacardImpl.class);
    xstream.alias("csw:Record", MetacardImpl.class);
    InputStream is = IOUtils.toInputStream(getRecordNoNamespaceDeclaration(), StandardCharsets.UTF_8);
    Metacard mc = (Metacard) xstream.fromXML(is);
    Metacard expectedMetacard = getTestMetacard();
    assertThat(mc, notNullValue());
    assertThat(mc.getContentTypeName(), is(expectedMetacard.getContentTypeName()));
    assertThat(mc.getCreatedDate(), is(expectedMetacard.getCreatedDate()));
    assertThat(mc.getEffectiveDate(), is(expectedMetacard.getEffectiveDate()));
    assertThat(mc.getId(), is(expectedMetacard.getId()));
    assertThat(mc.getModifiedDate(), is(expectedMetacard.getModifiedDate()));
    assertThat(mc.getTitle(), is(expectedMetacard.getTitle()));
    assertThat(mc.getResourceURI(), is(expectedMetacard.getResourceURI()));
}
Also used : Metacard(ddf.catalog.data.Metacard) XppDriver(com.thoughtworks.xstream.io.xml.XppDriver) XStream(com.thoughtworks.xstream.XStream) InputStream(java.io.InputStream) Test(org.junit.Test)

Example 13 with XppDriver

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

the class CswRecordConverterTest method testUnmarshalWriteNamespaces.

@Test
public void testUnmarshalWriteNamespaces() throws Exception {
    XStream xstream = createXstream(new XppDriver());
    xstream.registerConverter(converter);
    xstream.alias("Record", MetacardImpl.class);
    xstream.alias("csw:Record", MetacardImpl.class);
    InputStream is = IOUtils.toInputStream(getRecordNoNamespaceDeclaration(), StandardCharsets.UTF_8);
    HierarchicalStreamReader reader = new XppReader(new InputStreamReader(is), XmlPullParserFactory.newInstance().newPullParser());
    DataHolder args = xstream.newDataHolder();
    Map<String, String> namespaces = new HashMap<>();
    namespaces.put(CswConstants.XMLNS + CswConstants.NAMESPACE_DELIMITER + CswConstants.CSW_NAMESPACE_PREFIX, CswConstants.CSW_OUTPUT_SCHEMA);
    namespaces.put(CswConstants.XMLNS + CswConstants.NAMESPACE_DELIMITER + CswConstants.DUBLIN_CORE_NAMESPACE_PREFIX, CswConstants.DUBLIN_CORE_SCHEMA);
    namespaces.put(CswConstants.XMLNS + CswConstants.NAMESPACE_DELIMITER + CswConstants.DUBLIN_CORE_TERMS_NAMESPACE_PREFIX, CswConstants.DUBLIN_CORE_TERMS_SCHEMA);
    namespaces.put(CswConstants.XMLNS + CswConstants.NAMESPACE_DELIMITER + CswConstants.OWS_NAMESPACE_PREFIX, CswConstants.OWS_NAMESPACE);
    args.put(CswConstants.NAMESPACE_DECLARATIONS, namespaces);
    Metacard mc = (Metacard) xstream.unmarshal(reader, null, args);
    Metacard expectedMetacard = getTestMetacard();
    assertThat(mc, notNullValue());
    assertThat(mc.getContentTypeName(), is(mc.getContentTypeName()));
    assertThat(mc.getCreatedDate(), is(expectedMetacard.getCreatedDate()));
    assertThat(mc.getEffectiveDate(), is(expectedMetacard.getEffectiveDate()));
    assertThat(mc.getId(), is(expectedMetacard.getId()));
    assertThat(mc.getModifiedDate(), is(expectedMetacard.getModifiedDate()));
    assertThat(mc.getTitle(), is(expectedMetacard.getTitle()));
    assertThat(mc.getResourceURI(), is(expectedMetacard.getResourceURI()));
    XMLUnit.setIgnoreWhitespace(true);
    assertXMLEqual(mc.getMetadata(), getControlRecord());
}
Also used : Metacard(ddf.catalog.data.Metacard) InputStreamReader(java.io.InputStreamReader) XppDriver(com.thoughtworks.xstream.io.xml.XppDriver) HashMap(java.util.HashMap) XStream(com.thoughtworks.xstream.XStream) InputStream(java.io.InputStream) XppReader(com.thoughtworks.xstream.io.xml.XppReader) DataHolder(com.thoughtworks.xstream.converters.DataHolder) HierarchicalStreamReader(com.thoughtworks.xstream.io.HierarchicalStreamReader) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 14 with XppDriver

use of com.thoughtworks.xstream.io.xml.XppDriver in project openmeetings by apache.

the class LibraryChartLoader method loadChart.

@SuppressWarnings("rawtypes")
public static List loadChart(File dir, String fileName) {
    try {
        File file = new File(dir, fileName + CHART_EXT);
        log.error("filepathComplete: " + file);
        XStream xStream = new XStream(new XppDriver());
        xStream.setMode(XStream.NO_REFERENCES);
        try (InputStream is = new FileInputStream(file);
            BufferedReader reader = new BufferedReader(new InputStreamReader(is, UTF_8))) {
            return (List) xStream.fromXML(reader);
        }
    } catch (Exception err) {
        log.error("Unexpected error while loading chart", err);
    }
    return new ArrayList<>();
}
Also used : InputStreamReader(java.io.InputStreamReader) XppDriver(com.thoughtworks.xstream.io.xml.XppDriver) XStream(com.thoughtworks.xstream.XStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) BufferedReader(java.io.BufferedReader) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 15 with XppDriver

use of com.thoughtworks.xstream.io.xml.XppDriver in project openmeetings by apache.

the class WbConverter method loadWmlFile.

public static List<?> loadWmlFile(String hash) {
    String name = OmFileHelper.getName(hash, EXTENSION_WML);
    File file = new File(OmFileHelper.getUploadWmlDir(), name);
    log.debug("filepathComplete: {}", file);
    XStream xStream = new XStream(new XppDriver());
    xStream.setMode(XStream.NO_REFERENCES);
    try (InputStream is = new FileInputStream(file);
        BufferedReader reader = new BufferedReader(new InputStreamReader(is, UTF_8))) {
        return (List<?>) xStream.fromXML(reader);
    } catch (Exception err) {
        log.error("loadWmlFile", err);
    }
    return new ArrayList<>();
}
Also used : InputStreamReader(java.io.InputStreamReader) XppDriver(com.thoughtworks.xstream.io.xml.XppDriver) XStream(com.thoughtworks.xstream.XStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) BufferedReader(java.io.BufferedReader) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) File(java.io.File) FileInputStream(java.io.FileInputStream)

Aggregations

XppDriver (com.thoughtworks.xstream.io.xml.XppDriver)15 XStream (com.thoughtworks.xstream.XStream)13 InputStream (java.io.InputStream)6 HierarchicalStreamWriter (com.thoughtworks.xstream.io.HierarchicalStreamWriter)5 InputStreamReader (java.io.InputStreamReader)5 Writer (java.io.Writer)5 Test (org.junit.Test)5 DataHolder (com.thoughtworks.xstream.converters.DataHolder)4 NoNameCoder (com.thoughtworks.xstream.io.naming.NoNameCoder)4 Metacard (ddf.catalog.data.Metacard)4 QuickWriter (com.thoughtworks.xstream.core.util.QuickWriter)3 PrettyPrintWriter (com.thoughtworks.xstream.io.xml.PrettyPrintWriter)3 HierarchicalStreamReader (com.thoughtworks.xstream.io.HierarchicalStreamReader)2 CompactWriter (com.thoughtworks.xstream.io.xml.CompactWriter)2 XppReader (com.thoughtworks.xstream.io.xml.XppReader)2 BufferedReader (java.io.BufferedReader)2 File (java.io.File)2 FileInputStream (java.io.FileInputStream)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2