Search in sources :

Example 16 with DomDriver

use of com.thoughtworks.xstream.io.xml.DomDriver in project XobotOS by xamarin.

the class SharpenProject method createXStream.

private XStream createXStream() {
    XStream stream = new XStream(new DomDriver());
    stream.alias("sharpen", Remembrance.class);
    return stream;
}
Also used : DomDriver(com.thoughtworks.xstream.io.xml.DomDriver) XStream(com.thoughtworks.xstream.XStream)

Example 17 with DomDriver

use of com.thoughtworks.xstream.io.xml.DomDriver in project GDSC-SMLM by aherbert.

the class SettingsManager method createXStream.

private static XStream createXStream() {
    if (xs == null) {
        xs = new XStream(new DomDriver());
        // Map the object names/fields for a nicer configuration file
        xs.alias("gdsc.fitting.settings", GlobalSettings.class);
        xs.alias("gdsc.fitting.configuration", FitEngineConfiguration.class);
        xs.aliasField("gdsc.fitting.configuration", GlobalSettings.class, "fitEngineConfiguration");
        xs.aliasField("peakParameters", FitEngineConfiguration.class, "fitConfiguration");
        xs.aliasField("smoothing", FitEngineConfiguration.class, "smooth");
        //xs.aliasField("width0", FitConfiguration.class, "initialPeakWidth0");
        //xs.aliasField("width1", FitConfiguration.class, "initialPeakWidth1");
        //xs.aliasField("angle", FitConfiguration.class, "initialAngle");
        xs.aliasField("enableValidation", FitConfiguration.class, "fitValidation");
        xs.omitField(FitConfiguration.class, "flags");
        xs.omitField(FitConfiguration.class, "signalThreshold");
        //xs.omitField(FitConfiguration.class, "noise");
        xs.omitField(FitConfiguration.class, "enableValidation");
        xs.omitField(FitConfiguration.class, "computeResiduals");
        // Smart filter settings
        xs.omitField(FitConfiguration.class, "directFilter");
        xs.omitField(FitConfiguration.class, "dynamicPeakResult");
        xs.omitField(FitConfiguration.class, "filterResult");
        xs.omitField(FitConfiguration.class, "widthEnabled");
        xs.omitField(FitConfiguration.class, "offset");
    }
    return xs;
}
Also used : DomDriver(com.thoughtworks.xstream.io.xml.DomDriver) XStream(com.thoughtworks.xstream.XStream)

Example 18 with DomDriver

use of com.thoughtworks.xstream.io.xml.DomDriver in project GDSC-SMLM by aherbert.

the class BatchPeakFit method createXStream.

private XStream createXStream() {
    XStream xs = new XStream(new DomDriver());
    xs.alias("gdsc.fitting.batchSettings", BatchSettings.class);
    xs.alias("parameter", ParameterSettings.class);
    xs.alias("gdsc.fitting.batchRun", BatchRun.class);
    xs.omitField(FitConfiguration.class, "flags");
    xs.omitField(FitConfiguration.class, "signalThreshold");
    //xs.omitField(FitConfiguration.class, "noise");
    xs.omitField(FitConfiguration.class, "enableValidation");
    return xs;
}
Also used : DomDriver(com.thoughtworks.xstream.io.xml.DomDriver) XStream(com.thoughtworks.xstream.XStream)

Example 19 with DomDriver

use of com.thoughtworks.xstream.io.xml.DomDriver in project spatial-portal by AtlasOfLivingAustralia.

the class MapComposer method loadUserSession.

public void loadUserSession(String sessionid) {
    onClick$removeAllLayers();
    Scanner scanner = null;
    try {
        String sfld = getSettingsSupplementary().getProperty(StringConstants.ANALYSIS_OUTPUT_DIR) + "session/" + sessionid;
        File sessfolder = new File(sfld);
        if (!sessfolder.exists()) {
            showMessage("Session information does not exist. Please provide a valid session id");
            return;
        }
        scanner = new Scanner(new File(sfld + "/details.txt"));
        // first grab the zoom level and bounding box
        String[] mapdetails = scanner.nextLine().split(",");
        BoundingBox bb = new BoundingBox();
        bb.setMinLongitude(Float.parseFloat(mapdetails[1]));
        bb.setMinLatitude(Float.parseFloat(mapdetails[2]));
        bb.setMaxLongitude(Float.parseFloat(mapdetails[3]));
        bb.setMaxLatitude(Float.parseFloat(mapdetails[4]));
        openLayersJavascript.setAdditionalScript(openLayersJavascript.zoomToBoundingBox(bb, true));
        String[] scatterplotNames = null;
        while (scanner.hasNextLine()) {
            String line = scanner.nextLine();
            if (line.startsWith("scatterplotNames")) {
                scatterplotNames = line.substring(17).split("___");
            }
        }
        ArrayUtils.reverse(scatterplotNames);
        // ignore fields not found
        XStream xstream = new XStream(new DomDriver()) {

            protected MapperWrapper wrapMapper(MapperWrapper next) {
                return new MapperWrapper(next) {

                    public boolean shouldSerializeMember(Class definedIn, String fieldName) {
                        if (definedIn == Object.class || !super.shouldSerializeMember(definedIn, fieldName))
                            System.out.println("faled to read: " + definedIn + ", " + fieldName);
                        return definedIn != Object.class ? super.shouldSerializeMember(definedIn, fieldName) : false;
                    }
                };
            }

            @Override
            public Object unmarshal(HierarchicalStreamReader reader) {
                Object o = super.unmarshal(reader);
                if (o instanceof BiocacheQuery)
                    ((BiocacheQuery) o).getFullQ(false);
                return o;
            }

            @Override
            public Object unmarshal(HierarchicalStreamReader reader, Object root) {
                Object o = super.unmarshal(reader, root);
                if (o instanceof BiocacheQuery)
                    ((BiocacheQuery) o).getFullQ(false);
                return o;
            }

            @Override
            public Object unmarshal(HierarchicalStreamReader reader, Object root, DataHolder dataHolder) {
                Object o = super.unmarshal(reader, root, dataHolder);
                if (o instanceof BiocacheQuery)
                    ((BiocacheQuery) o).getFullQ(false);
                return o;
            }
        };
        PersistenceStrategy strategy = new FilePersistenceStrategy(new File(sfld), xstream);
        List list = new XmlArrayList(strategy);
        ListIterator it = list.listIterator(list.size());
        int scatterplotIndex = 0;
        while (it.hasPrevious()) {
            Object o = it.previous();
            MapLayer ml = null;
            if (o instanceof MapLayer) {
                ml = (MapLayer) o;
                LOGGER.debug("Loading " + ml.getName() + " -> " + ml.isDisplayed());
                addUserDefinedLayerToMenu(ml, false);
            } else if (o instanceof ScatterplotDataDTO) {
                ScatterplotDataDTO spdata = (ScatterplotDataDTO) o;
                loadScatterplot(spdata, "My Scatterplot " + scatterplotIndex++);
            }
            if (ml != null) {
                addUserDefinedLayerToMenu(ml, true);
            }
        }
    } catch (Exception e) {
        try {
            File f = new File("/data/sessions/" + sessionid + ".txt");
            PrintWriter pw = new PrintWriter(f);
            e.printStackTrace(pw);
            pw.close();
        } catch (Exception ex) {
        }
        LOGGER.error("Unable to load session data", e);
        showMessage("Unable to load session data");
    } finally {
        if (scanner != null) {
            scanner.close();
        }
        try {
            File f = new File("/data/sessions/ok/" + sessionid + ".txt");
            FileUtils.writeStringToFile(f, "ok");
        } catch (Exception ex) {
        }
    }
}
Also used : ScatterplotDataDTO(au.org.ala.spatial.dto.ScatterplotDataDTO) XStream(com.thoughtworks.xstream.XStream) HasMapLayer(au.org.emii.portal.menu.HasMapLayer) MapLayer(au.org.emii.portal.menu.MapLayer) XmlArrayList(com.thoughtworks.xstream.persistence.XmlArrayList) ParseException(org.json.simple.parser.ParseException) PersistenceStrategy(com.thoughtworks.xstream.persistence.PersistenceStrategy) FilePersistenceStrategy(com.thoughtworks.xstream.persistence.FilePersistenceStrategy) DomDriver(com.thoughtworks.xstream.io.xml.DomDriver) MapperWrapper(com.thoughtworks.xstream.mapper.MapperWrapper) DataHolder(com.thoughtworks.xstream.converters.DataHolder) BoundingBox(au.org.emii.portal.value.BoundingBox) HierarchicalStreamReader(com.thoughtworks.xstream.io.HierarchicalStreamReader) JSONObject(org.json.simple.JSONObject) LegendObject(au.org.ala.legend.LegendObject) XmlArrayList(com.thoughtworks.xstream.persistence.XmlArrayList) List(java.util.List) FilePersistenceStrategy(com.thoughtworks.xstream.persistence.FilePersistenceStrategy)

Example 20 with DomDriver

use of com.thoughtworks.xstream.io.xml.DomDriver in project universa by UniversaBlockchain.

the class CLIMain method updateFields.

/**
 * Update fields for specified contract.
 *
 * @param contract - contract for update.
 * @param fields   - map of field names and values.
 */
private static void updateFields(Contract contract, HashMap<String, String> fields) throws IOException {
    for (String fieldName : fields.keySet()) {
        report("update field: " + fieldName + " -> " + fields.get(fieldName));
        Binder binder = new Binder();
        Binder data = null;
        try {
            XStream xstream = new XStream(new DomDriver());
            xstream.registerConverter(new MapEntryConverter());
            xstream.alias(fieldName, Binder.class);
            data = Binder.convertAllMapsToBinders(xstream.fromXML(fields.get(fieldName)));
        } catch (Exception xmlEx) {
            // xmlEx.printStackTrace();
            try {
                Gson gson = new GsonBuilder().create();
                binder = Binder.convertAllMapsToBinders(gson.fromJson(fields.get(fieldName), Binder.class));
                data = (Binder) data.get(fieldName);
            } catch (Exception jsonEx) {
                // jsonEx.printStackTrace();
                try {
                    Yaml yaml = new Yaml();
                    data = Binder.convertAllMapsToBinders(yaml.load(fields.get(fieldName)));
                    data = (Binder) data.get(fieldName);
                } catch (Exception yamlEx) {
                    yamlEx.printStackTrace();
                }
            }
        }
        if (data != null) {
            BiDeserializer bm = DefaultBiMapper.getInstance().newDeserializer();
            binder.put("data", bm.deserialize(data));
            contract.set(fieldName, binder);
            report("update field " + fieldName + " ok");
        } else {
            report("update field " + fieldName + " error: no valid data");
        }
    }
    report("contract expires at " + DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").format(contract.getExpiresAt()));
}
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) BiDeserializer(net.sergeych.biserializer.BiDeserializer) BackingStoreException(java.util.prefs.BackingStoreException) OptionException(joptsimple.OptionException) Yaml(org.yaml.snakeyaml.Yaml)

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