@Override public void onSuccess(UserVerifierDto key) { String jsonConfig = key.getJsonConfiguration(); JSONObject json; //Some verifiers (ex:Trustful) has no jsonConfiguration field if (jsonConfig != null && !jsonConfig.isEmpty()) { json = (JSONObject) JSONParser.parseLenient(jsonConfig); } else { json = new JSONObject(); } json.put("pluginTypeName", new JSONString(key.getPluginTypeName())); json.put("pluginClassName", new JSONString(key.getPluginClassName())); ServletHelper.downloadJsonFile(json.toString(), key.getPluginTypeName() + ".json"); } };
@Override public void onSuccess(LogAppenderDto key) { JSONObject json = (JSONObject) JSONParser.parseLenient(key.getJsonConfiguration()); json.put("minLogSchemaVersion", new JSONNumber(key.getMinLogSchemaVersion())); json.put("maxLogSchemaVersion", new JSONNumber(key.getMaxLogSchemaVersion())); json.put("pluginTypeName", new JSONString(key.getPluginTypeName())); json.put("pluginClassName", new JSONString(key.getPluginClassName())); JSONArray headersStructure = new JSONArray(); for (LogHeaderStructureDto header : key.getHeaderStructure()) { headersStructure.set(headersStructure.size(), new JSONString(header.getValue())); } json.put("headerStructure", headersStructure); ServletHelper.downloadJsonFile(json.toString(), key.getPluginTypeName() + ".json"); } };
/** * Evaluates a trusted JSON string and returns its JSONValue representation. * CAUTION! This method calls the JavaScript <code>eval()</code> function, * which can execute arbitrary script. DO NOT pass an untrusted string into * this method. * * <p> * This method has been deprecated. Please call either * {@link #parseStrict(String)} (for inputs that strictly follow the JSON * specification) or {@link #parseLenient(String)}. The implementation of this * method calls parseLenient. * * @param jsonString a JSON object to parse * @return a JSONValue that has been built by parsing the JSON string * @throws NullPointerException if <code>jsonString</code> is * <code>null</code> * @throws IllegalArgumentException if <code>jsonString</code> is empty * * @deprecated use {@link #parseStrict(String)} or * {@link #parseLenient(String)} */ @Deprecated public static JSONValue parse(String jsonString) { return parseLenient(jsonString); }
/** * Evaluates a trusted JSON string and returns its JSONValue representation. * CAUTION! This method calls the JavaScript <code>eval()</code> function, * which can execute arbitrary script. DO NOT pass an untrusted string into * this method. * * <p> * This method has been deprecated. Please call either * {@link #parseStrict(String)} (for inputs that strictly follow the JSON * specification) or {@link #parseLenient(String)}. The implementation of this * method calls parseLenient. * * @param jsonString a JSON object to parse * @return a JSONValue that has been built by parsing the JSON string * @throws NullPointerException if <code>jsonString</code> is * <code>null</code> * @throws IllegalArgumentException if <code>jsonString</code> is empty * * @deprecated use {@link #parseStrict(String)} or * {@link #parseLenient(String)} */ @Deprecated public static JSONValue parse(String jsonString) { return parseLenient(jsonString); }
@Override public Object deserialize(String message) throws SerializationException { return deserialize(JSONParser.parseLenient(message)); }
@Override @SuppressWarnings("unchecked") public Map<String, List<MenuItemDescription>> decodeMenuItemsMap(String json) throws FormEncodingException { JSONObject jsonObj = JSONParser.parseLenient(json).isObject(); Map<String, Object> dataMap = asMap(jsonObj); Map<String, List<MenuItemDescription>> retval = null; if (dataMap != null) { retval = new HashMap<String, List<MenuItemDescription>>(); for (Map.Entry<String, Object> entry : dataMap.entrySet()) { List<MenuItemDescription> itemsList = new ArrayList<MenuItemDescription>(); String key = entry.getKey(); Object obj = entry.getValue(); if (obj != null) { List<Object> itemsMapList = (List<Object>) obj; for (Object itemObj : itemsMapList) { Map<String, Object> itemDescMap = (Map<String, Object>) itemObj; MenuItemDescription desc = new MenuItemDescription(); desc.setDataMap(itemDescMap); itemsList.add(desc); } } retval.put(key, itemsList); } } return retval; }
@Override public FormItemRepresentation decodeItem(String json) throws FormEncodingException { JSONValue jsonValue = JSONParser.parseLenient(json); if (jsonValue.isObject() != null) { JSONObject jsonObj = jsonValue.isObject(); Map<String, Object> dataMap = asMap(jsonObj); return (FormItemRepresentation) decode(dataMap); } else { throw new FormEncodingException("Expected JSON Object: " + jsonValue); } }
@Override public ModelNode get() { ModelNode node; if (contentType.startsWith(APPLICATION_DMR_ENCODED)) { node = ModelNode.fromBase64(payload); } else if (contentType.startsWith(APPLICATION_JSON)) { node = new ModelNode(); JSONObject response = JSONParser.parseLenient(payload).isObject(); JSONString outcome = response.get(OUTCOME).isString(); node.get(OUTCOME).set(outcome.stringValue()); if (outcome.stringValue().equals(SUCCESS)) { if (response.containsKey(RESULT) && response.get(RESULT).isObject() != null) { node.get(RESULT).set(stringify(response.get(RESULT).isObject().getJavaScriptObject(), 2)); } else { node.get(RESULT).set(new ModelNode()); } } else { String failure = extractFailure(response); node.get(FAILURE_DESCRIPTION).set(failure); } } else { node = new ModelNode(); node.get(OUTCOME).set(FAILED); node.get(FAILURE_DESCRIPTION).set("Unable to parse response with content-type " + contentType); } return node; }
private void handleCompleteJson(String reponseData) { if (Strings.isNullOrEmpty(reponseData)) { handleError("500", "Unable to post data"); } JSONObject jsObject = JSONParser.parseLenient(reponseData).isObject(); final FileDto file = new FileDto(); file.setName(jsObject.get("name").isString().stringValue()); file.setExtension(jsObject.get("extension").isString().stringValue()); file.setMime(jsObject.get("mime").isString().stringValue()); file.setToken(jsObject.get("token").isString().stringValue()); file.setContentLength((long) jsObject.get("contentLength").isNumber().doubleValue()); if (this.uploadForm != null) { this.uploadForm = this.uploadForm.destroy(); } this.sendRequest = null; this.fileId = null; this.progressBar.edit(this.progressBar.getMax()); Scheduler.get().scheduleFixedDelay(new RepeatingCommand() { @Override public boolean execute() { InputFile.this.edit(file); return false; } }, this.params.inputFileProgressHideDelay()); }
private void handleCompleteJson(String reponseData) { if (Strings.isNullOrEmpty(reponseData)) { handleError("500", "Unable to post data"); } JSONObject jsObject = JSONParser.parseLenient(reponseData).isObject(); final FileDto file = new FileDto(); file.setName(jsObject.get("name").isString().stringValue()); file.setExtension(jsObject.get("extension").isString().stringValue()); file.setMime(jsObject.get("mime").isString().stringValue()); file.setToken(jsObject.get("token").isString().stringValue()); file.setContentLength((long) jsObject.get("contentLength").isNumber().doubleValue()); if (this.uploadForm != null) { this.uploadForm = this.uploadForm.destroy(); } this.sendRequest = null; this.fileId = null; this.progressBar.edit(this.progressBar.getMax()); Scheduler.get().scheduleFixedDelay(new RepeatingCommand() { @Override public boolean execute() { InputFile.this.edit(file); return false; } }, this.params.inputFileProgressHideDelay()); }
@Override public FormRepresentation decode(String code) throws FormEncodingException { FormRepresentation form = new FormRepresentation(); JSONValue json = JSONParser.parseLenient(code); if (json.isObject() != null) { JSONObject jsonObj = json.isObject();