Directory directory(JSONObject json) throws IOException { if (json.has("location")) { return new Directory(new File(json.getString("location"))); } else { return Directory.createNew(importer.getUploadRoot()); } }
public ImportTask task() throws IOException { if (json.has("task")) { json = json.getJSONObject("task"); } ImportTask task = new ImportTask(); if (json.has("id")) { task.setId(json.getInt("id")); } if (json.has("updateMode")) { task.setUpdateMode(UpdateMode.valueOf(json.getString("updateMode").toUpperCase())); } JSONObject data = null; if (json.has("data")) { data = json.getJSONObject("data"); } else if (json.has("source")) { // backward compatible check for source data = json.getJSONObject("source"); } if (data != null) { // we only support updating the charset if (data.has("charset")) { if (task.getData() == null) { task.setData(new ImportData.TransferObject()); } task.getData().setCharsetEncoding(data.getString("charset")); } } if (json.has("target")) { task.setStore(fromJSON(json.getJSONObject("target"), StoreInfo.class)); } LayerInfo layer = null; if (json.has("layer")) { layer = layer(json.getJSONObject("layer")); } else { layer = importer.getCatalog().getFactory().createLayer(); } task.setLayer(layer); if (json.has("transformChain")) { task.setTransform(transformChain(json.getJSONObject("transformChain"))); } return task; }
LayerInfo layer(JSONObject json) throws IOException { CatalogFactory f = importer.getCatalog().getFactory(); if (json.has("layer")) { json = json.getJSONObject("layer"); } ResourceInfo r = f.createFeatureType(); if (json.has("name")) { r.setName(json.getString("name")); } if (json.has("nativeName")) { r.setNativeName(json.getString("nativeName")); } if (json.has("srs")) { r.setSRS(json.getString("srs")); try { r.setNativeCRS(CRS.decode(json.getString("srs"))); } catch (Exception e) { // should fail later } } if (json.has("bbox")) { r.setNativeBoundingBox(bbox(json.getJSONObject("bbox"))); } LayerInfo l = f.createLayer(); l.setResource(r); // l.setName(); don't need to this, layer.name just forwards to name of underlying resource if (json.has("style")) { JSONObject sobj = new JSONObject(); sobj.put("defaultStyle", json.get("style")); JSONObject lobj = new JSONObject(); lobj.put("layer", sobj); LayerInfo tmp = fromJSON(lobj, LayerInfo.class); if (tmp.getDefaultStyle() != null) { l.setDefaultStyle(tmp.getDefaultStyle()); } else { sobj = new JSONObject(); sobj.put("style", json.get("style")); l.setDefaultStyle(fromJSON(sobj, StyleInfo.class)); } } return l; }
Mosaic mosaic(JSONObject json) throws IOException { Mosaic m = new Mosaic( json.has("location") ? new File(json.getString("location")) : Directory.createNew(importer.getUploadRoot()).getFile()); if (json.has("name")) { m.setName(json.getString("name")); } if (json.containsKey("time")) { JSONObject time = json.getJSONObject("time"); if (!time.containsKey("mode")) { throw new IllegalArgumentException( "time object must specific mode property as " + "one of " + TimeMode.values()); } m.setTimeMode(TimeMode.valueOf(time.getString("mode").toUpperCase())); m.getTimeHandler().init(time); } return m; }
<T> T fromJSON(JSONObject json, Class<T> clazz) throws IOException { XStreamPersister xp = importer.createXStreamPersisterJSON(); return (T) xp.load(new ByteArrayInputStream(json.toString().getBytes()), clazz); }