List of usage examples for org.json JSONObject put
public JSONObject put(String key, Object value) throws JSONException
From source file:com.shampan.services.SearchService.java
/** * This method will return users//from w w w .ja v a 2 s. c o m * * @param requestPatten, request String * @return users */ public static String getSearchResult(String searchValue, int offset, int limit) { JSONObject searchResult = new JSONObject(); searchResult.put("userList", searchModel.getUsers(searchValue, offset, limit)); searchResult.put("pageList", searchModel.getPages(searchValue, offset, limit)); return searchResult.toString(); }
From source file:edu.mit.scratch.ScratchProject.java
public boolean comment(final ScratchSession session, final String comment) throws ScratchProjectException { final RequestConfig globalConfig = RequestConfig.custom().setCookieSpec(CookieSpecs.DEFAULT).build(); final CookieStore cookieStore = new BasicCookieStore(); final BasicClientCookie lang = new BasicClientCookie("scratchlanguage", "en"); final BasicClientCookie sessid = new BasicClientCookie("scratchsessionsid", session.getSessionID()); final BasicClientCookie token = new BasicClientCookie("scratchcsrftoken", session.getCSRFToken()); final BasicClientCookie debug = new BasicClientCookie("DEBUG", "true"); lang.setDomain(".scratch.mit.edu"); lang.setPath("/"); sessid.setDomain(".scratch.mit.edu"); sessid.setPath("/"); token.setDomain(".scratch.mit.edu"); token.setPath("/"); debug.setDomain(".scratch.mit.edu"); debug.setPath("/"); cookieStore.addCookie(lang);//from ww w .j a va2s . com cookieStore.addCookie(sessid); cookieStore.addCookie(token); cookieStore.addCookie(debug); final CloseableHttpClient httpClient = HttpClients.custom().setDefaultRequestConfig(globalConfig) .setUserAgent("Mozilla/5.0 (Windows NT 6.1; WOW64)" + " AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.111 Safari/" + "537.36") .setDefaultCookieStore(cookieStore).build(); CloseableHttpResponse resp; final JSONObject obj = new JSONObject(); obj.put("content", comment); obj.put("parent_id", ""); obj.put("commentee_id", ""); final String strData = obj.toString(); HttpUriRequest update = null; try { update = RequestBuilder.post() .setUri("https://scratch.mit.edu/site-api/comments/project/" + this.getProjectID() + "/add/") .addHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8") .addHeader("Referer", "https://scratch.mit.edu/projects/" + this.getProjectID() + "/") .addHeader("Origin", "https://scratch.mit.edu/") .addHeader("Accept-Encoding", "gzip, deflate, sdch") .addHeader("Accept-Language", "en-US,en;q=0.8").addHeader("Content-Type", "application/json") .addHeader("X-Requested-With", "XMLHttpRequest") .addHeader("Cookie", "scratchsessionsid=" + session.getSessionID() + "; scratchcsrftoken=" + session.getCSRFToken()) .addHeader("X-CSRFToken", session.getCSRFToken()).setEntity(new StringEntity(strData)).build(); } catch (final UnsupportedEncodingException e1) { e1.printStackTrace(); } try { resp = httpClient.execute(update); System.out.println("cmntadd:" + resp.getStatusLine()); final BufferedReader rd = new BufferedReader(new InputStreamReader(resp.getEntity().getContent())); final StringBuffer result = new StringBuffer(); String line = ""; while ((line = rd.readLine()) != null) result.append(line); System.out.println("cmtline:" + result.toString()); } catch (final IOException e) { e.printStackTrace(); throw new ScratchProjectException(); } BufferedReader rd; try { rd = new BufferedReader(new InputStreamReader(resp.getEntity().getContent())); } catch (UnsupportedOperationException | IOException e) { e.printStackTrace(); throw new ScratchProjectException(); } return false; }
From source file:com.jennifer.ui.chart.grid.RuleGrid.java
@Override protected void drawTop(Transform root) { int width = chart.area("width"); int height = chart.area("height"); double half_width = (double) width / 2; double half_height = (double) height / 2; double centerPosition = center ? half_height : 0; JSONObject o = new JSONObject(); o.put("y1", centerPosition); o.put("y2", centerPosition); o.put("x2", chart.area("width")); root.append(this.axisLine(o)); double min = this.scale.min(); for (int i = 0, len = ticks.length(); i < len; i++) { boolean isZero = (ticks.getDouble(i) == 0); Transform axis = root.group().translate(this.values.getDouble(i), centerPosition); JSONObject lineOpt = new JSONObject(); lineOpt.put("y1", center ? -bar : 0); lineOpt.put("y2", bar); lineOpt.put("stroke", chart.theme("gridAxisBorderColor")); lineOpt.put("stroke-width", chart.theme("gridBorderWidth")); axis.append(line(lineOpt));// ww w .jav a2s . c o m if (!isZero || (isZero && !hideZero)) { JSONObject textOpt = new JSONObject(); textOpt.put("x", 0); textOpt.put("y", bar * 2 + 4); textOpt.put("text-anchor", "middle"); textOpt.put("fill", chart.theme("gridFontColor")); axis.append(chart.text(textOpt, getFormatString(ticks.get(i)))); } } }
From source file:com.jennifer.ui.chart.grid.RuleGrid.java
@Override protected void drawBottom(Transform root) { int width = chart.area("width"); int height = chart.area("height"); double half_width = (double) width / 2; double half_height = (double) height / 2; double centerPosition = center ? -half_height : 0; JSONObject o = new JSONObject(); o.put("y1", centerPosition); o.put("y2", centerPosition); o.put("x2", chart.area("width")); root.append(this.axisLine(o)); double min = this.scale.min(); for (int i = 0, len = ticks.length(); i < len; i++) { boolean isZero = (ticks.getDouble(i) == 0); Transform axis = root.group().translate(this.values.getDouble(i), centerPosition); JSONObject lineOpt = new JSONObject(); lineOpt.put("y1", center ? -bar : 0); lineOpt.put("y2", center ? bar : -bar); lineOpt.put("stroke", chart.theme("gridAxisBorderColor")); lineOpt.put("stroke-width", chart.theme("gridBorderWidth")); axis.append(line(lineOpt));//from w w w.java 2 s .co m if (!isZero || (isZero && !hideZero)) { JSONObject textOpt = new JSONObject(); textOpt.put("x", 0); textOpt.put("y", -bar * 2); textOpt.put("text-anchor", "middle"); textOpt.put("fill", chart.theme("gridFontColor")); axis.append(chart.text(textOpt, getFormatString(ticks.get(i)))); } } }
From source file:com.jennifer.ui.chart.grid.RuleGrid.java
@Override protected void drawLeft(Transform root) { int width = chart.area("width"); int height = chart.area("height"); double half_width = (double) width / 2; double half_height = (double) height / 2; double centerPosition = center ? half_width : 0; JSONObject o = new JSONObject(); o.put("x1", centerPosition); o.put("x2", centerPosition); o.put("y2", chart.area("height")); root.append(this.axisLine(o)); double min = this.scale.min(); for (int i = 0, len = ticks.length(); i < len; i++) { boolean isZero = (ticks.getDouble(i) == 0); Transform axis = root.group().translate(centerPosition, this.values.getDouble(i)); JSONObject lineOpt = new JSONObject(); lineOpt.put("x1", center ? -bar : 0); lineOpt.put("x2", bar); lineOpt.put("stroke", chart.theme("gridAxisBorderColor")); lineOpt.put("stroke-width", chart.theme("gridBorderWidth")); axis.append(line(lineOpt));/*from w w w. j a v a 2s .co m*/ if (!isZero || (isZero && !hideZero)) { JSONObject textOpt = new JSONObject(); textOpt.put("x", 2 * bar); textOpt.put("y", bar - 2); textOpt.put("text-anchor", "start"); textOpt.put("fill", chart.theme("gridFontColor")); axis.append(chart.text(textOpt, getFormatString(ticks.get(i)))); } } }
From source file:com.jennifer.ui.chart.grid.RuleGrid.java
@Override protected void drawRight(Transform root) { int width = chart.area("width"); int height = chart.area("height"); double half_width = (double) width / 2; double half_height = (double) height / 2; double centerPosition = center ? -half_width : 0; JSONObject o = new JSONObject(); o.put("x1", centerPosition); o.put("x2", centerPosition); o.put("y2", chart.area("width")); root.append(this.axisLine(o)); double min = this.scale.min(); for (int i = 0, len = ticks.length(); i < len; i++) { boolean isZero = (ticks.getDouble(i) == 0); Transform axis = root.group().translate(centerPosition, this.values.getDouble(i)); JSONObject lineOpt = new JSONObject(); lineOpt.put("x1", center ? -bar : 0); lineOpt.put("x2", center ? bar : -bar); lineOpt.put("stroke", chart.theme("gridAxisBorderColor")); lineOpt.put("stroke-width", chart.theme("gridBorderWidth")); axis.append(line(lineOpt));/*from ww w. j a v a2 s . c om*/ if (!isZero || (isZero && !hideZero)) { JSONObject textOpt = new JSONObject(); textOpt.put("x", -bar - 4); textOpt.put("y", bar - 2); textOpt.put("text-anchor", "middle"); textOpt.put("fill", chart.theme("gridFontColor")); axis.append(chart.text(textOpt, getFormatString(ticks.get(i)))); } } }
From source file:com.liferay.mobile.android.v7.journalfolder.JournalFolderService.java
public JSONObject getFolder(long folderId) throws Exception { JSONObject _command = new JSONObject(); try {//from w w w.j a v a 2 s. c om JSONObject _params = new JSONObject(); _params.put("folderId", folderId); _command.put("/journal.journalfolder/get-folder", _params); } catch (JSONException _je) { throw new Exception(_je); } JSONArray _result = session.invoke(_command); if (_result == null) { return null; } return _result.getJSONObject(0); }
From source file:com.liferay.mobile.android.v7.journalfolder.JournalFolderService.java
public JSONArray getFolders(long groupId, long parentFolderId, int status) throws Exception { JSONObject _command = new JSONObject(); try {//from w ww . ja va 2 s.c o m JSONObject _params = new JSONObject(); _params.put("groupId", groupId); _params.put("parentFolderId", parentFolderId); _params.put("status", status); _command.put("/journal.journalfolder/get-folders", _params); } catch (JSONException _je) { throw new Exception(_je); } JSONArray _result = session.invoke(_command); if (_result == null) { return null; } return _result.getJSONArray(0); }
From source file:com.liferay.mobile.android.v7.journalfolder.JournalFolderService.java
public JSONArray getFolders(long groupId) throws Exception { JSONObject _command = new JSONObject(); try {//ww w . j a v a 2 s.c om JSONObject _params = new JSONObject(); _params.put("groupId", groupId); _command.put("/journal.journalfolder/get-folders", _params); } catch (JSONException _je) { throw new Exception(_je); } JSONArray _result = session.invoke(_command); if (_result == null) { return null; } return _result.getJSONArray(0); }
From source file:com.liferay.mobile.android.v7.journalfolder.JournalFolderService.java
public JSONArray getFolders(long groupId, long parentFolderId) throws Exception { JSONObject _command = new JSONObject(); try {/* w w w . ja v a 2 s . co m*/ JSONObject _params = new JSONObject(); _params.put("groupId", groupId); _params.put("parentFolderId", parentFolderId); _command.put("/journal.journalfolder/get-folders", _params); } catch (JSONException _je) { throw new Exception(_je); } JSONArray _result = session.invoke(_command); if (_result == null) { return null; } return _result.getJSONArray(0); }