fable.adt
Class Article

java.lang.Object
  extended by fable.adt.FableComponent
      extended by fable.adt.Article
All Implemented Interfaces:
FableContainer

public class Article
extends FableComponent

This class represents an article.

Author:
Wonsik Kim, Christopher Moh

Constructor Summary
Article(Article a)
          Constructs a brand new article (cloning) an original one
Article(java.util.Date date, java.lang.String title, java.lang.String author, java.lang.String summary)
          Construct a new Article with provided date, title, author, and summary.
Article(java.util.Date date, java.lang.String title, java.lang.String articleURL, java.lang.String author, java.lang.String summary)
          Construct a new Article with provided date, title, articleURL, author, and summary.
 
Method Summary
 void accept(FableVisitor v)
          Accept the visitor v to visit this.
 void acceptRecursive(FableVisitor v)
          Accept the visitor v to visit this, and recurse on children of this.
 boolean activate()
          Activates it to the GUI
 void addArticleMarkChangeListener(ArticleMarkChangeListener amcl)
          Add a listener for mark change of this article.
 boolean addChild(FableComponent fc)
          Article cannot have any children, so it will always return false.
 void addKeywords(java.util.Set<java.lang.String> keywords)
          Add keywords to register as the article's keyword.
 java.net.URL getArticleURL()
          Returns an URL object represents where the article is.
 java.lang.String getAuthor()
          Returns a string that is a name of the author.
 java.lang.String getContent()
          Returns the path of the html file in the file system that contains the data If there is no such path, it returns an empty string
 java.lang.String getSummary()
          Returns a string that is a summary of this.
 boolean isKeywordRegistered(java.lang.String keyword)
          Returns ture if the keyword is registered for this article.
 boolean isMarkedAs(Mark m)
          Returns true if this article is marked as m.
 boolean isSimilarTo(FableComponent fc)
          Returns true if this article and the FableComponent are similar.
 void refresh()
          Refreshes this article according to the articleURL.
 void removeAllListeners()
          Removes all the listeners associated with this FableComponent.
 void removeArticleMarkChangeListener(ArticleMarkChangeListener amcl)
          Remove a listener for mark change of this article.
 void setContent(java.lang.String newContent)
          Replace the content of this article with the newContent.
 void setKeywords(java.util.Set<java.lang.String> keywords)
          Set the keywords of this article.
 void setMark(Mark m, boolean b)
          Set the mark m as boolean b.
 void setSummary(java.lang.String newSummary)
          Sets the summary of the Article
 java.lang.String toString()
          Returns string representation of this article.
 
Methods inherited from class fable.adt.FableComponent
addStructuralChangeListener, getChildren, getDate, getDescendants, getParent, getPosition, getTitle, isAncestorOf, moveDown, moveUp, removeChild, removeStructuralChangeListener, setParent, setPosition, setTitle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Article

public Article(java.util.Date date,
               java.lang.String title,
               java.lang.String articleURL,
               java.lang.String author,
               java.lang.String summary)
        throws java.net.MalformedURLException
Construct a new Article with provided date, title, articleURL, author, and summary.

Parameters:
date - a date that the article is posted.
title - a title of the article.
articleURL - a string corresponds to the article URL.
author - a string represents the author.
summary - a string represents the summary of this article.
Throws:
java.net.MalformedURLException - if articleURL is not a correct URL.
java.lang.NullPointerException - if any of the parameters is null.
Effects:
Construct a new Article
Modifies:
this

Article

public Article(java.util.Date date,
               java.lang.String title,
               java.lang.String author,
               java.lang.String summary)
Construct a new Article with provided date, title, author, and summary. In this case, URL will be null.

Parameters:
date - a date that the article is posted.
title - a title of the article.
author - a string represents the author.
summary - a string represents the summary of this article.
Throws:
java.net.MalformedURLException - if articleURL is not a correct URL.
java.lang.NullPointerException - if any of the parameters is null.
Effects:
Construct a new Article
Modifies:
this

Article

public Article(Article a)
        throws java.net.MalformedURLException
Constructs a brand new article (cloning) an original one

Parameters:
a - Article to duplicate
Throws:
java.net.MalformedURLException - if URL is invalid
java.lang.NullPointerException - if a is null.
Effects:
Construct a new Article
Modifies:
this
Method Detail

activate

public boolean activate()
Description copied from class: FableComponent
Activates it to the GUI

Overrides:
activate in class FableComponent
Returns:
true if it can be activated, false if it is already activated

refresh

public void refresh()
             throws java.io.IOException
Refreshes this article according to the articleURL.

Throws:
java.io.IOException - if connecting to the URL is failed.
Effects:
Update content of this according to the URL, or do nothing if this article is associated with no URL.
Modifies:
this.content

toString

public java.lang.String toString()
Returns string representation of this article.

Overrides:
toString in class java.lang.Object
Returns:
string representation of this article.

isMarkedAs

public final boolean isMarkedAs(Mark m)
Returns true if this article is marked as m. For example, if we get true from isMarkedAs( Mark.Read ), then we know that the article is marked as read.

Parameters:
m - mark to be checked.
Returns:
true if this is marked as m. When m is null, it returns false. =

isSimilarTo

public boolean isSimilarTo(FableComponent fc)
Returns true if this article and the FableComponent are similar. Similar means that two articles have the equal URL, equal author, equal date, equal description, and equal title.

Specified by:
isSimilarTo in class FableComponent
Parameters:
fc - FableComponent to
Returns:
true if two articles are similar.

isKeywordRegistered

public boolean isKeywordRegistered(java.lang.String keyword)
Returns ture if the keyword is registered for this article.

Parameters:
keyword - query keyword.
Returns:
true if the keyword is registered.

addChild

public boolean addChild(FableComponent fc)
Article cannot have any children, so it will always return false.

Specified by:
addChild in interface FableContainer
Overrides:
addChild in class FableComponent
Parameters:
fc - FableComponent object.
Returns:
true if c is succesfully added. false otherwise.
Returns:
false

addArticleMarkChangeListener

public final void addArticleMarkChangeListener(ArticleMarkChangeListener amcl)
Add a listener for mark change of this article.

Parameters:
amcl - a listener to be added to this.
Throws:
java.lang.NullPointerException - if amcl is null.
Effects:
add a listener for mark change of this article.
Modifies:
this.listeners

addKeywords

public final void addKeywords(java.util.Set<java.lang.String> keywords)
Add keywords to register as the article's keyword.

Parameters:
keywords - keywords to be added.
Throws:
java.lang.NullPointerException - when keywords is null.
Effects:
Construct a new Article
Modifies:
this

removeArticleMarkChangeListener

public final void removeArticleMarkChangeListener(ArticleMarkChangeListener amcl)
Remove a listener for mark change of this article.

Parameters:
amcl - a listener to be removed from this.
Throws:
java.lang.NullPointerException - if amcl is null.
Effects:
add a listener for mark change of this article.
Modifies:
this.listeners

removeAllListeners

public void removeAllListeners()
Removes all the listeners associated with this FableComponent.

Overrides:
removeAllListeners in class FableComponent

getArticleURL

public java.net.URL getArticleURL()
Returns an URL object represents where the article is.

Returns:
an URL object represents where the article is.

getAuthor

public java.lang.String getAuthor()
Returns a string that is a name of the author.

Returns:
a string that is a name of the author.

getSummary

public java.lang.String getSummary()
Returns a string that is a summary of this.

Returns:
a string that is a summary of this.

getContent

public java.lang.String getContent()
Returns the path of the html file in the file system that contains the data If there is no such path, it returns an empty string

Returns:
path of html file in file system that contains the data

setContent

public void setContent(java.lang.String newContent)
Replace the content of this article with the newContent.

Parameters:
newContent - a string to be the content of this.
Effects:
set content of this article.
Modifies:
this.content

setMark

public void setMark(Mark m,
                    boolean b)
Set the mark m as boolean b. For example, if we do setMark( Mark.READ, true ), it makes the article marked as read.

Parameters:
m - mark to change the status.
b - boolean value of desired state of the mark.
Throws:
java.lang.NullPointerException - if m is null.
Effects:
mark this article as m.
Modifies:
this.mark

setKeywords

public void setKeywords(java.util.Set<java.lang.String> keywords)
Set the keywords of this article.

Parameters:
keywords - keywords to replace current keywords.
Throws:
java.lang.NullPointerException - if keywords is null.

setSummary

public void setSummary(java.lang.String newSummary)
Sets the summary of the Article

Parameters:
newSummary - The new summary
Throws:
java.lang.NullPointerException - when newSummary is null.
Effects:
set summary of this.
Modifies:
this.summary

accept

public void accept(FableVisitor v)
Description copied from class: FableComponent
Accept the visitor v to visit this.

Specified by:
accept in class FableComponent
Parameters:
v - the visitor to visit this.

acceptRecursive

public void acceptRecursive(FableVisitor v)
Description copied from class: FableComponent
Accept the visitor v to visit this, and recurse on children of this.

Specified by:
acceptRecursive in class FableComponent
Parameters:
v - the visitor to visit this and decendants of this.