View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements. See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership. The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License. You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied. See the License for the
16   * specific language governing permissions and limitations under the License.
17   */
18  package org.apache.shindig.social.opensocial.model;
19  
20  import org.apache.shindig.social.core.model.MessageImpl;
21  
22  import com.google.inject.ImplementedBy;
23  
24  /***
25   *
26   * Base interface for all message objects.
27   *
28   * see
29   * http://code.google.com/apis/opensocial/docs/0.7/reference/opensocial.Message.html
30   *
31   */
32  
33  @ImplementedBy(MessageImpl.class)
34  @Exportablebean
35  public interface Message {
36  
37    /***
38     * An enumeration of field names in a message.
39     */
40    public static enum Field {
41      /*** the field name for body. */
42      BODY("body"),
43      /*** the field name for title. */
44      TITLE("title"),
45      /*** the field name for type. */
46      TYPE("type");
47  
48      /***
49       * the name of the field.
50       */
51      private final String jsonString;
52  
53      /***
54       * Create a field based on a name.
55       * @param jsonString the name of the field
56       */
57      private Field(String jsonString) {
58        this.jsonString = jsonString;
59      }
60  
61      /***
62       * @return a string representation of the enum.
63       */
64      @Override
65      public String toString() {
66        return this.jsonString;
67      }
68    }
69  
70    /***
71     * The type of a message.
72     */
73    public enum Type {
74      /*** An email. */
75      EMAIL("EMAIL"),
76      /*** A short private message. */
77      NOTIFICATION("NOTIFICATION"),
78      /*** A message to a specific user that can be seen only by that user. */
79      PRIVATE_MESSAGE("PRIVATE_MESSAGE"),
80      /*** A message to a specific user that can be seen by more than that user. */
81      PUBLIC_MESSAGE("PUBLIC_MESSAGE");
82  
83      /***
84       * The type of message.
85       */
86      private final String jsonString;
87  
88      /***
89       * Create a message type based on a string token.
90       * @param jsonString the type of message
91       */
92      private Type(String jsonString) {
93        this.jsonString = jsonString;
94      }
95  
96      /***
97       * @return a string representation of the enum.
98       */
99      @Override
100     public String toString() {
101       return this.jsonString;
102     }
103   }
104 
105   /***
106    * Gets the main text of the message.
107    * @return the main text of the message
108    */
109   String getBody();
110 
111   /***
112    * Sets the main text of the message.
113    * HTML attributes are allowed and are sanitized by the container
114    * @param newBody the main text of the message
115    */
116   void setBody(String newBody);
117 
118   /***
119    * Gets the title of the message.
120    * @return the title of the message
121    */
122   String getTitle();
123 
124   /***
125    * Sets the title of the message.
126    * HTML attributes are allowed and are sanitized by the container.
127    * @param newTitle the title of the message
128    */
129   void setTitle(String newTitle);
130 
131   /***
132    * Gets the type of the message, as specified by opensocial.Message.Type.
133    * @return the type of message (enum Message.Type)
134    */
135   Type getType();
136 
137   /***
138    * Sets the type of the message, as specified by opensocial.Message.Type.
139    * @param newType the type of message (enum Message.Type)
140    */
141   void setType(Type newType);
142 
143   /***
144    * TODO implement either a standard 'sanitizing' facility or
145    * define an interface that can be set on this class so
146    * others can plug in their own.
147    * @param htmlStr String to be sanitized.
148    * @return the sanitized HTML String
149    */
150   String sanitizeHTML(String htmlStr);
151 }