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.module.Module; 20 import com.sun.syndication.feed.module.impl.ModuleUtils; 21 import com.sun.syndication.feed.impl.ObjectBean; 22 import com.sun.syndication.feed.module.Extendable; 23 24 import java.util.ArrayList; 25 import java.util.Date; 26 import java.util.List; 27 import java.io.Serializable; 28 29 /** 30 * Bean for entry elements of Atom feeds. 31 * <p> 32 * @author Alejandro Abdelnur 33 * @author Dave Johnson (updated for Atom 1.0) 34 */ 35 public class Entry implements Cloneable, Serializable, Extendable { 36 37 private ObjectBean _objBean; 38 39 private String _xmlBase; 40 private List _authors; 41 private List _contributors; 42 private List _categories; 43 private List _contents; 44 private String _id; 45 private Date _published; // AKA issued 46 private String _rights; 47 private Feed _source; 48 private Content _summary; 49 private Content _title; 50 private Date _updated; // AKA modified 51 private List _alternateLinks; 52 private List _otherLinks; 53 private List _foreignMarkup; 54 55 private List _modules; 56 57 private Date _created; // Atom 0.3 only 58 59 60 /** 61 * Default constructor. All properties are set to <b>null</b>. 62 * <p> 63 * 64 */ 65 public Entry() { 66 _objBean = new ObjectBean(this.getClass(),this); 67 } 68 69 /** 70 * Creates a deep 'bean' clone of the object. 71 * <p> 72 * @return a clone of the object. 73 * @throws CloneNotSupportedException thrown if an element of the object cannot be cloned. 74 * 75 */ 76 public Object clone() throws CloneNotSupportedException { 77 return _objBean.clone(); 78 } 79 80 /** 81 * Indicates whether some other object is "equal to" this one as defined by the Object equals() method. 82 * <p> 83 * @param other he reference object with which to compare. 84 * @return <b>true</b> if 'this' object is equal to the 'other' object. 85 * 86 */ 87 public boolean equals(Object other) { 88 // can't use foreign markup in equals, due to JDOM equals impl 89 Object fm = getForeignMarkup(); 90 setForeignMarkup(((Entry)other).getForeignMarkup()); 91 boolean ret = _objBean.equals(other); 92 // restore foreign markup 93 setForeignMarkup(fm); 94 return ret; 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 entry title. 121 * <p> 122 * @return the entry title, <b>null</b> if none. 123 * 124 */ 125 public String getTitle() { 126 if (_title != null) return _title.getValue(); 127 return null; 128 } 129 130 /** 131 * Sets the entry title. 132 * <p> 133 * @param title the entry title, <b>null</b> if none. 134 * 135 */ 136 public void setTitle(String title) { 137 if (_title == null) _title = new Content(); 138 _title.setValue(title); 139 } 140 141 /** 142 * Returns the entry title as a text construct. 143 * <p> 144 * @return the entry title, <b>null</b> if none. 145 * 146 */ 147 public Content getTitleEx() { 148 return _title; 149 } 150 151 /** 152 * Sets the entry title as a text construct. 153 * <p> 154 * @param title the entry title, <b>null</b> if none. 155 * 156 */ 157 public void setTitleEx(Content title) { 158 _title = title; 159 } 160 161 /** 162 * Returns the entry alternate links. 163 * <p> 164 * @return a list of Link elements with the entry alternate links, an empty list if none. 165 */ 166 public List getAlternateLinks() { 167 return (_alternateLinks==null) ? (_alternateLinks=new ArrayList()) : _alternateLinks; 168 } 169 170 /** 171 * Sets the entry alternate links. 172 * <p> 173 * @param alternateLinks the list of Link elements with the entry alternate links to set, 174 * an empty list or <b>null</b> if none. 175 */ 176 public void setAlternateLinks(List alternateLinks) { 177 _alternateLinks = alternateLinks; 178 } 179 180 /** 181 * Returns the entry non-alternate links. 182 * <p> 183 * @return the list of Link elements with the entry non-alternate links to set, 184 * an empty list if none. 185 */ 186 public List getOtherLinks() { 187 return (_otherLinks==null) ? (_otherLinks=new ArrayList()) : _otherLinks; 188 } 189 190 /** 191 * Sets the entry non-alternate links. 192 * <p> 193 * @param otherLinks the list Link elements with the entry non-alternate links to set, 194 * an empty list or <b>null</b> if none. 195 */ 196 public void setOtherLinks(List otherLinks) { 197 _otherLinks = otherLinks; 198 } 199 200 /** 201 * Returns the entry author. 202 * <p> 203 * @return the entry author, <b>null</b> if none. 204 * 205 */ 206 public List getAuthors() { 207 return _authors; 208 } 209 210 /** 211 * Sets the author of the entry. 212 * <p> 213 * @param author the author of the entry, <b>null</b> if none. 214 * 215 */ 216 public void setAuthors(List authors) { 217 _authors = authors; 218 } 219 220 /** 221 * Returns the entry contributors. 222 * <p> 223 * @return a list of Person elements with the entry contributors, 224 * an empty list if none. 225 * 226 */ 227 public List getContributors() { 228 return (_contributors==null) ? (_contributors=new ArrayList()) : _contributors; 229 } 230 231 /** 232 * Sets the entry contributors. 233 * <p> 234 * @param contributors the list of Person elements with the entry contributors to set, 235 * an empty list or <b>null</b> if none. 236 * 237 */ 238 public void setContributors(List contributors) { 239 _contributors = contributors; 240 } 241 242 /** 243 * Returns the entry ID. 244 * <p> 245 * @return the entry ID, <b>null</b> if none. 246 * 247 */ 248 public String getId() { 249 return _id; 250 } 251 252 /** 253 * Sets the entry ID. 254 * <p> 255 * @param id the entry ID, <b>null</b> if none. 256 * 257 */ 258 public void setId(String id) { 259 _id = id; 260 } 261 262 /** 263 * Returns the entry modified date (Atom 0.3, maps to {@link getUpdated()}). 264 * <p> 265 * @return the entry modified date, <b>null</b> if none. 266 */ 267 public Date getModified() { 268 return _updated; 269 } 270 271 /** 272 * Sets the entry modified date (Atom 0.3, maps to {@link setUpdated()}). 273 * <p> 274 * @param modified the entry modified date, <b>null</b> if none. 275 */ 276 public void setModified(Date modified) { 277 _updated = modified; 278 } 279 280 /** 281 * Returns the entry issued date (Atom 0.3, maps to {@link getPublished()}). 282 * <p> 283 * @return the entry issued date, <b>null</b> if none. 284 */ 285 public Date getIssued() { 286 return _published; 287 } 288 289 /** 290 * Sets the entry issued date (Atom 0.3, maps to {@link setPublished()}). 291 * <p> 292 * @param issued the entry issued date, <b>null</b> if none. 293 */ 294 public void setIssued(Date issued) { 295 _published = issued; 296 } 297 298 /** 299 * Returns the entry created date (Atom 0.3 only) 300 * <p> 301 * @return the entry created date, <b>null</b> if none. 302 */ 303 public Date getCreated() { 304 return _created; 305 } 306 307 /** 308 * Sets the entry created date (Atom 0.3 only) 309 * <p> 310 * @param created the entry created date, <b>null</b> if none. 311 */ 312 public void setCreated(Date created) { 313 _created = created; 314 } 315 316 /** 317 * Returns the entry summary. 318 * <p> 319 * @return the entry summary, <b>null</b> if none. 320 * 321 */ 322 public Content getSummary() { 323 return _summary; 324 } 325 326 /** 327 * Sets the entry summary. 328 * <p> 329 * @param summary the entry summary, <b>null</b> if none. 330 * 331 */ 332 public void setSummary(Content summary) { 333 _summary = summary; 334 } 335 336 /** 337 * Returns the entry contents. 338 * <p> 339 * @return a list of Content elements with the entry contents, 340 * an empty list if none. 341 */ 342 public List getContents() { 343 return (_contents==null) ? (_contents=new ArrayList()) : _contents; 344 } 345 346 /** 347 * Sets the entry contents. 348 * <p> 349 * @param contents the list of Content elements with the entry contents to set, 350 * an empty list or <b>null</b> if none. 351 */ 352 public void setContents(List contents) { 353 _contents = contents; 354 } 355 356 /** 357 * Returns the entry modules. 358 * <p> 359 * @return a list of ModuleImpl elements with the entry modules, 360 * an emtpy list if none. 361 * 362 */ 363 public List getModules() { 364 return (_modules==null) ? (_modules=new ArrayList()) : _modules; 365 } 366 367 /** 368 * Sets the entry modules. 369 * <p> 370 * @param modules the list of ModuleImpl elements with the entry modules to set, 371 * an empty list or <b>null</b> if none. 372 * 373 */ 374 public void setModules(List modules) { 375 _modules = modules; 376 } 377 378 /** 379 * Returns the module identified by a given URI. 380 * <p> 381 * @param uri the URI of the ModuleImpl. 382 * @return The module with the given URI, <b>null</b> if none. 383 */ 384 public Module getModule(String uri) { 385 return ModuleUtils.getModule(_modules,uri); 386 } 387 388 /** 389 * Returns the published 390 * <p> 391 * @return Returns the published. 392 * @since Atom 1.0 393 */ 394 public Date getPublished() { 395 return _published; 396 } 397 398 /** 399 * Set the published 400 * <p> 401 * @param published The published to set. 402 * @since Atom 1.0 403 */ 404 public void setPublished(Date published) { 405 _published = published; 406 } 407 408 /** 409 * Returns the rights 410 * <p> 411 * @return Returns the rights. 412 * @since Atom 1.0 413 */ 414 public String getRights() { 415 return _rights; 416 } 417 418 /** 419 * Set the rights 420 * <p> 421 * @param rights The rights to set. 422 * @since Atom 1.0 423 */ 424 public void setRights(String rights) { 425 _rights = rights; 426 } 427 428 /** 429 * Returns the source 430 * <p> 431 * @return Returns the source. 432 */ 433 public Feed getSource() { 434 return _source; 435 } 436 437 /** 438 * Set the source 439 * <p> 440 * @param source The source to set. 441 */ 442 public void setSource(Feed source) { 443 _source = source; 444 } 445 446 /** 447 * Returns the updated 448 * <p> 449 * @return Returns the updated. 450 * @since Atom 1.0 451 */ 452 public Date getUpdated() { 453 return _updated; 454 } 455 456 /** 457 * Set the updated 458 * <p> 459 * @param updated The updated to set. 460 * @since Atom 1.0 461 */ 462 public void setUpdated(Date updated) { 463 _updated = updated; 464 } 465 466 /** 467 * Returns the categories 468 * <p> 469 * @return Returns the categories. 470 * @since Atom 1.0 471 */ 472 public List getCategories() { 473 return _categories; 474 } 475 476 /** 477 * Set the categories 478 * <p> 479 * @param categories The categories to set. 480 * @since Atom 1.0 481 */ 482 public void setCategories(List categories) { 483 _categories = categories; 484 } 485 486 /** 487 * Returns the xmlBase 488 * <p> 489 * @return Returns the xmlBase. 490 * @since Atom 1.0 491 */ 492 public String getXmlBase() { 493 return _xmlBase; 494 } 495 496 /** 497 * Set the xmlBase 498 * <p> 499 * @param xmlBase The xmlBase to set. 500 * @since Atom 1.0 501 */ 502 public void setXmlBase(String xmlBase) { 503 _xmlBase = xmlBase; 504 } 505 506 507 /** 508 * Returns foreign markup found at entry level. 509 * <p> 510 * @return list of Opaque object to discourage use 511 * 512 */ 513 public Object getForeignMarkup() { 514 return (_foreignMarkup==null) ? (_foreignMarkup=new ArrayList()) : _foreignMarkup; 515 } 516 517 /** 518 * Sets foreign markup found at entry level. 519 * <p> 520 * @param foreignMarkup Opaque object to discourage use 521 * 522 */ 523 public void setForeignMarkup(Object foreignMarkup) { 524 _foreignMarkup = (List)foreignMarkup; 525 } 526 527 }