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  import com.sun.syndication.feed.impl.ObjectBean;
21  
22  import java.io.Serializable;
23  import java.util.Set;
24  import java.util.HashSet;
25  
26  /***
27   * Bean for content elements of Atom feeds.
28   * <p>
29   * @author Alejandro Abdelnur
30   *
31   */
32  public class Content implements Cloneable,Serializable {
33      public static final String XML = "xml";
34      public static final String BASE64 = "base64";
35      public static final String ESCAPED = "escaped";
36  
37      private static final Set MODES = new HashSet();
38  
39      static {
40          MODES.add(XML);
41          MODES.add(BASE64);
42          MODES.add(ESCAPED);
43      }
44  
45      private ObjectBean _objBean;
46      private String _type;
47      private String _mode;
48      private String _value;
49  
50      /***
51       * Default constructor. All properties are set to <b>null</b>.
52       * <p>
53       *
54       */
55      public Content() {
56          _objBean = new ObjectBean(this.getClass(),this);
57      }
58  
59      /***
60       * Creates a deep 'bean' clone of the object.
61       * <p>
62       * @return a clone of the object.
63       * @throws CloneNotSupportedException thrown if an element of the object cannot be cloned.
64       *
65       */
66      public Object clone() throws CloneNotSupportedException {
67          return _objBean.clone();
68      }
69  
70      /***
71       * Indicates whether some other object is "equal to" this one as defined by the Object equals() method.
72       * <p>
73       * @param other he reference object with which to compare.
74       * @return <b>true</b> if 'this' object is equal to the 'other' object.
75       *
76       */
77      public boolean equals(Object other) {
78          return _objBean.equals(other);
79      }
80  
81      /***
82       * Returns a hashcode value for the object.
83       * <p>
84       * It follows the contract defined by the Object hashCode() method.
85       * <p>
86       * @return the hashcode of the bean object.
87       *
88       */
89      public int hashCode() {
90          return _objBean.hashCode();
91      }
92  
93      /***
94       * Returns the String representation for the object.
95       * <p>
96       * @return String representation for the object.
97       *
98       */
99      public String toString() {
100         return _objBean.toString();
101     }
102 
103     /***
104      * Returns the content type.
105      * <p>
106      * @return the content type, <b>null</b> if none.
107      *
108      */
109     public String getType() {
110         return _type;
111     }
112 
113     /***
114      * Sets the content type.
115      * <p>
116      * @param type the content type, <b>null</b> if none.
117      *
118      */
119     public void setType(String type) {
120         _type = type;
121     }
122 
123     /***
124      * Returns the content mode.
125      * <p>
126      * The mode indicates how the value was/will-be encoded in the XML feed.
127      * <p>
128      * @return the content mode, <b>null</b> if none.
129      *
130      */
131     public String getMode() {
132         return _mode;
133     }
134 
135     /***
136      * Sets the content mode.
137      * <p>
138      * The mode indicates how the value was/will-be encoded in the XML feed.
139      * <p>
140      * @param mode the content mode, <b>null</b> if none.
141      *
142      */
143     public void setMode(String mode) {
144         if (!MODES.contains(mode)) {
145             throw new IllegalArgumentException("Invalid mode ["+mode+"]");
146         }
147         _mode = mode;
148     }
149 
150     /***
151      * Returns the content value.
152      * <p>
153      * The return value should be decoded.
154      * <p>
155      * @return the content value, <b>null</b> if none.
156      *
157      */
158     public String getValue() {
159         return _value;
160     }
161 
162     /***
163      * Sets the content value.
164      * <p>
165      * The value being set should be decoded.
166      * <p>
167      * @param value the content value, <b>null</b> if none.
168      *
169      */
170     public void setValue(String value) {
171         _value = value;
172     }
173 
174 }
175 
176