org.clapper.curn.parser
Class RSSItem

java.lang.Object
  extended by org.clapper.curn.parser.RSSElement
      extended by org.clapper.curn.parser.RSSItem
All Implemented Interfaces:
java.lang.Cloneable, java.lang.Comparable
Direct Known Subclasses:
RSSItemAdapter, RSSItemAdapter

public abstract class RSSItem
extends RSSElement
implements java.lang.Cloneable, java.lang.Comparable

This abstract class defines a simplified view of an RSS item, providing only the methods necessary for curn to work. curn uses the RSSParserFactory class to get a specific implementation of RSSParser, which returns RSSChannel-conforming objects that, in turn, return item objects that subclass RSSItem. This strategy isolates the bulk of the code from the underlying RSS parser, making it easier to substitute different parsers as more of them become available. RSSItem. This strategy isolates the bulk of the code from the underlying RSS parser, making it easier to substitute different parsers as more of them become available.

Version:
$Revision: 6524 $
See Also:
RSSParserFactory, RSSParser, RSSChannel

Field Summary
static java.lang.String DEFAULT_CONTENT_TYPE
          Constant defining the pseudo-MIME type to use for default content.
static int NO_SUMMARY_LIMIT
          Unlimited summary size
 
Constructor Summary
protected RSSItem()
          Default constructor
 
Method Summary
abstract  void addAuthor(java.lang.String author)
          Add to the item's author list.
abstract  void clearAuthors()
          Clear the authors list.
 void clearContent()
          Clear the stored content for all MIME types, without clearing any other fields.
 java.lang.Object clone()
          Clone this channel.
 int compareTo(java.lang.Object other)
          Compare two items for order.
 boolean equals(java.lang.Object o)
          Compare this item to some other object for equality.
abstract  java.util.Collection<java.lang.String> getAuthors()
          Get the item's author list.
abstract  java.util.Collection<java.lang.String> getCategories()
          Get the categories the item belongs to.
 java.lang.String getContent(java.lang.String mimeType)
          Get the item's content, if available.
 java.lang.String getFirstContentOfType(java.lang.String... mimeTypes)
          Get the first content item that matches one of a list of MIME types.
abstract  java.lang.String getID()
          Get the item's ID field, if any.
abstract  java.util.Collection<RSSLink> getLinks()
          Get the item's published links.
abstract  RSSChannel getParentChannel()
          Get the parent channel
abstract  java.util.Date getPublicationDate()
          Get the item's publication date.
abstract  java.lang.String getSummary()
          Get the item's summary (also sometimes called the description or synopsis).
abstract  java.lang.String getTitle()
          Get the item's title
 int hashCode()
          Generate a hash code for this item.
 RSSItem makeCopy(RSSChannel parentChannel)
          Make a deep copy of this RSSItem object.
abstract  RSSItem newInstance(RSSChannel channel)
          Create a new, empty instance of the underlying concrete class.
abstract  void setCategories(java.util.Collection<java.lang.String> categories)
          Set the categories the item belongs to.
 void setContent(java.lang.String content, java.lang.String mimeType)
          Set the content for a specific MIME type.
abstract  void setID(java.lang.String id)
          Set the item's ID field, if any.
abstract  void setLinks(java.util.Collection<RSSLink> links)
          Set the item's published links.
abstract  void setPublicationDate(java.util.Date date)
          Set the item's publication date.
abstract  void setSummary(java.lang.String newSummary)
          Set the item's summary (also sometimes called the description or synopsis).
abstract  void setTitle(java.lang.String newTitle)
          Set the item's title
 java.lang.String toString()
          Return the string value of the item (which, right now, is its title).
 
Methods inherited from class org.clapper.curn.parser.RSSElement
getAuthor, getLink, getLink, getLink, getLinkWithFallback, getURL, setAuthor, setAuthors
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_CONTENT_TYPE

public static final java.lang.String DEFAULT_CONTENT_TYPE
Constant defining the pseudo-MIME type to use for default content.

See Also:
Constant Field Values

NO_SUMMARY_LIMIT

public static final int NO_SUMMARY_LIMIT
Unlimited summary size

See Also:
Constant Field Values
Constructor Detail

RSSItem

protected RSSItem()
Default constructor

Method Detail

clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
Clone this channel. This method simply calls the type-safe makeCopy(org.clapper.curn.parser.RSSChannel) method. The clone is a deep-clone (i.e., the items are cloned, too).

Overrides:
clone in class java.lang.Object
Returns:
the cloned RSSChannel
Throws:
java.lang.CloneNotSupportedException - doesn't, actually, but the Cloneable interface requires that this exception be declared
See Also:
makeCopy(org.clapper.curn.parser.RSSChannel)

makeCopy

public RSSItem makeCopy(RSSChannel parentChannel)
Make a deep copy of this RSSItem object.

Parameters:
parentChannel - the parent channel to assign to the new instance
Returns:
the copy

getContent

public java.lang.String getContent(java.lang.String mimeType)
Get the item's content, if available. Some feed types (e.g., Atom) support multiple content sections, each with its own MIME type; the mimeType parameter specifies the caller's desired MIME type.

Parameters:
mimeType - the desired MIME type
Returns:
the content (or the default content), or null if no content of the desired MIME type is available
See Also:
clearContent(), getFirstContentOfType(java.lang.String...), setContent(java.lang.String, java.lang.String)

getFirstContentOfType

public final java.lang.String getFirstContentOfType(java.lang.String... mimeTypes)
Get the first content item that matches one of a list of MIME types.

Parameters:
mimeTypes - an array of MIME types to match, in order
Returns:
the first matching content string, or null if none was found. Returns the default content (if set), if there's no exact match.
See Also:
getContent(java.lang.String), clearContent(), setContent(java.lang.String, java.lang.String)

setContent

public void setContent(java.lang.String content,
                       java.lang.String mimeType)
Set the content for a specific MIME type. If the isDefault flag is true, then this content is served up as the default whenever content for a specific MIME type is requested but isn't available.

Parameters:
content - the content string
mimeType - the MIME type to associate with the content
See Also:
getContent(java.lang.String), getFirstContentOfType(java.lang.String...), clearContent()

clearContent

public void clearContent()
Clear the stored content for all MIME types, without clearing any other fields. (In particular, the summary is not cleared.)

See Also:
getContent(java.lang.String), getFirstContentOfType(java.lang.String...), setContent(java.lang.String, java.lang.String)

compareTo

public int compareTo(java.lang.Object other)
Compare two items for order. The channels are ordered first by publication date (if any), then by title, then by unique ID, then by hash code (if all else is equal).

Specified by:
compareTo in interface java.lang.Comparable
Parameters:
other - the other object
Returns:
negative number: this item is less than other;
0: this item is equivalent to other
positive unmber: this item is greater than other

hashCode

public int hashCode()
Generate a hash code for this item.

Overrides:
hashCode in class java.lang.Object
Returns:
the hash code

equals

public boolean equals(java.lang.Object o)
Compare this item to some other object for equality.

Overrides:
equals in class java.lang.Object
Parameters:
o - the object
Returns:
true if the objects are equal, false if not

toString

public java.lang.String toString()
Return the string value of the item (which, right now, is its title).

Overrides:
toString in class java.lang.Object
Returns:
the title

newInstance

public abstract RSSItem newInstance(RSSChannel channel)
Create a new, empty instance of the underlying concrete class.

Parameters:
channel - the parent channel
Returns:
the new instance

getParentChannel

public abstract RSSChannel getParentChannel()
Get the parent channel

Returns:
the parent channel

getTitle

public abstract java.lang.String getTitle()
Get the item's title

Returns:
the item's title, or null if there isn't one
See Also:
setTitle(java.lang.String)

setTitle

public abstract void setTitle(java.lang.String newTitle)
Set the item's title

Parameters:
newTitle - the item's title, or null if there isn't one
See Also:
getTitle()

getSummary

public abstract java.lang.String getSummary()
Get the item's summary (also sometimes called the description or synopsis).

Returns:
the summary, or null if not available
See Also:
setSummary(java.lang.String)

setSummary

public abstract void setSummary(java.lang.String newSummary)
Set the item's summary (also sometimes called the description or synopsis).

Parameters:
newSummary - the summary, or null if not available
See Also:
getSummary()

getAuthors

public abstract java.util.Collection<java.lang.String> getAuthors()
Get the item's author list.

Specified by:
getAuthors in class RSSElement
Returns:
the authors, or null (or an empty Collection) if not available
See Also:
addAuthor(java.lang.String), clearAuthors(), RSSElement.setAuthors(java.util.Collection)

addAuthor

public abstract void addAuthor(java.lang.String author)
Add to the item's author list.

Specified by:
addAuthor in class RSSElement
Parameters:
author - another author string to add
See Also:
getAuthors(), clearAuthors(), RSSElement.setAuthors(java.util.Collection)

clearAuthors

public abstract void clearAuthors()
Clear the authors list.

Specified by:
clearAuthors in class RSSElement
See Also:
getAuthors(), addAuthor(java.lang.String), RSSElement.setAuthors(java.util.Collection)

getLinks

public abstract java.util.Collection<RSSLink> getLinks()
Get the item's published links.

Specified by:
getLinks in class RSSElement
Returns:
the collection of links, or an empty collection
See Also:
setLinks(java.util.Collection)

setLinks

public abstract void setLinks(java.util.Collection<RSSLink> links)
Set the item's published links.

Parameters:
links - the collection of links, or an empty collection (or null)
See Also:
getLinks()

getCategories

public abstract java.util.Collection<java.lang.String> getCategories()
Get the categories the item belongs to.

Returns:
a Collection of category strings (String objects) or null if not applicable
See Also:
setCategories(java.util.Collection)

setCategories

public abstract void setCategories(java.util.Collection<java.lang.String> categories)
Set the categories the item belongs to.

Parameters:
categories - a Collection of category strings or null if not applicable
See Also:
getCategories()

getPublicationDate

public abstract java.util.Date getPublicationDate()
Get the item's publication date.

Returns:
the date, or null if not available
See Also:
getPublicationDate()

setPublicationDate

public abstract void setPublicationDate(java.util.Date date)
Set the item's publication date.

See Also:
getPublicationDate()

getID

public abstract java.lang.String getID()
Get the item's ID field, if any.

Returns:
the ID field, or null if not set
See Also:
setID(java.lang.String)

setID

public abstract void setID(java.lang.String id)
Set the item's ID field, if any.

Parameters:
id - the ID field, or null


Copyright © 2004-2006 Brian M. Clapper. All Rights Reserved.