private void call(final JSONValue... params) { final JSONArray aryParams = new JSONArray(); for (final JSONValue p : params) { aryParams.set(aryParams.size(), p); } nativeCall(aryParams.getJavaScriptObject()); }
@Override protected void onInit(final JSONValue data) { try { final JSONArray criteria = data.isArray(); this.criteria.clear(); for (int i = 0; i < criteria.size(); i++) { final JSONObject searchTypeJSON = criteria.get(i).isObject(); final Map<String, Criterion> searchType = new LinkedHashMap<String, Criterion>(); for (int j = 0; j < searchTypeJSON.get("elements").isArray().size(); j++) { final Criterion criterion = Criterion.readMe(j, searchTypeJSON); if (j == 0 && (selectedCriterion == null && i == 0 || selectedCriterion != null && criterion.displaytype.equalsIgnoreCase(selectedCriterion.displaytype))) { selectedCriterion = criterion; selectedCriterionHistory.put(selectedCriterion.displaytype, selectedCriterion); } searchType.put(criterion.getName(), criterion); } this.criteria.put( searchTypeJSON.get("displaytype").isString().stringValue().trim(), searchType); } } catch (final Exception e) { getLogger().severe(getClass().getName().replace("Impl", "") + ".onInit() : " + e); } }
private static JSONArray intArrayToJSONArray(int[] values) { JSONArray vals = new JSONArray(); for (int i = 0, len = values.length; i < len; i++) { vals.set(i, new JSONNumber(values[i])); } return vals; }
/** Show publish dialog. */ public void publish(String msg) { JSONObject data = new JSONObject(); data.put("method", new JSONString("stream.publish")); data.put("message", new JSONString(msg)); JSONObject attachment = new JSONObject(); attachment.put("name", new JSONString("Mancala")); attachment.put("caption", new JSONString("The Board Game")); attachment.put("description", new JSONString(msg)); attachment.put("href", new JSONString("http://10.mymancala.appspot.com")); data.put("attachment", attachment); JSONObject actionLink = new JSONObject(); actionLink.put("text", new JSONString("Mancala")); actionLink.put("href", new JSONString("http://10.mymancala.appspot.com")); JSONArray actionLinks = new JSONArray(); actionLinks.set(0, actionLink); data.put("action_links", actionLinks); data.put("user_message_prompt", new JSONString("Share your thoughts about Mancala")); /* * Execute facebook method */ fbCore.ui(data.getJavaScriptObject(), new Callback()); }
protected List<String> readStringRepeated( JSONObject jsonObject, String fieldLabel, int fieldNumber) throws InvalidProtocolBufferException { List<String> fieldStringRepeated = null; if (jsonObject != null && fieldLabel != null) { JSONValue fieldValue = jsonObject.get(fieldLabel); if (fieldValue != null) { JSONArray fieldJSONArray = jsonValueToArray(fieldValue); if (fieldJSONArray != null) { fieldStringRepeated = new ArrayList<String>(); for (int i = 0; i < fieldJSONArray.size(); ++i) { String fieldString = jsonValueToString(fieldJSONArray.get(i)); if (fieldString != null) { fieldStringRepeated.add(fieldString); } else { throw InvalidProtocolBufferException.failedToReadStringRepeated(fieldLabel); } } } else { throw InvalidProtocolBufferException.failedToReadStringRepeated(fieldLabel); } } } return fieldStringRepeated; }
@Override public JSONObject toJSONObject() { JSONObject object = super.toJSONObject(); ImageDataFilterChain chain = m_filters; if ((null != chain) && (chain.size() > 0)) { JSONArray filters = new JSONArray(); JSONObject filter = new JSONObject(); filter.put("active", JSONBoolean.getInstance(chain.isActive())); for (ImageDataFilter<?> ifilter : chain.getFilters()) { if (null != ifilter) { JSONObject make = ifilter.toJSONObject(); if (null != make) { filters.set(filters.size(), make); } } } filter.put("filters", filters); object.put("filter", filter); } return object; }
/* * view Album contents */ private void viewAlbum(JSONValue a_Value) { JSONArray jsonArray = (JSONArray) a_Value; Item item = null; int id; JSONObject jso; m_Items.clear(); for (int i = 0; i < jsonArray.size(); ++i) { jso = (JSONObject) jsonArray.get(i); id = Utils.extractId(jso.get("id")); if (m_IDtoItem.containsKey(id)) { item = m_IDtoItem.get(id); item.updateValues(jso); } else { item = new Item(this, jso, m_Container); m_IDtoItem.put(id, item); if (item.isAlbum()) { linkAlbum(item); } } m_Items.add(item); } m_View.setAlbum(this); addPendingDownloads(); }
public static <Type> JSONValue toJSON( Map<String, Type> value, AbstractJsonEncoderDecoder<Type> encoder, Style style) { if (value == null) { return JSONNull.getInstance(); } switch (style) { case DEFAULT: case SIMPLE: { JSONObject rc = new JSONObject(); for (Entry<String, Type> t : value.entrySet()) { rc.put(t.getKey(), encoder.encode(t.getValue())); } return rc; } case JETTISON_NATURAL: { JSONObject rc = new JSONObject(); JSONArray entries = new JSONArray(); int i = 0; for (Entry<String, Type> t : value.entrySet()) { JSONObject entry = new JSONObject(); entry.put("key", new JSONString(t.getKey())); entry.put("value", encoder.encode(t.getValue())); entries.set(i++, entry); } rc.put("entry", entries); return rc; } default: throw new UnsupportedOperationException( "The encoding style is not yet suppored: " + style.name()); } }
private static JSONValue toJSON(SerValue serValue) { if (serValue.isString()) { return new JSONString(serValue.asString()); } else if (serValue.isReal()) { return new JSONNumber(serValue.asReal()); } else if (serValue.isArray()) { SerArray serArray = serValue.asArray(); JSONArray jsonArray = new JSONArray(); for (int i = 0; i != serArray.size(); ++i) { jsonArray.set(i, toJSON(serArray.get(i))); } return jsonArray; } else if (serValue.isObject()) { SerObject serObject = serValue.asObject(); JSONObject jsonObject = new JSONObject(); for (String key : serObject.keySet()) { jsonObject.put(key, toJSON(serObject.get(key))); } return jsonObject; } else { throw new IllegalArgumentException(); } }
/** Render publish */ public void streamPublish() { JSONObject streamPublish = new JSONObject(); streamPublish.put("method", new JSONString("stream.publish")); streamPublish.put( "message", new JSONString("Getting education about Facebook Connect and GwtFB")); JSONObject attachment = new JSONObject(); attachment.put("name", new JSONString("GwtFB")); attachment.put("caption", new JSONString("The Facebook Connect Javascript SDK and GWT")); attachment.put( "description", new JSONString( "A small GWT library that allows you to interact with Facebook Javascript SDK in GWT ")); attachment.put("href", new JSONString("http://www.gwtfb.com")); streamPublish.put("attachment", attachment); JSONObject actionLink = new JSONObject(); actionLink.put("text", new JSONString("Code")); actionLink.put("href", new JSONString("http://www.gwtfb.com")); JSONArray actionLinks = new JSONArray(); actionLinks.set(0, actionLink); streamPublish.put("action_links", actionLinks); streamPublish.put( "user_message_prompt", new JSONString("Share your thoughts about Connect and GWT")); fbCore.ui(streamPublish.getJavaScriptObject(), new Callback()); }
public static int getSize(JSONValue value) { if (value == null || value.isNull() != null) { return 0; } JSONArray array = asArray(value); return array.size(); }
public List<JsonStream> readStreamRepeated( JSONObject jsonObject, String fieldLabel, int fieldNumber) throws InvalidProtocolBufferException { List<JsonStream> fieldStreamRepeated = null; if (jsonObject != null) { JSONValue fieldValue = jsonObject.get(fieldLabel); if (fieldValue != null) { JSONArray fieldJSONArray = jsonValueToArray(fieldValue); if (fieldJSONArray != null) { fieldStreamRepeated = new ArrayList<JsonStream>(); for (int i = 0; i < fieldJSONArray.size(); ++i) { JsonStream fieldStream = null; JSONObject fieldJSONObject = jsonValueToObject(fieldJSONArray.get(i)); if (fieldJSONObject != null) { fieldStream = this.newStream(fieldJSONObject); } if (fieldStream != null) { fieldStreamRepeated.add(fieldStream); } else { throw InvalidProtocolBufferException.failedToReadObjectRepeated(fieldLabel); } } } else { throw InvalidProtocolBufferException.failedToReadObjectRepeated(fieldLabel); } } } return fieldStreamRepeated; }
public static <KeyType, ValueType> Map<KeyType, ValueType> toMap( JSONValue value, AbstractJsonEncoderDecoder<KeyType> keyEncoder, AbstractJsonEncoderDecoder<ValueType> valueEncoder, Style style) { if (value == null || value.isNull() != null) { return null; } switch (style) { case DEFAULT: case SIMPLE: { JSONObject object = value.isObject(); if (object == null) { throw new DecodingException("Expected a json object, but was given: " + value); } HashMap<KeyType, ValueType> rc = new HashMap<KeyType, ValueType>(object.size() * 2); for (String key : object.keySet()) { rc.put(keyEncoder.decode(key), valueEncoder.decode(object.get(key))); } return rc; } case JETTISON_NATURAL: { JSONObject object = value.isObject(); if (object == null) { throw new DecodingException("Expected a json object, but was given: " + value); } value = object.get("entry"); if (value == null) { throw new DecodingException("Expected an entry array not found"); } JSONArray entries = value.isArray(); if (entries == null) { throw new DecodingException("Expected an entry array, but was given: " + value); } HashMap<KeyType, ValueType> rc = new HashMap<KeyType, ValueType>(object.size() * 2); for (int i = 0; i < entries.size(); i++) { JSONObject entry = entries.get(i).isObject(); if (entry == null) throw new DecodingException("Expected an entry object, but was given: " + value); JSONValue key = entry.get("key"); if (key == null) throw new DecodingException("Expected an entry key field not found"); JSONString k = key.isString(); if (k == null) throw new DecodingException( "Expected an entry key to be a string, but was given: " + value); rc.put(keyEncoder.decode(k.stringValue()), valueEncoder.decode(entry.get("value"))); } return rc; } default: throw new UnsupportedOperationException( "The encoding style is not yet supported: " + style.name()); } }
/** * 为菜单添加他所对应的Tab列表 * * @param jsonTabArray json中的Tab数组对象 */ private void AddTabItem(JSONArray jsonTabArray) { if (jsonTabArray == null || jsonTabArray.size() == 0) return; List<GWTMenuTab> tabList = new ArrayList<GWTMenuTab>(); for (int i = 0; i < jsonTabArray.size(); i++) { tabList.add(new GWTMenuTab(jsonTabArray.get(i).isObject())); } this.set(TabItem, tabList); }
private JSONArray toArray(Iterable<? extends QueryElement> elements) { JSONArray a = new JSONArray(); int i = 0; for (QueryElement element : elements) { a.set(i++, element.accept(this)); } return a; }
private static void unwrap(final List<MarshalledMessage> messages, final JSONArray val) { for (int i = 0; i < val.size(); i++) { final JSONValue v = val.get(i); if (v.isArray() != null) { unwrap(messages, v.isArray()); } else { messages.add(new MarshalledMessageImpl((JSONObject) v)); } } }
/** * 静态函数:根据输入的Json字符串,解析成一个完整的菜单树 * * @param menuStr Json字符串 * @return 菜单树形根节点 */ public static GWTMenu GetMenuList(String menuStr) { // 解析菜单 JSONValue obj1 = JSONParser.parse(menuStr); JSONArray menuList = obj1.isArray(); GWTMenu menu = new GWTMenu(); for (int i = 0; i < menuList.size(); i++) { AddGWTMenu(menu, menuList.get(i)); } return menu; }
public static <Type> JSONValue toJSON(byte[] value, AbstractJsonEncoderDecoder<Type> encoder) { if (value == null) { return JSONNull.getInstance(); } JSONArray rc = new JSONArray(); int i = 0; for (byte t : value) { rc.set(i++, new JSONNumber(t)); } return rc; }
private void parseProperties(final JSONObject json) { JSONArray jsonProperties = JsonUtil.getArray(json, PROPERTIES); if (jsonProperties != null) { for (int i = 0, len = jsonProperties.size(); i < len; i++) { JSONObject jsonProperty = JsonUtil.getObjectAt(jsonProperties, i); addProperty(new Property(jsonProperty)); } } }
public static <Type> JSONValue toJSON( Collection<Type> value, AbstractJsonEncoderDecoder<Type> encoder) { if (value == null) { return JSONNull.getInstance(); } JSONArray rc = new JSONArray(); int i = 0; for (Type t : value) { rc.set(i++, encoder.encode(t)); } return rc; }
/** * JSONObject-Array * * <p>タグバリュー型のJSONObjectを生成する * * @param key * @param value * @return */ public JSONObject tagValue(String key, JSONObject[] value) { JSONObject arrayObj = new JSONObject(); JSONArray array = new JSONArray(); int i = 0; for (JSONObject currentValue : value) { array.set(i++, currentValue); } arrayObj.put(key, array); return arrayObj; }
public static <Type> Set<Type> toSet(JSONValue value, AbstractJsonEncoderDecoder<Type> encoder) { if (value == null || value.isNull() != null) { return null; } JSONArray array = asArray(value); HashSet<Type> rc = new HashSet<Type>(array.size() * 2); int size = array.size(); for (int i = 0; i < size; i++) { rc.add(encoder.decode(array.get(i))); } return rc; }
public static boolean[] toArray( JSONValue value, AbstractJsonEncoderDecoder<Boolean> encoder, boolean[] template) { if (value == null || value.isNull() != null) { return null; } JSONArray array = asArray(value); int size = array.size(); for (int i = 0; i < size; i++) { template[i] = encoder.decode(array.get(i)); } return template; }
// TODO(sbeutel): new map method to handle other key values than String public static <KeyType, ValueType> JSONValue toJSON( Map<KeyType, ValueType> value, AbstractJsonEncoderDecoder<KeyType> keyEncoder, AbstractJsonEncoderDecoder<ValueType> valueEncoder, Style style) { if (value == null) { return JSONNull.getInstance(); } switch (style) { case DEFAULT: case SIMPLE: { JSONObject rc = new JSONObject(); for (Entry<KeyType, ValueType> t : value.entrySet()) { // TODO find a way to check only once JSONValue k = keyEncoder.encode(t.getKey()); if (k.isString() != null) { rc.put(k.isString().stringValue(), valueEncoder.encode(t.getValue())); } else { rc.put(k.toString(), valueEncoder.encode(t.getValue())); } } return rc; } case JETTISON_NATURAL: { JSONObject rc = new JSONObject(); JSONArray entries = new JSONArray(); int i = 0; for (Entry<KeyType, ValueType> t : value.entrySet()) { JSONObject entry = new JSONObject(); // TODO find a way to check only once JSONValue k = keyEncoder.encode(t.getKey()); if (k.isString() != null) { entry.put("key", k); } else { entry.put("key", new JSONString(k.toString())); } entry.put("value", valueEncoder.encode(t.getValue())); entries.set(i++, entry); } rc.put("entry", entries); return rc; } default: throw new UnsupportedOperationException( "The encoding style is not yet supported: " + style.name()); } }
private void saveSecuritySettings(final AsyncCallback<Boolean> callback) { JSONObject jsNewRoleAssignments = new JSONObject(); JSONArray jsLogicalRoleAssignments = new JSONArray(); int x = 0; for (Map.Entry<String, List<String>> roleAssignment : newRoleAssignments.entrySet()) { JSONArray jsLogicalRoles = new JSONArray(); int y = 0; for (String logicalRoleName : roleAssignment.getValue()) { jsLogicalRoles.set(y++, new JSONString(logicalRoleName)); } JSONObject jsRoleAssignment = new JSONObject(); jsRoleAssignment.put("roleName", new JSONString(roleAssignment.getKey())); jsRoleAssignment.put("logicalRoles", jsLogicalRoles); jsLogicalRoleAssignments.set(x++, jsRoleAssignment); } jsNewRoleAssignments.put("logicalRoleAssignments", jsLogicalRoleAssignments); RequestBuilder saveSettingRequestBuilder = new RequestBuilder(RequestBuilder.PUT, contextURL + "api/userrole/roleAssignments"); saveSettingRequestBuilder.setHeader( "Content-Type", "application/json"); // $NON-NLS-1$//$NON-NLS-2$ WaitPopup.getInstance().setVisible(true); try { saveSettingRequestBuilder.sendRequest( jsNewRoleAssignments.toString(), new RequestCallback() { @Override public void onError(Request request, Throwable exception) { WaitPopup.getInstance().setVisible(false); callback.onFailure(exception); } @Override public void onResponseReceived(Request request, Response response) { WaitPopup.getInstance().setVisible(false); if (response.getStatusCode() == 200) { masterRoleMap.putAll(newRoleAssignments); newRoleAssignments.clear(); callback.onSuccess(true); } else { callback.onSuccess(false); } } }); } catch (RequestException e) { WaitPopup.getInstance().setVisible(false); callback.onFailure(e); } }
protected JSONObject writeStringRepeated( JSONObject jsonObject, String fieldLabel, Collection<String> fieldStringRepeated) { if (jsonObject != null && fieldLabel != null && fieldStringRepeated != null && !fieldStringRepeated.isEmpty()) { JSONArray fieldJSONArray = new JSONArray(); int i = 0; for (String fieldString : fieldStringRepeated) { fieldJSONArray.set(i++, new JSONString(fieldString)); } jsonObject.put(fieldLabel, fieldJSONArray); } return jsonObject; }
protected JSONObject writeBooleanRepeated( JSONObject jsonObject, String fieldLabel, Collection<Boolean> fieldBooleanRepeated) { if (jsonObject != null && fieldLabel != null && fieldBooleanRepeated != null && !fieldBooleanRepeated.isEmpty()) { JSONArray fieldJSONArray = new JSONArray(); int i = 0; for (Boolean fieldBoolean : fieldBooleanRepeated) { fieldJSONArray.set(i++, JSONBoolean.getInstance(fieldBoolean.booleanValue())); } jsonObject.put(fieldLabel, fieldJSONArray); } return jsonObject; }
protected JSONObject writeDoubleRepeated( JSONObject jsonObject, String fieldLabel, Collection<Double> fieldDoubleRepeated) { if (jsonObject != null && fieldLabel != null && fieldDoubleRepeated != null && !fieldDoubleRepeated.isEmpty()) { JSONArray fieldJSONArray = new JSONArray(); int i = 0; for (Double fieldDouble : fieldDoubleRepeated) { fieldJSONArray.set(i++, new JSONNumber(fieldDouble.doubleValue())); } jsonObject.put(fieldLabel, fieldJSONArray); } return jsonObject; }
protected JSONObject writeFloatRepeated( JSONObject jsonObject, String fieldLabel, Collection<Float> fieldFloatRepeated) { if (jsonObject != null && fieldLabel != null && fieldFloatRepeated != null && !fieldFloatRepeated.isEmpty()) { JSONArray fieldJSONArray = new JSONArray(); int i = 0; for (Float fieldFloat : fieldFloatRepeated) { fieldJSONArray.set(i++, new JSONNumber(fieldFloat.floatValue())); } jsonObject.put(fieldLabel, fieldJSONArray); } return jsonObject; }
protected JSONObject writeIntegerRepeated( JSONObject jsonObject, String fieldLabel, Collection<Integer> fieldIntegerRepeated) { if (jsonObject != null && fieldLabel != null && fieldIntegerRepeated != null && !fieldIntegerRepeated.isEmpty()) { JSONArray fieldJSONArray = new JSONArray(); int i = 0; for (Integer fieldInteger : fieldIntegerRepeated) { fieldJSONArray.set(i++, new JSONNumber(fieldInteger.intValue())); } jsonObject.put(fieldLabel, fieldJSONArray); } return jsonObject; }