List of usage examples for com.google.gwt.json.client JSONValue toString
@Override public abstract String toString();
From source file:fr.insalyon.creatis.vip.warehouse.client.view.WarehouseListTab.java
License:Open Source License
private void readJSON(String jslist, TreeItem parent) { JSONValue value = JSONParser.parseStrict(jslist); JSONObject jobj = value.isObject();/* w w w .ja v a2 s .co m*/ for (String key : jobj.keySet()) { JSONValue jsonValue = jobj.get(key); TreeItem item = new TreeItem("<b>" + key + "</b> "); parent.addItem(item); if (jsonValue != null) { if (jsonValue.isObject() != null) { readJSON(jsonValue.isObject().toString(), item); } else if (jsonValue.isArray() != null) { } else { if ("oldValue".equals(key)) { item.setHTML("<b>before:</b> " + jsonValue.toString()); } else { item.setHTML("<b>after:</b> " + jsonValue.toString()); } } } else { item.setText("<b>" + item.getText() + ":</b> null"); } } }
From source file:my.plugin.ide.editor.StringListUnmarshaller.java
License:Open Source License
public List<String> toList(String jsonStr) { JSONValue parsed = JSONParser.parseStrict(jsonStr); JSONArray jsonArray = parsed.isArray(); if (jsonArray == null) { return Collections.emptyList(); }/*w ww.j av a2 s .c o m*/ List<String> list = new ArrayList<>(); for (int i = 0; i < jsonArray.size(); i++) { JSONValue jsonValue = jsonArray.get(i); JSONString jsonString = jsonValue.isString(); String stringValue = (jsonString == null) ? jsonValue.toString() : jsonString.stringValue(); list.add(stringValue); } return list; }
From source file:nl.sense_os.commonsense.main.client.viz.panels.table.SensorDataGrid.java
License:Open Source License
private String renderJsonValue(JSONObject json) { LOG.finest("Render JSON value: " + json.toString()); StringBuilder sb = new StringBuilder(); for (String key : json.keySet()) { // first print the field label sb.append("<b>").append(key).append(":</b> "); // get the field value JSONValue value = json.get(key); JSONString jsonString = value.isString(); String valueString = ""; if (null != jsonString) { valueString = jsonString.stringValue(); } else {// w w w . java 2 s. c om valueString = value.toString(); } sb.append(valueString).append("<br />"); } return sb.toString(); }
From source file:nl.strohalm.cyclos.mobile.client.model.Parameters.java
License:Open Source License
/** * Parses current JSONObject list and set the outputs in the given StringBuilder *//*from w w w . j a v a 2 s . c om*/ private String parseJSONObjectList() { StringBuilder sb = new StringBuilder(); String keyPrefix = ""; if (objectList != null) { for (String key : objectList.keySet()) { String objectPrefix = ""; StringBuilder sb2 = new StringBuilder(); sb.append(keyPrefix); sb2.append("["); JSONArray objects = objectList.get(key); for (int i = 0; i < objects.size(); i++) { try { JSONValue value = objects.get(i); sb2.append(objectPrefix); objectPrefix = ","; sb2.append(value.toString()); } catch (ClassCastException e) { //Ignore } } sb2.append("]"); sb.append(pairToJSON(key, sb2.toString(), false)); } } return sb.toString(); }
From source file:org.broadleafcommerce.openadmin.client.datasource.dynamic.module.BasicClientEntityModule.java
License:Apache License
protected void buildCriteria(JSONArray criteriaArray, CriteriaTransferObject cto) { if (criteriaArray != null) { for (int i = 0; i <= criteriaArray.size() - 1; i++) { JSONObject itemObj = criteriaArray.get(i).isObject(); if (itemObj != null) { JSONValue val = itemObj.get("fieldName"); if (val == null) { JSONArray array = itemObj.get("criteria").isArray(); buildCriteria(array, cto); } else { FilterAndSortCriteria filterCriteria = cto.get(val.isString().stringValue()); String[] items = filterCriteria.getFilterValues(); String[] newItems = new String[items.length + 1]; int j = 0; for (String item : items) { newItems[j] = item; j++;//w ww. j a v a 2 s . com } JSONValue value = itemObj.get("value"); newItems[j] = value.toString(); newItems[j] = newItems[j].replaceAll("\"", ""); String fieldTypeVal = null; DataSourceField field = dataSource.getField(val.isString().stringValue()); if (field != null) { fieldTypeVal = field.getAttribute("fieldType"); } SupportedFieldType fieldType = fieldTypeVal == null ? SupportedFieldType.STRING : SupportedFieldType.valueOf(fieldTypeVal); if (fieldType != null) { switch (fieldType) { case DECIMAL: processFilterValueClause(filterCriteria, newItems[j]); break; case INTEGER: processFilterValueClause(filterCriteria, newItems[j]); break; case MONEY: processFilterValueClause(filterCriteria, newItems[j]); break; case DATE: if (newItems.length > 1) { for (int x = 0; x < newItems.length; x++) { newItems[x] = updateMinutesFromDateFilter(newItems[x], x); } filterCriteria.setFilterValues(newItems); } else { String[] dateItems = new String[2]; JSONValue operator = itemObj.get("operator"); String op = operator.isString().stringValue(); if (op.startsWith("greater")) { dateItems[0] = newItems[0]; dateItems[1] = null; } else { dateItems[0] = null; dateItems[1] = newItems[0]; } for (int x = 0; x < dateItems.length; x++) { dateItems[x] = updateMinutesFromDateFilter(dateItems[x], x); } filterCriteria.setFilterValues(dateItems); } break; default: filterCriteria.setFilterValues(newItems); break; } } else { filterCriteria.setFilterValues(newItems); } } } } } }
From source file:org.datacleaner.monitor.shared.widgets.FileUploadFunctionHandler.java
License:Open Source License
public static void uploadFile(String fileUploadElementId) { final Element element = Document.get().getElementById(fileUploadElementId); final InputElement inputElement = getFileInput(element); if (inputElement == null) { throw new IllegalArgumentException("No file input found within element id: " + fileUploadElementId); }/*from w w w . j a v a2 s.co m*/ GWT.log("Found file input element: " + inputElement); final String inputName = inputElement.getName(); final Element parent = inputElement.getParentElement(); parent.setInnerHTML("<div class='loader'></div>"); // use "contentType" param because form submission requires everything // to be text/html final String url = Urls.createRelativeUrl("util/upload?contentType=text/html"); final RootPanel rootPanel = RootPanel.get(); final FormPanel form = new FormPanel(); form.setVisible(false); form.setAction(url); form.setMethod(FormPanel.METHOD_POST); form.setEncoding(FormPanel.ENCODING_MULTIPART); form.getElement().appendChild(inputElement); form.addSubmitCompleteHandler(new SubmitCompleteHandler() { @Override public void onSubmitComplete(SubmitCompleteEvent event) { final String stringResponse = event.getResults(); GWT.log("File upload form submit complete! Results: " + stringResponse); try { final JSONValue jsonResponse = JSONParser.parseLenient(stringResponse); final JSONArray jsonFiles = jsonResponse.isObject().get("files").isArray(); final JSONValue jsonFile = jsonFiles.get(0); final String jsonFileStr = jsonFile.toString(); parent.setInnerHTML("<p>File uploaded!</p><input type='hidden' name='" + inputName + "' value='" + jsonFileStr + "' />"); rootPanel.remove(form); } catch (Exception e) { ErrorHandler.showErrorDialog("Unexpected error occurred", "An error occurred when uploading the file to the server.", stringResponse); } } }); rootPanel.add(form); GWT.log("Submitting hidden file upload form"); form.submit(); }
From source file:org.eclipse.che.ide.editor.preferences.editorproperties.property.EditorNumberPropertyWidget.java
License:Open Source License
@Override public void setValue(JSONValue value) { propertyValueBox.setValue(value.toString()); }
From source file:org.eclipse.che.ide.editor.preferences.editorproperties.property.EditorPropertyWidgetFactory.java
License:Open Source License
/** * Creates one of implementations of {@link EditorPropertyWidget}. * * @return an instance of {@link EditorPropertyWidget} *//* ww w . j a va 2 s . c o m*/ public EditorPropertyWidget create(@NotNull String propertyName, @NotNull JSONValue value) { if (value.isBoolean() != null) { return new EditorBooleanPropertyWidget(propertyName, value.isBoolean().booleanValue()); } if (value.isNumber() != null) { Double doubleValue = value.isNumber().doubleValue(); return new EditorNumberPropertyWidget(propertyName, doubleValue.intValue()); } return new EditorStringPropertyWidget(propertyName, value.toString()); }
From source file:org.eclipse.che.ide.json.JsonHelper.java
License:Open Source License
public static Map<String, String> toMap(String jsonStr) { Map<String, String> map = new HashMap<String, String>(); JSONValue parsed = JSONParser.parseStrict(jsonStr); JSONObject jsonObj = parsed.isObject(); if (jsonObj != null) { for (String key : jsonObj.keySet()) { JSONValue jsonValue = jsonObj.get(key); JSONString jsonString = jsonValue.isString(); // if the json value is a string, set the unescaped value, else set the json representation of the value String stringValue = (jsonString == null) ? jsonValue.toString() : jsonString.stringValue(); map.put(key, stringValue);//from ww w . j a va2 s . c o m } } return map; }
From source file:org.eclipse.che.ide.jsonrpc.impl.ResponseDispatcher.java
License:Open Source License
private void processError(final String endpointId, final String id, final JSONValue error) { rejectFunctions.get(endpointId + '@' + id).apply(new PromiseError() { @Override/*from w w w. java2s. c o m*/ public String getMessage() { return error.toString(); } @Override public Throwable getCause() { return null; } }); }