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;
}
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;
}
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;
}
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);
}
}
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;
}
Aggregations