com.google.gwt.json.client.JSONString Java Examples

The following examples show how to use com.google.gwt.json.client.JSONString. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: UploadFile.java    From proarc with GNU General Public License v3.0 6 votes vote down vote up
private void uploadFile() {
    JSONObject post = new JSONObject();
    String mime = form.getValueAsString(FIELD_MIMETYPE);
    if (mime != null && !mime.trim().isEmpty()) {
        post.put(FIELD_MIMETYPE, new JSONString(mime));
    }
    post.put(FIELD_PID, new JSONString(dobj.getPid()));
    String batchId = dobj.getBatchId();
    if (batchId != null) {
        post.put(FIELD_BATCHID, new JSONString(batchId));
    }
    post.put(DigitalObjectResourceApi.DISSEMINATION_ERROR, JSONBoolean.getInstance(true));
    uploader.setPostParams(post);
    uploader.startUpload();
    showUploading(true);
}
 
Example #2
Source File: Application.java    From SensorWebClient with GNU General Public License v2.0 6 votes vote down vote up
private static TimeseriesRenderingOptions createRenderingOptions(String options) {
    if (options == null) {
        return new TimeseriesRenderingOptions();
    }
    TimeseriesRenderingOptions tsOptions = new TimeseriesRenderingOptions();
    JSONObject tsRenderingOptions = new JSONObject(parseUntrustedJson(options));
    if (tsRenderingOptions.containsKey("color")) {
        JSONString color = tsRenderingOptions.get("color").isString();
        tsOptions.setColor(color.stringValue());
    }
    if (tsRenderingOptions.containsKey("lineWidth")) {
        JSONNumber lineWidth = tsRenderingOptions.get("lineWidth").isNumber();
        tsOptions.setLineWidth((int)lineWidth.doubleValue());
    }
    return tsOptions;
}
 
Example #3
Source File: Index.java    From core with GNU Lesser General Public License v2.1 6 votes vote down vote up
public List<Document> search(final String text) {
    List<Document> results = new ArrayList<Document>();
    JsArray jsonResult = searchInternal(text);
    if (jsonResult != null) {
        for (int i = 0; i < jsonResult.length(); i++) {
            JSONObject json = new JSONObject(jsonResult.get(i));
            JSONString jsonId = json.get("ref").isString();
            if (jsonId != null) {
                long id = Long.parseLong(jsonId.stringValue());
                String documentJson = localStorage.getItem(key(id));
                if (documentJson != null) {
                    AutoBean<Document> autoBean = AutoBeanCodex.decode(beanFactory, Document.class, documentJson);
                    results.add(autoBean.as());
                }
            }
        }
    }
    return results;
}
 
Example #4
Source File: Project.java    From geowe-core with GNU General Public License v3.0 6 votes vote down vote up
public String toJSON() {

		JSONObject projectObject = new JSONObject();
		projectObject.put("version", new JSONString(getVersion()));
		projectObject.put("title", new JSONString(getTitle()));
		projectObject.put("description", new JSONString(getDescription()));
		projectObject.put("date", new JSONString(getDate()));		
		
		JSONArray layersArray = new JSONArray();
		int index = 0;
		for(ProjectVectorLayer projectLayer: vectors) {
			layersArray.set(index, projectLayer.getJSONObject());
			
			index++;
		}
		
		projectObject.put("vectors", layersArray);

		return projectObject.toString();
	}
 
Example #5
Source File: WaitForBuildResultCommand.java    From appinventor-extensions with Apache License 2.0 6 votes vote down vote up
private static String extractFormName(RpcResult result) {
  String extraString = result.getExtra();
  if (extraString != null) {
    JSONValue extraJSONValue = JSONParser.parseStrict(extraString);
    JSONObject extraJSONObject = extraJSONValue.isObject();
    if (extraJSONObject != null) {
      JSONValue formNameJSONValue = extraJSONObject.get("formName");
      if (formNameJSONValue != null) {
        JSONString formNameJSONString = formNameJSONValue.isString();
        if (formNameJSONString != null) {
          return formNameJSONString.stringValue();
        }
      }
    }
  }
  return "Screen1";
}
 
Example #6
Source File: TemplateUploadWizard.java    From appinventor-extensions with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the dynamic template Urls from a jsonStr.  This method is
 * called during start up where jsonStr is retrieved from User
 * settings.
 *
 * @param jsonStr
 */
public static void setStoredTemplateUrls(String jsonStr) {
  if (jsonStr == null || jsonStr.length() == 0)
    return;
  JSONValue jsonVal = JSONParser.parseLenient(jsonStr);
  JSONArray jsonArr = jsonVal.isArray();
  for (int i = 0; i < jsonArr.size(); i++) {
    JSONValue value = jsonArr.get(i);
    JSONString str = value.isString();
    dynamicTemplateUrls.add(str.stringValue());
  }
}
 
Example #7
Source File: UploadResponse.java    From core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@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;
}
 
Example #8
Source File: GadgetNonEditorGwtTest.java    From incubator-retired-wave with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a test gadget metadata object.
 *
 * @param xmlSource gadget xml
 * @return the metadata object
 */
public GadgetMetadata getTestMetadata(String xmlSource) {
  String iFrameUrl =
      "//0" + GADGET_SERVER + "/gadgets/ifr?url=http://test.com/gadget.xml&view=canvas";
  JSONObject canvasViewData = new JSONObject();
  JSONObject viewData = new JSONObject();
  viewData.put(VIEW_NAME, canvasViewData);
  JSONObject jsonData = new JSONObject();
  jsonData.put("iframeUrl", new JSONString(iFrameUrl));
  jsonData.put("views", viewData);
  jsonData.put("url", new JSONString(xmlSource));
  jsonData.put("userPrefs", new JSONObject());
  return new GadgetMetadata(jsonData);
}
 
Example #9
Source File: GadgetMetadata.java    From incubator-retired-wave with Apache License 2.0 5 votes vote down vote up
/**
 * Helper function to extract a string value from given JSON object.
 *
 * @param json JSON object to extract the value from.
 * @param key key of the value to extract.
 * @return the string object extracted from JSON (can be null if the value
 *         does not exist or is invalid.
 */
private static String getJsonStringValue(JSONObject json, String key) {
  JSONValue value = json.get(key);
  JSONString string = (value == null) ? null : value.isString();
  if (string != null) {
    return string.stringValue();
  } else {
    return null;
  }
}
 
Example #10
Source File: GadgetNonEditorGwtTest.java    From swellrt with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a test gadget metadata object.
 *
 * @param xmlSource gadget xml
 * @return the metadata object
 */
public GadgetMetadata getTestMetadata(String xmlSource) {
  String iFrameUrl =
      "//0" + GADGET_SERVER + "/gadgets/ifr?url=http://test.com/gadget.xml&view=canvas";
  JSONObject canvasViewData = new JSONObject();
  JSONObject viewData = new JSONObject();
  viewData.put(VIEW_NAME, canvasViewData);
  JSONObject jsonData = new JSONObject();
  jsonData.put("iframeUrl", new JSONString(iFrameUrl));
  jsonData.put("views", viewData);
  jsonData.put("url", new JSONString(xmlSource));
  jsonData.put("userPrefs", new JSONObject());
  return new GadgetMetadata(jsonData);
}
 
Example #11
Source File: GadgetMetadata.java    From swellrt with Apache License 2.0 5 votes vote down vote up
/**
 * Helper function to extract a string value from given JSON object.
 *
 * @param json JSON object to extract the value from.
 * @param key key of the value to extract.
 * @return the string object extracted from JSON (can be null if the value
 *         does not exist or is invalid.
 */
private static String getJsonStringValue(JSONObject json, String key) {
  JSONValue value = json.get(key);
  JSONString string = (value == null) ? null : value.isString();
  if (string != null) {
    return string.stringValue();
  } else {
    return null;
  }
}
 
Example #12
Source File: ProjectVectorLayer.java    From geowe-core with GNU General Public License v3.0 5 votes vote down vote up
public JSONObject getJSONObject() {
	JSONObject projectLayerObject = new JSONObject();
	projectLayerObject.put("name", new JSONString(getName()));
	projectLayerObject.put("content", new JSONString(getContent()));
	projectLayerObject.put("style", style.getJSONObject());
	
	
	return projectLayerObject;		
}
 
Example #13
Source File: ProjectLayerStyle.java    From geowe-core with GNU General Public License v3.0 5 votes vote down vote up
public JSONObject getJSONObject() {
	JSONObject projectLayerObject = new JSONObject();
	
	projectLayerObject.put(FILL_COLOR_NAME, new JSONString(getFillColor()));
	projectLayerObject.put(FILL_OPACITY_NAME, new JSONNumber(getFillOpacity()));
	projectLayerObject.put(STROKE_COLOR_NAME, new JSONString(getStrokeColor()));
	projectLayerObject.put(STROKE_WIDTH_NAME, new JSONNumber(getStrokeWidth()));
	
	return projectLayerObject;		
}
 
Example #14
Source File: ErrorHandler.java    From proarc with GNU General Public License v3.0 5 votes vote down vote up
/**
     * Creates response object from JSON response string in
     * {@link com.smartgwt.client.data.RestDataSource SmartGWT format}.
     * @param response JSON response string
     * @return response object
     */
    public static DSResponse getDsResponse(String response) {
        DSResponse dsResponse;
//        ClientUtils.info(LOG, "response: %s", response);
        if (response == null || response.isEmpty()) {
            // not JSON response
            LOG.log(Level.WARNING, null, new IllegalStateException("Empty response!"));
            dsResponse = new DSResponse();
            dsResponse.setStatus(RPCResponse.STATUS_SUCCESS);
        } else {
            JSONValue rVal = JSONParser.parseStrict(response);
            if (rVal.isObject() != null) {
                rVal = rVal.isObject().get("response");
            }
            if (rVal != null && rVal.isObject() != null) {
                JSONObject rObj = rVal.isObject();
                dsResponse = DSResponse.getOrCreateRef(rObj.getJavaScriptObject());
            } else {
                // not JSON response in expected format
                JSONObject jsonObject = new JSONObject();
                jsonObject.put("data", new JSONString(response));
                dsResponse = new DSResponse(jsonObject.getJavaScriptObject());
                dsResponse.setStatus(RPCResponse.STATUS_FAILURE);
            }
        }
        return dsResponse;
    }
 
Example #15
Source File: JSONUtil.java    From document-management-system with GNU General Public License v2.0 5 votes vote down vote up
/**
 * toJson
 *
 */
public static JSONObject toJson(Object obj) {
	JSONObject json = new JSONObject();
	if (obj instanceof GWTQueryParams) {
		GWTQueryParams params = (GWTQueryParams) obj;
		json.put("author", new JSONString(params.getAuthor()));
		json.put("keywords", new JSONString(params.getKeywords()));
		json.put("content", new JSONString(params.getContent()));
		json.put("name", new JSONString(params.getName()));
		json.put("path", new JSONString(URL.encodeQueryString(params.getPath())));
		json.put("mimeType", new JSONString(params.getMimeType()));
		json.put("domain", new JSONNumber(params.getDomain()));
		json.put("mailFrom", new JSONString(params.getMailFrom()));
		json.put("mailTo", new JSONString(params.getMailTo()));
		json.put("mailSubject", new JSONString(params.getMailSubject()));
		json.put("categoryUuid", new JSONString(params.getCategoryUuid()));
		json.put("categoryPath", new JSONString(URL.encodeQueryString(params.getCategoryPath())));
		json.put("operator", new JSONString(params.getOperator()));
		if (params.getLastModifiedFrom() != null) {
			json.put("lastModifiedFrom", new JSONString(ISO8601.formatBasic(params.getLastModifiedFrom())));
		}
		if (params.getLastModifiedTo() != null) {
			json.put("lastModifiedTo", new JSONString(ISO8601.formatBasic(params.getLastModifiedTo())));
		}
		if (!params.getProperties().isEmpty()) {
			JSONObject properties = new JSONObject();
			for (String key : params.getProperties().keySet()) {
				GWTPropertyParams propertyParam = params.getProperties().get(key);
				JSONObject property = new JSONObject();
				// Only is necessary groupName and value
				property.put("grpName", new JSONString(propertyParam.getGrpName()));
				property.put("value", new JSONString(propertyParam.getValue()));
				properties.put(key, property);
			}
			json.put("properties", properties);
		}
	}
	return json;
}
 
Example #16
Source File: UpdateDatasetPanel.java    From EasyML with Apache License 2.0 4 votes vote down vote up
public void initFileUploader(){
	uploaderPanel = new UploadFileModule();
	uploaderPanel.setUpLoadDataset(dataset);
	verticalPanel.add(uploaderPanel);
	uploaderPanel.getUploader().setUploadCompleteHandler(new UploadCompleteHandler() {
		@Override
		public boolean onUploadComplete(UploadCompleteEvent uploadCompleteEvent) {
			uploaderPanel.getCancelButtons().get(uploadCompleteEvent.getFile().getId())
			.removeFromParent();
			DatasetLeaf node = new DatasetLeaf(uploaderPanel.getUpLoadDataset());
			DatasetTreeLoader.addContextMenu(tree,node);
			DatasetTreeLoader.addDatasetLeaf(tree, node,AppController.email);
			Window.alert("update successed!");
			UpdateDatasetPanel.this.hide();
			UpdateDatasetPanel.this.clean();
			//Add code here so that the UploadModelPanel is hidden
			uploaderPanel.getUploader().cancelUpload(uploaderPanel.getFileQueuedId(), false);
			return true;
		}
	});
	uploaderPanel.getStartbt().addClickHandler(new ClickHandler() {
		@Override
		public void onClick(ClickEvent event) {
			JSONObject params = new JSONObject();
			if (!uploaderPanel.getIsFileQueued()) {
				Window.alert("Please choose a file to upload, can not be empty");
				return;
			}
			if (uploaderPanel.getFileQueuedName().endsWith(".zip")) {
				uploaderPanel.getUploader().cancelUpload(uploaderPanel.getFileQueuedId(), false);
				uploaderPanel.getProgressBars().clear();
				Window.alert("Data can not be zip-formatted files, please re-select the file");
				return;
			}
			uploaderPanel.setNewFileUUID(UUID.randomUUID());
			params.put("Datauuid", new JSONString(uploaderPanel.getNewFileUUID()));
			uploaderPanel.getUploader().setOption("post_params", params).setPostParams(params);
			try {
				if (dbController.submitUpdateDataset2DB(uploaderPanel,tree,node,dataset,grid)) {
					uploaderPanel.getUploader().startUpload();
					uploaderPanel.getStartbt().setEnabled(false);
				}
			} catch (CommandParseException e) {
				Window.alert(e.getMessage());
			}
		}
	});
}
 
Example #17
Source File: UploadDatasetPanel.java    From EasyML with Apache License 2.0 4 votes vote down vote up
public void initFileUploader(){
	uploaderPanel = new UploadFileModule();
	uploaderPanel.setUpLoadDataset(dataset);
	verticalPanel.add(uploaderPanel);
	uploaderPanel.getUploader().setUploadCompleteHandler(new UploadCompleteHandler() {
		@Override
		public boolean onUploadComplete(UploadCompleteEvent uploadCompleteEvent) {
			uploaderPanel.getCancelButtons().get(uploadCompleteEvent.getFile().getId())
			.removeFromParent();
			Window.alert("Uploaded successfully!");
			UploadDatasetPanel.this.hide();
			UploadDatasetPanel.this.clean();
			// Add code here so that the UploadModelPanel is hidden
			uploaderPanel.getUploader().cancelUpload(uploaderPanel.getFileQueuedId(), false);
			return true;
		}
	});
	uploaderPanel.getStartbt().addClickHandler(new ClickHandler() {
		@Override
		public void onClick(ClickEvent event) {
			JSONObject params = new JSONObject();
			if (!uploaderPanel.getIsFileQueued()) {
				Window.alert("Please choose a file to upload, can not be empty");
				return;
			}
			if (uploaderPanel.getFileQueuedName().endsWith(".zip")) {
				uploaderPanel.getUploader().cancelUpload(uploaderPanel.getFileQueuedId(), false);
				uploaderPanel.getProgressBars().clear();
				Window.alert("Data can not be zip-formatted files, please re-select the file");
				return;
			}
			uploaderPanel.setNewFileUUID(UUID.randomUUID());
			params.put("Datauuid", new JSONString(uploaderPanel.getNewFileUUID()));
			uploaderPanel.getUploader().setOption("post_params", params).setPostParams(params);
			try {
				if (dbController.submitUploadDataset2DB(presenter,presenter.getView(),uploaderPanel,dataset,grid)) {
					uploaderPanel.getUploader().startUpload();
					uploaderPanel.getStartbt().setEnabled(false);
				}
			} catch (CommandParseException e) {
				Window.alert(e.getMessage());
			}
		}
	});
}
 
Example #18
Source File: JsonTokenizer.java    From proarc with GNU General Public License v3.0 4 votes vote down vote up
public static String getString(JSONObject json, String name) {
    JSONValue jsonVal = json.get(name);
    JSONString jsonString = (jsonVal == null) ? null : jsonVal.isString();
    return (jsonString == null) ? null : jsonString.stringValue();
}
 
Example #19
Source File: JsonTokenizer.java    From proarc with GNU General Public License v3.0 4 votes vote down vote up
public static void putString(JSONObject json, String name, String value) {
    if (value != null) {
        json.put(name, new JSONString(value));
    }
}
 
Example #20
Source File: UploadProgramPanel.java    From EasyML with Apache License 2.0 4 votes vote down vote up
public void initFileUploader(){
	uploaderPanel = new UploadFileModule();
	uploaderPanel.setUpLoadProgram(program);
	verticalPanel.add(uploaderPanel);
	uploaderPanel.getUploader().setUploadCompleteHandler(new UploadCompleteHandler() {
		@Override
		public boolean onUploadComplete(UploadCompleteEvent uploadCompleteEvent) {
			uploaderPanel.getCancelButtons().get(uploadCompleteEvent.getFile().getId())
			.removeFromParent();
			uploaderPanel.getUploader().cancelUpload(uploaderPanel.getFileQueuedId(), false);

			Window.alert("Uploaded successfully!");
			UploadProgramPanel.this.hide();
			UploadProgramPanel.this.clean();
			return true;
		}
	});
	uploaderPanel.getStartbt().addClickHandler(new ClickHandler() {
		@Override
		public void onClick(ClickEvent event) {
			JSONObject params = new JSONObject();
			if (!uploaderPanel.getIsFileQueued()) {
				Window.alert("Please choose a file to upload, can not be empty");
				return;
			}
			if (!uploaderPanel.getFileQueuedName().endsWith(".zip")) {
				uploaderPanel.getUploader().cancelUpload(uploaderPanel.getFileQueuedId(), false);
				uploaderPanel.getProgressBars().clear();
				Window.alert("The file must be in the standard zip format, please re-select the file");
				return;
			}
			uploaderPanel.setNewFileUUID(UUID.randomUUID());
			params.put("Fileuuid", new JSONString(uploaderPanel.getNewFileUUID()));
			uploaderPanel.getUploader().setOption("post_params", params).setPostParams(params);
			try {
				if (dbController.submitUploadProgram2DB(presenter,presenter.getView(), uploaderPanel,program,grid)) {
					uploaderPanel.getUploader().startUpload();
					uploaderPanel.getStartbt().setEnabled(false);
				}
			} catch (CommandParseException e) {
				logger.info(e.getMessage());
				Window.alert(e.getMessage());
			}
		}
	});
}
 
Example #21
Source File: UpdateProgramPanel.java    From EasyML with Apache License 2.0 4 votes vote down vote up
public void initFileUploader(){
	uploaderPanel = new UploadFileModule();
	uploaderPanel.setUpLoadProgram(program);
	verticalPanel.add(uploaderPanel);
	uploaderPanel.getUploader().setUploadCompleteHandler(new UploadCompleteHandler() {
		@Override
		public boolean onUploadComplete(UploadCompleteEvent uploadCompleteEvent) {
			uploaderPanel.getCancelButtons().get(uploadCompleteEvent.getFile().getId()).removeFromParent();
			uploaderPanel.getUploader().cancelUpload(uploaderPanel.getFileQueuedId(), false);
			ProgramLeaf node = new ProgramLeaf(uploaderPanel.getUpLoadProgram());
			ProgramTreeLoader.addContextMenu(tree, node);
			ProgramTreeLoader.addProgramLeaf(tree, node,AppController.email);
			Window.alert("Uploaded Success!");
			UpdateProgramPanel.this.hide();
			UpdateProgramPanel.this.clean();
			return true;
		}
	});
	uploaderPanel.getStartbt().addClickHandler(new ClickHandler() {
		@Override
		public void onClick(ClickEvent event) {
			JSONObject params = new JSONObject();
			if (!uploaderPanel.getIsFileQueued()) {
				Window.alert("Please choose a file to upload, can not be empty");
				return;
			}
			if (!uploaderPanel.getFileQueuedName().endsWith(".zip")) {
				uploaderPanel.getUploader().cancelUpload(uploaderPanel.getFileQueuedId(), false);
				uploaderPanel.getProgressBars().clear();
				Window.alert("The file must be in the standard zip format, please re-select the file");
				return;
			}
			uploaderPanel.setNewFileUUID(UUID.randomUUID());
			params.put("Fileuuid", new JSONString(uploaderPanel.getNewFileUUID()));
			uploaderPanel.getUploader().setOption("post_params", params).setPostParams(params);
			try {
				if (dbController.submitUpdateProgram2DB(uploaderPanel,tree,node,program,grid)) {
					uploaderPanel.getUploader().startUpload();
					uploaderPanel.getStartbt().setEnabled(false);
				}
			} catch (CommandParseException e) {
				Window.alert(e.getMessage());
			}
		}
	});
}