/** * Retrieves the OpenSocial ID associated with the instance. Returns an * empty string if no ID has been set. */ public String getId() { OpenSocialField IDField = this.getField("id"); if (IDField != null && !IDField.isComplex()) { return(IDField.getStringValue()); } return(""); }
/** * Retrieves the display name (typically given name followed by family name) * associated with the instance. Returns an empty string if no name has been * set. * * @throws OpenSocialException */ public String getDisplayName() { OpenSocialField nicknameField = this.getField("nickname"); OpenSocialField nameField = this.getField("name"); StringBuilder name = new StringBuilder(); if (nameField != null) { if (nameField.isComplex()) { OpenSocialObject nameObject = nameField.getValue(); if (nameObject.hasField("givenName")) { name.Append(nameObject.getField("givenName").getStringValue()); } if (nameObject.hasField("givenName") && nameObject.hasField("familyName")) { name.Append(" "); } if (nameObject.hasField("familyName")) { name.Append(nameObject.getField("familyName").getStringValue()); } } else { name.Append(nameField.getStringValue()); } } else if (nicknameField != null) { if (!nicknameField.isComplex()) { name.Append(nicknameField.getStringValue()); } } return(name.ToString()); }
/** * Recursively iterates through the properties of the passed JsonObject * object and returns a Map of OpenSocialField objects keyed on Strings * representing the property values and names respectively. * * @param o Object-oriented representation of a JSON object which is * transformed into and returned as a Map of OpenSocialField * objects keyed on Strings * @throws JSONException */ private static Dictionary <String, OpenSocialField> createObjectRepresentation( JsonObject o) { Dictionary <String, OpenSocialField> r = new Dictionary <String, OpenSocialField>(); var keys = o.Names; foreach (string key in keys) { String property = o[key].ToString(); if (property.Length > 0 && property[0] == '{') { JsonObject p = o.getJSONObject(key); OpenSocialField field = new OpenSocialField(true); field.addValue(new OpenSocialObject(createObjectRepresentation(p))); r.Add(key, field); } else if (property.Length > 0 && property[0] == '[') { JsonArray p = (JsonArray)o[key]; var values = createArrayRepresentation(p); OpenSocialField field = new OpenSocialField(true); foreach (var v in values) { field.addValue(v); } r.Add(key, field); } else if (property.Length > 0) { OpenSocialField field = new OpenSocialField(false); field.addValue(unescape(property)); r.Add(key, field); } } return(r); }
/** * Creates a new entry in fields Map, associating the passed OpenSocialField * object with the passed key. * * @param key Field name * @param value OpenSocialField object to associate with key */ public void setField(String key, OpenSocialField value) { this.fields.Add(key, value); }
/** * Recursively iterates through the properties of the passed JsonObject * object and returns a Map of OpenSocialField objects keyed on Strings * representing the property values and names respectively. * * @param o Object-oriented representation of a JSON object which is * transformed into and returned as a Map of OpenSocialField * objects keyed on Strings * @throws JSONException */ private static Dictionary<String, OpenSocialField> createObjectRepresentation( JsonObject o) { Dictionary<String,OpenSocialField> r = new Dictionary<String,OpenSocialField>(); var keys = o.Names; foreach (string key in keys) { String property = o[key].ToString(); if (property.Length > 0 && property[0] == '{') { JsonObject p = o.getJSONObject(key); OpenSocialField field = new OpenSocialField(true); field.addValue(new OpenSocialObject(createObjectRepresentation(p))); r.Add(key, field); } else if (property.Length > 0 && property[0] == '[') { JsonArray p = (JsonArray)o[key]; var values = createArrayRepresentation(p); OpenSocialField field = new OpenSocialField(true); foreach(var v in values) { field.addValue(v); } r.Add(key, field); } else if (property.Length > 0) { OpenSocialField field = new OpenSocialField(false); field.addValue(unescape(property)); r.Add(key, field); } } return r; }