use of com.thoughtworks.xstream.io.xml.DomDriver in project GDSC-SMLM by aherbert.
the class ImageSource method fromXml.
/**
* Create the image source from serialised XML.
*
* @param xml the xml
* @return the image source
* @see #toXml()
*/
public static ImageSource fromXml(String xml) {
final XStream xs = new XStream(new DomDriver());
try {
xs.allowTypesByWildcard(new String[] { "uk.ac.sussex.gdsc.smlm.**" });
xs.autodetectAnnotations(true);
// Support package gdsc.smlm renamed to uk.ac.sussex.gdsc.smlm
return (ImageSource) xs.fromXML(XStreamUtils.updateGdscPackageName(xml));
} catch (final Exception ex) {
Logger.getLogger(ImageSource.class.getName()).log(Level.SEVERE, "Failed to deserialise from XML", ex);
}
return null;
}
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.
*
* @param results the results
* @return the updated results
*/
private List<CorrelationResult> loadResults(final List<CorrelationResult> results) {
if (getDirectory()) {
final File[] fileList = (new File(settings.resultsDirectory)).listFiles((arg0, arg1) -> arg1.endsWith("xml"));
if (fileList == null) {
return results;
}
// New list
final List<CorrelationResult> newResults = new ArrayList<>(results);
int count = 0;
for (int i = 0; i < fileList.length; i++) {
final XStream xs = new XStream(new DomDriver());
// to be removed after 1.5
XStream.setupDefaultSecurity(xs);
xs.allowTypes(new Class[] { CorrelationResult.class });
if (fileList[i].isFile() && loadResult(newResults, xs, fileList[i].getPath())) {
count++;
}
}
if (count > 0) {
Collections.sort(newResults, CorrelationResult::compare);
}
log("Loaded %d results", count);
return newResults;
}
return results;
}
Aggregations