}
@Override
public FileConversionActions convertFile(File file, JSONObject doc, CouchDesignDocument dd) throws Exception {
FileConversionActions actions = new FileConversionActions();
GpxFactory factory = new GpxFactory();
try {
Gpx gpx = factory.loadFromFile(file);
if( null == gpx ) {
throw new Exception("Conversion returns null object");
}
GpxConversionContext context = new GpxConversionContext();
context.setLayerName( doc.getString("_id") );
context.setSourceDocumentId( doc.getString("_id") );
context.setDesignDocument(dd);
// Creator
{
JSONObject creator = doc.optJSONObject("created");
if( null != creator ) {
context.setCreated(creator);
}
}
// Last Updated
{
JSONObject lastUpdated = doc.optJSONObject("lastUpdated");
if( null != lastUpdated ) {
context.setLastUpdated(lastUpdated);
}
}
convertGpx(context, gpx, doc);
actions.setDocumentModified(true);
// Upload original file
actions.addUploadAction( new FileConversionActionUpload("original", "application/xml", file) );
return actions;
} catch(Exception e) {
throw new Exception("Unable to convert using GPX: "+file.getAbsolutePath(),e);