Search in sources :

Example 51 with XStream

use of com.thoughtworks.xstream.XStream in project jmeter by apache.

the class TemplateManager method initXStream.

private XStream initXStream() {
    XStream xstream = new XStream(new DomDriver() {

        /**
             * Create the DocumentBuilderFactory instance.
             * See https://blog.compass-security.com/2012/08/secure-xml-parser-configuration/
             * See https://github.com/x-stream/xstream/issues/25
             * @return the new instance
             */
        @Override
        protected DocumentBuilderFactory createDocumentBuilderFactory() {
            final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
            try {
                factory.setFeature("http://xml.org/sax/features/external-general-entities", false);
                factory.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
            } catch (ParserConfigurationException e) {
                throw new StreamException(e);
            }
            factory.setExpandEntityReferences(false);
            return factory;
        }
    });
    xstream.alias("template", Template.class);
    xstream.alias("templates", Templates.class);
    xstream.useAttributeFor(Template.class, "isTestPlan");
    // templates i
    xstream.addImplicitMap(Templates.class, // $NON-NLS-1$
    "templates", Template.class, // $NON-NLS-1$
    "name");
    return xstream;
}
Also used : DomDriver(com.thoughtworks.xstream.io.xml.DomDriver) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) XStream(com.thoughtworks.xstream.XStream) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) StreamException(com.thoughtworks.xstream.io.StreamException)

Example 52 with XStream

use of com.thoughtworks.xstream.XStream in project jmeter by apache.

the class ObjectMessageRenderer method getValueFromText.

/**
     * Try to load an object via XStream from XML text, so that it can be used as body
     * for a JMS message.
     * An {@link IllegalStateException} will be thrown if transforming the XML to an object fails.
     *
     * @param xmlMessage String containing XML text as input for the transformation
     * @return Serialized object instance
     */
@Override
public Serializable getValueFromText(final String xmlMessage) {
    Serializable readObject = null;
    try {
        XStream xstream = new XStream();
        readObject = (Serializable) xstream.fromXML(xmlMessage, readObject);
    } catch (Exception e) {
        throw new IllegalStateException("Unable to load object instance from text", e);
    }
    return readObject;
}
Also used : Serializable(java.io.Serializable) XStream(com.thoughtworks.xstream.XStream) XMLStreamException(javax.xml.stream.XMLStreamException) IOException(java.io.IOException)

Example 53 with XStream

use of com.thoughtworks.xstream.XStream in project GDSC-SMLM by aherbert.

the class PCPALMAnalysis method loadResults.

/**
	 * Load all the results from a directory. File must have the XML suffix
	 * 
	 * @return DONE
	 */
private int loadResults() {
    if (getDirectory()) {
        File[] fileList = (new File(resultsDirectory)).listFiles(new FilenameFilter() {

            public boolean accept(File arg0, String arg1) {
                return arg1.endsWith("xml");
            }
        });
        if (fileList == null)
            return DONE;
        int count = 0;
        for (int i = 0; i < fileList.length; i++) {
            XStream xs = new XStream(new DomDriver());
            if (fileList[i].isFile())
                if (loadResult(xs, fileList[i].getPath()))
                    count++;
        }
        if (count > 0)
            Collections.sort(results);
        log("Loaded %d results", count);
    }
    return DONE;
}
Also used : FilenameFilter(java.io.FilenameFilter) DomDriver(com.thoughtworks.xstream.io.xml.DomDriver) XStream(com.thoughtworks.xstream.XStream) File(java.io.File)

Example 54 with XStream

use of com.thoughtworks.xstream.XStream in project jgnash by ccavanaugh.

the class AccountTreeXMLFactory method exportAccountTree.

public static void exportAccountTree(final Engine engine, final Path file) {
    RootAccount account = engine.getRootAccount();
    XStream xstream = getStream();
    try (final Writer writer = Files.newBufferedWriter(file, ENCODING);
        final ObjectOutputStream out = xstream.createObjectOutputStream(new PrettyPrintWriter(writer))) {
        out.writeObject(account);
    } catch (IOException e) {
        Logger.getLogger(AccountTreeXMLFactory.class.getName()).log(Level.SEVERE, e.getLocalizedMessage(), e);
    }
}
Also used : XStream(com.thoughtworks.xstream.XStream) PrettyPrintWriter(com.thoughtworks.xstream.io.xml.PrettyPrintWriter) IOException(java.io.IOException) ObjectOutputStream(java.io.ObjectOutputStream) PrettyPrintWriter(com.thoughtworks.xstream.io.xml.PrettyPrintWriter) Writer(java.io.Writer)

Example 55 with XStream

use of com.thoughtworks.xstream.XStream in project jgnash by ccavanaugh.

the class AccountTreeXMLFactory method loadAccountTree.

/**
     * Load an account tree given a reader.
     *
     * @param reader Reader to use
     * @return RootAccount if reader is valid
     */
private static RootAccount loadAccountTree(final Reader reader) {
    RootAccount account = null;
    XStream xstream = getStream();
    try (final ObjectInputStream in = xstream.createObjectInputStream(reader)) {
        final Object o = in.readObject();
        if (o instanceof RootAccount) {
            account = (RootAccount) o;
        }
    } catch (IOException | ClassNotFoundException ex) {
        Logger.getLogger(AccountTreeXMLFactory.class.getName()).log(Level.SEVERE, null, ex);
    }
    return account;
}
Also used : XStream(com.thoughtworks.xstream.XStream) IOException(java.io.IOException) ObjectInputStream(java.io.ObjectInputStream)

Aggregations

XStream (com.thoughtworks.xstream.XStream)199 Test (org.junit.Test)55 IOException (java.io.IOException)33 InputStream (java.io.InputStream)29 WstxDriver (com.thoughtworks.xstream.io.xml.WstxDriver)22 Metacard (ddf.catalog.data.Metacard)21 DomDriver (com.thoughtworks.xstream.io.xml.DomDriver)17 HashMap (java.util.HashMap)14 ByteArrayInputStream (java.io.ByteArrayInputStream)13 StaxDriver (com.thoughtworks.xstream.io.xml.StaxDriver)12 XStreamUtils.createTrustingXStream (org.kie.soup.commons.xstream.XStreamUtils.createTrustingXStream)12 Matchers.anyString (org.mockito.Matchers.anyString)11 HierarchicalStreamWriter (com.thoughtworks.xstream.io.HierarchicalStreamWriter)10 CswRecordCollection (org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection)10 FileNotFoundException (java.io.FileNotFoundException)9 Writer (java.io.Writer)8 ArrayList (java.util.ArrayList)8 GmlGeometryConverter (org.codice.ddf.spatial.ogc.wfs.catalog.converter.impl.GmlGeometryConverter)8 XStreamException (com.thoughtworks.xstream.XStreamException)7 MarshallingContext (com.thoughtworks.xstream.converters.MarshallingContext)7