1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package com.sun.syndication.feed;
18
19 import com.sun.syndication.feed.impl.ObjectBean;
20 import com.sun.syndication.feed.module.Module;
21 import com.sun.syndication.feed.module.impl.ModuleUtils;
22 import com.sun.syndication.feed.module.Extendable;
23
24 import java.util.List;
25 import java.util.ArrayList;
26 import java.io.Serializable;
27
28 /***
29 * Parent class of the RSS (Channel) and Atom (Feed) feed beans.
30 * <p>
31 * NOTE: We don't like this class at this package level but the alternative would have
32 * been a proliferation of packages (one more level to hold atom and rss package with
33 * this class just in that package).
34 * <p>
35 * The format of the 'type' property must be [FEEDNAME]_[FEEDVERSION] with the FEEDNAME in lower case,
36 * for example: rss_0.9, rss_0.93, atom_0.3
37 * <p>
38 * @author Alejandro Abdelnur
39 *
40 */
41 public abstract class WireFeed implements Cloneable, Serializable, Extendable {
42 private ObjectBean _objBean;
43 private String _feedType;
44 private String _encoding;
45 private List _modules;
46 private List _foreignMarkup;
47
48 /***
49 * Default constructor, for bean cloning purposes only.
50 * <p>
51 *
52 */
53 protected WireFeed() {
54 _objBean = new ObjectBean(this.getClass(),this);
55 }
56
57 /***
58 * Creates a feed for a given type.
59 * <p>
60 * @param type of the feed to create.
61 *
62 */
63 protected WireFeed(String type) {
64 this();
65 _feedType = type;
66 }
67
68 /***
69 * Creates a deep 'bean' clone of the object.
70 * <p>
71 * @return a clone of the object.
72 * @throws CloneNotSupportedException thrown if an element of the object cannot be cloned.
73 *
74 */
75 public Object clone() throws CloneNotSupportedException {
76 return _objBean.clone();
77 }
78
79 /***
80 * Indicates whether some other object is "equal to" this one as defined by the Object equals() method.
81 * <p>
82 * @param other he reference object with which to compare.
83 * @return <b>true</b> if 'this' object is equal to the 'other' object.
84 *
85 */
86 public boolean equals(Object other) {
87 if (other == null) {
88 return false;
89 }
90
91 Object fm = getForeignMarkup();
92 setForeignMarkup(((WireFeed)other).getForeignMarkup());
93 boolean ret = _objBean.equals(other);
94
95 setForeignMarkup(fm);
96 return ret;
97 }
98
99 /***
100 * Returns a hashcode value for the object.
101 * <p>
102 * It follows the contract defined by the Object hashCode() method.
103 * <p>
104 * @return the hashcode of the bean object.
105 *
106 */
107 public int hashCode() {
108 return _objBean.hashCode();
109 }
110
111 /***
112 * Returns the String representation for the object.
113 * <p>
114 * @return String representation for the object.
115 *
116 */
117 public String toString() {
118 return _objBean.toString();
119 }
120
121
122
123
124
125 /***
126 * Sets the feedType of a the feed. <b>Do not use</b>, for bean cloning purposes only.
127 * <p>
128 * @param feedType the feedType of the feed.
129 *
130 */
131 public void setFeedType(String feedType) {
132 _feedType = feedType;
133 }
134
135 /***
136 * Returns the type of the feed.
137 *
138 * @return the type of the feed.
139 */
140 public String getFeedType() {
141 return _feedType;
142 }
143
144 /***
145 * Returns the charset encoding of a the feed.
146 * <p>
147 * This property is not set by feed parsers. But it is used by feed generators
148 * to set the encoding in the XML prolog.
149 * <p>
150 * @return the charset encoding of the feed.
151 *
152 */
153 public String getEncoding() {
154 return _encoding;
155 }
156
157 /***
158 * Sets the charset encoding of a the feed.
159 * <p>
160 * This property is not set by feed parsers. But it is used by feed generators
161 * to set the encoding in the XML prolog.
162 * <p>
163 * @param encoding the charset encoding of the feed.
164 *
165 */
166 public void setEncoding(String encoding) {
167 _encoding = encoding;
168 }
169
170
171 /***
172 * Returns the channel modules.
173 * <p>
174 * @return a list of ModuleImpl elements with the channel modules,
175 * an empty list if none.
176 *
177 */
178 public List getModules() {
179 return (_modules==null) ? (_modules=new ArrayList()) : _modules;
180 }
181
182 /***
183 * Sets the channel modules.
184 * <p>
185 * @param modules the list of ModuleImpl elements with the channel modules to set,
186 * an empty list or <b>null</b> if none.
187 *
188 */
189 public void setModules(List modules) {
190 _modules = modules;
191 }
192
193 /***
194 * Returns the module identified by a given URI.
195 * <p>
196 * @param uri the URI of the ModuleImpl.
197 * @return The module with the given URI, <b>null</b> if none.
198 */
199 public Module getModule(String uri) {
200 return ModuleUtils.getModule(_modules,uri);
201 }
202
203 /***
204 * Returns foreign markup found at channel level.
205 * <p>
206 * @return Opaque object to discourage use
207 *
208 */
209 public Object getForeignMarkup() {
210 return (_foreignMarkup==null) ? (_foreignMarkup=new ArrayList()) : _foreignMarkup;
211 }
212
213 /***
214 * Sets foreign markup found at channel level.
215 * <p>
216 * @param foreignMarkup Opaque object to discourage use
217 *
218 */
219 public void setForeignMarkup(Object foreignMarkup) {
220 _foreignMarkup = (List)foreignMarkup;
221 }
222 }