Example usage for com.google.gwt.json.client JSONValue isObject

List of usage examples for com.google.gwt.json.client JSONValue isObject

Introduction

In this page you can find the example usage for com.google.gwt.json.client JSONValue isObject.

Prototype

public JSONObject isObject() 

Source Link

Document

Returns non-null if this JSONValue is really a JSONObject.

Usage

From source file:fi.jyu.student.jatahama.onlineinquirytool.shared.ClaimAnalysis.java

License:Open Source License

private boolean fromJSONString(String json) {
    JSONObject obj = null;//from   w ww.  ja v  a2 s . co  m
    try {
        JSONValue parsed = JSONParser.parseStrict(json);
        if (parsed != null) {
            obj = parsed.isObject();
        }
    } catch (Exception e) {
        return false;
    }
    if (obj == null) {
        return false;
    } else {
        fromJSONObject(obj);
    }

    return true;
}

From source file:fi.jyu.student.jatahama.onlineinquirytool.shared.ClaimAnalysis.java

License:Open Source License

public void fromJSONObject(JSONObject obj) {
    reset();/*  w w w  .  j  ava  2  s.co  m*/
    JSONValue val = obj.get("claim");
    JSONString js = null;
    if (val != null) {
        js = val.isString();
        if (js != null) {
            claim = js.stringValue();
        }
    }
    val = obj.get("conclusion");
    if (val != null) {
        js = val.isString();
        if (js != null) {
            conclusion = js.stringValue();
        }
    }
    val = obj.get("perspectives");
    if (val != null) {
        JSONArray pa = val.isArray();
        if (pa != null) {
            for (int i = 0; i < pa.size(); i++) {
                val = pa.get(i);
                JSONObject pe = val.isObject();
                if (pe != null) {
                    perspectives.add(new AnalysisPerspective(pe));
                }
            }
        }
    }
}

From source file:fr.insalyon.creatis.vip.warehouse.client.view.WarehouseListTab.java

License:Open Source License

private String addProject(String jslist) {
    String result;/*from ww  w . j a v  a 2s  .  co  m*/
    logger = Logger.getLogger("warehouse");
    logger.log(Level.SEVERE, "warehouse access");
    JSONValue value = JSONParser.parseStrict(jslist);
    JSONObject jobj = value.isObject();
    //HashMap<String, String> maps = new HashMap<String, String>();
    result = "<b>" + jobj.get("name") + "</b> <br>";
    if (jobj.get("ID") != null) {
        result += "<b> projet ID: " + jobj.get("ID") + "</b>";
    }
    if (jobj.get("pi_firstname") != null) {
        result += "<b> PI: " + jobj.get("pi_firstname") + " " + jobj.get("pi_lastname") + "</b> <br>";
    }
    if (jobj.get("description") != null) {
        result += jobj.get("description") + "<br>";
    }
    return result;
}

From source file:fr.insalyon.creatis.vip.warehouse.client.view.WarehouseListTab.java

License:Open Source License

private String addSubjects(String jslist) {
    String result;/*from  ww  w .jav a2 s. c o  m*/

    JSONValue value = JSONParser.parseStrict(jslist);
    JSONObject jobj = value.isObject();
    //HashMap<String, String> maps = new HashMap<String, String>();
    result = "<b>" + jobj.get("name") + "</b> <br>";
    if (jobj.get("label") != null) {
        result += "<b> projet ID: " + jobj.get("ID") + "</b>";
    }
    if (jobj.get("pi_firstname") != null) {
        result += "<b> PI: " + jobj.get("pi_firstname") + " " + jobj.get("pi_lastname") + "</b> <br>";
    }
    if (jobj.get("description") != null) {
        result += jobj.get("description") + "<br>";
    }
    return result;
}

From source file:fr.insalyon.creatis.vip.warehouse.client.view.WarehouseListTab.java

License:Open Source License

private String getProjectID(String jslist) {
    String res = "";
    JSONValue value = JSONParser.parseStrict(jslist);
    JSONObject jobj = value.isObject();
    if (jobj.get("ID") != null) {
        res = jobj.get("ID").isObject().toString();
    }//w  ww .j a  v a 2 s.co m
    return res;
}

From source file:fr.insalyon.creatis.vip.warehouse.client.view.WarehouseListTab.java

License:Open Source License

private void readJSonProjects(String jslist) {
    JSONValue value = JSONParser.parseStrict(jslist);
    JSONObject jobj = value.isObject();
    JSONValue jsonValue = jobj.get("ResultSet").isObject().get("Result");
    int id = 0;/*  w w w.j  a  v a 2s.co m*/
    for (String key : jsonValue.isObject().keySet()) {
        Record rc = new Record();
        rc.setAttribute("subject", id);
        JSONValue subjs = jsonValue.isObject().get(key).isObject();
        rc.setAttribute("label", subjs.isObject().get("label").toString());
        rc.setAttribute("date", subjs.isObject().get("insert_date").toString());
        rc.setAttribute("user", subjs.isObject().get("insert_user").toString());
        rc.setAttribute("subjectid", subjs.isObject().get("ID").toString());
        dbGrid.addData(rc);
        id++;
    }
}

From source file:fr.insalyon.creatis.vip.warehouse.client.view.WarehouseListTab.java

License:Open Source License

private void readJSON(String jslist, TreeItem parent) {
    JSONValue value = JSONParser.parseStrict(jslist);
    JSONObject jobj = value.isObject();
    for (String key : jobj.keySet()) {
        JSONValue jsonValue = jobj.get(key);
        TreeItem item = new TreeItem("<b>" + key + "</b> ");
        parent.addItem(item);//ww w .  j av a 2s . co  m

        if (jsonValue != null) {
            if (jsonValue.isObject() != null) {
                readJSON(jsonValue.isObject().toString(), item);
            } else if (jsonValue.isArray() != null) {
            } else {
                if ("oldValue".equals(key)) {
                    item.setHTML("<b>before:</b> " + jsonValue.toString());
                } else {
                    item.setHTML("<b>after:</b> " + jsonValue.toString());
                }
            }
        } else {
            item.setText("<b>" + item.getText() + ":</b> null");
        }
    }

}

From source file:fr.insalyon.creatis.vip.warehouse.client.view.WarehouseListTab.java

License:Open Source License

private void extractSubjects(String project) {
    JSONValue value = JSONParser.parseStrict(project);
    JSONObject jobj = value.isObject();
    JSONArray subArray = jobj.get("ResultSet").isObject().get("Result").isArray();
    for (int i = 0; i < subArray.size(); i++) {
        Record rc = new Record();
        rc.setAttribute("ID", i);
        rc.setAttribute("Projects", addSubjects(subArray.get(i).isObject().toString()));
        //rc.setAttribute("projectid",getProjectID(jsonValue.isObject().get(key).isObject().toString()));
        dbGrid.addData(rc);// w  w w . j a  v a2s.c  o  m
    }
}

From source file:gate.mimir.gus.client.Application.java

License:Open Source License

/**
 * Display the results for the <code>currentPage</code>
 * in the <code>resultsTable</code>.
 *//*from  w w  w.java2 s  . co m*/
private void displayFirstQueryResults() {
    statisticsLabel.displayMessage(
            "Retrieving " + resultsPerPage + " results starting from " + (resultsStartIndex + 1) + "...");

    final long startTime = System.currentTimeMillis();
    gusService.search(getIndexId(), query, new AsyncCallback<String>() {
        String error = "A very very unexpected exception.";

        public void onFailure(Throwable caught) {
            try {
                throw caught;
            } catch (IncompatibleRemoteServiceException e) {
                error = "This client is not compatible with the "
                        + "server. Please cleanup and refresh the browser.";
            } catch (InvocationException e) {
                error = "The call didn't complete cleanly.";
            } catch (SearchException e) {
                error = e.getMessage();
            } catch (Throwable e) {
                error = "A very unexpected exception. Is the server ready? "
                        + "Please wait few seconds before trying again.";
            } finally {
                displayMessage(error);
            }
        }

        public void onSuccess(String result) {
            JSONValue jsonValue;
            try {
                jsonValue = JSONParser.parse(result);
            } catch (JSONException e) {
                displayMessage("Failed to parse JSON response: " + result);
                return;
            }
            JSONObject jsonObject;
            JSONString jsonString;
            if ((jsonObject = jsonValue.isObject()) != null
                    && (jsonString = jsonObject.get("id").isString()) != null) {
                queryID = jsonString.stringValue();
            } else {
                displayMessage("No id returned for this query.");
                return;
            }
            timer = new Timer() {
                public void run() {
                    displayNextQueryResults(startTime);
                }
            };
            // wait for the search to retrieve some results
            timer.schedule(500);
        }
    });
}

From source file:gov.nist.spectrumbrowser.admin.AccountManagement.java

License:Open Source License

@Override
public void onSuccess(String result) {
    try {//from w  w  w.ja  v a  2  s  . c  om
        JSONValue jsonValue = JSONParser.parseLenient(result);
        userAccounts = jsonValue.isObject().get(Defines.USER_ACCOUNTS).isArray();
        logger.finer("Returned " + userAccounts.size());
        String serverStatus = jsonValue.isObject().get(Defines.STATUS).isString().stringValue();
        String serverStatusMessage = jsonValue.isObject().get(Defines.STATUS_MESSAGE).isString().stringValue();
        logger.finer("serverStatus " + serverStatus);
        logger.finer("serverStatusMessage " + serverStatusMessage);

        if (serverStatus != "OK") {
            Window.alert(serverStatusMessage);
        }

        if (redraw) {
            this.draw();
        }
    } catch (Throwable th) {
        Window.alert("Error parsing returned JSON");
        logger.log(Level.SEVERE, "Problem parsing JSON", th);
    }
}