1 17 package com.sun.syndication.feed.synd; 18 19 import com.sun.syndication.feed.impl.ObjectBean; 20 import com.sun.syndication.feed.impl.CopyFromHelper; 21 import com.sun.syndication.feed.WireFeed; 22 import com.sun.syndication.feed.module.*; 23 import com.sun.syndication.feed.module.impl.ModuleUtils; 24 import com.sun.syndication.feed.synd.impl.Converters; 25 import com.sun.syndication.feed.synd.impl.URINormalizer; 26 27 import java.util.*; 28 import java.io.Serializable ; 29 30 38 public class SyndFeedImpl implements Serializable ,SyndFeed { 39 private ObjectBean _objBean; 40 private String _encoding; 41 private String _uri; 42 private String _title; 43 private String _feedType; 44 private String _link; 45 private String _description; 46 private SyndImage _image; 47 private List _entries; 48 private List _modules; 49 50 private static final Converters CONVERTERS = new Converters(); 51 52 private static final Set IGNORE_PROPERTIES = new HashSet(); 53 54 60 61 public static final Set CONVENIENCE_PROPERTIES = Collections.unmodifiableSet(IGNORE_PROPERTIES); 62 63 static { 64 IGNORE_PROPERTIES.add("publishedDate"); 65 IGNORE_PROPERTIES.add("author"); 66 IGNORE_PROPERTIES.add("copyright"); 67 IGNORE_PROPERTIES.add("categories"); 68 IGNORE_PROPERTIES.add("language"); 69 } 70 71 76 public List getSupportedFeedTypes() { 77 return CONVERTERS.getSupportedFeedTypes(); 78 } 79 80 89 protected SyndFeedImpl(Class beanClass,Set convenienceProperties) { 90 _objBean = new ObjectBean(beanClass,this,convenienceProperties); 91 } 92 93 98 public SyndFeedImpl() { 99 this(null); 100 } 101 102 109 public SyndFeedImpl(WireFeed feed) { 110 this(SyndFeed.class,IGNORE_PROPERTIES); 111 if (feed!=null) { 112 _feedType = feed.getFeedType(); 113 Converter converter = CONVERTERS.getConverter(_feedType); 114 if (converter==null) { 115 throw new IllegalArgumentException ("Invalid feed type ["+_feedType+"]"); 116 } 117 converter.copyInto(feed,this); 118 } 119 } 120 121 128 public Object clone() throws CloneNotSupportedException { 129 return _objBean.clone(); 130 } 131 132 139 public boolean equals(Object other) { 140 return _objBean.equals(other); 141 } 142 143 151 public int hashCode() { 152 return _objBean.hashCode(); 153 } 154 155 161 public String toString() { 162 return _objBean.toString(); 163 } 164 165 173 public WireFeed createWireFeed() { 174 return createWireFeed(_feedType); 175 } 176 177 184 public WireFeed createWireFeed(String feedType) { 185 if (feedType==null) { 186 throw new IllegalArgumentException ("Feed type cannot be null"); 187 } 188 Converter converter = CONVERTERS.getConverter(feedType); 189 if (converter==null) { 190 throw new IllegalArgumentException ("Invalid feed type ["+feedType+"]"); 191 } 192 return converter.createRealFeed(this); 193 } 194 195 201 public String getFeedType() { 202 return _feedType; 203 } 204 205 211 public void setFeedType(String feedType) { 212 _feedType = feedType; 213 } 214 215 221 public String getEncoding() { 222 return _encoding; 223 } 224 225 231 public void setEncoding(String encoding) { 232 _encoding = encoding; 233 } 234 235 247 public String getUri() { 248 return _uri; 249 } 250 251 261 public void setUri(String uri) { 262 _uri = URINormalizer.normalize(uri); 263 } 264 265 271 public String getTitle() { 272 return _title; 273 } 274 275 281 public void setTitle(String title) { 282 _title = title; 283 } 284 285 291 public String getLink() { 292 return _link; 293 } 294 295 301 public void setLink(String link) { 302 _link = link; 303 } 304 305 311 public String getDescription() { 312 return _description; 313 } 314 315 321 public void setDescription(String description) { 322 _description = description; 323 } 324 325 333 public Date getPublishedDate() { 334 return getDCModule().getDate(); 335 } 336 337 345 public void setPublishedDate(Date publishedDate) { 346 getDCModule().setDate(publishedDate); 347 } 348 349 357 public String getAuthor() { 358 return getDCModule().getCreator(); 359 } 360 361 369 public void setAuthor(String author) { 370 getDCModule().setCreator(author); 371 } 372 373 381 public String getCopyright() { 382 return getDCModule().getRights(); 383 } 384 385 393 public void setCopyright(String copyright) { 394 getDCModule().setRights(copyright); 395 } 396 397 403 public SyndImage getImage() { 404 return _image; 405 } 406 407 413 public void setImage(SyndImage image) { 414 _image = image; 415 } 416 417 426 public List getCategories() { 427 return new SyndCategoryListFacade(getDCModule().getSubjects()); 428 } 429 430 439 public void setCategories(List categories) { 440 getDCModule().setSubjects(SyndCategoryListFacade.convertElementsSyndCategoryToSubject(categories)); 441 } 442 443 450 public List getEntries() { 451 return (_entries==null) ? (_entries=new ArrayList()) : _entries; 452 } 453 454 461 public void setEntries(List entries) { 462 _entries = entries; 463 } 464 465 473 public String getLanguage() { 474 return getDCModule().getLanguage(); 475 } 476 477 485 public void setLanguage(String language) { 486 getDCModule().setLanguage(language); 487 } 488 489 496 public List getModules() { 497 if (_modules==null) { 498 _modules=new ArrayList(); 499 } 500 if (ModuleUtils.getModule(_modules,DCModule.URI)==null) { 501 _modules.add(new DCModuleImpl()); 502 } 503 return _modules; 504 } 505 506 507 514 public void setModules(List modules) { 515 _modules = modules; 516 } 517 518 524 public Module getModule(String uri) { 525 return ModuleUtils.getModule(getModules(),uri); 526 } 527 528 533 private DCModule getDCModule() { 534 return (DCModule) getModule(DCModule.URI); 535 } 536 537 public Class getInterface() { 538 return SyndFeed.class; 539 } 540 541 public void copyFrom(Object obj) { 542 COPY_FROM_HELPER.copy(this,obj); 543 } 544 545 546 548 private static final CopyFromHelper COPY_FROM_HELPER; 549 550 static { 551 Map basePropInterfaceMap = new HashMap(); 552 basePropInterfaceMap.put("feedType",String .class); 553 basePropInterfaceMap.put("encoding",String .class); 554 basePropInterfaceMap.put("uri",String .class); 555 basePropInterfaceMap.put("title",String .class); 556 basePropInterfaceMap.put("link",String .class); 557 basePropInterfaceMap.put("description",String .class); 558 basePropInterfaceMap.put("image",SyndImage.class); 559 basePropInterfaceMap.put("entries",SyndEntry.class); 560 basePropInterfaceMap.put("modules",Module.class); 561 562 Map basePropClassImplMap = new HashMap(); 563 basePropClassImplMap.put(SyndEntry.class,SyndEntryImpl.class); 564 basePropClassImplMap.put(SyndImage.class,SyndImageImpl.class); 565 basePropClassImplMap.put(DCModule.class,DCModuleImpl.class); 566 basePropClassImplMap.put(SyModule.class,SyModuleImpl.class); 567 568 COPY_FROM_HELPER = new CopyFromHelper(SyndFeed.class,basePropInterfaceMap,basePropClassImplMap); 569 } 570 571 } 572 | Popular Tags |