use of com.thoughtworks.xstream.persistence.PersistenceStrategy 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) {
}
}
}
use of com.thoughtworks.xstream.persistence.PersistenceStrategy in project spatial-portal by AtlasOfLivingAustralia.
the class MapComposer method saveSession.
private String saveSession() {
String jsessionid = getCookieValue("JSESSIONID");
if (jsessionid == null) {
jsessionid = "test";
}
PrintWriter out = null;
try {
String sfld = getSettingsSupplementary().getProperty(StringConstants.ANALYSIS_OUTPUT_DIR) + "session/" + jsessionid;
// if the session dir exists, then clear it,
// if not let's create it.
File sessfolder = new File(sfld + "/");
if (!sessfolder.exists()) {
sessfolder.mkdirs();
} else {
FileUtils.deleteDirectory(sessfolder);
sessfolder.mkdirs();
}
StringBuilder sbSession = new StringBuilder();
sbSession.append(String.valueOf(mapZoomLevel)).append(",").append(getLeftmenuSearchComposer().getViewportBoundingBox().toString());
sbSession.append(System.getProperty("line.separator"));
PersistenceStrategy strategy = new FilePersistenceStrategy(new File(sfld));
List list = new XmlArrayList(strategy);
String scatterplotNames = "";
List udl = getPortalSession().getActiveLayers();
Iterator iudl = udl.iterator();
while (iudl.hasNext()) {
MapLayer ml = (MapLayer) iudl.next();
if (ml.getType() != LayerUtilitiesImpl.MAP) {
if (ml.getSubType() == LayerUtilitiesImpl.SCATTERPLOT) {
list.add(ml.getScatterplotDataDTO());
scatterplotNames += ((scatterplotNames.length() > 1) ? "___" + ml.getName() : ml.getName());
} else {
list.add(ml);
}
}
}
sbSession.append("scatterplotNames=").append(scatterplotNames);
sbSession.append(System.getProperty("line.separator"));
out = new PrintWriter(new BufferedWriter(new FileWriter(sfld + "/details.txt")));
out.write(sbSession.toString());
out.close();
} catch (Exception e) {
LOGGER.error("failed to save session", e);
} finally {
if (out != null) {
out.close();
}
}
return CommonData.getWebportalServer() + "?ss=" + jsessionid;
}
Aggregations