net.sourceforge.rssowl.controller.thread
Class AmphetaRateThread

java.lang.Object
  extended byjava.lang.Thread
      extended bynet.sourceforge.rssowl.controller.thread.AmphetaRateThread
All Implemented Interfaces:
Runnable

public class AmphetaRateThread
extends Thread

This class is used to implement AmphetaRate functionality to RSSOwl. A running thread submits ratings (connects to an URL for each rating) every 15 minutes. The ratings are stored in a Hashtable. The user may rate each news from a newsfeed. Possible ratings are given throught the constants Wow!, Good and Crap.

Version:
1.1.3
Author:
Benjamin Pasero

Field Summary
private  boolean isSubmitting
          Flag indicates that the thread is currently submitting ratings
private  boolean keepRunning
          Flag indicates that the thread was not stopped yet
private static String PARAM_CLIENT
          Tell that RSSOwl querrys AmphetaRate
private static String PARAM_HTML
          Tell that the recommendation articles should not be formatted with HTML
private static String PARAM_LINKINDESC
          Tell that we dont want the feed link in the description
static String PARAM_LIST
          Complete list of parameters as we want AmphetaRate to behave
private static String PARAM_ORIGURL
          Tell that we need the origurl-tag in the recommendations
static int RATE_BAD
          Rate-level: Bad
static int RATE_FANTASTIC
          Rate-level: Fantastic
static int RATE_GOOD
          Rate-level: Good
static int RATE_MODERATE
          Rate-level: Moderate
static int RATE_VERY_BAD
          Rate-level: Very Bad
static Hashtable ratedNews
          Store the news that have been rated in this session
private static Hashtable ratings
          Holds all not yet submitted ratings
private static String STATUS_ERROR
          Server status code for an erroneous submission of a rating
static String STATUS_OK
          Server status code for a successfull submission of a rating
private static int SUBMIT_INTERVAL
          Interval for the thread to submit the collected ratings
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
AmphetaRateThread()
          Instantiate a new AmphetaRateThread
 
Method Summary
static Hashtable getRatings()
          Get all ratings
static String getTranslatedRatingLevel(int rateLevel)
          Get the translated rating level for the giving level
static boolean isOldUser()
          Get if the user is an old one using the AmphetaRate user id and not the new username alias and password
static boolean rate(NewsItem rssNewsItem, int rating)
          Rate a newsitem from a newschannel
static String register(String user, String password, String oldId)
          Register to AmphetaRate
 void run()
          Will check the ratings Hashtable every 15 minutes and connect to all URLs that are int (= perform the rating).
 void stopThread()
          Stop this Thread
private static boolean submitRating(String url)
          Submits a rating from with connecting to the given URL.
 void wakeUp()
          Wake up submit thread
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

RATE_BAD

public static final int RATE_BAD
Rate-level: Bad

See Also:
Constant Field Values

RATE_FANTASTIC

public static final int RATE_FANTASTIC
Rate-level: Fantastic

See Also:
Constant Field Values

RATE_GOOD

public static final int RATE_GOOD
Rate-level: Good

See Also:
Constant Field Values

RATE_MODERATE

public static final int RATE_MODERATE
Rate-level: Moderate

See Also:
Constant Field Values

RATE_VERY_BAD

public static final int RATE_VERY_BAD
Rate-level: Very Bad

See Also:
Constant Field Values

ratedNews

public static Hashtable ratedNews
Store the news that have been rated in this session


STATUS_OK

public static final String STATUS_OK
Server status code for a successfull submission of a rating

See Also:
Constant Field Values

PARAM_CLIENT

private static final String PARAM_CLIENT
Tell that RSSOwl querrys AmphetaRate

See Also:
Constant Field Values

PARAM_HTML

private static final String PARAM_HTML
Tell that the recommendation articles should not be formatted with HTML

See Also:
Constant Field Values

PARAM_LINKINDESC

private static final String PARAM_LINKINDESC
Tell that we dont want the feed link in the description

See Also:
Constant Field Values

PARAM_ORIGURL

private static final String PARAM_ORIGURL
Tell that we need the origurl-tag in the recommendations

See Also:
Constant Field Values

PARAM_LIST

public static final String PARAM_LIST
Complete list of parameters as we want AmphetaRate to behave

See Also:
Constant Field Values

ratings

private static final Hashtable ratings
Holds all not yet submitted ratings


STATUS_ERROR

private static final String STATUS_ERROR
Server status code for an erroneous submission of a rating

See Also:
Constant Field Values

SUBMIT_INTERVAL

private static final int SUBMIT_INTERVAL
Interval for the thread to submit the collected ratings

See Also:
Constant Field Values

isSubmitting

private boolean isSubmitting
Flag indicates that the thread is currently submitting ratings


keepRunning

private boolean keepRunning
Flag indicates that the thread was not stopped yet

Constructor Detail

AmphetaRateThread

public AmphetaRateThread()
Instantiate a new AmphetaRateThread

Method Detail

getRatings

public static Hashtable getRatings()
Get all ratings

Returns:
Hashtable holding the ratings

getTranslatedRatingLevel

public static String getTranslatedRatingLevel(int rateLevel)
Get the translated rating level for the giving level

Parameters:
rateLevel - The level of the rating
Returns:
String The translated level for the given level

isOldUser

public static boolean isOldUser()
Get if the user is an old one using the AmphetaRate user id and not the new username alias and password

Returns:
boolean TRUE if AmphetaRate user id is given

rate

public static boolean rate(NewsItem rssNewsItem,
                           int rating)
Rate a newsitem from a newschannel

Parameters:
rssNewsItem - Selected newsitem
rating - either fantastic, good, moderate, bad or very bad
Returns:
boolean TRUE if newsitem is a valid item to rate

register

public static String register(String user,
                              String password,
                              String oldId)
                       throws IOException
Register to AmphetaRate

Parameters:
user - Desired username
password - Desired password
oldId - Optional oldId
Returns:
String An User ID that is 3 digits followed by 3 numbers or an empty String if an warning occured
Throws:
IOException - if an error occurs

submitRating

private static boolean submitRating(String url)
                             throws IOException
Submits a rating from with connecting to the given URL.

Parameters:
url - The rating-URL consists of title, newsfeed XML URL, description, newsitem link and the user id.
Returns:
TRUE if submit was successfull or the rating URL is malformed. FALSE if the connection could not be established.
Throws:
IOException - If an error occurs

run

public void run()
Will check the ratings Hashtable every 15 minutes and connect to all URLs that are int (= perform the rating). All submitted ratings are deleted from the Hashtable.


stopThread

public void stopThread()
Stop this Thread


wakeUp

public void wakeUp()
Wake up submit thread



RSSOwl - RSS / RDF / Atom Newsreader

SourceForge.net Logo