yarfraw.io
Class FeedAppender

java.lang.Object
  extended by yarfraw.io.FeedAppender

public class FeedAppender
extends Object

Provides a set of function to facilitate modifications to an RSS 2.0 feed.
*Note* This class is not thread safe.

Author:
jliang

Constructor Summary
FeedAppender(File file)
           
FeedAppender(File file, FeedFormat format)
           
FeedAppender(String pathName)
           
FeedAppender(String pathName, FeedFormat format)
           
FeedAppender(URI uri)
           
FeedAppender(URI uri, FeedFormat format)
           
 
Method Summary
 FeedAppender appendAllItemsAt(int index, List<ItemEntry> items)
          Appends all of the ItemEntry in the specified collection into the current feed at the specified position (optional operation).
 FeedAppender appendAllItemsToBeginning(ItemEntry... items)
          Appends all of the ItemEntry to the beginning of the item list in the current feed.
 FeedAppender appendAllItemsToBeginning(List<ItemEntry> items)
          Appends all of the ItemEntry to the beginning of the item list in the current feed.
 FeedAppender appendAllItemsToEnd(ItemEntry... items)
          Appends all of the ItemEntry to the end of the item list in the current feed.
 FeedAppender appendAllItemsToEnd(List<ItemEntry> items)
          Appends all of the ItemEntry to the end of the item list in current feed.
 FeedFormat getFormat()
          The FeedFormat this writer should be using.
if this is not set, the default is RSS 2.0 format.
 int getNumItemToKeep()
          Maximum number of items to keep in a feed.
 FeedAppender removeItem(int index)
          * Remove the item at index index from the feed.
 void setFormat(FeedFormat format)
          The FeedFormat this writer should be using.
if this is not set, the default is RSS 2.0 format.
 FeedAppender setItem(int index, ItemEntry item)
          Set the item at index index to be the input item
 FeedAppender setNumItemToKeep(int numItemToKeep)
          Maximum number of items to keep in a feed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FeedAppender

public FeedAppender(File file,
                    FeedFormat format)

FeedAppender

public FeedAppender(String pathName,
                    FeedFormat format)

FeedAppender

public FeedAppender(URI uri,
                    FeedFormat format)

FeedAppender

public FeedAppender(File file)

FeedAppender

public FeedAppender(String pathName)

FeedAppender

public FeedAppender(URI uri)
Method Detail

getFormat

public FeedFormat getFormat()
The FeedFormat this writer should be using.
if this is not set, the default is RSS 2.0 format. null format is ignored

Returns:
a FeedFormat enum

setFormat

public void setFormat(FeedFormat format)
The FeedFormat this writer should be using.
if this is not set, the default is RSS 2.0 format. null format is ignored

Parameters:
format - a FeedFormat enum

getNumItemToKeep

public int getNumItemToKeep()
Maximum number of items to keep in a feed. If the number of actual items If numItemToKeep is non-negative and the actual number of ItemEntry (after appends) in the feed greater than numItemToKeep, the appender will remove items from the END of the feed to ensure there is at most numItemToKeep items in the feed.

Returns:
the current numberItemToKepp, -1 if the value has not yet been set or there's no limit.

setNumItemToKeep

public FeedAppender setNumItemToKeep(int numItemToKeep)
Maximum number of items to keep in a feed. If the number of actual items If numItemToKeep is non-negative and the actual number of ItemEntry (after appends) in the feed greater than numItemToKeep, the appender will remove items from the END of the feed to ensure there is at most numItemToKeep items in the feed.

Parameters:
numItemToKeep - number of items to keep in the current feed. no limit if it's negative.
Returns:
this

appendAllItemsAt

public FeedAppender appendAllItemsAt(int index,
                                     List<ItemEntry> items)
                              throws YarfrawException
Appends all of the ItemEntry in the specified collection into the current feed at the specified position (optional operation). Shifts the ItemEntry currently at that position (if any) and any subsequent ItemEntry to the right (increases their indices).
As in feedItemList.addAll(index, inputlist)
If numItemToKeep is set and the resulting number of ItemEntry (after the append) in the feed greater than numItemToKeep, the appender will remove items from the END of the feed to ensure there is at most numItemToKeep items in the feed.

Parameters:
index - index to append to
items - any number of ItemEntry
Returns:
this
Throws:
YarfrawException - if operation failed.

appendAllItemsToBeginning

public FeedAppender appendAllItemsToBeginning(List<ItemEntry> items)
                                       throws YarfrawException
Appends all of the ItemEntry to the beginning of the item list in the current feed. Shifts the ItemEntry currently at that position (if any) and any subsequent ItemEntry to the right (increases their indices).
This is equivalent to appendAllItemsAt(0, inputlist)
If numItemToKeep is set and the resulting number of ItemEntry (after the append) in the feed greater than numItemToKeep, the appender will remove items from the END of the feed to ensure there is at most numItemToKeep items in the feed.

Parameters:
items -
Returns:
Throws:
YarfrawException - if the appender failed to read or write the feed file.

appendAllItemsToBeginning

public FeedAppender appendAllItemsToBeginning(ItemEntry... items)
                                       throws YarfrawException
Appends all of the ItemEntry to the beginning of the item list in the current feed. Shifts the ItemEntry currently at that position (if any) and any subsequent ItemEntry to the right (increases their indices).
This is equivalent to appendAllItemsAt(0, Arrays.asList(item1, item2, item3))
If numItemToKeep is set and the resulting number of ItemEntry (after the append) in the feed greater than numItemToKeep, the appender will remove items from the END of the feed to ensure there is at most numItemToKeep items in the feed.

Parameters:
items -
Returns:
Throws:
YarfrawException - if the appender failed to read or write the feed file.

appendAllItemsToEnd

public FeedAppender appendAllItemsToEnd(List<ItemEntry> items)
                                 throws YarfrawException
Appends all of the ItemEntry to the end of the item list in current feed. Shifts the ItemEntry currently at that position (if any) and any subsequent ItemEntry to the right (increases their indices).
If numItemToKeep is set and the resulting number of ItemEntry (after the append) in the feed greater than numItemToKeep, the appender will remove items from the END of the feed to ensure there is at most numItemToKeep items in the feed.

Parameters:
items -
Returns:
Throws:
YarfrawException - if the appender failed to read or write the feed file.

appendAllItemsToEnd

public FeedAppender appendAllItemsToEnd(ItemEntry... items)
                                 throws YarfrawException
Appends all of the ItemEntry to the end of the item list in the current feed. Shifts the ItemEntry currently at that position (if any) and any subsequent ItemEntry to the right (increases their indices).
If numItemToKeep is set and the resulting number of ItemEntry (after the append) in the feed greater than numItemToKeep, the appender will remove items from the END of the feed to ensure there is at most numItemToKeep items in the feed.

Parameters:
items -
Returns:
Throws:
YarfrawException - if the appender failed to read or write the feed file.

removeItem

public FeedAppender removeItem(int index)
                        throws YarfrawException
* Remove the item at index index from the feed.

Parameters:
index -
Returns:
Throws:
YarfrawException - if the appender failed to read or write the feed file.

setItem

public FeedAppender setItem(int index,
                            ItemEntry item)
                     throws YarfrawException
Set the item at index index to be the input item

Parameters:
index -
item -
Returns:
Throws:
YarfrawException - if the appender failed to read or write the feed file.


Copyright © 2008. All Rights Reserved.