001: /*
002: * Copyright 2004 Sun Microsystems, Inc.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: *
016: */
017: package com.sun.syndication.feed;
018:
019: import com.sun.syndication.feed.impl.ObjectBean;
020: import com.sun.syndication.feed.module.Module;
021: import com.sun.syndication.feed.module.impl.ModuleUtils;
022: import com.sun.syndication.feed.module.Extendable;
023:
024: import java.util.List;
025: import java.util.ArrayList;
026: import java.io.Serializable;
027:
028: /**
029: * Parent class of the RSS (Channel) and Atom (Feed) feed beans.
030: * <p>
031: * NOTE: We don't like this class at this package level but the alternative would have
032: * been a proliferation of packages (one more level to hold atom and rss package with
033: * this class just in that package).
034: * <p>
035: * The format of the 'type' property must be [FEEDNAME]_[FEEDVERSION] with the FEEDNAME in lower case,
036: * for example: rss_0.9, rss_0.93, atom_0.3
037: * <p>
038: * @author Alejandro Abdelnur
039: *
040: */
041: public abstract class WireFeed implements Cloneable, Serializable,
042: Extendable {
043: private ObjectBean _objBean;
044: private String _feedType;
045: private String _encoding;
046: private List _modules;
047: private List _foreignMarkup;
048:
049: /**
050: * Default constructor, for bean cloning purposes only.
051: * <p>
052: *
053: */
054: protected WireFeed() {
055: _objBean = new ObjectBean(this .getClass(), this );
056: }
057:
058: /**
059: * Creates a feed for a given type.
060: * <p>
061: * @param type of the feed to create.
062: *
063: */
064: protected WireFeed(String type) {
065: this ();
066: _feedType = type;
067: }
068:
069: /**
070: * Creates a deep 'bean' clone of the object.
071: * <p>
072: * @return a clone of the object.
073: * @throws CloneNotSupportedException thrown if an element of the object cannot be cloned.
074: *
075: */
076: public Object clone() throws CloneNotSupportedException {
077: return _objBean.clone();
078: }
079:
080: /**
081: * Indicates whether some other object is "equal to" this one as defined by the Object equals() method.
082: * <p>
083: * @param other he reference object with which to compare.
084: * @return <b>true</b> if 'this' object is equal to the 'other' object.
085: *
086: */
087: public boolean equals(Object other) {
088: // can't use foreign markup in equals, due to JDOM equals impl
089: Object fm = getForeignMarkup();
090: setForeignMarkup(((WireFeed) other).getForeignMarkup());
091: boolean ret = _objBean.equals(other);
092: // restore foreign markup
093: setForeignMarkup(fm);
094: return ret;
095: }
096:
097: /**
098: * Returns a hashcode value for the object.
099: * <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: * Sets the feedType of a the feed. <b>Do not use</b>, for bean cloning purposes only.
121: * <p>
122: * @param feedType the feedType of the feed.
123: *
124: */
125: public void setFeedType(String feedType) {
126: _feedType = feedType;
127: }
128:
129: /**
130: * Returns the type of the feed.
131: *
132: * @return the type of the feed.
133: */
134: public String getFeedType() {
135: return _feedType;
136: }
137:
138: /**
139: * Returns the charset encoding of a the feed.
140: * <p>
141: * This property is not set by feed parsers. But it is used by feed generators
142: * to set the encoding in the XML prolog.
143: * <p>
144: * @return the charset encoding of the feed.
145: *
146: */
147: public String getEncoding() {
148: return _encoding;
149: }
150:
151: /**
152: * Sets the charset encoding of a the feed.
153: * <p>
154: * This property is not set by feed parsers. But it is used by feed generators
155: * to set the encoding in the XML prolog.
156: * <p>
157: * @param encoding the charset encoding of the feed.
158: *
159: */
160: public void setEncoding(String encoding) {
161: _encoding = encoding;
162: }
163:
164: /**
165: * Returns the channel modules.
166: * <p>
167: * @return a list of ModuleImpl elements with the channel modules,
168: * an empty list if none.
169: *
170: */
171: public List getModules() {
172: return (_modules == null) ? (_modules = new ArrayList())
173: : _modules;
174: }
175:
176: /**
177: * Sets the channel modules.
178: * <p>
179: * @param modules the list of ModuleImpl elements with the channel modules to set,
180: * an empty list or <b>null</b> if none.
181: *
182: */
183: public void setModules(List modules) {
184: _modules = modules;
185: }
186:
187: /**
188: * Returns the module identified by a given URI.
189: * <p>
190: * @param uri the URI of the ModuleImpl.
191: * @return The module with the given URI, <b>null</b> if none.
192: */
193: public Module getModule(String uri) {
194: return ModuleUtils.getModule(_modules, uri);
195: }
196:
197: /**
198: * Returns foreign markup found at channel level.
199: * <p>
200: * @return Opaque object to discourage use
201: *
202: */
203: public Object getForeignMarkup() {
204: return (_foreignMarkup == null) ? (_foreignMarkup = new ArrayList())
205: : _foreignMarkup;
206: }
207:
208: /**
209: * Sets foreign markup found at channel level.
210: * <p>
211: * @param foreignMarkup Opaque object to discourage use
212: *
213: */
214: public void setForeignMarkup(Object foreignMarkup) {
215: _foreignMarkup = (List) foreignMarkup;
216: }
217: }
|