List of usage examples for org.json.simple JSONObject keySet
Set<K> keySet();
From source file:org.jaggeryjs.jaggery.app.mgt.TomcatJaggeryWebappsDeployer.java
private static void addParameters(Context context, JSONObject obj) { if (obj != null) { Iterator<?> keys = obj.keySet().iterator(); while (keys.hasNext()) { String key = (String) keys.next(); if (obj.get(key) instanceof String) { context.addParameter(key, (String) obj.get(key)); }// w w w . j a v a 2s.c o m } } }
From source file:org.jaggeryjs.jaggery.core.manager.JaggeryDeployerManager.java
private static void addParameters(Context context, JSONObject obj) { if (obj != null) { Iterator<?> keys = obj.keySet().iterator(); while (keys.hasNext()) { String key = (String) keys.next(); if (obj.get(key) instanceof String) { context.addParameter(key, (String) obj.get(key)); }//from w w w.j av a 2 s.c om } } }
From source file:org.jasig.ssp.reference.ChallengeIT.java
private final boolean checkChallengeResponseEqualToExpected(final JSONObject expected, final Map actual) { boolean result = false; if (expected.keySet().size() != actual.keySet().size()) { if (expected.keySet().size() > actual.keySet().size()) { fail("JSON Expected size is greater than actual! Check for missing values in returned JSON or " + "non-updated test data structure."); } else {/* w ww . j a v a 2s . c o m*/ fail("JSON Expected size is less than actual! Check for improper or non-updated test data JSON " + "structure."); } } else if (!expected.keySet().containsAll(actual.keySet())) { fail("JSON Names don't match! Check for improper or non-updated test data JSON structure"); } else { for (Object nameIndex : expected.keySet()) { if (!nameIndex.toString().equals("challengeChallengeReferrals") && !nameIndex.toString().equals("selfHelpGuideQuestions")) { try { if (!expected.get(nameIndex).equals(actual.get(nameIndex))) { fail("JSON Doesn't match for Challenge : " + expected.get("name") + "! Name : " + nameIndex.toString() + " value does not match."); } } catch (NullPointerException npe) { if (actual.get(nameIndex) != null) { fail("JSON Doesn't match for Challenge: " + expected.get("name") + " in name " + nameIndex.toString() + " value is not null. Actual value is " + actual.get(nameIndex) + ". "); } } } else { ArrayList expectedList = (ArrayList) expected.get(nameIndex); ArrayList actualList = (ArrayList) actual.get(nameIndex); if (expectedList.size() != actualList.size()) { fail("Expected JSONArray length doesn't match for " + expected.get("name") + " in value " + nameIndex.toString() + ". Expected: " + expectedList.size() + " and " + "Actual: " + actualList.size() + ". "); } else { for (Object listIndex : expectedList) { if (!expectedList.contains(listIndex)) { fail("Expected JSONArray value(s) don't match for " + expected.get("name") + " in name " + nameIndex.toString() + ". The arraylist value of concern is: " + ((JSONObject) listIndex).get("name") + ". "); } } } result = true; } } } return result; }
From source file:org.jboss.aerogear.unifiedpush.service.util.FCMTopicManager.java
public Set<String> getSubscribedCategories(Installation installation) { String url = IID_URL + "info/" + installation.getDeviceToken() + "?details=true"; String deviceInfo;// w w w . j a v a2s . c o m try { deviceInfo = get(url); } catch (IOException e) { logger.debug("Couldn't get list of subscribed topics from Instance ID service."); return Collections.emptySet(); } JSONParser parser = new JSONParser(); JSONObject info; try { info = (JSONObject) parser.parse(deviceInfo); } catch (ParseException e) { logger.debug("Couldn't parse list of subscribed topics from Instance ID service."); return Collections.emptySet(); } JSONObject rel = (JSONObject) info.get("rel"); if (rel == null) { logger.debug("Couldn't parse rel object Instance ID service."); return Collections.emptySet(); } JSONObject topics = (JSONObject) rel.get("topics"); return topics.keySet(); }
From source file:org.jenkinsci.plugins.drupal.beans.DrushInvocation.java
/** * Get a map of projects installed on Drupal, keyed by machine name. *//*from w ww.j a v a 2 s . c o m*/ public Map<String, DrupalExtension> getProjects(boolean modulesOnly, boolean enabledOnly) { ArgumentListBuilder args = getArgumentListBuilder(); args.add("pm-list").add("--pipe").add("--format=json"); if (modulesOnly) { args.add("--type=module"); } if (enabledOnly) { args.add("--status=enabled"); } OutputStream json = new ByteArrayOutputStream(); try { execute(args, new StreamTaskListener(json)); } catch (IOException e1) { listener.getLogger().println(e1); return MapUtils.EMPTY_MAP; } catch (InterruptedException e2) { listener.getLogger().println(e2); return MapUtils.EMPTY_MAP; } Map<String, DrupalExtension> projects = new HashMap<String, DrupalExtension>(); JSONObject entries = (JSONObject) JSONValue.parse(json.toString()); if (entries == null) { listener.getLogger().println("[DRUPAL] Could not list available projects"); return MapUtils.EMPTY_MAP; } for (Object name : entries.keySet()) { JSONObject entry = (JSONObject) entries.get(name); DrupalExtension project = new DrupalExtension(Objects.toString(name, ""), Objects.toString(entry.get("type"), ""), Objects.toString(entry.get("status"), ""), Objects.toString(entry.get("version"), "")); projects.put(name.toString(), project); } return projects; }
From source file:org.jitsi.jicofo.log.EventFactory.java
/** * Parses <tt>statsStr</tt> as JSON in the format used by Jitsi Meet, and * returns an Object[][] containing the values to be used in an * <tt>Event</tt> for the given JSON. * @param conferenceId the value to use for the conference_id field. * @param endpointId the value to use for the endpoint_id field. * @param statsStr the PeerConnection JSON string. * @return an Object[][] containing the values to be used in an * <tt>Event</tt> for the given JSON. * @throws Exception if parsing fails for any reason. *//*from w ww . jav a2 s . co m*/ private static Object[] parsePeerConnectionStats(String conferenceId, String endpointId, String statsStr) throws Exception { // An example JSON in the format that we expect: // { // "timestamps": [1, 2, 3], // "stats": { // "group1": { // "type": "some string", // "stat1": ["some", "values", ""] // "stat2": ["some", "more", "values"] // }, // "bweforvideo": { // "type":"VideoBwe", // "googActualEncBitrate": ["12","34","56"], // "googAvailableSendBandwidth": ["78", "90", "12"] // } // } // } // time: 1 // conference_id: blabla // endpoint_id: blabla // value: [ // ["group1", "some string", {"stat1": "some", "stat2": "some"}], // ["bweforvideo", "VideoBwe", {"googActualEncBitrate": "12", "googAvailableSendBandwidth": "78"}] // ] JSONParser parser = new JSONParser(); JSONObject jsonObject = (JSONObject) parser.parse(statsStr); List<Object[]> values = new LinkedList<Object[]>(); JSONArray timestamps = (JSONArray) jsonObject.get("timestamps"); JSONObject stats = (JSONObject) jsonObject.get("stats"); for (int i = 0; i < timestamps.size(); i++) { long timestamp = (Long) timestamps.get(i); JSONArray value = new JSONArray(); for (Object groupName : stats.keySet()) { JSONArray groupValue = new JSONArray(); JSONObject group = ((JSONObject) stats.get(groupName)); Object type = group.get("type"); groupValue.add(groupName); groupValue.add(type); JSONObject s = new JSONObject(); for (Object statName : group.keySet()) { if ("type".equals(statName)) continue; JSONArray statValues = (JSONArray) group.get(statName); s.put(statName, statValues.get(i)); } groupValue.add(s); value.add(groupValue); } Object[] point = new Object[LoggingHandler.PEER_CONNECTION_STATS_COLUMNS.length]; point[0] = timestamp; point[1] = conferenceId; point[2] = endpointId; point[3] = value.toJSONString(); values.add(point); } return values.toArray(); }
From source file:org.jitsi.videobridge.rest.JSONDeserializer.java
public static ShutdownIQ deserializeShutdownIQ(JSONObject requestJSONObject) { String element = (String) requestJSONObject.keySet().iterator().next(); return ShutdownIQ.isValidElementName(element) ? ShutdownIQ.createShutdownIQ(element) : null; }
From source file:org.jolokia.client.request.J4pReadResponse.java
/** * Get all MBean names for which the request fetched values. If the request * contained an MBean pattern then all MBean names matching this pattern and which contained * attributes of the given name are returned. If the MBean wasnt a pattern a single * value collection with the single MBean name of the request is returned. * * @return list of MBean names//from w w w . j a v a 2 s .co m * @throws MalformedObjectNameException if the returned MBean names could not be converted to * {@link ObjectName}s. Shouldnt occur, though. */ public Collection<ObjectName> getObjectNames() throws MalformedObjectNameException { ObjectName mBean = getRequest().getObjectName(); if (mBean.isPattern()) { // The result value contains the list of fetched object names JSONObject values = getValue(); Set<ObjectName> ret = new HashSet<ObjectName>(); for (Object name : values.keySet()) { ret.add(new ObjectName((String) name)); } return ret; } else { return Arrays.asList(mBean); } }
From source file:org.jolokia.client.request.J4pReadResponse.java
/** * Get the name of all attributes fetched for a certain MBean name. If the request was * performed for a single MBean, then the given name must match that of the MBean name * provided in the request. If <code>null</code> is given as argument, then this method * will return all attributes for the single MBean given in the request * * @param pObjectName MBean for which to get the attribute names, * @return a collection of attribute names *//*from w ww . ja v a 2s . co m*/ public Collection<String> getAttributes(ObjectName pObjectName) { ObjectName requestMBean = getRequest().getObjectName(); if (requestMBean.isPattern()) { // We need to got down one level in the returned values JSONObject attributes = getAttributesForObjectNameWithPatternRequest(pObjectName); return attributes.keySet(); } else { if (pObjectName != null && !pObjectName.equals(requestMBean)) { throw new IllegalArgumentException("Given ObjectName " + pObjectName + " doesn't match with" + " the single ObjectName " + requestMBean + " given in the request"); } return getAttributes(); } }
From source file:org.jolokia.client.request.J4pReadResponse.java
/** * Get all attributes obtained. This method can be only used, if the requested MBean * was not a pattern (i.e. the request was for a single MBean). * * @return a list of attributes for this request. If the request was performed for * only a single attribute, the attribute name of the request is returend as * a single valued list. For more than one attribute, the attribute names * a returned from the returned list. *//*from w ww . j av a2s . c om*/ public Collection<String> getAttributes() { J4pReadRequest request = getRequest(); ObjectName requestBean = request.getObjectName(); if (requestBean.isPattern()) { throw new IllegalArgumentException("Attributes can be fetched only for non-pattern request (current: " + requestBean.getCanonicalName() + ")"); } // The attribute names are the same as from the request if (request.hasSingleAttribute()) { // Contains only a single attribute: return request.getAttributes(); } else { JSONObject attributes = getValue(); return attributes.keySet(); } }