List of usage examples for org.json JSONObject optString
public String optString(String key)
From source file:org.uiautomation.ios.server.command.web.ScrollHandler.java
public ScrollHandler(IOSServerManager driver, WebDriverLikeRequest request) throws Exception { super(driver, request); JSONObject payload = request.getPayload(); String elementId = payload.optString("element"); Dimension screenSize = driver.getSession(request.getSession()).getNativeDriver().getScreenSize(); Point fromPoint;/*from w ww. ja va2s. co m*/ if (!payload.isNull("element") && !elementId.equals("")) { RemoteWebNativeBackedElement element = (RemoteWebNativeBackedElement) getSession().getRemoteWebDriver() .createElement(elementId); fromPoint = element.getLocation(); } else { fromPoint = new Point(screenSize.getWidth() / 2, screenSize.getHeight() / 2); } fromPoint = CoordinateUtils.forcePointOnScreen(fromPoint, screenSize); Point toPoint = new Point(fromPoint.getX() + payload.getInt("xoffset"), fromPoint.getY() + payload.getInt("yoffset")); toPoint = CoordinateUtils.forcePointOnScreen(toPoint, screenSize); String js = scrollTemplate.replace(":sessionId", request.getSession()) .replace("fromX", Integer.toString(fromPoint.getX())) .replace("fromY", Integer.toString(fromPoint.getY())) .replace("toX", Integer.toString(toPoint.getX())).replace("toY", Integer.toString(toPoint.getY())); setJS(js); }
From source file:com.phelps.liteweibo.model.weibo.Group.java
public static Group parse(JSONObject jsonObject) { if (null == jsonObject) { return null; }//from w w w .jav a2 s. com Group group = new Group(); group.user = User.parse(jsonObject.optJSONObject("user")); group.id = jsonObject.optString("id"); group.idStr = jsonObject.optString("idstr"); group.name = jsonObject.optString("name"); group.mode = jsonObject.optString("mode"); group.visible = jsonObject.optInt("visible"); group.like_count = jsonObject.optInt("like_count"); group.member_count = jsonObject.optInt("member_count"); group.description = jsonObject.optString("description"); group.profile_image_url = jsonObject.optString("profile_image_url"); group.createAtTime = jsonObject.optString("create_time", ""); JSONArray jsonArray = jsonObject.optJSONArray("tags"); if (jsonArray != null && jsonObject.length() > 0) { int length = jsonArray.length(); group.tags = new ArrayList<Tag>(length); for (int ix = 0; ix < length; ix++) { group.tags.add(Tag.parse(jsonArray.optJSONObject(ix))); } } return group; }
From source file:org.chromium.ChromeI18n.java
private String getReplacement(String match) { // get the message from __MSG_messagename__ String messageName = match.substring(6, match.length() - 2).toLowerCase(Locale.ENGLISH); if (messageName.startsWith("@@")) { Locale locale = Locale.getDefault(); if ("@@extension_id".equals(messageName)) { return "{appId}"; } else if ("@@ui_locale".equals(messageName)) { return locale.toString(); } else if ("@@bidi_dir".equals(messageName)) { return isRtlLocale(locale) ? "rtl" : "ltr"; } else if ("@@bidi_reversed_dir".equals(messageName)) { return isRtlLocale(locale) ? "ltr" : "rtl"; } else if ("@@bidi_start_edge".equals(messageName)) { return isRtlLocale(locale) ? "right" : "left"; } else if ("@@bidi_end_edge".equals(messageName)) { return isRtlLocale(locale) ? "left" : "right"; }/*from w ww . ja v a2 s . com*/ } // Look for replacement in messages.json files List<String> localeChain = getLocalesToUse(); JSONObject messageObject = getMessageFromMessageJson(messageName, localeChain); if (messageObject != null) { String ret = messageObject.optString("message"); if (ret != null) { return ret; } } // Didn't find a match, just return string as is return match; }
From source file:org.chromium.ChromeI18n.java
private String getDefaultLocale() throws JSONException, IOException { JSONObject manifestContents = getAssetContents("www/manifest.json"); String defaultLocale = manifestContents.optString("default_locale"); if (defaultLocale == null) { throw new IllegalArgumentException("Default Locale not defined"); }//from www .j av a 2s. c om return defaultLocale; }
From source file:org.catnut.metadata.Comment.java
@Override public ContentValues convert(JSONObject data) { ContentValues values = new ContentValues(); values.put(BaseColumns._ID, data.optLong(Constants.ID)); values.put(created_at, data.optString(created_at)); values.put(columnText, data.optString(text)); values.put(source, data.optString(source)); JSONObject user = data.optJSONObject(User.SINGLE); if (user != null) { values.put(uid, user.optLong(Constants.ID)); }/*from w w w. j av a2 s .c o m*/ values.put(status, data.optString(status)); values.put(reply_comment, data.optString(reply_comment)); return values; }
From source file:com.vk.sdkweb.api.model.VKApiLink.java
/** * Fills a Link instance from JSONObject. */// www . j a v a 2 s.c om public VKApiLink parse(JSONObject source) { url = source.optString("url"); title = source.optString("title"); description = source.optString("description"); image_src = source.optString("image_src"); preview_page = source.optString("preview_page"); return this; }
From source file:org.eclipse.orion.server.tests.servlets.git.GitPushTest.java
@Test public void testPushHeadSshWithPrivateKeyPassphrase() throws Exception { Assume.assumeTrue(sshRepo2 != null); Assume.assumeTrue(knownHosts2 != null); Assume.assumeTrue(privateKey != null); Assume.assumeTrue(passphrase != null); URI workspaceLocation = createWorkspace(getMethodName()); String workspaceId = workspaceIdFromLocation(workspaceLocation); URIish uri = new URIish(sshRepo2); // clone1: create JSONObject project1 = createProjectOrLink(workspaceLocation, getMethodName() + "1", null); IPath clonePath = getClonePath(workspaceId, project1); WebRequest request = new PostGitCloneRequest().setURIish(uri).setFilePath(clonePath) .setKnownHosts(knownHosts2).setPrivateKey(privateKey).setPublicKey(publicKey) .setPassphrase(passphrase).getWebRequest(); String cloneContentLocation1 = clone(request); // clone1: get project/folder metadata request = getGetRequest(cloneContentLocation1); WebResponse response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); project1 = new JSONObject(response.getText()); // clone1: get git links JSONObject gitSection1 = project1.getJSONObject(GitConstants.KEY_GIT); String gitRemoteUri1 = gitSection1.optString(GitConstants.KEY_REMOTE); String gitIndexUri1 = gitSection1.optString(GitConstants.KEY_INDEX); String gitHeadUri1 = gitSection1.optString(GitConstants.KEY_HEAD); // clone2: create JSONObject project2 = createProjectOrLink(workspaceLocation, getMethodName() + "2", null); clonePath = getClonePath(workspaceId, project2); request = new PostGitCloneRequest().setURIish(uri).setFilePath(clonePath).setKnownHosts(knownHosts2) .setPrivateKey(privateKey).setPublicKey(publicKey).setPassphrase(passphrase).getWebRequest(); String cloneContentLocation2 = clone(request); // clone2: get project/folder metadata request = getGetRequest(cloneContentLocation2); response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); project2 = new JSONObject(response.getText()); // clone2: get git links JSONObject gitSection2 = project2.getJSONObject(GitConstants.KEY_GIT); String gitRemoteUri2 = gitSection2.getString(GitConstants.KEY_REMOTE); String gitCommitUri2 = gitSection2.getString(GitConstants.KEY_COMMIT); // clone1: list remotes request = GitRemoteTest.getGetGitRemoteRequest(gitRemoteUri1); response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); JSONObject remotes = new JSONObject(response.getText()); JSONArray remotesArray = remotes.getJSONArray(ProtocolConstants.KEY_CHILDREN); assertEquals(1, remotesArray.length()); JSONObject remote = remotesArray.getJSONObject(0); assertNotNull(remote);//w w w .ja v a2 s.c om assertEquals(Constants.DEFAULT_REMOTE_NAME, remote.getString(ProtocolConstants.KEY_NAME)); // clone1: change JSONObject testTxt1 = getChild(project1, "test.txt"); modifyFile(testTxt1, "incoming change"); // clone1: add request = GitAddTest.getPutGitIndexRequest(gitIndexUri1); response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); // clone1: commit request = GitCommitTest.getPostGitCommitRequest(gitHeadUri1, "incoming change commit", false); response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); // clone1: push ServerStatus pushStatus = push(gitRemoteUri1, 1, 0, Constants.MASTER, Constants.HEAD, false, null, knownHosts2, privateKey, publicKey, passphrase, true); assertEquals(true, pushStatus.isOK()); // clone2: get remote branch location JSONObject remoteBranch = getRemoteBranch(gitRemoteUri2, 1, 0, Constants.MASTER); String remoteBranchLocation2 = remoteBranch.getString(ProtocolConstants.KEY_LOCATION); // clone2: fetch fetch(remoteBranchLocation2, null, knownHosts2, privateKey, publicKey, passphrase, true); // clone2: get remote details JSONObject remoteBranch2 = getRemoteBranch(gitRemoteUri2, 1, 0, Constants.MASTER); String newRefId2 = remoteBranch2.getString(ProtocolConstants.KEY_ID); // clone2: merge into HEAD, "git merge origin/master" gitCommitUri2 = remoteBranch2.getString(GitConstants.KEY_HEAD); JSONObject merge = merge(gitCommitUri2, newRefId2); MergeStatus mergeResult = MergeStatus.valueOf(merge.getString(GitConstants.KEY_RESULT)); assertEquals(MergeStatus.FAST_FORWARD, mergeResult); // clone2: assert change from clone1 is in place JSONObject testTxt2 = getChild(project2, "test.txt"); request = getGetRequest(testTxt2.getString(ProtocolConstants.KEY_LOCATION)); response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); assertEquals("incoming change", response.getText()); }
From source file:org.eclipse.orion.server.tests.servlets.git.GitPushTest.java
@Test public void testPushRejected() throws Exception { URI workspaceLocation = createWorkspace(getMethodName()); String workspaceId = workspaceIdFromLocation(workspaceLocation); // clone1/*from www . j a v a 2s . c o m*/ JSONObject project1 = createProjectOrLink(workspaceLocation, getMethodName() + "1", null); IPath clonePath1 = getClonePath(workspaceId, project1); clone(clonePath1); // get project1 metadata WebRequest request = getGetRequest(project1.getString(ProtocolConstants.KEY_CONTENT_LOCATION)); WebResponse response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); project1 = new JSONObject(response.getText()); JSONObject gitSection1 = project1.optJSONObject(GitConstants.KEY_GIT); assertNotNull(gitSection1); String gitRemoteUri1 = gitSection1.optString(GitConstants.KEY_REMOTE); String gitIndexUri1 = gitSection1.optString(GitConstants.KEY_INDEX); String gitHeadUri1 = gitSection1.optString(GitConstants.KEY_HEAD); // clone2 JSONObject project2 = createProjectOrLink(workspaceLocation, getMethodName() + "2", null); IPath clonePath2 = getClonePath(workspaceId, project2); clone(clonePath2); // get project2 metadata request = getGetRequest(project2.getString(ProtocolConstants.KEY_CONTENT_LOCATION)); response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); project2 = new JSONObject(response.getText()); JSONObject gitSection2 = project2.optJSONObject(GitConstants.KEY_GIT); assertNotNull(gitSection2); String gitRemoteUri2 = gitSection2.getString(GitConstants.KEY_REMOTE); String gitIndexUri2 = gitSection2.getString(GitConstants.KEY_INDEX); String gitHeadUri2 = gitSection2.getString(GitConstants.KEY_HEAD); // clone1: change JSONObject testTxt1 = getChild(project1, "test.txt"); modifyFile(testTxt1, "clone1 change"); // clone1: add request = GitAddTest.getPutGitIndexRequest(gitIndexUri1); response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); // clone1: commit request = GitCommitTest.getPostGitCommitRequest(gitHeadUri1, "clone1 change commit", false); response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); // clone1: push ServerStatus pushStatus = push(gitRemoteUri1, 1, 0, Constants.MASTER, Constants.HEAD, false); assertEquals(true, pushStatus.isOK()); // clone2: change JSONObject testTxt2 = getChild(project2, "test.txt"); modifyFile(testTxt2, "clone2 change"); // clone2: add request = GitAddTest.getPutGitIndexRequest(gitIndexUri2); response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); // clone2: commit request = GitCommitTest.getPostGitCommitRequest(gitHeadUri2, "clone2 change commit", false); response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); // clone2: push pushStatus = push(gitRemoteUri2, 1, 0, Constants.MASTER, Constants.HEAD, false); assertEquals(IStatus.WARNING, pushStatus.getSeverity()); Status pushResult = Status.valueOf(pushStatus.getMessage()); assertEquals(Status.REJECTED_NONFASTFORWARD, pushResult); }
From source file:org.eclipse.orion.server.tests.servlets.git.GitPushTest.java
@Test public void testPushTags() throws Exception { URI workspaceLocation = createWorkspace(getMethodName()); String workspaceId = workspaceIdFromLocation(workspaceLocation); // clone1/* w w w . j av a 2 s.c om*/ JSONObject project1 = createProjectOrLink(workspaceLocation, getMethodName() + "1", null); IPath clonePath1 = getClonePath(workspaceId, project1); clone(clonePath1); // get project1 metadata WebRequest request = getGetRequest(project1.getString(ProtocolConstants.KEY_CONTENT_LOCATION)); WebResponse response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); project1 = new JSONObject(response.getText()); JSONObject gitSection1 = project1.optJSONObject(GitConstants.KEY_GIT); assertNotNull(gitSection1); String gitRemoteUri1 = gitSection1.optString(GitConstants.KEY_REMOTE); String gitTagUri1 = gitSection1.optString(GitConstants.KEY_TAG); // clone2 JSONObject project2 = createProjectOrLink(workspaceLocation, getMethodName() + "2", null); IPath clonePath2 = getClonePath(workspaceId, project2); clone(clonePath2); // get project2 metadata request = getGetRequest(project2.getString(ProtocolConstants.KEY_CONTENT_LOCATION)); response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); project2 = new JSONObject(response.getText()); JSONObject gitSection2 = project2.getJSONObject(GitConstants.KEY_GIT); String gitRemoteUri2 = gitSection2.getString(GitConstants.KEY_REMOTE); String gitHeadUri2 = gitSection2.getString(GitConstants.KEY_HEAD); String gitTagUri2 = gitSection2.getString(GitConstants.KEY_TAG); // clone1: tag HEAD with 'tag' tag(gitTagUri1, "tag", Constants.HEAD); ServerStatus pushStatus = push(gitRemoteUri1, 1, 0, Constants.MASTER, Constants.HEAD, true); assertEquals(true, pushStatus.isOK()); // clone2: list tags JSONArray tags = listTags(gitTagUri2); assertEquals(0, tags.length()); // clone2: fetch + merge JSONObject remoteBranch = getRemoteBranch(gitRemoteUri2, 1, 0, Constants.MASTER); String remoteBranchLocation2 = remoteBranch.getString(ProtocolConstants.KEY_LOCATION); fetch(remoteBranchLocation2); String id = remoteBranch.getString(ProtocolConstants.KEY_ID); merge(gitHeadUri2, id); // clone2: list tags again tags = listTags(gitTagUri2); assertEquals(1, tags.length()); }
From source file:org.b3log.symphony.model.Tag.java
/** * Normalizes the specified title. For example, Normalizes "JS" to "JavaScript. * * @param title the specified title/*ww w . jav a2 s . com*/ * @return normalized title */ private static String normalize(final String title) { final TagCache cache = LatkeBeanManagerImpl.getInstance().getReference(TagCache.class); final List<JSONObject> iconTags = cache.getIconTags(Integer.MAX_VALUE); Collections.sort(iconTags, new Comparator<JSONObject>() { @Override public int compare(final JSONObject t1, final JSONObject t2) { final String u1Title = t1.optString(Tag.TAG_T_TITLE_LOWER_CASE); final String u2Title = t2.optString(Tag.TAG_T_TITLE_LOWER_CASE); return u1Title.length() - u2Title.length(); } }); for (final JSONObject iconTag : iconTags) { final String iconTagTitle = iconTag.optString(Tag.TAG_TITLE); if (iconTagTitle.length() < 2) { continue; } if (StringUtils.containsIgnoreCase(title, iconTagTitle)) { return iconTagTitle; } } for (final Map.Entry<String, Set<String>> entry : NORMALIZE_MAPPINGS.entrySet()) { final Set<String> oddTitles = entry.getValue(); for (final String oddTitle : oddTitles) { if (StringUtils.equalsIgnoreCase(title, oddTitle)) { return entry.getKey(); } } } return title; }