use of com.thoughtworks.xstream.io.xml.DomDriver in project universa by UniversaBlockchain.
the class CLIMain method exportContract.
/**
* Export contract to specified xml or json file.
*
* @param contract - contract to export.
* @param fileName - name of file to export to.
* @param format - format of file to export to. Can be xml, yaml or json.
* @param jsonPretty - if true, json will be pretty formated.
*/
public static void exportContract(Contract contract, 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_" + DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").format(contract.getCreatedAt());
} else {
fileName = "Universa_" + DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").format(contract.getCreatedAt());
}
}
Binder binder = contract.serialize(DefaultBiMapper.getInstance().newSerializer());
byte[] data;
if ("xml".equals(format)) {
XStream xstream = new XStream(new DomDriver());
xstream.registerConverter(new MapEntryConverter());
xstream.alias("contract", 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(fileName + " export as " + format + " ok");
}
use of com.thoughtworks.xstream.io.xml.DomDriver in project tmdm-studio-se by Talend.
the class ModelImpactAnalyseService method getParser.
private static XStream getParser() {
if (xstream == null) {
xstream = new XStream(new DomDriver());
// $NON-NLS-1$
xstream.alias("result", Result.class);
// $NON-NLS-1$
xstream.alias("change", Change.class);
// $NON-NLS-1$
xstream.alias("medium", SeverityMedium.class);
// $NON-NLS-1$
xstream.alias("low", SeverityLow.class);
// $NON-NLS-1$
xstream.alias("high", SeverityHigh.class);
// $NON-NLS-1$
xstream.alias("entitiesToDrop", EntitiesToDrop.class);
// $NON-NLS-1$
xstream.alias("entity", String.class);
// $NON-NLS-1$
xstream.addImplicitCollection(Result.class, "severities");
// $NON-NLS-1$
xstream.addImplicitCollection(Severity.class, "changes");
// $NON-NLS-1$
xstream.addImplicitCollection(EntitiesToDrop.class, "entities");
}
return xstream;
}
use of com.thoughtworks.xstream.io.xml.DomDriver in project kie-wb-common by kiegroup.
the class KModuleContentHandler method createXStream.
private XStream createXStream() {
XStream xStream = XStreamUtils.createTrustingXStream(new DomDriver());
xStream.registerConverter(new KModuleConverter());
xStream.registerConverter(new KBaseConverter());
xStream.registerConverter(new KSessionConverter());
xStream.registerConverter(new ClockTypeConverter());
xStream.registerConverter(new ListenerConverter());
xStream.registerConverter(new QualifierConverter());
xStream.registerConverter(new WorkItemHandlerConverter());
xStream.registerConverter(new FileLoggerConverter());
xStream.alias("kmodule", KModuleModel.class);
xStream.alias("kbase", KBaseModel.class);
xStream.alias("ksession", KSessionModel.class);
xStream.alias("clockType", ClockTypeOption.class);
xStream.alias("listener", ListenerModel.class);
xStream.alias("qualifier", QualifierModel.class);
xStream.alias("workItemHandler", WorkItemHandlerModel.class);
return xStream;
}
use of com.thoughtworks.xstream.io.xml.DomDriver in project restfulie-java by caelum.
the class CustomXStreamXMLDeserializer method getXStream.
/**
* Extension point to configure your xstream instance.
* @return the configured xstream instance
*/
@Override
protected XStream getXStream() {
XStream xStream = new XStream(new DomDriver());
xStream.alias("item", br.com.caelum.example.model.Item.class);
return xStream;
}
use of com.thoughtworks.xstream.io.xml.DomDriver in project drools by kiegroup.
the class XmlBifParser method loadBif.
public static Bif loadBif(Resource resource, ArrayList<KnowledgeBuilderError> 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 ? createNonTrustingXStream(new DomDriver(encoding)) : createNonTrustingXStream();
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;
}
}
Aggregations