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:com.dawg6.web.dhcalc.client.JsonUtil.java

License:Open Source License

public static Hero[] parseHeroList(String text) {

    if (text == null) {
        return new Hero[0];
    } else {/*from w w  w  .  j a v  a 2 s . c om*/

        try {
            JSONValue value = JSONParser.parseLenient(text);
            JSONArray array = value.isArray();

            if (array == null)
                return null;

            List<Hero> list = new Vector<Hero>(array.size());

            for (int i = 0; i < array.size(); i++) {
                JSONValue e = array.get(i);

                if (e != null) {
                    JSONObject obj = e.isObject();

                    if (obj != null) {
                        Hero h = JsonUtil.toHero(obj);
                        list.add(h);
                    }
                }
            }

            return list.toArray(new Hero[0]);
        } catch (Exception e) {
            return new Hero[0];
        }
    }
}

From source file:com.dimdim.conference.ui.envcheck.client.layout.PostResponse.java

License:Open Source License

public PostResponse(String responseText) {
    try {/*from   w  ww  .jav  a 2  s . c  om*/
        JSONValue responseObject = JSONParser.parse(responseText);
        if (responseObject != null) {
            JSONObject obj = responseObject.isObject();
            if (obj != null) {
                if (obj.containsKey("result")) {
                    //         System.out.println("1");
                    result = obj.get("result").isString().stringValue();//.stringValue();
                }
                if (obj.containsKey("url")) {
                    //         System.out.println("1");
                    url = obj.get("url").isString().stringValue();//.stringValue();
                }
                if (obj.containsKey("message")) {
                    //         System.out.println("1");
                    message = obj.get("message").isString().stringValue();//.stringValue();
                }
            }
        }
    } catch (Exception e) {

    }
}

From source file:com.dimdim.conference.ui.json.client.ResponseAndEventReader.java

License:Open Source License

public UIServerResponse readGetEventsResponse(JSONValue value) {
    JSONArray eventsArray = value.isArray();
    UIServerResponse resp = null;//from w  ww  .ja  va 2  s.co m
    if (eventsArray == null) {
        JSONObject obj = value.isObject();
        //Window.alert("ResponseAndEventReader:readResponse value.isObject()?::"+obj);
        if (obj != null) {
            eventsArray = obj.isArray();
            //Window.alert("ResponseAndEventReader:readResponse value.isArray()?::"+eventsArray);
            if (eventsArray == null) {
                //   Read and make array out of it. We know this is an array.
                eventsArray = new JSONArray();
                //            String[] keys = obj.getKeys();
                //            for (int i=0; i<keys.length; i++)
                //            {
                //               eventsArray.add(obj.get(keys[i]));
                //            }
            }
        }
    }
    //Window.alert("ResponseAndEventReader:readResponse array?::"+eventsArray);
    if (eventsArray != null) {
        //Window.alert("Reading array");
        resp = new UIServerResponse();
        resp.setSuccess(true);
        ArrayList aryList = new ArrayList();
        int size = eventsArray.size();
        for (int i = 0; i < size; i++) {
            JSONValue arrayMember = eventsArray.get(i);
            //Window.alert("Reading array member:"+arrayMember);
            Object data = readResponse(arrayMember);
            //Window.alert("Read array member:"+data);
            aryList.add(data);
        }
        resp.setArrayList(aryList);
    }
    //      else if (obj != null)
    //      {
    //         resp = readResponse(value);
    //      }
    return resp;
}

From source file:com.dimdim.conference.ui.json.client.ResponseAndEventReader.java

License:Open Source License

public UIServerResponse readResponse(JSONValue value) {
    UIServerResponse resp = new UIServerResponse();
    JSONObject obj = value.isObject();
    //Window.alert("ResponseAndEventReader:readResponse::"+obj);
    //      Window.alert("ResponseAndEventReader:readResponse::"+obj.isArray());
    //      Window.alert("ResponseAndEventReader:readResponse::"+obj.isObject());
    if (obj != null) {
        //   At present we use only object returns for all urls.
        //Window.alert("Reading non array return");
        if (obj.containsKey(KEY_TYPE)) {
            //         System.out.println("1");
            String str = obj.get(KEY_TYPE).isString().stringValue();//.stringValue();
            //Window.alert(KEY_TYPE+":"+str);
            if (str.equals(KEY_VALUE_SUCCESS) || str.equals(KEY_VALUE_EVENT) || str.equals(KEY_VALUE_MESSAGE)) {
                resp.setSuccess(true);/*from  w w  w  . j  a v  a2s. c o m*/
            }
        }
        if (obj.containsKey(KEY_FEATURE_ID)) {
            String featureId = obj.get(KEY_FEATURE_ID).isString().stringValue();//.stringValue();
            //Window.alert(KEY_FEATURE_ID+":"+featureId);
            resp.setFeatureId(featureId);
        }
        if (obj.containsKey(KEY_EVENT_ID)) {
            String eventId = obj.get(KEY_EVENT_ID).isString().stringValue();//.stringValue();
            //Window.alert(KEY_EVENT_ID+":"+eventId);
            resp.setEventId(eventId);
        }
        JSONValue v = obj.get(KEY_DATA);
        if (v != null) {
            //Window.alert(KEY_DATA+":");
            if (obj.containsKey(KEY_DATA_TYPE)) {
                //   Supported types are array, string and object.
                String dataType = obj.get(KEY_DATA_TYPE).isString().stringValue();//.stringValue();
                //Window.alert(KEY_DATA_TYPE+":"+dataType);
                if (dataType.equals(KEY_VALUE_DATA_TYPE_OBJECT)) {
                    Object data = readObject(obj.get(KEY_DATA).isObject());
                    resp.setData(data);
                } else if (dataType.equals(KEY_VALUE_DATA_TYPE_STRING)) {
                    //   Assume a simple string.
                    String str = obj.get(KEY_DATA).toString();
                    resp.setData(str);
                } else if (dataType.equals(KEY_VALUE_DATA_TYPE_ARRAY)) {
                    //   Assume a simple string.
                    //Window.alert(KEY_DATA+":v:"+v);
                    JSONObject vo = v.isObject();
                    //Window.alert(KEY_DATA+":v:"+vo);
                    JSONArray ary = v.isArray();
                    //Window.alert(KEY_DATA+":v:"+ary);
                    if (ary == null && vo != null) {
                        ary = vo.isArray();
                    }
                    ArrayList aryList = new ArrayList();
                    if (ary != null) {
                        int size = ary.size();
                        for (int i = 0; i < size; i++) {
                            JSONObject jsonObj = ary.get(i).isObject();
                            Object data = readObject(jsonObj);
                            aryList.add(data);
                        }
                    }
                    resp.setArrayList(aryList);
                } else {
                    //Window.alert("Unrecognized data type:"+dataType);
                }
            }
        } else {
            //Window.alert("No data found");
        }
    }
    return resp;
}

From source file:com.dimdim.conference.ui.model.client.dms.DMSjsonResponseHandler.java

License:Open Source License

public StartConversionResponse readStartConversionResponse(String responseText) {
    StartConversionResponse scr = null;//from www.j  av  a2 s  .  co  m
    try {
        JSONValue jsonResponse = JSONParser.parse(responseText);
        if (jsonResponse.isObject() != null) {
            scr = new StartConversionResponse(jsonResponse.isObject());
        }
    } catch (Exception e) {
    }
    return scr;
}

From source file:com.dimdim.conference.ui.model.client.dms.DMSjsonResponseHandler.java

License:Open Source License

public ConversionProgressCheckResponse readConversionProgressCheckResponse(String responseText) {
    ConversionProgressCheckResponse cpcr = null;
    try {/*from   ww w  .j  a v  a 2 s  . co m*/
        JSONValue jsonResponse = JSONParser.parse(responseText);
        if (jsonResponse.isObject() != null) {
            cpcr = new ConversionProgressCheckResponse(jsonResponse.isObject());
        }
    } catch (Exception e) {
    }
    return cpcr;
}

From source file:com.dimdim.conference.ui.model.client.PopoutCallbackReader.java

License:Open Source License

/**
 * Convert the text into /* w  w  w  . j av  a2s  .c  om*/
 * @param dataText
 */
private final void readDataText(String dataText) {
    try {
        //            Window.alert("-"+dataText+"-");
        JSONValue jsonObject = JSONParser.parse(dataText);
        if (jsonObject != null) {
            //               Window.alert("-"+jsonObject+"-");
            JSONObject jObj = jsonObject.isObject();
            if (jObj != null) {
                UIPopoutPanelData ppd = (UIPopoutPanelData) jsonReader.readObject(jObj);
                if (ppd != null) {
                    //                     Window.alert(ppd.toString());
                    PopoutWindowProxy pwp = (PopoutWindowProxy) this.popoutWindowProxies.get(ppd.getWindowId());
                    if (pwp != null) {
                        if (ppd.getDataText().equals("POPOUT_CLOSED")) {
                            pwp.popoutWindowClosed();
                        } else if (ppd.getDataText().equals("POPOUT_LOADED")) {
                            pwp.popoutWindowLoaded();
                        } else if (ppd.getDataText().equals("POPOUT_DATA_RECEIVED")) {
                            pwp.popoutDataTransferReceived();
                        } else {
                            pwp.receivePanelDataFromPopout(ppd);
                        }
                    } else {
                        //                        Window.alert("No popout window proxy available for:"+ppd.getWindowId());
                    }
                } else {
                    //                     Window.alert("No callback available to pass on the data:");
                }
            }
        } else {
            //               Window.alert("*** JSONParser.parse returned null");
        }
    } catch (Exception e) {
        //         Window.alert(e.getMessage());
    }
    return;
}

From source file:com.dimdim.conference.ui.publisher.client.PublisherInterfaceManager.java

License:Open Source License

/**
 * @return//ww  w .  ja v a  2  s. com
 */
public int isSharingActive() {
    String tempString = null;
    Element elem = null;

    elem = getPubElement();
    //Window.alert("inside pub intf mngr's isSharingActive -- ");
    if (null != elem) {
        tempString = PublisherMethodHandler.getScreencastResult(elem);
    } else {
        //Window.alert("isSharingActive publisher not found..");
    }

    JSONValue jVal = JSONParser.parse(tempString);
    JSONObject jObj = jVal.isObject();
    String returnVal = jObj.get("screencastResult").isString().stringValue();

    //    DebugPanel.getDebugPanel().addDebugMessage( "Is SharingActive : " + returnVal);

    return Integer.parseInt(returnVal);
}

From source file:com.dimdim.conference.ui.sharing.client.ResourceSharingPanel.java

License:Open Source License

public void readPanelData(String dataText) {
    //   A simple safety precaution.
    //      Window.alert("In popped out resource player: ");
    //      if (this.inPopout)
    //      {/*from w  w  w  .j a v a  2 s .c  om*/
    String s = this.decodeBase64(dataText);
    //         Window.alert("In popped out resource player: "+s);
    if (!s.equals("no_data")) {
        //            Window.alert("In popped out resource player: "+s);
        try {
            JSONValue jsonObject = JSONParser.parse(s);
            if (jsonObject != null) {
                //                  Window.alert("-"+jsonObject+"-");
                JSONObject jObj = jsonObject.isObject();
                if (jObj != null) {
                    UIResourceObject res = (UIResourceObject) jsonReader.readObject(jObj);
                    if (res != null) {
                        this.activeResource = null;
                        this.onSharingStarted(res);
                    } else {
                        //                        Window.alert("JSON parsing error");
                    }
                }
            }
        } catch (Exception e) {
            //               Window.alert(e.getMessage());
        }
    }
    //      }
}

From source file:com.dimdim.ui.common.client.data.SelectList.java

License:Open Source License

public SelectList(String name, JSONArray options) {
    this.name = name;
    this.options = new Vector();
    if (options != null) {
        int num = options.size();
        for (int i = 0; i < num; i++) {
            JSONValue v = options.get(i);
            JSONObject option = v.isObject();
            if (option != null) {
                this.options.addElement(new SelectListOption(option));
            }/*from   w  w w.jav a2  s .c  om*/
        }
    }
}