List of usage examples for org.json.simple JSONObject containsKey
boolean containsKey(Object key);
From source file:formatter.handler.get.Version1Handler.java
/** * Get the version1 metadata item from the CORTEX BSON * @param conn the database connection// w ww. java 2 s . c o m * @throws CompareException if the database fetch failed */ void getMetadataFromCortex(Connection conn) throws FormatterException { try { String res = conn.getFromDb(Database.CORTEX, docid); JSONObject jObj2 = (JSONObject) JSONValue.parse(res); if (jObj2.containsKey(JSONKeys.VERSION1)) metadataValue = (String) jObj2.get(JSONKeys.VERSION1); else getMetadataFromObject(jObj2); } catch (Exception e) { throw new FormatterException(e); } }
From source file:formatter.handler.get.MetadataHandler.java
@Override public void handle(HttpServletRequest request, HttpServletResponse response, String urn) throws FormatterException { // we need the docid only // return the metadata for the document try {/* w ww. j a v a 2 s. com*/ this.docid = request.getParameter(Params.DOCID); Connection conn = Connector.getConnection(); String bson = conn.getFromDb(Database.METADATA, docid); if (bson != null) { JSONObject jObj = (JSONObject) JSONValue.parse(bson); JSONArray sources; if (jObj.containsKey(JSONKeys.SOURCES)) { sources = (JSONArray) jObj.get(JSONKeys.SOURCES); } else sources = new JSONArray(); response.setContentType("application/json"); response.getWriter().write(sources.toJSONString()); } } catch (Exception e) { throw new FormatterException(e); } }
From source file:mml.handler.MMLHandler.java
/** * Fetch one annotation from some database * @param conn the connection to the database * @param coll the database collection/*from w ww . j av a2 s. c o m*/ * @param docId the specific docid to match against * @return a JSONObject or null * @throws DbException */ protected JSONObject fetchAnnotation(Connection conn, String coll, String docId) throws DbException { String jDoc = conn.getFromDb(coll, docId); JSONObject jObj = (JSONObject) JSONValue.parse(jDoc); if (isAnnotation(jObj)) { if (jObj.containsKey(JSONKeys.VERSIONS)) { JSONArray versions = (JSONArray) jObj.get(JSONKeys.VERSIONS); if (versions.contains(version1)) return jObj; } } return null; }
From source file:net.jakobnielsen.imagga.crop_slice.convert.DivisionRegionConverter.java
@Override public List<DivisionRegion> convert(String jsonString) { if (jsonString == null) { throw new ConverterException("The given JSON string is null"); }/*from w ww .j av a2 s.c om*/ JSONObject json = (JSONObject) JSONValue.parse(jsonString); if (!json.containsKey(DIVISION_REGIONS)) { throw new ConverterException(DIVISION_REGIONS + " key missing from json : " + jsonString); } JSONArray jsonArray = (JSONArray) json.get(DIVISION_REGIONS); List<DivisionRegion> divisionRegions = new ArrayList<DivisionRegion>(); for (Object aJsonArray : jsonArray) { JSONObject divisionRegionObject = (JSONObject) aJsonArray; String url = getString("url", divisionRegionObject); List<Region> regions = new ArrayList<Region>(); if (divisionRegionObject.containsKey(REGIONS)) { if (divisionRegionObject.get(REGIONS) != null && divisionRegionObject.get(REGIONS) instanceof JSONArray) { JSONArray regionsArrays = (JSONArray) divisionRegionObject.get(REGIONS); for (Object aRegionsArray : regionsArrays) { JSONObject regionObject = (JSONObject) aRegionsArray; regions.add(new Region(getInteger("x1", regionObject), getInteger("y1", regionObject), getInteger("x2", regionObject), getInteger("y2", regionObject))); } divisionRegions.add(new DivisionRegion(url, regions)); } } } return divisionRegions; }
From source file:net.jakobnielsen.imagga.crop_slice.convert.SmartCroppingConverter.java
@Override public List<SmartCropping> convert(String jsonString) { if (jsonString == null) { throw new ConverterException("The given JSON string is null"); }//from w w w . ja v a2s .c o m JSONObject json = (JSONObject) JSONValue.parse(jsonString); if (!json.containsKey(SMART_CROPPINGS)) { throw new ConverterException(SMART_CROPPINGS + " key missing from json : " + jsonString); } JSONArray jsonArray = (JSONArray) json.get(SMART_CROPPINGS); List<SmartCropping> smartCroppings = new ArrayList<SmartCropping>(); for (Object aJsonArray : jsonArray) { JSONObject smartCroppingObject = (JSONObject) aJsonArray; String url = getString("url", smartCroppingObject); List<Cropping> croppings = new ArrayList<Cropping>(); if (smartCroppingObject.containsKey(CROPPINGS)) { JSONArray croppingsArray = (JSONArray) smartCroppingObject.get(CROPPINGS); for (Object aCroppingsArray : croppingsArray) { JSONObject croppingObject = (JSONObject) aCroppingsArray; croppings.add(new Cropping( new Resolution(getInteger("target_width", croppingObject), getInteger("target_height", croppingObject)), new Region(getInteger("x1", croppingObject), getInteger("y1", croppingObject), getInteger("x2", croppingObject), getInteger("y2", croppingObject)))); } smartCroppings.add(new SmartCropping(url, croppings)); } } return smartCroppings; }
From source file:mml.handler.get.MMLGetVersion1Handler.java
public void handle(HttpServletRequest request, HttpServletResponse response, String urn) throws MMLException { try {/* w ww.j ava 2s. c om*/ Connection conn = Connector.getConnection(); docid = request.getParameter(Params.DOCID); String res = conn.getFromDb(Database.CORTEX, docid); if (res != null) { JSONObject jObj = (JSONObject) JSONValue.parse(res); if (jObj.containsKey(JSONKeys.VERSION1)) { version1 = (String) jObj.get(JSONKeys.VERSION1); if (!Layers.isNewStyleLayer(version1)) { if (((String) jObj.get(JSONKeys.FORMAT)).startsWith("MVD")) { String body = (String) jObj.get(JSONKeys.BODY); if (body != null) { MVD mvd = MVDFile.internalise(body); String[] all = getAllVersions(mvd); version1 = Layers.upgradeLayerName(all, version1); } } else { String[] all = new String[1]; all[0] = version1; version1 = Layers.upgradeLayerName(all, version1); } } } else if (((String) jObj.get(JSONKeys.FORMAT)).startsWith("MVD")) { String body = (String) jObj.get(JSONKeys.BODY); if (body != null) { MVD mvd = MVDFile.internalise(body); String[] all = getAllVersions(mvd); String groupPath = mvd.getGroupPath((short) 1); String shortName = mvd.getVersionShortName((short) 1); version1 = Layers.upgradeLayerName(all, groupPath + "/" + shortName); jObj.put(JSONKeys.VERSION1, version1); jObj.remove(JSONKeys._ID); conn.putToDb(Database.CORTEX, docid, jObj.toJSONString()); } else version1 = ""; // nothing there } else version1 = "/base"; } else version1 = ""; response.setContentType("text/plain"); response.getWriter().write(version1.replaceAll("\\\\/", "/")); } catch (Exception e) { throw new MMLException(e); } }
From source file:compare.handler.get.MetadataHandler.java
/** * Get the version1 metadata item from the CORTEX BSON * @param conn the database connection// w w w. j a v a 2 s. c o m * @throws CompareException if the database fetch failed */ public void getMetadataFromCortex(Connection conn) throws CompareException { try { String res = conn.getFromDb(Database.CORTEX, docid); JSONObject jObj2 = (JSONObject) JSONValue.parse(res); if (jObj2.containsKey(metadataKey)) metadataValue = (String) jObj2.get(metadataKey); else getMetadataFromObject(jObj2); } catch (Exception e) { throw new CompareException(e); } }
From source file:copter.GpioControl.java
public String doAction(JSONObject jsonParam) { if (!jsonParam.containsKey("action")) { return "Missing 'action' param!"; }/*w w w . j a v a 2s .c om*/ String action = (String) jsonParam.get("action"); int pinNumber; int pinState; switch (action) { case Constants.GPIO_PULSE_ACTION: pinNumber = (int) (long) jsonParam.get("pin_number"); int durationMilliseconds = (int) (long) jsonParam.get("duration_milliseconds"); return this.pulsePin(pinNumber, durationMilliseconds); case Constants.GPIO_SET_PIN_STATE_ACTION: pinNumber = (int) (long) jsonParam.get("pin_number"); pinState = (int) (long) jsonParam.get("pin_state"); return this.setPinState(pinNumber, pinState != 0); case Constants.GPIO_TOGGLE_PIN_STATE_ACTION: pinNumber = (int) (long) jsonParam.get("pin_number"); return this.togglePinState(pinNumber); } return "Unknown 'action' param: " + action; }
From source file:com.dare2date.externeservice.lastfm.LastfmAPI.java
/** * Adds venue data to an event.//w w w .j av a2 s. c om * @param eventdata Raw event data from lastfm. * @param event An LastfmData object. */ private void addVenueDataToEvent(JSONObject eventdata, LastfmEvent event) { JSONObject venue = (JSONObject) eventdata.get("venue"); event.setVenueName(venue.get("name").toString()); JSONObject location = (JSONObject) venue.get("location"); if (location.containsKey("city")) { event.setCity(location.get("city").toString()); } if (location.containsKey("country")) { event.setCountry(location.get("country").toString()); } if (location.containsKey("street")) { event.setStreet(location.get("street").toString()); } }
From source file:com.opensoc.parsing.AbstractParserBolt.java
/** * @param parser//from w w w . j a va2 s .co m * The parser class for parsing the incoming raw message byte * stream * @return Instance of this class */ public boolean checkForSchemaCorrectness(JSONObject message) { int correct = 0; if (!(message.containsKey("original_string"))) { LOG.trace("[OpenSOC] Message does not have original_string: " + message); return false; } else if (!(message.containsKey("timestamp"))) { LOG.trace("[OpenSOC] Message does not have timestamp: " + message); return false; } else { LOG.trace("[OpenSOC] Message conforms to schema: " + message); return true; } }