Java Code Examples for com.google.gwt.json.client.JSONObject#put()

The following examples show how to use com.google.gwt.json.client.JSONObject#put() . 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: 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 3
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 4
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 5
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 6
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 7
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 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: 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));
    }
}