View Javadoc

1   /*
2    * Copyright 2004 Sun Microsystems, Inc.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   *
16   */
17  package com.sun.syndication.feed.atom;
18  
19  import com.sun.syndication.feed.impl.ObjectBean;
20  
21  import java.io.Serializable;
22  import java.util.HashSet;
23  import java.util.Set;
24  
25  /***
26   * Bean for content elements of Atom feeds.
27   * <p>
28   * @author Alejandro Abdelnur
29   * @author Dave Johnson (updated for Atom 1.0)
30   */
31  public class Content implements Cloneable,Serializable {
32      
33      private ObjectBean _objBean;
34      
35      private String _value;
36      private String _src; 
37      private String _type;
38      
39      /*** @since Atom 1.0 */
40      public static final String TEXT = "text";
41      
42      /*** @since Atom 1.0 */
43      public static final String HTML = "html";
44   
45      /*** @since Atom 1.0 */
46      public static final String XHTML = "xhtml";
47  
48      /*** Atom 0.3 only */
49      public static final String XML = "xml";   
50      
51      /*** Atom 0.3 only */   
52      public static final String BASE64 = "base64"; 
53      
54      /*** Atom 0.3 only */
55      public static final String ESCAPED = "escaped"; 
56  
57      private String _mode;  
58      private static final Set MODES = new HashSet(); 
59      static {
60          MODES.add(XML);
61          MODES.add(BASE64);
62          MODES.add(ESCAPED);
63      }
64  
65  
66      /***
67       * Default constructor. All properties are set to <b>null</b>.
68       * <p>
69       *
70       */
71      public Content() {
72          _objBean = new ObjectBean(this.getClass(),this);
73      }
74  
75      /***
76       * Creates a deep 'bean' clone of the object.
77       * <p>
78       * @return a clone of the object.
79       * @throws CloneNotSupportedException thrown if an element of the object cannot be cloned.
80       *
81       */
82      public Object clone() throws CloneNotSupportedException {
83          return _objBean.clone();
84      }
85  
86      /***
87       * Indicates whether some other object is "equal to" this one as defined by the Object equals() method.
88       * <p>
89       * @param other he reference object with which to compare.
90       * @return <b>true</b> if 'this' object is equal to the 'other' object.
91       *
92       */
93      public boolean equals(Object other) {
94          return _objBean.equals(other);
95      }
96  
97      /***
98       * Returns a hashcode value for the object.
99       * <p>
100      * It follows the contract defined by the Object hashCode() method.
101      * <p>
102      * @return the hashcode of the bean object.
103      *
104      */
105     public int hashCode() {
106         return _objBean.hashCode();
107     }
108 
109     /***
110      * Returns the String representation for the object.
111      * <p>
112      * @return String representation for the object.
113      *
114      */
115     public String toString() {
116         return _objBean.toString();
117     }
118 
119     /***
120      * Returns the content type.
121      * <p>
122      * @return the content type, <b>null</b> if none.
123      * @since Atom 1.0
124      */
125     public String getType() {
126         return _type;
127     }
128 
129     /***
130      * Sets the content type.
131      * <p>
132      * @param type the content type, <b>null</b> if none.
133      * @since Atom 1.0
134      */
135     public void setType(String type) {
136         _type = type;
137     }
138 
139     /***
140      * Returns the content mode (Atom 0.3 only).
141      * <p>
142      * The mode indicates how the value was/will-be encoded in the XML feed.
143      * <p>
144      * @return the content mode, <b>null</b> if none.
145      */
146     public String getMode() {
147         return _mode;
148     }
149 
150     /***
151      * Sets the content mode (Atom 0.3 only).
152      * <p>
153      * The mode indicates how the value was/will-be encoded in the XML feed.
154      * <p>
155      * @param mode the content mode, <b>null</b> if none.
156      */
157     public void setMode(String mode) {
158         mode = (mode!=null) ? mode.toLowerCase() : null;
159         if (mode==null || !MODES.contains(mode)) {
160             throw new IllegalArgumentException("Invalid mode ["+mode+"]");
161         }
162         _mode = mode;
163     }
164 
165     /***
166      * Returns the content value.
167      * <p>
168      * The return value should be decoded.
169      * <p>
170      * @return the content value, <b>null</b> if none.
171      *
172      */
173     public String getValue() {
174         return _value;
175     }
176 
177     /***
178      * Sets the content value.
179      * <p>
180      * The value being set should be decoded.
181      * <p>
182      * @param value the content value, <b>null</b> if none.
183      *
184      */
185     public void setValue(String value) {
186         _value = value;
187     }
188 
189     /***
190      * Returns the src
191      * <p>
192      * @return Returns the src.
193      * @since Atom 1.0
194      */
195     public String getSrc() {
196         return _src;
197     }
198     
199     /***
200      * Set the src
201      * <p>
202      * @param src The src to set.
203      * @since Atom 1.0
204      */
205     public void setSrc(String src) {
206         _src = src;
207     }
208 }
209 
210