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; 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 // can't use foreign markup in equals, due to JDOM equals impl 88 Object fm = getForeignMarkup(); 89 setForeignMarkup(((WireFeed)other).getForeignMarkup()); 90 boolean ret = _objBean.equals(other); 91 // restore foreign markup 92 setForeignMarkup(fm); 93 return ret; 94 } 95 96 /** 97 * Returns a hashcode value for the object. 98 * <p> 99 * It follows the contract defined by the Object hashCode() method. 100 * <p> 101 * @return the hashcode of the bean object. 102 * 103 */ 104 public int hashCode() { 105 return _objBean.hashCode(); 106 } 107 108 /** 109 * Returns the String representation for the object. 110 * <p> 111 * @return String representation for the object. 112 * 113 */ 114 public String toString() { 115 return _objBean.toString(); 116 } 117 118 119 120 121 122 /** 123 * Sets the feedType of a the feed. <b>Do not use</b>, for bean cloning purposes only. 124 * <p> 125 * @param feedType the feedType of the feed. 126 * 127 */ 128 public void setFeedType(String feedType) { 129 _feedType = feedType; 130 } 131 132 /** 133 * Returns the type of the feed. 134 * 135 * @return the type of the feed. 136 */ 137 public String getFeedType() { 138 return _feedType; 139 } 140 141 /** 142 * Returns the charset encoding of a the feed. 143 * <p> 144 * This property is not set by feed parsers. But it is used by feed generators 145 * to set the encoding in the XML prolog. 146 * <p> 147 * @return the charset encoding of the feed. 148 * 149 */ 150 public String getEncoding() { 151 return _encoding; 152 } 153 154 /** 155 * Sets the charset encoding of a the feed. 156 * <p> 157 * This property is not set by feed parsers. But it is used by feed generators 158 * to set the encoding in the XML prolog. 159 * <p> 160 * @param encoding the charset encoding of the feed. 161 * 162 */ 163 public void setEncoding(String encoding) { 164 _encoding = encoding; 165 } 166 167 168 /** 169 * Returns the channel modules. 170 * <p> 171 * @return a list of ModuleImpl elements with the channel modules, 172 * an empty list if none. 173 * 174 */ 175 public List getModules() { 176 return (_modules==null) ? (_modules=new ArrayList()) : _modules; 177 } 178 179 /** 180 * Sets the channel modules. 181 * <p> 182 * @param modules the list of ModuleImpl elements with the channel modules to set, 183 * an empty list or <b>null</b> if none. 184 * 185 */ 186 public void setModules(List modules) { 187 _modules = modules; 188 } 189 190 /** 191 * Returns the module identified by a given URI. 192 * <p> 193 * @param uri the URI of the ModuleImpl. 194 * @return The module with the given URI, <b>null</b> if none. 195 */ 196 public Module getModule(String uri) { 197 return ModuleUtils.getModule(_modules,uri); 198 } 199 200 /** 201 * Returns foreign markup found at channel level. 202 * <p> 203 * @return Opaque object to discourage use 204 * 205 */ 206 public Object getForeignMarkup() { 207 return (_foreignMarkup==null) ? (_foreignMarkup=new ArrayList()) : _foreignMarkup; 208 } 209 210 /** 211 * Sets foreign markup found at channel level. 212 * <p> 213 * @param foreignMarkup Opaque object to discourage use 214 * 215 */ 216 public void setForeignMarkup(Object foreignMarkup) { 217 _foreignMarkup = (List)foreignMarkup; 218 } 219 }