List of usage examples for org.json JSONObject getJSONObject
public JSONObject getJSONObject(String key) throws JSONException
From source file:org.eclipse.orion.server.tests.servlets.git.GitAddTest.java
@Test public void testAddFolder() throws Exception { URI workspaceLocation = createWorkspace(getMethodName()); String projectName = getMethodName(); JSONObject project = createProjectOrLink(workspaceLocation, projectName, gitDir.toString()); JSONObject testTxt = getChild(project, "test.txt"); modifyFile(testTxt, "hello"); JSONObject folder = getChild(project, "folder"); JSONObject folderTxt = getChild(folder, "folder.txt"); modifyFile(folderTxt, "hello"); JSONObject gitSection = project.getJSONObject(GitConstants.KEY_GIT); String gitStatusUri = gitSection.getString(GitConstants.KEY_STATUS); assertStatus(new StatusResult().setModified(2), gitStatusUri); addFile(folder);/*from www.java2s.c o m*/ assertStatus(new StatusResult().setChanged(1).setModified(1), gitStatusUri); }
From source file:org.eclipse.orion.server.tests.servlets.git.GitAddTest.java
@Test public void testAddAllWhenInFolder() throws Exception { URI workspaceLocation = createWorkspace(getMethodName()); IPath[] clonePaths = createTestProjects(workspaceLocation); for (IPath clonePath : clonePaths) { // clone a repo JSONObject clone = clone(clonePath); String cloneContentLocation = clone.getString(ProtocolConstants.KEY_CONTENT_LOCATION); // get project/folder metadata WebRequest request = getGetRequest(cloneContentLocation); WebResponse response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); JSONObject folder = new JSONObject(response.getText()); JSONObject testTxt = getChild(folder, "test.txt"); modifyFile(testTxt, "hello"); JSONObject folder1 = getChild(folder, "folder"); JSONObject folder1Txt = getChild(folder1, "folder.txt"); modifyFile(folder1Txt, "hello"); // in folder JSONObject folder1GitSection = folder1.getJSONObject(GitConstants.KEY_GIT); String folder1GitStatusUri = folder1GitSection.getString(GitConstants.KEY_STATUS); assertStatus(new StatusResult().setModified(2), folder1GitStatusUri); clone = getCloneForGitResource(folder1); String gitIndexUri = clone.getString(GitConstants.KEY_INDEX); request = getPutGitIndexRequest(gitIndexUri /* add all*/, null); response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); assertStatus(new StatusResult().setChanged(2), folder1GitStatusUri); }/*from www . j a va 2s . co m*/ }
From source file:org.eclipse.orion.server.tests.servlets.git.GitAddTest.java
@Test public void testAddSelected() throws Exception { URI workspaceLocation = createWorkspace(getMethodName()); JSONObject project = createProjectOrLink(workspaceLocation, getMethodName(), gitDir.toString()); // get project/folder metadata WebRequest request = getGetRequest(project.getString(ProtocolConstants.KEY_CONTENT_LOCATION)); WebResponse response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); project = new JSONObject(response.getText()); request = getPostFilesRequest(project.getString(ProtocolConstants.KEY_LOCATION), getNewFileJSON("added.txt").toString(), "added.txt"); response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_CREATED, response.getResponseCode()); JSONObject addedTxt = getChild(project, "added.txt"); request = getPostFilesRequest(project.getString(ProtocolConstants.KEY_LOCATION), getNewFileJSON("untracked.txt").toString(), "untracked.txt"); response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_CREATED, response.getResponseCode()); JSONObject testTxt = getChild(project, "test.txt"); modifyFile(testTxt, "testAddSelected"); JSONObject folder = getChild(project, "folder"); JSONObject folderTxt = getChild(folder, "folder.txt"); modifyFile(folderTxt, "testAddSelected"); // add 2 of 4 addFile(testTxt, addedTxt);/*w w w . j a v a2 s .com*/ JSONObject gitSection = project.getJSONObject(GitConstants.KEY_GIT); String gitStatusUri = gitSection.getString(GitConstants.KEY_STATUS); assertStatus(new StatusResult().setChangedNames("test.txt").setModifiedNames("folder/folder.txt") .setAddedNames("added.txt").setUntrackedNames("untracked.txt"), gitStatusUri); }
From source file:net.dv8tion.jda.core.handle.SocketHandler.java
public final void handle(long responseTotal, JSONObject o) { this.allContent = o; this.responseNumber = responseTotal; final Long guildId = handleInternally(o.getJSONObject("d")); if (guildId != null) api.getGuildLock().queue(guildId, o); }
From source file:pe.chalk.takoyaki.target.NaverCafe.java
public NaverCafe(JSONObject properties) { super(properties.getString("prefix"), properties.getLong("interval")); this.getFilters() .addAll(Utils.buildStream(String.class, properties.getJSONArray("filters")).map(filterName -> { switch (filterName) { case ArticleFilter.NAME: return new ArticleFilter(this); case CommentaryFilter.NAME: return new CommentaryFilter(this); case VisitationFilter.NAME: return new VisitationFilter(this); default: return null; }/* w w w.j a v a 2s . c om*/ }).filter(filter -> filter != null).collect(Collectors.toList())); this.staff = new Staff(this.getLogger(), properties.getInt("timeout"), properties.getJSONObject("naverAccount")); this.address = properties.getString("address"); this.contentUrl = String.format(STRING_CONTENT, this.getAddress()); try { Document contentDocument = Jsoup.parse(this.getStaff().parse(this.contentUrl)); this.setName(contentDocument.select("h1.d-none").text()); Matcher clubIdMatcher = NaverCafe.PATTERN_CLUB_ID .matcher(contentDocument.head().select("script:not([type]):not([src])").first().html()); if (!clubIdMatcher.find()) { throw new IllegalArgumentException(" ID ? : " + this.getName()); } this.clubId = Integer.parseInt(clubIdMatcher.group(1)); this.menus = contentDocument.select("a[id^=menuLink]").stream() .map(element -> new Menu(this, Integer.parseInt(element.id().substring(8)), element.text())) .collect(Collectors.toList()); this.articleUrl = String.format(STRING_ARTICLE, this.getClubId()); Files.write(Paths.get("Takoyaki-menus-" + this.getAddress() + ".log"), this.getMenus().stream().map(Menu::toString).collect(Collectors.toList()), StandardCharsets.UTF_8); } catch (IOException | JSONException e) { String errorMessage = "?? : " + e.getClass().getName() + ": " + e.getMessage(); this.getLogger().error(errorMessage); throw new IllegalStateException(errorMessage); } }
From source file:com.cleanwiz.applock.service.AppUpdateService.java
public void checkVersion() { requestQueue = Volley.newRequestQueue(context); String url = "http://www.toolwiz.com/android/checkfiles.php"; final String oldVersionString = getApplicationVersion(); Uri.Builder builder = Uri.parse(url).buildUpon(); builder.appendQueryParameter("uid", AndroidUtil.getUdid(context)); builder.appendQueryParameter("version", oldVersionString); builder.appendQueryParameter("action", "checkfile"); builder.appendQueryParameter("app", "locklocker"); jsonObjectRequest = new JsonObjectRequest(Request.Method.GET, builder.toString(), null, new Response.Listener<JSONObject>() { @Override/*from w w w. ja va2 s. c o m*/ public void onResponse(JSONObject arg0) { // TODO Auto-generated method stub LogUtil.e("colin", "success"); if (arg0.has("status")) { try { String status = arg0.getString("status"); if (Integer.valueOf(status) == 1) { JSONObject msgJsonObject = arg0.getJSONObject("msg"); double version = msgJsonObject.getDouble("version"); if (Double.valueOf(oldVersionString) < version) { // ??? String intro = msgJsonObject.getString("intro"); AlertDialog.Builder alert = new AlertDialog.Builder(context); alert.setTitle("?").setMessage(intro) .setPositiveButton("", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { // ?? } }) .setNegativeButton("?", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); alert.create().show(); } } else { LogUtil.e("colin", "check update status is error"); } } catch (JSONException e) { // TODO Auto-generated catch block LogUtil.e("colin", "JSONException" + e.getMessage()); e.printStackTrace(); } } } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError arg0) { // TODO Auto-generated method stub } }); requestQueue.add(jsonObjectRequest); }
From source file:org.activiti.cycle.impl.connector.signavio.SignavioConnector.java
public JSONObject getPublicRootDirectory() throws IOException, JSONException { Response directoryResponse = getJsonResponse(conf.getDirectoryUrl()); JsonRepresentation jsonData = new JsonRepresentation(directoryResponse.getEntity()); JSONArray rootJsonArray = jsonData.toJsonArray(); if (log.isLoggable(Level.FINEST)) { SignavioLogHelper.logJSONArray(log, rootJsonArray); }// w w w . ja va2 s . c o m // find the directory of type public which contains all directories and // models of this account for (int i = 0; i < rootJsonArray.length(); i++) { JSONObject rootObject = rootJsonArray.getJSONObject(i); if ("public".equals(rootObject.getJSONObject("rep").get("type"))) { return rootObject; } } if (log.isLoggable(Level.FINEST)) { SignavioLogHelper.logCookieAndBody(log, directoryResponse); } throw new RepositoryException("No directory root found in signavio repository."); }
From source file:org.activiti.cycle.impl.connector.signavio.SignavioConnector.java
private RepositoryFolder getFolderInfo(JSONObject jsonDirectoryObject) throws JSONException { if (!"dir".equals(jsonDirectoryObject.getString("rel"))) { // TODO: Think about that! throw new RepositoryException(jsonDirectoryObject + " is not a directory"); }/*from w ww .j a v a2 s . c o m*/ String directoryName = jsonDirectoryObject.getJSONObject("rep").getString("name"); log.finest("Directoryname: " + directoryName); // String directoryDescription = // jsonDirectoryObject.getJSONObject("rep").getString("description"); String href = jsonDirectoryObject.getString("href"); // for (JSONObject subDirectoryInfo : getSubDirectoryInfos(href)) { // printDirectory(subDirectoryInfo, indention); // } // // for (JSONObject modelInfo : getSubModelInfos(href)) { // String modelName = modelInfo.getJSONObject("rep").getString("name"); // String modelType = modelInfo.getJSONObject("rep").getString("type"); // System.out.println(indention + "- MODEL " + modelName + " (" + modelType // + ")"); // } RepositoryFolder folderInfo = new RepositoryFolder(this); // folderInfo.setId( directoryId ); // TODO: Check where we get the real ID from! folderInfo.setId(conf.getDirectoryIdFromUrl(href)); folderInfo.getMetadata().setName(directoryName); // TODO: Where do we get the path from? // folderInfo.getMetadata().setPath(); return folderInfo; }
From source file:org.activiti.cycle.impl.connector.signavio.SignavioConnector.java
private RepositoryArtifact getArtifactInfoFromFolderLink(JSONObject json) throws JSONException { String id = conf.getModelIdFromUrl(json.getString("href")); return getArtifactInfoFromFile(id, json.getJSONObject("rep")); }
From source file:com.marketcloud.marketcloud.Users.java
/** * Authentication: allows the user to login. * * @param email user's email/*from w w w . ja va2 s. c om*/ * @param password user's password * @return true if the login is successful, false if not */ @SuppressWarnings("unused") public boolean authenticate(String email, String password) throws NullPointerException, ExecutionException, InterruptedException, JSONException { JSONObject jsonObject = toJsonObject(email, password); if (jsonObject != null) { jsonObject = new Connect(context).run("post", "http://api.marketcloud.it/v0/users/authenticate", publicKey, jsonObject.toString()); if (!(boolean) jsonObject.get("status")) return false; else { tm.setToken("auth", jsonObject.getJSONObject("data").getString("token")); return true; } } return false; }