List of usage examples for com.google.gwt.json.client JSONValue isObject
public JSONObject isObject()
From source file:org.sonatype.nexus.gwt.ui.client.JSONUtil.java
License:Open Source License
private static JSONObject lookupObject(JSONObject obj, String[] path, boolean createAllowed) { JSONObject node = obj;//ww w . jav a2 s . c om if (path.length > 1) { for (int i = 0; i < path.length - 1; i++) { JSONValue v = node.get(path[i]); if (v != null) { node = v.isObject(); } else if (createAllowed) { JSONObject childNode = new JSONObject(); node.put(path[i], childNode); node = childNode; } if (node == null) { break; } } } return node; }
From source file:org.sonatype.nexus.gwt.ui.client.repository.RepositoriesPage.java
License:Open Source License
public RepositoriesPage(JSONArrayDataStore repositories) { this.dataStore = repositories; repositoryTable = createTable(dataStore, new String[] { "name", "repoType", "repoPolicy", "status.proxyMode", "status.localStatus", "status.remoteStatus" }); repositoryTable.getToolBar().addToolBarListener(new ToolBarListener() { public void onRefresh(ToolBar sender) { sendRepositoryListRequest(); }/*from w ww. ja v a2s . c o m*/ public void onAdd(ToolBar sender) { NexusUI.openCreateRepositoryPage(new JSONObject()); } public void onEdit(ToolBar sender) { String repoId = getSelectedRepoId(); if (repoId != null) { NexusUI.server.getLocalInstance().getRepositoriesService().getRepositoryById(repoId) .read(new EntityResponseHandler() { public void onSuccess(Representation entity) { JSONValue json = (JSONValue) entity.getParsed(); JSONObject repo = json.isObject().get("data").isObject(); NexusUI.openEditRepositoryPage(repo); } public void onError(Request request, Throwable error) { Window.alert("Error: " + error); } }); } } public void onDelete(ToolBar sender) { String repoId = getSelectedRepoId(); if (repoId != null) { NexusUI.server.getLocalInstance().getRepositoriesService().getRepositoryById(repoId) .delete(new StatusResponseHandler() { public void onSuccess() { Window.alert("Repository deleted"); } public void onError(Request request, Throwable error) { Window.alert("Delete repository failed"); } }); } } }); add(new Header("Repositories")); add(repositoryTable); repositoryTable.setWidth("100%"); sendRepositoryListRequest(); }
From source file:org.spiffyui.client.JSONUtil.java
License:Apache License
/** * Get a JSONObject from the JSON object or null if it doesn't exist or * isn't a JSONObject/*from ww w.j a v a2 s .c o m*/ * * @param obj the object with the value * @param key the key for the object * * @return the value or null it could not be decoded */ public static JSONObject getJSONObject(JSONObject obj, String key) { JSONValue v = obj.get(key); if (v != null) { JSONObject a = v.isObject(); if (a != null) { return a; } } return null; }
From source file:org.spiffyui.client.JSONUtil.java
License:Apache License
/** * Get the RESTException containing the information in the specified JSON or null if the * JSON object does not correspond to the NCAC exception format. * // w w w . jav a 2s.co m * @param val the JSON value containing the exception * @param statusCode the status code of the response that generated this data * @param url the URL that was called to get this JSON * * @return the RESTException if this JSON represented an NCAC fault or null if it wasn't an NCAC fault */ public static RESTException getRESTException(JSONValue val, int statusCode, String url) { if (val.isObject() != null && containsKeyIgnoreCase(val.isObject(), "Fault")) { JSONObject fault = getIgnoreCase(val.isObject(), "Fault").isObject(); JSONObject objCode = getIgnoreCase(fault, "Code").isObject(); String code = getStringValueIgnoreCase(objCode, "Value"); String subcode = null; if (getIgnoreCase(objCode, "Subcode") != null) { subcode = getStringValueIgnoreCase(getIgnoreCase(objCode, "Subcode").isObject(), "Value"); } String reason = null; if (getIgnoreCase(fault, "Reason") != null && getIgnoreCase(fault, "Reason").isObject() != null && getIgnoreCase(getIgnoreCase(fault, "Reason").isObject(), "Text") != null) { reason = getStringValueIgnoreCase(getIgnoreCase(fault, "Reason").isObject(), "Text"); } HashMap<String, String> detailMap = new HashMap<String, String>(); if (getIgnoreCase(fault, "Detail") != null) { JSONObject details = getIgnoreCase(fault, "Detail").isObject(); for (String key : details.keySet()) { detailMap.put(key, getIgnoreCase(details, key).isString().stringValue()); } } return new RESTException(code, subcode, reason, detailMap, statusCode, url); } else { return null; } }
From source file:org.spiffyui.client.rest.AuthUtil.java
License:Apache License
private void doLogin(final RESTObjectCallBack<String> callback, JSONValue val, String username, String authUrl) {// w w w. ja v a 2 s .c o m RESTility.setTokenServerURL(authUrl); RESTility.setUsername(username); if (val == null) { callback.error(STRINGS.loginDataError("")); MessageUtil.showError(STRINGS.loginDataError("")); return; } JSONObject o = val.isObject(); if (o == null) { callback.error(STRINGS.loginDataError(val.toString())); MessageUtil.showError(STRINGS.loginDataError(val.toString())); return; } RESTility.setUserToken(o.get("Token").isString().stringValue()); RESTility.fireLoginSuccess(); callback.success(o.get("Token").isString().stringValue()); }
From source file:org.spiffyui.client.widgets.multivaluesuggest.MultivalueSuggestBoxBase.java
License:Apache License
/** * Handle the query response for getting items to suggest. * /*www . j a v a2 s .c o m*/ * @param callback the callback for the request * @param val the value we are getting suggestions for */ protected void handleQueryResponse(RESTObjectCallBack<OptionResultSet> callback, JSONValue val) { JSONObject obj = val.isObject(); int totSize = JSONUtil.getIntValue(obj, m_helper.getTotalSizeKey()); OptionResultSet options = new OptionResultSet(totSize); JSONArray optionsArray = JSONUtil.getJSONArray(obj, m_helper.getOptionsKey()); if (options.getTotalSize() > 0 && optionsArray != null) { for (int i = 0; i < optionsArray.size(); i++) { if (optionsArray.get(i) == null) { /* This happens when a JSON array has an invalid trailing comma */ continue; } JSONObject jsonOpt = optionsArray.get(i).isObject(); Option option = createOption(jsonOpt); options.addOption(option); } } callback.success(options); }
From source file:org.spiffyui.hellospiffylocalization.client.Index.java
License:Apache License
/** * Show the successful message result of our REST call. * // ww w . ja v a2s .com * @param val the value containing the JSON response from the server */ private void showSuccessMessage(JSONValue val) { JSONObject obj = val.isObject(); String name = JSONUtil.getStringValue(obj, "user"); String browser = JSONUtil.getStringValue(obj, "userAgent"); String server = JSONUtil.getStringValue(obj, "serverInfo"); String message = PROJ_STRINGS.message(name, browser, server); m_longMessage.setHTML(message); }
From source file:org.spiffyui.hellospiffyoauth.client.Contacts.java
License:Apache License
/** * Static method to load the contacts/* www .j a v a2 s . c o m*/ * and return them in the callback * @param oauthVerifier - the oauth verifier string * @param oauthToken - the oauth request token * @param callback - the RESTObjectCallBack to handle the response */ public static void loadContacts(final String oauthVerifier, final String oauthToken, final RESTObjectCallBack<Contacts> callback) { /* * Use the URL parameters from the google callback as parameters to the REST service. */ RESTility.callREST("./contacts?" + Index.OAUTH_VERIFIER + "=" + oauthVerifier + "&" + Index.OAUTH_TOKEN + "=" + oauthToken, new RESTCallback() { @Override public void onSuccess(JSONValue val) { JSONObject resp = val.isObject(); JSONObject feed = JSONUtil.getJSONObject(resp, "feed"); List<Contact> contactList = new ArrayList<Contact>(); JSONArray entries = JSONUtil.getJSONArray(feed, "entry"); for (int i = 0, len = entries.size(); i < len; i++) { Contact contact = new Contact(); JSONObject entry = entries.get(i).isObject(); JSONObject title = JSONUtil.getJSONObject(entry, "title"); String entryTitle = JSONUtil.getStringValue(title, "$t"); contact.setTitle(entryTitle); List<Email> emailList = new ArrayList<Email>(); JSONArray emails = JSONUtil.getJSONArray(entry, "gd$email"); if (emails != null) { for (int j = 0, size = emails.size(); j < size; j++) { Email email = new Email(); JSONObject emailJson = emails.get(j).isObject(); String address = JSONUtil.getStringValue(emailJson, "address"); email.setPrimary(JSONUtil.getBooleanValue(emailJson, "primary")); email.setAddress(address); emailList.add(email); } } contact.setEmails(emailList); contactList.add(contact); } callback.success(new Contacts(contactList)); } @Override public void onError(int statusCode, String errorResponse) { callback.error(errorResponse); } @Override public void onError(RESTException e) { callback.error(e); } }); }
From source file:org.spiffyui.spsample.client.rest.SampleAuthBean.java
License:Apache License
private static void createSampleAuthBean(JSONValue val, RESTObjectCallBack<SampleAuthBean> callback) { JSONObject info = val.isObject(); if (info == null) { MessageUtil.showError("An error occurred trying to get sample data."); return;//from w w w . j a v a2 s . c o m } Date date = null; try { String dateString = info.get("date").isString().stringValue(); date = new Date(Long.parseLong(dateString)); } catch (Exception e) { MessageUtil.showError("Invalid date: " + info.get("date").isString().stringValue()); } g_sampleAuthBean = new SampleAuthBean(info.get("message").isString().stringValue(), info.get("token").isString().stringValue(), date); callback.success(g_sampleAuthBean); }
From source file:org.spiffyui.spsample.client.rest.SampleOAuthBean.java
License:Apache License
private static void createSampleAuthBean(JSONValue val, RESTObjectCallBack<SampleOAuthBean> callback) { JSONObject info = val.isObject(); if (info == null) { MessageUtil.showError("An error occurred trying to get sample data."); return;//from w w w.jav a 2s. co m } Date date = null; try { String dateString = info.get("date").isString().stringValue(); date = new Date(Long.parseLong(dateString)); } catch (Exception e) { MessageUtil.showError("Invalid date: " + info.get("date").isString().stringValue()); } g_sampleAuthBean = new SampleOAuthBean(info.get("message").isString().stringValue(), info.get("token").isString().stringValue(), date); callback.success(g_sampleAuthBean); }