net.sourceforge.java.feednread.backend.model.newstable
Class NewsFeed

java.lang.Object
  extended bynet.sourceforge.java.feednread.backend.model.newstable.NewsFeed
All Implemented Interfaces:
Comparable, IArchivable, INewsFeedStatus, Serializable
Direct Known Subclasses:
AggregatedNewsFeed, ArchivedNewsFeed

public class NewsFeed
extends Object
implements Comparable, Serializable, IArchivable, INewsFeedStatus

Wrapper class for Rome SyndFeed newsfeed representation that adds support for wrapping and unwrapping SyndEntry news representations to/from NewsFeedEntry instances.

Author:
Sebastian Machhausen
See Also:
Serialized Form

Field Summary
protected  List newsFeedEntries
           The List of NewsFeedEntry wrapper objects
protected  SyndFeed originalFeed
           The original Rome SyndFeed representation
static long serialVersionUID
           The serialVersionUID of this class
protected  String url
           The url of the NewsFeed
 
Constructor Summary
NewsFeed()
           Creates a new empty NewsFeed.
NewsFeed(String url, SyndFeed originalFeed)
           Creates a new NewsFeed for the newsfeed at the specified url wrapping up the specified Rome SyndFeed representation.
 
Method Summary
 void addToArchive(NewsFeedArchive archive)
           Adds this NewsFeed to the specified NewsFeedArchive.
 int compareTo(Object obj)
           Compares this NewsFeed to another NewsFeed object based on the published date as returned by the getPublishedDate() method.
 boolean equals(Object obj)
           Tests if this NewsFeed is equal to the specified obj.
 List getAuthors()
           Gets the feed authors.
 String getCopyright()
           Gets the feed copyright.
 String getDescription()
           Gets the feed description.
 String getEncoding()
           Gets the charset encoding of a the feed.
 List getEntries()
           Gets the feed entries.
 String getFeedType()
           Returns the type of this NewsFeed Currently the following syndication types are supported: rss_0.90 rss_0.91 rss_0.92 rss_0.93 rss_0.94 rss_1.0 rss_2.0 atom_0.3
 SyndImage getImage()
           Gets the feed image.
 String getLanguage()
           Gets the feed language.
 String getLink()
           Gets the feed link.
 List getOriginalEntries()
           Gets the original Rome SyndEntry entries.
 SyndFeed getOriginalFeed()
           Gets the original Rome SyndFeed representation that this NewsFeed wraps up.
 Date getPublishedDate()
           Gets the feed published date.
 int getReadCount()
           Gets the number of read news in this NewsFeed.
 NewsFeedEntry[] getReadNews()
           Gets all read news of this NewsFeed.
 String getTitle()
           Gets the feed title.
 int getUnreadCount()
           Gets the number of unread news in this NewsFeed.
 NewsFeedEntry[] getUnreadNews()
           Gets all unread news of this NewsFeed.
 String getUrl()
           Gets the url of this NewsFeed
 int hashCode()
           Calculates the hashcode of this NewsFeed.
private  void initializeEntries()
           Initializes the news embedded in the wrapped SyndFeed by creating a NewsFeedEntry wrapper object for each single Rome SyndEntrynews entry.
 boolean isUnread()
           Returns true if this NewsFeed is unread.
 void markAllRead()
           Marks all news as read.
 void markAllUnread()
           Marks all news as unread.
 void setAuthors(List authors)
           Sets the feed authors.
 void setCopyright(String copyright)
           Sets the feed copyright.
 void setDescription(String description)
           Sets the feed description.
 void setEncoding(String encoding)
           Sets the charset encoding of a the feed.
 void setEntries(List entries)
           Sets the feed entries.
 void setFeedType(String feedType)
           Sets the feed type of this NewsFeed Currently the following syndication types are supported: rss_0.90 rss_0.91 rss_0.92 rss_0.93 rss_0.94 rss_1.0 rss_2.0 atom_0.3
 void setImage(SyndImage image)
           Sets the feed image.
 void setLanguage(String language)
           Sets the feed language.
 void setLink(String link)
           Sets the feed link.
 void setOriginalEntries(List entries)
           Sets the original Rome SyndEntry entries.
 void setPublishedDate(Date publishedDate)
           Sets the feed published date.
 void setTitle(String title)
           Sets the feed title.
 void setUrl(String url)
           Sets the url of this NewsFeed
 void synchronizeWithArchive(NewsFeedArchive archive)
           Synchronizes this NewsFeed with the specified NewsFeedArchive.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

serialVersionUID

public static final long serialVersionUID

The serialVersionUID of this class

See Also:
Constant Field Values

url

protected String url

The url of the NewsFeed


originalFeed

protected SyndFeed originalFeed

The original Rome SyndFeed representation


newsFeedEntries

protected List newsFeedEntries

The List of NewsFeedEntry wrapper objects

Constructor Detail

NewsFeed

public NewsFeed()

Creates a new empty NewsFeed.


NewsFeed

public NewsFeed(String url,
                SyndFeed originalFeed)

Creates a new NewsFeed for the newsfeed at the specified url wrapping up the specified Rome SyndFeed representation.

Parameters:
url - the url of this NewsFeed
originalFeed - the original Rome SyndFeed representation
Method Detail

equals

public boolean equals(Object obj)

Tests if this NewsFeed is equal to the specified obj. Two NewsFeed instances are considered equal if they are both instances of the NewsFeed class and if both point to the same url as returned by the getUrl() method.

Parameters:
obj - the Object to be tested against this NewsFeed for equality
Returns:
true if this NewsFeed is equal to the specified obj; false otherwise

hashCode

public int hashCode()

Calculates the hashcode of this NewsFeed.

Returns:
the hashcode of this NewsFeed

compareTo

public int compareTo(Object obj)

Compares this NewsFeed to another NewsFeed object based on the published date as returned by the getPublishedDate() method.

Specified by:
compareTo in interface Comparable
Parameters:
obj - a second NewsFeed object to compare this NewsFeed to
Returns:
a negative integer, zero, or a positive integer as this NewsFeed is less than, equal to, or greater than the specified NewsFeed object.

getOriginalFeed

public SyndFeed getOriginalFeed()

Gets the original Rome SyndFeed representation that this NewsFeed wraps up.

Returns:
the original Rome SyndFeed representation

setUrl

public void setUrl(String url)

Sets the url of this NewsFeed

Parameters:
url - the url of this NewsFeed.

getUrl

public String getUrl()

Gets the url of this NewsFeed

Returns:
the url of this NewsFeed.

setTitle

public void setTitle(String title)

Sets the feed title.

Parameters:
title - the feed title to set, null if none

getTitle

public String getTitle()

Gets the feed title.

Returns:
the feed title, an empty String if none set

setLanguage

public void setLanguage(String language)

Sets the feed language.

Parameters:
language - the feed language to set, null if none

getLanguage

public String getLanguage()

Gets the feed language.

Returns:
the feed language, null if none

setPublishedDate

public void setPublishedDate(Date publishedDate)

Sets the feed published date.

Parameters:
publishedDate - the feed published date to set, null if none

getPublishedDate

public Date getPublishedDate()

Gets the feed published date.

Returns:
the feed published date, null if none

setLink

public void setLink(String link)

Sets the feed link.

Parameters:
link - the feed link to set, null if none

getLink

public String getLink()

Gets the feed link.

Returns:
the feed link, null if none

setDescription

public void setDescription(String description)

Sets the feed description.

Parameters:
description - the feed description to set, null if none

getDescription

public String getDescription()

Gets the feed description.

Returns:
the feed description, null if none

setAuthors

public void setAuthors(List authors)

Sets the feed authors.

Parameters:
authors - a List of SyndPerson objects representing the feed authors; null if none

getAuthors

public List getAuthors()

Gets the feed authors.

Returns:
a List of SyndPerson objects representing the feed authors; null if none

setCopyright

public void setCopyright(String copyright)

Sets the feed copyright.

Parameters:
copyright - the feed copyright to set, null if none

getCopyright

public String getCopyright()

Gets the feed copyright.

Returns:
the feed copyright, null if none

setImage

public void setImage(SyndImage image)

Sets the feed image.

Parameters:
image - the feed image to set, null if none

getImage

public SyndImage getImage()

Gets the feed image.

Returns:
the feed image, null if none

setFeedType

public void setFeedType(String feedType)

Sets the feed type of this NewsFeed

Currently the following syndication types are supported:

Parameters:
feedType - the feed type to set, null if none

getFeedType

public String getFeedType()

Returns the type of this NewsFeed

Currently the following syndication types are supported:

Returns:
the feed type, null if none

setEncoding

public void setEncoding(String encoding)

Sets the charset encoding of a the feed. This is not set by Rome parsers.

Parameters:
encoding - the charset encoding of the feed

getEncoding

public String getEncoding()

Gets the charset encoding of a the feed. This is not set by Rome parsers.

Returns:
the charset encoding of the feed

setOriginalEntries

public void setOriginalEntries(List entries)

Sets the original Rome SyndEntry entries.

Parameters:
entries - the list of SyndEntry elements with the feed entries to set, an empty list or null if none

getOriginalEntries

public List getOriginalEntries()

Gets the original Rome SyndEntry entries.

Returns:
a list of SyndEntry elements with the original feed entries, an empty list if none

setEntries

public void setEntries(List entries)

Sets the feed entries.

Parameters:
entries - the list of NewsFeedEntry elements with the feed entries to set, an empty list or null if none

getEntries

public List getEntries()

Gets the feed entries.

Returns:
a list of NewsFeedEntry elements with the wrapped feed entries, an empty list if none

getUnreadCount

public int getUnreadCount()

Gets the number of unread news in this NewsFeed.

Specified by:
getUnreadCount in interface INewsFeedStatus
Returns:
the number of unread news in this NewsFeed

getReadCount

public int getReadCount()

Gets the number of read news in this NewsFeed.

Returns:
the number of read news in this NewsFeed

isUnread

public boolean isUnread()

Returns true if this NewsFeed is unread.

Specified by:
isUnread in interface INewsFeedStatus
Returns:
true if this NewsFeed is unread; false otherwise

markAllRead

public void markAllRead()

Marks all news as read.


markAllUnread

public void markAllUnread()

Marks all news as unread.


getUnreadNews

public NewsFeedEntry[] getUnreadNews()

Gets all unread news of this NewsFeed.

Returns:
all unread news of this NewsFeed; an empty array if all read or no news available

getReadNews

public NewsFeedEntry[] getReadNews()

Gets all read news of this NewsFeed.

Returns:
all read news of this NewsFeed; an empty array if all unread or no news available

addToArchive

public void addToArchive(NewsFeedArchive archive)

Adds this NewsFeed to the specified NewsFeedArchive. This is done by querying a potential existing ArchivedNewsFeed and adding all NewsFeedEntry objects to it. If no ArchivedNewsFeed yet exists in the specified NewsFeedArchive a new one has to be created and filled with this NewsFeed's entries.

Specified by:
addToArchive in interface IArchivable
Parameters:
archive - the NewsFeedArchive to use for synchronization
See Also:
NewsFeedArchive

synchronizeWithArchive

public void synchronizeWithArchive(NewsFeedArchive archive)

Synchronizes this NewsFeed with the specified NewsFeedArchive. This is done by reconciling each embedded NewsFeedEntry with the entries in a potential archived ArchivedNewsFeed.

Specified by:
synchronizeWithArchive in interface IArchivable
Parameters:
archive - the NewsFeedArchive to use for synchronization
See Also:
NewsFeedArchive

initializeEntries

private void initializeEntries()

Initializes the news embedded in the wrapped SyndFeed by creating a NewsFeedEntry wrapper object for each single Rome SyndEntrynews entry.