@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"); } };
@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"); } };
private static JSONString getJsonString(String s) { if (s == null) { return new JSONString(""); } return new JSONString(s); }
private static JSONObject throwableAsJsonObject(Throwable t) { JSONObject obj = new JSONObject(); if (t != null) { obj.put("type", getJsonString(t.getClass().getName())); obj.put("message", getJsonString(t.getMessage())); obj.put("cause", throwableAsJsonObject(t.getCause())); StackTraceElement[] stackTrace = t.getStackTrace(); if (stackTrace != null && stackTrace.length > 0) { JSONArray arr = new JSONArray(); for (int i = 0; i < stackTrace.length; i++) { arr.set(i, stackTraceElementAsJsonObject(stackTrace[i])); } obj.put("stackTrace", arr); } } return obj; } }
public void addCell( String columnName, String value ) { JSONObject cell = new JSONObject(); cell.put( "column", new JSONString( columnName ) ); cell.put( "value", new JSONString( value ) ); row.set( row.size(), cell ); }
public Integer getTokenValueInt( String name ) { JSONValue value = values.get( name ); if( value == null ) return null; JSONNumber number = value.isNumber(); if( number == null ) return null; return (int) (number.doubleValue()); }
if ((jsonObject = jsonValue.isObject()) == null) { Window.alert("Error parsing the JSON"); if ((jsonArray = jsonValue.isArray()) == null) { Window.alert("Error parsing the JSON"); if ((jsonObject = jsonValue.isObject()) == null) { Window.alert("Error parsing the JSON"); if ((jsonString = jsonValue.isString()) == null) { Window.alert("Error parsing the JSON"); Window.alert(jsonString.stringValue()); // Finally!
private static JSONObject logRecordAsJsonObject(LogRecord lr) { JSONObject obj = new JSONObject(); obj.put("level", getJsonString(lr.getLevel().toString())); obj.put("loggerName", getJsonString(lr.getLoggerName())); obj.put("msg", getJsonString(lr.getMessage())); obj.put("timestamp", new JSONString("" + lr.getMillis())); obj.put("thrown", throwableAsJsonObject(lr.getThrown())); return obj; }
public void initToken( String token ) { try { values = JSONParser.parseStrict( token ).isObject(); } catch( Exception e ) { values = new JSONObject(); } }
public static List<Message> decodePayload(final String jsonString) { if (jsonString == null || jsonString.trim().length() == 0) return Collections.emptyList(); final JSONValue val = JSONParser.parseStrict(jsonString); if (val == null || val.isArray() == null) { throw new RuntimeException("illegal payload: must be JSONArray"); } final JSONArray jsonArray = val.isArray(); final List<Message> messageList = new ArrayList<Message>(jsonArray.size()); for (int i = 0; i < jsonArray.size(); i++) { messageList.add(decodeCommandMessage(GWTJSON.wrap(jsonArray.get(i)))); } return messageList; }
public static String getAsString(JSONValue jsonValue) { if (jsonValue == null) { return null; } JSONString jsonString; if ((jsonString = jsonValue.isString()) == null) { JSONNumber jsonNumber = jsonValue.isNumber(); return jsonNumber != null ? jsonNumber.toString() : null; } return jsonString.stringValue(); }
private static JSONObject stackTraceElementAsJsonObject( StackTraceElement e) { JSONObject obj = new JSONObject(); if (e != null) { obj.put("className", getJsonString(e.getClassName())); obj.put("fileName", getJsonString(e.getFileName())); obj.put("methodName", getJsonString(e.getMethodName())); obj.put("lineNumber", getJsonString("" + e.getLineNumber())); } return obj; }
public static Boolean getBoolean(JSONObject json, String field) { JSONValue jsonValue; JSONBoolean jsonBoolean; if ((jsonValue = json.get(field)) == null) { return null; } if ((jsonBoolean = jsonValue.isBoolean()) == null) { return null; } return jsonBoolean.booleanValue(); }
public static String logRecordAsJson(LogRecord lr) { return logRecordAsJsonObject(lr).toString(); }
public static JSONValue And( JSONValue... operands ) { JSONObject obj = new JSONObject(); obj.put( "op", new JSONString( "and" ) ); JSONArray ops = new JSONArray(); for( int i = 0; i < operands.length; i++ ) ops.set( i, operands[i] ); obj.put( "ops", ops ); return obj; }
public Integer getTokenValueInt( String name ) { JSONValue value = values.get( name ); if( value == null ) return null; JSONNumber number = value.isNumber(); if( number == null ) return null; return (int) (number.doubleValue()); }
public class SmartBean { private String name; public String getName() { return name; } public void setName(String value) { name = value; } public JSONObject toJson() { JSONObject result = new JSONObject(); result.put("name", new JSONString(this.name)); return result; } public void fromJson(JSONObject value) { this.name = value.get("name").isString().stringValue(); } }
public static String throwableAsJson(Throwable t) { return throwableAsJsonObject(t).toString(); }
public static JSONValue And( List<JSONValue> operands ) { JSONObject obj = new JSONObject(); obj.put( "op", new JSONString( "and" ) ); JSONArray ops = new JSONArray(); int i = 0; for( JSONValue op : operands ) ops.set( i++, op ); obj.put( "ops", ops ); return obj; }
public static Double getDouble(JSONObject json, String field) { JSONValue jsonValue; JSONNumber jsonNumber; if ((jsonValue = json.get(field)) == null) { return null; } if ((jsonNumber = jsonValue.isNumber()) == null) { return null; } return jsonNumber.doubleValue(); }