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

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

Introduction

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

Prototype

public JSONArray isArray() 

Source Link

Document

Returns a non-null reference if this JSONValue is really a JSONArray.

Usage

From source file:org.talend.mdm.webapp.welcomeportal.client.rest.StatisticsRestServiceHandler.java

License:Open Source License

public void getContainerJournalStats(String dataContainer, ConfigModel configModel,
        final SessionAwareAsyncCallback<JSONArray> callback) {
    if (dataContainer == null) {
        throw new IllegalArgumentException("Data container required"); //$NON-NLS-1$
    }/*from   w  w w .  j a  va2  s  . c om*/

    client.init(Method.GET,
            restServiceUrl + "/journal/" + dataContainer + "?top=0&timeframe=" + configModel.getSettingValue()); //$NON-NLS-1$ //$NON-NLS-2$
    client.setCallback(new ResourceSessionAwareCallbackHandler() {

        @Override
        public void doProcess(Request request, Response response) throws Exception {

            JsonRepresentation jsonRepresentation = RestServiceHelper
                    .getJsonRepresentationFromResponse(response);
            if (jsonRepresentation != null) {
                JSONValue jsonValue = jsonRepresentation.getJsonObject().get("journal"); //$NON-NLS-1$
                callback.onSuccess(jsonValue.isArray());
            }

        }
    });
    client.request(MediaType.APPLICATION_JSON);

}

From source file:org.talend.mdm.webapp.welcomeportal.client.rest.StatisticsRestServiceHandler.java

License:Open Source License

public void getContainerMatchingStats(String dataContainer, ConfigModel configModel,
        final SessionAwareAsyncCallback<JSONArray> callback) {
    if (dataContainer == null) {
        throw new IllegalArgumentException("Data container required"); //$NON-NLS-1$
    }//from  w w w .j  av  a  2 s  . c  om

    client.init(Method.GET,
            restServiceUrl + "/matching/" + dataContainer + "?top=" + configModel.getSettingValue()); //$NON-NLS-1$ //$NON-NLS-2$
    client.setCallback(new ResourceSessionAwareCallbackHandler() {

        @Override
        public void doProcess(Request request, Response response) throws Exception {

            JsonRepresentation jsonRepresentation = RestServiceHelper
                    .getJsonRepresentationFromResponse(response);
            if (jsonRepresentation != null) {
                JSONValue jsonValue = jsonRepresentation.getJsonObject().get("matching"); //$NON-NLS-1$
                callback.onSuccess(jsonValue.isArray());
            }

        }
    });
    client.request(MediaType.APPLICATION_JSON);

}

From source file:org.talend.mdm.webapp.welcomeportal.client.rest.StatisticsRestServiceHandler.java

License:Open Source License

public void getRoutingEventStats(ConfigModel configModel, final SessionAwareAsyncCallback<JSONArray> callback) {
    client.init(Method.GET, restServiceUrl + "/events?top=5&timeframe=" + configModel.getSettingValue()); //$NON-NLS-1$
    client.setCallback(new ResourceSessionAwareCallbackHandler() {

        @Override//from w  ww  . j a va 2  s . c  o  m
        public void doProcess(Request request, Response response) throws Exception {

            JsonRepresentation jsonRepresentation = RestServiceHelper
                    .getJsonRepresentationFromResponse(response);
            if (jsonRepresentation != null) {
                JSONValue jsonValue = jsonRepresentation.getJsonObject().get("events"); //$NON-NLS-1$
                callback.onSuccess(jsonValue.isArray());
            }

        }
    });
    client.request(MediaType.APPLICATION_JSON);

}

From source file:org.thechiselgroup.biomixer.client.json.JsJsonParser.java

License:Apache License

@Override
public Object get(Object jsonValue, int index) {
    JSONValue node = (JSONValue) jsonValue;

    if (node == null) {
        return null;
    }//  www  . j  a va2s  .  c o m

    return node.isArray().get(index);
}

From source file:org.utgenome.gwt.utgb.client.db.DatabaseTable.java

License:Apache License

public void setTableData(String jsonData) {
    // clear the row data
    while (_table.getRowCount() > 1)
        _table.removeRow(_table.getRowCount() - 1);

    try {//from  w w  w  . j  a  va  2  s . c o m
        JSONValue json = JSONParser.parse(jsonData);
        JSONObject root;
        if ((root = json.isObject()) != null) {
            JSONValue array = root.get("data");
            if (array == null)
                return;
            JSONArray rowArray;
            if ((rowArray = array.isArray()) != null) {
                for (int i = 0; i < rowArray.size(); i++) {
                    addRow(rowArray.get(i));
                }
            }
        }
    } catch (JSONException e) {
        GWT.log("JSON error", e);
    }
}

From source file:org.utgenome.gwt.utgb.client.track.lib.NavigatorTrack.java

License:Apache License

@Override
public void restoreProperties(CanonicalProperties properties) {

    try {// w  ww  .  j  a  va  2 s  .c  o  m
        JSONValue v = JSONParser.parse(properties.get("sequenceList", "[]"));
        sequenceInfoList.clear();
        JSONArray list = v.isArray();
        if (list != null) {
            for (int i = 0; i < list.size(); i++) {
                JSONObject sequenceInfo = list.get(i).isObject();
                if (sequenceInfo != null) {
                    JSONValue speciesValue = sequenceInfo.get("species");
                    if (speciesValue == null)
                        continue;

                    String species = JSONUtil.toStringValue(speciesValue);
                    SequenceInfo si = new SequenceInfo(species);
                    JSONValue arrayValue = sequenceInfo.get("revision");
                    JSONArray revisionArray = arrayValue.isArray();
                    for (int j = 0; j < revisionArray.size(); j++) {
                        String revision = JSONUtil.toStringValue(revisionArray.get(j));
                        si.addRevision(revision);
                    }
                    sequenceInfoList.add(si);
                }
            }
        }
    } catch (JSONException e) {
        GWT.log("failed to parse json : " + properties.get("sequenceList"), e);
    }

}

From source file:org.utgenome.gwt.utgb.client.util.JSONUtil.java

License:Apache License

public static ArrayList<String> parseJSONArray(String jsonArray) {
    if (jsonArray == null)
        return new ArrayList<String>();

    if (!jsonArray.startsWith("[") || !jsonArray.endsWith("]"))
        throw new IllegalArgumentException("invalid json array data");

    ArrayList<String> elementList = new ArrayList<String>();
    JSONValue v = JSONParser.parse(jsonArray);
    JSONArray array = v.isArray();
    if (array != null) {
        for (int i = 0; i < array.size(); i++)
            elementList.add(toStringValue(array.get(i)));
    }//from   w w w.ja  v a  2  s . co m
    return elementList;
}

From source file:org.vaadin.alump.offlinebuilder.client.offline.OfflineStorage.java

License:Open Source License

protected static List<String> getStringList(String key) {
    String value = storage.getItem(key);
    if (value == null) {
        return null;
    }/*  w  w w .j  ava 2  s .  c om*/
    List<String> list = new ArrayList<String>();
    JSONValue array = JSONParser.parseStrict(value);
    for (int i = 0; i < array.isArray().size(); ++i) {
        list.add(array.isArray().get(i).isString().stringValue());
    }
    return list;
}

From source file:org.waveprotocol.wave.client.wavepanel.impl.toolbar.gadget.GwtGadgetInfoParser.java

License:Apache License

@Override
public List<GadgetInfo> parseGadgetInfoJson(String json) {
    List<GadgetInfo> gadgetList = new ArrayList<GadgetInfo>();
    JSONValue value = JSONParser.parseStrict(json);
    JSONArray array = value.isArray();
    if (array != null) {
        for (int i = 0; i < array.size(); i++) {
            JSONValue item = array.get(i);
            GadgetInfo info = parseGadgetInfo(item);
            if (info != null) {
                gadgetList.add(info);/*from   w  ww.  j  av  a 2 s . c  o m*/
            }
        }
    }
    return gadgetList;
}

From source file:org.xwiki.gwt.wysiwyg.client.MenuItemDescriptorJSONParser.java

License:Open Source License

/**
 * Creates a list of menu item descriptors from the given JSON value.
 * /* ww  w .  j  av  a  2 s  .  c o m*/
 * @param value a JSON value
 * @return a list of menu item descriptors
 */
private List<MenuItemDescriptor> getMenuItemDescriptors(JSONValue value) {
    JSONArray jsDescriptors = value.isArray();
    if (jsDescriptors == null) {
        return Collections.emptyList();
    }
    List<MenuItemDescriptor> descriptors = new ArrayList<MenuItemDescriptor>();
    for (int i = 0; i < jsDescriptors.size(); i++) {
        MenuItemDescriptor descriptor = getMenuItemDescriptor(jsDescriptors.get(i));
        if (descriptor != null) {
            descriptors.add(descriptor);
        }
    }
    return descriptors;
}