List of usage examples for org.json.simple JSONObject entrySet
Set<Map.Entry<K, V>> entrySet();
From source file:org.jitsi.videobridge.rest.JSONDeserializer.java
public static void deserializeParameters(JSONObject parameters, PayloadTypePacketExtension payloadTypeIQ) { if (parameters != null) { Iterator<Map.Entry<Object, Object>> i = parameters.entrySet().iterator(); while (i.hasNext()) { Map.Entry<Object, Object> e = i.next(); Object name = e.getKey(); Object value = e.getValue(); if ((name != null) || (value != null)) { payloadTypeIQ.addParameter(new ParameterPacketExtension((name == null) ? null : name.toString(), (value == null) ? null : value.toString())); }/*from ww w .ja v a2 s . co m*/ } } }
From source file:org.jolokia.handler.list.MBeanInfoData.java
private Object truncateJSONObject(JSONObject pValue, int pMaxDepth) { if (pMaxDepth == 0) { return 1; }/* www. j a v a2 s . c o m*/ JSONObject ret = new JSONObject(); Set<Map.Entry> entries = pValue.entrySet(); for (Map.Entry entry : entries) { Object value = entry.getValue(); Object key = entry.getKey(); if (value instanceof JSONObject) { ret.put(key, truncateJSONObject((JSONObject) value, pMaxDepth - 1)); } else { ret.put(key, value); } } return ret; }
From source file:org.kuali.hr.lm.leaveCalendar.LeaveCalendarWorkflowIntegrationTest.java
/** * Examines the JSON structure that is written to each output TimeDetails * page.//from w w w . jav a 2 s .c om * @param json The JSON Object to examine * @param thdList The (optional) list of Time Hour Details values * @param checkValues The list of values to check for in the JSON object * @return true if the JSON object contains the required values, false otherwise. */ public static boolean checkJSONValues(JSONObject json, List<Map<String, Object>> thdList, Map<String, Object> checkValues) { boolean contains = false; for (Object eso : json.entrySet()) { // This is the outer TimeBlock ID -> Time Block Data mapping Map.Entry e = (Map.Entry) eso; JSONObject innerMap = (JSONObject) e.getValue(); // the values we actually care about. boolean localContains = true; for (Map.Entry<String, Object> cve : checkValues.entrySet()) { Object joValue = innerMap.get(cve.getKey()); Object cvValue = cve.getValue(); // Null Checks.. if (cvValue == null && joValue == null) localContains &= true; else if (joValue == null || cvValue == null) localContains = false; else localContains &= StringUtils.equals(joValue.toString(), cvValue.toString()); } contains |= localContains; } return contains; }
From source file:org.kuali.hr.time.workflow.TimesheetWebTestBase.java
/** * Examines the JSON structure that is written to each output TimeDetails * page./*from w w w. j ava 2 s . c om*/ * @param json The JSON Object to examine * @param thdList The (optional) list of Time Hour Details values * @param checkValues The list of values to check for in the JSON object * @return true if the JSON object contains the required values, false otherwise. */ public static boolean checkJSONValues(JSONObject json, List<Map<String, Object>> thdList, Map<String, Object> checkValues) { boolean contains = false; for (Object eso : json.entrySet()) { // This is the outer TimeBlock ID -> Time Block Data mapping Map.Entry e = (Map.Entry) eso; JSONObject innerMap = (JSONObject) e.getValue(); // the values we actually care about. boolean localContains = true; for (Map.Entry<String, Object> cve : checkValues.entrySet()) { Object joValue = innerMap.get(cve.getKey()); Object cvValue = cve.getValue(); // Null Checks.. if (cvValue == null && joValue == null) localContains &= true; else if (joValue == null || cvValue == null) localContains = false; else localContains &= StringUtils.equals(joValue.toString(), cvValue.toString()); } // Check Time Hour Details if (localContains && thdList != null) { JSONArray thdjarray = (JSONArray) JSONValue.parse((String) innerMap.get("timeHourDetails")); // For each user provided THD check element for (Map<String, Object> u_thd_o : thdList) { // Look at each Inner TimeHourDetails Map boolean thd_l = false; for (final Object o : thdjarray) { thd_l |= checkJSONValues(new JSONObject() { { put("outer", o); } }, null, u_thd_o); } localContains &= thd_l; } } contains |= localContains; } return contains; }
From source file:org.o3project.odenos.remoteobject.rest.servlet.SubscriptionsServlet.java
@SuppressWarnings("unchecked") private Map<String, Set<String>> deserialize(String reqBody) { JSONObject reqMap; try {/*from w w w. j a va 2 s. c o m*/ reqMap = (JSONObject) JSONValue.parseWithException(reqBody); } catch (Exception e) { return null; } if (reqMap == null) { return null; } Map<String, Set<String>> result = new HashMap<String, Set<String>>(); for (Entry<String, ?> entry : (Set<Entry<String, ?>>) reqMap.entrySet()) { Object value = entry.getValue(); if (!(value instanceof List<?>)) { return null; } Set<String> eventTypeSet = new HashSet<String>(); List<?> reqList = (List<?>) value; for (Object eventType : reqList) { if (!(eventType instanceof String)) { return null; } eventTypeSet.add((String) eventType); } if (!eventTypeSet.isEmpty()) { result.put(entry.getKey(), eventTypeSet); } } return result; }
From source file:org.opencastproject.metadata.dublincore.DublinCoreCatalogImpl.java
/** * Reads values from a JSON object//from w w w .j a va 2 s. co m * * @param json * the json object representing the dublin core catalog * @return the dublin core catalog */ @SuppressWarnings("unchecked") protected void readFromJsonObject(JSONObject json) { Set<Entry<String, JSONObject>> namespaceEntrySet = json.entrySet(); for (Entry<String, JSONObject> namespaceEntry : namespaceEntrySet) { // e.g. http://purl.org/dc/terms/ String namespace = namespaceEntry.getKey(); // String prefix = bindings.lookupPrefix(namespace); JSONObject namespaceObj = namespaceEntry.getValue(); Set<Entry<String, JSONArray>> entrySet = namespaceObj.entrySet(); for (Entry<String, JSONArray> entry : entrySet) { // e.g. title String key = entry.getKey(); JSONArray values = entry.getValue(); for (Object valueObject : values) { JSONObject value = (JSONObject) valueObject; // e.g. English title // the value String valueString = (String) value.get("value"); // the language String lang = (String) value.get("lang"); if (lang == null) { lang = LANGUAGE_UNDEFINED; } // the encoding scheme String encodingSchemeString = (String) value.get("type"); EName encodingScheme = null; if (encodingSchemeString != null) { encodingScheme = this.toEName(encodingSchemeString); } // add the new value to this DC document this.add(new EName(namespace, key), valueString, lang, encodingScheme); } } } }
From source file:org.ScripterRon.BitcoinMonitor.Utils.java
/** * Create a formatted string for a JSON structure * * @param builder String builder * @param indent Output indentation * @param object The JSON object *//*from ww w . ja v a 2 s .c o m*/ private static void formatJSON(StringBuilder builder, String indent, JSONAware object) { String itemIndent = indent + " "; if (object instanceof JSONArray) { JSONArray array = (JSONArray) object; builder.append(indent).append("[\n"); array.stream().forEach((value) -> { if (value == null) { builder.append(itemIndent).append("null").append('\n'); } else if (value instanceof Boolean) { builder.append(itemIndent).append((Boolean) value ? "true\n" : "false\n"); } else if (value instanceof Long) { builder.append(itemIndent).append(((Long) value).toString()).append('\n'); } else if (value instanceof Double) { builder.append(itemIndent).append(((Double) value).toString()).append('\n'); } else if (value instanceof String) { builder.append(itemIndent).append('"').append((String) value).append("\"\n"); } else if (value instanceof JSONAware) { builder.append('\n'); formatJSON(builder, itemIndent + " ", (JSONAware) value); } else { builder.append(itemIndent).append("Unknown\n"); } }); builder.append(indent).append("]\n"); } else { builder.append(indent).append("{\n"); JSONObject map = (JSONObject) object; Iterator<Map.Entry> it = map.entrySet().iterator(); while (it.hasNext()) { Map.Entry entry = it.next(); builder.append(itemIndent).append("\"").append((String) entry.getKey()).append("\": "); Object value = entry.getValue(); if (value == null) { builder.append("null").append('\n'); } else if (value instanceof Boolean) { builder.append((Boolean) value ? "true\n" : "false\n"); } else if (value instanceof Long) { builder.append(((Long) value).toString()).append('\n'); } else if (value instanceof Double) { builder.append(((Double) value).toString()).append('\n'); } else if (value instanceof String) { builder.append('"').append((String) value).append("\"\n"); } else if (value instanceof JSONAware) { builder.append('\n'); formatJSON(builder, itemIndent + " ", (JSONAware) value); } else { builder.append("Unknown\n"); } } builder.append(indent).append("}\n"); } }
From source file:org.webservice.fotolia.FotoliaApi.java
/** * Returns the list of subaccount IDs of the given api key * * @return ArrayList<Long>/*from w ww . j av a2 s . c om*/ */ public ArrayList<Long> subaccountGetIds() { JSONObject response; Iterator iter; ArrayList<Long> ids; Map.Entry entry; response = this._api("user/subaccount/getIds"); iter = response.entrySet().iterator(); ids = new ArrayList<Long>(); while (iter.hasNext()) { entry = (Map.Entry) iter.next(); ids.add(Long.parseLong((String) entry.getValue())); } return ids; }
From source file:org.wso2.carbon.apimgt.hostobjects.APIStoreHostObject.java
/** * this method used to iterate environments according to type * @param environments json// www . j a va 2s .c om * @param api API object of selected api . * @param version version of API * @param myn * @param envCount count parameter * @param type type of environment */ private static int createAPIEndpointsPerType(JSONObject environments, API api, String version, NativeArray myn, int envCount, String type) { for (Object prodKeys : environments.keySet()) { JSONObject environmentObject = (JSONObject) environments.get(prodKeys); NativeObject appObj = new NativeObject(); appObj.put("environmentName", appObj, prodKeys); appObj.put("environmentType", appObj, type); NativeArray envs = new NativeArray(0); int index = 0; for (Object envURL : environmentObject.entrySet()) { envs.put(index, envs, envURL + api.getContext()); if (api.isDefaultVersion()) { String apiContext = api.getContext(); apiContext = apiContext.replace(version + "/", ""); envs.put(++index, envs, envURL + apiContext); } index++; appObj.put("environmentURLs", appObj, envs); myn.put(envCount, myn, appObj); } } envCount++; return envCount; }
From source file:org.wso2.carbon.apimgt.impl.definitions.APIDefinitionFromOpenAPISpec.java
@Override public String generateAPIDefinition(API api, String swagger) throws APIManagementException { JSONParser parser = new JSONParser(); try {// w w w. j ava 2s . c o m JSONObject swaggerObj = (JSONObject) parser.parse(swagger); //Generates below model using the API's URI template // path -> [verb1 -> template1, verb2 -> template2, ..] Map<String, Map<String, URITemplate>> uriTemplateMap = getURITemplateMap(api); JSONObject pathsJsonObj = (JSONObject) swaggerObj.get(APIConstants.SWAGGER_PATHS); Iterator pathEntriesIterator = pathsJsonObj.entrySet().iterator(); while (pathEntriesIterator.hasNext()) { Object pathObj = pathEntriesIterator.next(); Map.Entry pathEntry = (Map.Entry) pathObj; String pathName = (String) pathEntry.getKey(); JSONObject pathJsonObj = (JSONObject) pathEntry.getValue(); Map<String, URITemplate> uriTemplatesForPath = uriTemplateMap.get(pathName); if (uriTemplatesForPath == null) { //remove paths that are not in URI Templates pathEntriesIterator.remove(); } else { Iterator operationEntriesIterator = pathJsonObj.entrySet().iterator(); while (operationEntriesIterator.hasNext()) { Object operationObj = operationEntriesIterator.next(); Map.Entry operationEntry = (Map.Entry) operationObj; String verb = (String) operationEntry.getKey(); JSONObject operationJsonObj = (JSONObject) operationEntry.getValue(); URITemplate template = uriTemplatesForPath.get(verb.toUpperCase()); if (template == null) { // if particular operation is not available in URI templates, then remove it from swagger operationEntriesIterator.remove(); } else { // if operation is available in URI templates, update swagger operation // with auth type, scope etc updateOperationManagedInfo(template, operationJsonObj); } } // if there are any verbs (operations) exists in uri template not defined in current path item // (pathJsonObj) in swagger then add them for (Map.Entry<String, URITemplate> uriTemplatesForPathEntry : uriTemplatesForPath.entrySet()) { String verb = uriTemplatesForPathEntry.getKey(); URITemplate uriTemplate = uriTemplatesForPathEntry.getValue(); JSONObject operationJsonObj = (JSONObject) pathJsonObj.get(verb.toLowerCase()); if (operationJsonObj == null) { operationJsonObj = createOperationFromTemplate(uriTemplate); pathJsonObj.put(verb.toLowerCase(), operationJsonObj); } } } } // add to swagger if there are any new path templates for (Map.Entry<String, Map<String, URITemplate>> uriTemplateMapEntry : uriTemplateMap.entrySet()) { String path = uriTemplateMapEntry.getKey(); Map<String, URITemplate> verbMap = uriTemplateMapEntry.getValue(); if (pathsJsonObj.get(path) == null) { for (Map.Entry<String, URITemplate> verbMapEntry : verbMap.entrySet()) { URITemplate uriTemplate = verbMapEntry.getValue(); addOrUpdatePathsFromURITemplate(pathsJsonObj, uriTemplate); } } } return swaggerObj.toJSONString(); } catch (ParseException e) { throw new APIManagementException("Error while parsing swagger definition", e); } }