use of com.thoughtworks.xstream.io.xml.DomDriver in project GDSC-SMLM by aherbert.
the class CreateData method createXStream.
private XStream createXStream() {
if (xs == null) {
xs = new XStream(new DomDriver());
xs.autodetectAnnotations(true);
xs.alias("Compound", Compound.class);
xs.alias("Atom", Atom.class);
}
return xs;
}
use of com.thoughtworks.xstream.io.xml.DomDriver 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.io.xml.DomDriver 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.io.xml.DomDriver in project drools by kiegroup.
the class XmlBifParser method loadBif.
public static Bif loadBif(Resource resource, KnowledgeBuilderErrors errors) {
InputStream is = null;
try {
is = resource.getInputStream();
} catch (IOException e) {
errors.add(new ParserError(resource, "Exception opening Stream:\n" + e.toString(), 0, 0));
return null;
}
try {
String encoding = resource instanceof InternalResource ? ((InternalResource) resource).getEncoding() : null;
XStream xstream = encoding != null ? createTrustingXStream(new DomDriver(encoding)) : createTrustingXStream();
initXStream(xstream);
Bif bif = (Bif) xstream.fromXML(is);
return bif;
} catch (Exception e) {
errors.add(new BayesNetworkAssemblerError(resource, "Unable to parse opening Stream:\n" + e.toString()));
return null;
}
}
use of com.thoughtworks.xstream.io.xml.DomDriver in project universa by UniversaBlockchain.
the class CLIMain method exportFields.
/**
* Export fields from specified contract.
*
* @param contract - contract to export.
* @param fieldNames - list of field names to export.
* @param fileName - name of file to export to.
* @param format - format of file to export to. Can be xml or json.
*/
private static void exportFields(Contract contract, List<String> fieldNames, String fileName, String format, Boolean jsonPretty) throws IOException {
format = format.toLowerCase();
report("export format: " + format);
if (fileName == null) {
if (testMode && testRootPath != null) {
fileName = testRootPath + "Universa_fields_" + DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").format(contract.getCreatedAt());
} else {
fileName = "Universa_fields_" + DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").format(contract.getCreatedAt());
}
}
Binder hm = new Binder();
try {
for (String fieldName : fieldNames) {
report("export field: " + fieldName + " -> " + contract.get(fieldName));
hm.put(fieldName, contract.get(fieldName));
}
Binder binder = DefaultBiMapper.getInstance().newSerializer().serialize(hm);
byte[] data;
if ("xml".equals(format)) {
XStream xstream = new XStream(new DomDriver());
xstream.registerConverter(new MapEntryConverter());
xstream.alias("fields", Binder.class);
data = xstream.toXML(binder).getBytes();
} else if ("yaml".equals(format) || "yml".equals(format)) {
Yaml yaml = new Yaml();
data = yaml.dumpAsMap(binder).getBytes();
} else {
Gson gson;
if (jsonPretty) {
gson = new GsonBuilder().setPrettyPrinting().create();
} else {
gson = new GsonBuilder().create();
}
String jsonString = gson.toJson(binder);
data = jsonString.getBytes();
}
try (FileOutputStream fs = new FileOutputStream(fileName)) {
fs.write(data);
fs.close();
}
report("export fields as " + format + " ok");
} catch (IllegalArgumentException e) {
report("export fields error: " + e.getMessage());
}
}
Aggregations