1
2
3
4
5
6
7
8
9
10
11
12
13
14
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 _type;
36 private String _value;
37 private String _src;
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 * The type indicates how the value was/will-be encoded in the XML feed.
123 * </p>
124 * @since Atom 1.0
125 */
126 public String getType() {
127 return _type;
128 }
129
130 /***
131 * Sets the content type.
132 * <p>
133 * The type indicates how the value was/will-be encoded in the XML feed.
134 * </p>
135 * @since Atom 1.0
136 */
137 public void setType(String type) {
138 _type = type;
139 }
140
141 /***
142 * Returns the content mode (Atom 0.3 only).
143 * <p>
144 * The mode indicates how the value was/will-be encoded in the XML feed.
145 * <p>
146 * @return the content mode, <b>null</b> if none.
147 */
148 public String getMode() {
149 return _mode;
150 }
151
152 /***
153 * Sets the content mode (Atom 0.3 only).
154 * <p>
155 * The mode indicates how the value was/will-be encoded in the XML feed.
156 * <p>
157 * @param mode the content mode, <b>null</b> if none.
158 */
159 public void setMode(String mode) {
160 mode = (mode!=null) ? mode.toLowerCase() : null;
161 if (mode==null || !MODES.contains(mode)) {
162 throw new IllegalArgumentException("Invalid mode ["+mode+"]");
163 }
164 _mode = mode;
165 }
166
167 /***
168 * Returns the content value.
169 * <p>
170 * The return value should be decoded.
171 * <p>
172 * @return the content value, <b>null</b> if none.
173 *
174 */
175 public String getValue() {
176 return _value;
177 }
178
179 /***
180 * Sets the content value.
181 * <p>
182 * The value being set should be decoded.
183 * <p>
184 * @param value the content value, <b>null</b> if none.
185 *
186 */
187 public void setValue(String value) {
188 _value = value;
189 }
190
191 /***
192 * Returns the src
193 * <p>
194 * @return Returns the src.
195 * @since Atom 1.0
196 */
197 public String getSrc() {
198 return _src;
199 }
200
201 /***
202 * Set the src
203 * <p>
204 * @param src The src to set.
205 * @since Atom 1.0
206 */
207 public void setSrc(String src) {
208 _src = src;
209 }
210 }
211
212