List of usage examples for com.google.gwt.json.client JSONValue isObject
public JSONObject isObject()
From source file:org.cruxframework.crux.core.client.utils.JsUtils.java
License:Apache License
/** * Extract the associated native javascript object from the given json object * @param jsonValue//from w w w . j av a 2s .c o m * @return */ public static JavaScriptObject fromJSONValue(JSONValue jsonValue) { if (jsonValue.isNull() != null) { return null; } JSONArray jsonArray = jsonValue.isArray(); if (jsonArray != null) { return jsonArray.getJavaScriptObject(); } return jsonValue.isObject().getJavaScriptObject(); }
From source file:org.dashbuilder.displayer.client.json.DataSetLookupJSONMarshaller.java
License:Apache License
private DataSetGroup parseDataSetGroup(JSONObject dataSetGroupJson) { if (dataSetGroupJson == null) return null; DataSetGroup dataSetGroup = new DataSetGroup(); dataSetGroup.setColumnGroup(null);/*from w w w . j a va2 s. c o m*/ JSONValue value = dataSetGroupJson.get(COLUMNGROUP); if (value != null) dataSetGroup.setColumnGroup(parseColumnGroup(value.isObject())); List<GroupFunction> groupFunctions = parseGroupFunctions( (value = dataSetGroupJson.get(GROUPFUNCTIONS)) != null ? value.isArray() : null); if (groupFunctions != null) dataSetGroup.getGroupFunctions().addAll(groupFunctions); dataSetGroup.setSelectedIntervalNames(null); value = dataSetGroupJson.get(SELECTEDINTERVALS); if (value != null) dataSetGroup.setSelectedIntervalNames(parseSelectedIntervals(value.isArray())); dataSetGroup.setJoin(false); value = dataSetGroupJson.get(JOIN); if (value != null) dataSetGroup.setJoin(Boolean.valueOf(value.isString().stringValue())); return dataSetGroup; }
From source file:org.dashbuilder.displayer.client.json.DisplayerSettingsJSONMarshaller.java
License:Apache License
public DisplayerSettings fromJsonString(String jsonString) { DisplayerSettings ds = new DisplayerSettings(); if (!StringUtils.isBlank(jsonString)) { JSONObject parseResult = JSONParser.parseStrict(jsonString).isObject(); if (parseResult != null) { // UUID JSONValue uuidValue = parseResult.get(SETTINGS_UUID); ds.setUUID(uuidValue != null && uuidValue.isString() != null ? uuidValue.isString().stringValue() : null);// w w w . j a v a2 s .com // First look if a dataset 'on-the-fly' has been specified JSONValue data = parseResult.get(JSON_DATASET_PREFIX); if (data != null) { DataSet dataSet = dataSetJSONMarshaller.fromJson(data.isObject()); ds.setDataSet(dataSet); // Remove from the json input so that it doesn't end up in the settings map. parseResult.put(JSON_DATASET_PREFIX, null); // If none was found, look for a dataset lookup definition } else if ((data = parseResult.get(JSON_DATASET_LOOKUP_PREFIX)) != null) { DataSetLookup dataSetLookup = dataSetLookupJSONMarshaller.fromJson(data.isObject()); ds.setDataSetLookup(dataSetLookup); // Remove from the json input so that it doesn't end up in the settings map. parseResult.put(JSON_DATASET_LOOKUP_PREFIX, null); } else { throw new RuntimeException("Either a DataSet or a DataSetLookup should be specified"); } // Now parse all other settings ds.setSettingsFlatMap(parseSettingsFromJson(parseResult)); } } return ds; }
From source file:org.dashbuilder.displayer.client.json.DisplayerSettingsJSONMarshaller.java
License:Apache License
private void fillRecursive(String parentPath, JSONObject json, Map<String, String> settings) { String sb = new String(StringUtils.isBlank(parentPath) ? "" : parentPath + "."); for (String key : json.keySet()) { String path = sb + key;//from w ww .j ava2s . co m JSONValue value = json.get(key); if (value.isObject() != null) fillRecursive(path, value.isObject(), settings); else if (value.isString() != null) settings.put(path, value.isString().stringValue()); } }
From source file:org.dashbuilder.renderer.c3.client.charts.map.geojson.impl.GWTGeoJsonLoader.java
License:Apache License
@Override public FeatureCollection load() { String geoJsonStr = NativeLibraryResources.INSTANCE.countriesgeojson().getText(); JSONValue geoJsonObject = JSONParser.parseStrict(geoJsonStr); return Js.cast(geoJsonObject.isObject().getJavaScriptObject()); }
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 www . ja va2 s. c o 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.drools.workbench.screens.scenariosimulation.client.collectioneditor.CollectionPresenter.java
License:Apache License
protected void populateMap(JSONValue jsonValue) { final JSONObject jsValueObject = jsonValue.isObject(); jsValueObject.keySet().forEach(key -> { Map<String, String> keyPropertiesValues = new HashMap<>(); Map<String, String> valuePropertiesValues = new HashMap<>(); final JSONObject jsonObjectKey = getJSONObject(key); if (jsonObjectKey == null) { keyPropertiesValues.put("value", key); } else {/* w w w .j a v a2 s . c om*/ jsonObjectKey.keySet().forEach(propertyName -> keyPropertiesValues.put(propertyName, jsonObjectKey.get(propertyName).isString().stringValue())); } JSONObject jsonObjectValue = jsValueObject.get(key).isObject(); if (jsonObjectValue != null) { jsonObjectValue.keySet().forEach(propertyName -> valuePropertiesValues.put(propertyName, jsonObjectValue.get(propertyName).isString().stringValue())); } else { valuePropertiesValues.put("value", jsValueObject.get(key).toString()); } addMapItem(keyPropertiesValues, valuePropertiesValues); }); }
From source file:org.drools.workbench.screens.scenariosimulation.client.collectioneditor.CollectionPresenter.java
License:Apache License
/** * * @param jsonObject//from www .j a va 2 s .c o m * @return a <code>Map</code> where the <b>key</b> is the name of the complex property, and the value is a a <code>Map</code> with * the nested <b>propertyName/propertyValue</b> */ protected Map<String, Map<String, String>> getExpandablePropertiesValues(JSONObject jsonObject) { Map<String, Map<String, String>> toReturn = new HashMap<>(); jsonObject.keySet().forEach(propertyName -> { final JSONValue jsonValue = jsonObject.get(propertyName); if (jsonValue.isObject() != null) { final Map<String, String> simplePropertiesMap = getSimplePropertiesMap(jsonValue.isObject()); toReturn.put(propertyName, simplePropertiesMap); } }); return toReturn; }
From source file:org.drools.workbench.screens.scenariosimulation.client.renderers.ScenarioGridColumnRenderer.java
License:Apache License
protected String getCollectionString(String jsonString, boolean isList) { try {// ww w . j a va2s . c om int size = -1; String toFormat = isList ? "List(%s)" : "Map(%s)"; JSONValue jsonValue = JSONParser.parseStrict(jsonString); if (isList) { size = jsonValue.isArray().size(); } else { size = jsonValue.isObject().keySet().size(); } return toFormat.replace("%s", String.valueOf(size)); } catch (Exception e) { return jsonString; } }
From source file:org.eclipse.che.api.languageserver.util.EitherUtil.java
License:Open Source License
private static boolean matches(JSONValue element, JsonDecision decision) { if (decision == JsonDecision.LIST) { return element.isArray() != null; }//w w w. j a v a2 s . co m if (decision == JsonDecision.BOOLEAN) { return element.isBoolean() != null; } if (decision == JsonDecision.NUMBER) { return element.isNumber() != null; } if (decision == JsonDecision.STRING) { return element.isString() != null; } return element.isObject() != null; }