OntologyManager om= workspace.getOntologyManager();
WorksheetToFeatureCollection geo = new WorksheetToFeatureCollection(worksheet, om, selection);//ying
//WorksheetToFeatureCollections geo = new WorksheetToFeatureCollections(worksheet);
// Send an error update if no geospatial data found!
if (geo.hasNoGeospatialData()) {
return new UpdateContainer(new ErrorUpdate(
"No geospatial data found in the worksheet!"));
}
try {
//final File file = geo.SaveSpatialData();
// Transfer the file to a public server
final String kmlFileName = geo.SaveSpatialDataAndReturnKMLString();//new RandomGUID().toString(); // save this line for using networkLink in GE plugin (see geospatial.js)
final String zippedSpatialDataPath = geo.getZippedSpatialDataPath();
final boolean transfer = true;//transferFileToPublicServer(kmlFileName,file); // save this line for using networkLink in GE plugin (see geospatial.js)
//if (!transfer) { // save this line for using networkLink in GE plugin (see geospatial.js)
// logger.error("Published KML file could not be moved to a public server to display on Google Maps!");
//}
return new UpdateContainer(new AbstractUpdate() {
@Override
public void generateJson(String prefix, PrintWriter pw,
VWorkspace vWorkspace) {
JSONObject outputObject = new JSONObject();
try {
outputObject.put(JsonKeys.updateType.name(),
"PublishKMLUpdate");
outputObject.put(JsonKeys.fileName.name(),
kmlFileName);
//publicKMLAddress + kmlFileName+".kml"); // save this line for using networkLink in GE plugin (see geospatial.js)
outputObject.put(JsonKeys.transferSuccessful.name(),
transfer);
outputObject.put(JsonKeys.localFileName.name(),
"publish/SpatialData/" + zippedSpatialDataPath);
pw.println(outputObject.toString(4));
} catch (JSONException e) {
logger.error("Error occured while generating JSON!");
}
}
});
} catch (FileNotFoundException e) {
logger.error("KML File not found!", e);
return new UpdateContainer(new ErrorUpdate(
"Error occurred while publishing KML layer!"));
} catch (Exception shapfileException) {
// TODO Auto-generated catch block
shapfileException.printStackTrace();
return new UpdateContainer(new ErrorUpdate(
"Error occurred while saving Shapefile!"));
}
}