Search in sources :

Example 21 with DomDriver

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");
}
Also used : Binder(net.sergeych.tools.Binder) DomDriver(com.thoughtworks.xstream.io.xml.DomDriver) GsonBuilder(com.google.gson.GsonBuilder) XStream(com.thoughtworks.xstream.XStream) Gson(com.google.gson.Gson) Yaml(org.yaml.snakeyaml.Yaml)

Example 22 with DomDriver

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;
}
Also used : DomDriver(com.thoughtworks.xstream.io.xml.DomDriver) XStream(com.thoughtworks.xstream.XStream)

Example 23 with DomDriver

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;
}
Also used : DomDriver(com.thoughtworks.xstream.io.xml.DomDriver) ClockTypeConverter(org.kie.workbench.common.services.backend.kmodule.converters.ClockTypeConverter) KBaseConverter(org.kie.workbench.common.services.backend.kmodule.converters.KBaseConverter) QualifierConverter(org.kie.workbench.common.services.backend.kmodule.converters.QualifierConverter) XStream(com.thoughtworks.xstream.XStream) KModuleConverter(org.kie.workbench.common.services.backend.kmodule.converters.KModuleConverter) WorkItemHandlerConverter(org.kie.workbench.common.services.backend.kmodule.converters.WorkItemHandlerConverter) ListenerConverter(org.kie.workbench.common.services.backend.kmodule.converters.ListenerConverter) KSessionConverter(org.kie.workbench.common.services.backend.kmodule.converters.KSessionConverter) FileLoggerConverter(org.kie.workbench.common.services.backend.kmodule.converters.FileLoggerConverter)

Example 24 with DomDriver

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;
}
Also used : DomDriver(com.thoughtworks.xstream.io.xml.DomDriver) XStream(com.thoughtworks.xstream.XStream)

Example 25 with DomDriver

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;
    }
}
Also used : InternalResource(org.drools.core.io.internal.InternalResource) DomDriver(com.thoughtworks.xstream.io.xml.DomDriver) ParserError(org.drools.drl.parser.ParserError) InputStream(java.io.InputStream) XStream(com.thoughtworks.xstream.XStream) XStreamUtils.createNonTrustingXStream(org.kie.utll.xml.XStreamUtils.createNonTrustingXStream) BayesNetworkAssemblerError(org.drools.beliefs.bayes.assembler.BayesNetworkAssemblerError) IOException(java.io.IOException) IOException(java.io.IOException)

Aggregations

XStream (com.thoughtworks.xstream.XStream)32 DomDriver (com.thoughtworks.xstream.io.xml.DomDriver)32 IOException (java.io.IOException)8 Gson (com.google.gson.Gson)5 File (java.io.File)5 InputStream (java.io.InputStream)5 ObjectInputStream (java.io.ObjectInputStream)5 GsonBuilder (com.google.gson.GsonBuilder)4 Binder (net.sergeych.tools.Binder)4 Yaml (org.yaml.snakeyaml.Yaml)4 HttpClient (org.apache.commons.httpclient.HttpClient)3 HttpException (org.apache.commons.httpclient.HttpException)3 HttpMethod (org.apache.commons.httpclient.HttpMethod)3 GetMethod (org.apache.commons.httpclient.methods.GetMethod)3 XStreamException (com.thoughtworks.xstream.XStreamException)2 FileInputStream (java.io.FileInputStream)2 ArrayList (java.util.ArrayList)2 BackingStoreException (java.util.prefs.BackingStoreException)2 OptionException (joptsimple.OptionException)2 BiDeserializer (net.sergeych.biserializer.BiDeserializer)2