You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@shindig.apache.org by li...@apache.org on 2008/03/21 08:45:46 UTC

svn commit: r639560 - in /incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/social/opensocial/model: Enum.java Message.java Person.java

Author: lindner
Date: Fri Mar 21 00:45:40 2008
New Revision: 639560

URL: http://svn.apache.org/viewvc?rev=639560&view=rev
Log:
Apply patch from Michael Papp for SHINDIG-124
- Implementation POJO for opensocial.Enum.xx and opensocial.Message

Added:
    incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/social/opensocial/model/Enum.java
    incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/social/opensocial/model/Message.java
Modified:
    incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/social/opensocial/model/Person.java

Added: incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/social/opensocial/model/Enum.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/social/opensocial/model/Enum.java?rev=639560&view=auto
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/social/opensocial/model/Enum.java (added)
+++ incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/social/opensocial/model/Enum.java Fri Mar 21 00:45:40 2008
@@ -0,0 +1,176 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+package org.apache.shindig.social.opensocial.model;
+
+import org.apache.shindig.social.AbstractGadgetData;
+import org.apache.shindig.social.Mandatory;
+
+
+/**
+ * see
+ * http://code.google.com/apis/opensocial/docs/0.7/reference/opensocial.Enum.html
+ * 
+ * Base class for all Enum objects. This class allows containers to use constants
+ * for fields that have a common set of values.
+ *
+ */
+public final class Enum<E extends java.lang.Enum<E>> extends AbstractGadgetData {
+  @Mandatory private String displayValue = null;
+  private java.lang.Enum<E> key = null;
+
+  /**
+   * public java.lang.Enum for opensocial.Enum.Drinker
+   */
+  public enum Drinker {
+    HEAVILY("HEAVILY"),
+    NO("NO"),
+    OCCASIONALLY("OCCASIONALLY"),
+    QUIT("QUIT"),
+    QUITTING("QUITTING"),
+    REGULARLY("REGULARLY"),
+    SOCIALLY("SOCIALLY"),
+    YES("YES");
+
+    private final String jsonString;
+
+    private Drinker(String jsonString) {
+      this.jsonString = jsonString;
+    }
+
+    @Override
+    public String toString() {
+      return this.jsonString;
+    }
+  }
+
+  /**
+   * public java.lang.Enum for opensocial.Enum.Gender
+   */
+  public enum Gender {
+    FEMALE("FEMALE"),
+    MALE("MALE");
+
+    private final String jsonString;
+
+    private Gender(String jsonString) {
+      this.jsonString = jsonString;
+    }
+
+    @Override
+    public String toString() {
+      return this.jsonString;
+    }
+  }
+
+  /**
+   * public java.lang.Enum for opensocial.Enum.Smoker
+   */
+  public enum Smoker {
+    HEAVILY("HEAVILY"),
+    NO("NO"),
+    OCCASIONALLY("OCCASIONALLY"),
+    QUIT("QUIT"),
+    QUITTING("QUITTING"),
+    REGULARLY("REGULARLY"),
+    SOCIALLY("SOCIALLY"),
+    YES("YES");
+
+    private final String jsonString;
+
+    private Smoker(String jsonString) {
+      this.jsonString = jsonString;
+    }
+
+    @Override
+    public String toString() {
+      return this.jsonString;
+    }
+  }
+
+  /**
+   * Constructor
+   * @param initKey java.lang.Enum initial key
+   * @param initValue String initial display value
+   * @throws NullPointerException if initValue is null
+   */
+  public Enum(java.lang.Enum<E> initKey, String initValue) throws NullPointerException {
+    
+    if (null != initValue) {
+      this.displayValue = initValue;
+      this.key = initKey;
+    }
+    else {
+      throw new NullPointerException("Enum.setDisplayValue cannot be set to null");
+    }
+  }
+
+  /**
+   * Gets the value of this Enum. This is the string displayed to the user.
+   * If the container supports localization, the string will be localized.
+   * @return the Enum's user visible value
+   */
+  public String getDisplayValue() {
+    return this.displayValue;
+  }
+
+  /**
+   * Sets the value of this Enum. This is the string displayed to the user.
+   * If the container supports localization, the string will be localized.
+   * @throws NullPointerException if the String passed is null.
+   */
+  public void setDisplayValue(String newStr) throws NullPointerException {
+    if (null != newStr) {
+      // TODO: Is this string localized??
+//      this.key = SmokerKey.get(newStr.trim().toUpperCase());
+      this.displayValue = newStr;
+    }
+    else {
+      throw new NullPointerException("Enum.setDisplayValue cannot be set to null");
+    }
+  }
+
+  /**
+   * Gets the key for this Enum.
+   * Use this for logic within your gadget.
+   * @return java.lang.Enum key object for this Enum.
+   */
+  public java.lang.Enum<E> getKey() {
+    return this.key;
+  }
+
+  /**
+   * Sets the key for this Enum.
+   * Use this for logic within your gadget.
+   */
+  public void setKey(java.lang.Enum<E> newKey) {
+    this.key = newKey;
+  }
+
+
+  /**
+   * Helper method that converts a String to an equivalent key value (if any)
+   * @param value the String value to be matched with appropriate keys.
+   * @return the matching java.lang.Enum key matching the string, if any
+   */
+  public java.lang.Enum<E> stringToKey(String value) {
+    if ((null != value) && (null != key)) {
+      return java.lang.Enum.valueOf(key.getDeclaringClass(), value);
+    }
+    return null;
+  }
+}

Added: incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/social/opensocial/model/Message.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/social/opensocial/model/Message.java?rev=639560&view=auto
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/social/opensocial/model/Message.java (added)
+++ incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/social/opensocial/model/Message.java Fri Mar 21 00:45:40 2008
@@ -0,0 +1,123 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+package org.apache.shindig.social.opensocial.model;
+
+import org.apache.shindig.social.AbstractGadgetData;
+
+/**
+ * 
+ * Base interface for all message objects.
+ * 
+ * see
+ * http://code.google.com/apis/opensocial/docs/0.7/reference/opensocial.Message.html
+ *
+ */
+public final class Message extends AbstractGadgetData {
+  private String body;
+  private String title;
+  private Type type;
+
+  public enum Type {
+    /* An email */
+    EMAIL("EMAIL"),
+    /* A short private message */
+    NOTIFICATION("NOTIFICATION"),
+    /* A message to a specific user that can be seen only by that user */
+    PRIVATE_MESSAGE("PRIVATE_MESSAGE"),
+    /* A message to a specific user that can be seen by more than that user */
+    PUBLIC_MESSAGE("PUBLIC_MESSAGE");
+
+    private final String jsonString;
+
+    private Type(String jsonString) {
+      this.jsonString = jsonString;
+    }
+
+    @Override
+    public String toString() {
+      return this.jsonString;
+    }
+  }
+
+  public Message(String initBody, String initTitle, Type initType) {
+    this.body = initBody;
+    this.title = initTitle;
+    this.type = initType;
+  }
+
+  /**
+   * Gets the main text of the message.
+   * @return the main text of the message
+   */
+  public String getBody() {
+    return this.body;
+  }
+
+  /**
+   * Sets the main text of the message.
+   * HTML attributes are allowed and are sanitized by the container
+   * @param newBody the main text of the message
+   */
+  public void setBody(String newBody) {
+    this.body = newBody;
+  }
+
+  /**
+   * Gets the title of the message
+   * @return the title of the message
+   */
+  public String getTitle() {
+    return this.title;
+  }
+
+  /**
+   * Sets the title of the message
+   * HTML attributes are allowed and are sanitized by the container.
+   * @param newTitle the title of the message
+   */
+  public void setTitle(String newTitle) {
+    this.title = newTitle;
+  }
+
+  /**
+   * Gets the type of the message, as specified by opensocial.Message.Type
+   * @return the type of message (enum Message.Type)
+   */
+  public Type getType() {
+    return type;
+  }
+
+  /**
+   * Sets the type of the message, as specified by opensocial.Message.Type
+   * @param newType the type of message (enum Message.Type)
+   */
+  public void setType(Type newType) {
+    this.type = newType;
+  }
+
+  /**
+   * TODO implement either a standard 'sanitizing' facility or
+   * define an interface that can be set on this class so
+   * others can plug in their own.
+   * @param htmlStr String to be sanitized.
+   * @return the sanitized HTML String
+   */
+  public String sanitizeHTML(String htmlStr) {
+    return htmlStr;
+  }	  
+}

Modified: incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/social/opensocial/model/Person.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/social/opensocial/model/Person.java?rev=639560&r1=639559&r2=639560&view=diff
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/social/opensocial/model/Person.java (original)
+++ incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/social/opensocial/model/Person.java Fri Mar 21 00:45:40 2008
@@ -40,14 +40,12 @@
   private String children;
   private Address currentLocation;
   private Date dateOfBirth;
-  // drinker : Person's drinking status, specified as an opensocial.Enum with
-  // the enum's key referencing opensocial.Enum.Drinker.
+  private Enum<Enum.Drinker> drinker;
   private List<Email> emails;
   private String ethnicity;
   private String fashion;
   private List<String> food;
-  // gender : Person's gender, specified as an opensocial.Enum with the enum's
-  // key referencing opensocial.Enum.Gender.
+  private Enum<Enum.Gender> gender;
   private String happiestWhen;
   private List<String> heroes;
   private String humor;
@@ -75,8 +73,7 @@
   private String scaredOf;
   private List<Organization> schools;
   private String sexualOrientation;
-  // smoker Person's smoking status, specified as an opensocial.Enum with the
-  // enum's key referencing opensocial.Enum.Smoker.
+  private Enum<Enum.Smoker> smoker;
   private List<String> sports;
   private String status;
   private List<String> tags;
@@ -176,6 +173,14 @@
     this.dateOfBirth = dateOfBirth;
   }
 
+  public Enum<Enum.Drinker> getDrinker() {
+    return this.drinker;
+  }
+
+  public void setDrinker(Enum<Enum.Drinker> newDrinker) {
+    this.drinker = newDrinker;
+  }
+
   public List<Email> getEmails() {
     return emails;
   }
@@ -208,6 +213,14 @@
     this.food = food;
   }
 
+  public Enum<Enum.Gender> getGender() {
+    return this.gender;
+  }
+
+  public void setGender(Enum<Enum.Gender> newGender) {
+    this.gender = newGender;
+  }
+
   public String getHappiestWhen() {
     return happiestWhen;
   }
@@ -422,6 +435,14 @@
 
   public void setSexualOrientation(String sexualOrientation) {
     this.sexualOrientation = sexualOrientation;
+  }
+
+  public Enum<Enum.Smoker> getSmoker() {
+    return this.smoker;
+  }
+
+  public void setSmoker(Enum<Enum.Smoker> newSmoker) {
+    this.smoker = newSmoker;
   }
 
   public List<String> getSports() {