ch.claudio.pediacache.data
Class CachedPage

java.lang.Object
  extended by ch.claudio.pediacache.data.CachedPage

public class CachedPage
extends java.lang.Object

Contains a cahcede page or the request for a page to fetch.

Note: hasCode and equals considers only url.

Version:
$Id: CachedPage.java 162 2006-10-14 17:55:35Z claudio $
Author:
Claudio Nieder

Copyright (C) 2006 Claudio Nieder <private@claudio.ch>, CH-8610 Uster

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA


Constructor Summary
CachedPage(java.net.URL urlArg, byte[] contentArg, java.lang.String contentTypeArg, Source sourceArg)
          A page needs the URL and its content with meta information.
CachedPage(java.net.URL urlArg, Source sourceArg, int priorityArg)
          A page needs the URL and its content with meta information.
 
Method Summary
 boolean equals(java.lang.Object obj)
           
static java.lang.String extractCharset(java.lang.String contentType)
          Determine the charset given a content type
 java.lang.String getCharset()
          Return the charset part of the content type.
 byte[] getContent()
           
 java.lang.String getContentAsString()
          Convert content into a string using the specified charset.
 java.lang.String getContentType()
           
 long getLastFetchTime()
           
 long getLastReadTime()
           
 int getPriority()
           
 java.net.URL getRedirected()
           
 Source getSource()
           
 java.net.URL getUrl()
           
 java.lang.String getUrlAsString()
           
 int hashCode()
           
 boolean hasPriority(int priorityArg)
          Tells if the page has requested priority
 boolean hasURL(java.lang.String urlArg)
          Tells the url of this page matches given url
 boolean isFetched()
          Tells if the page is not just queued but actually fetched and cached
 boolean isHTML()
          Tells if is it an html page
 boolean isNewer(long limit)
          Tells if the was read since the specified time
 boolean isNotFetched()
          Tells if the page is not just queued but actually fetched and cached
 boolean isRedirected()
          Tells if the page is a redirection to another locateion
static void main(java.lang.String[] args)
          Print license.
 void refreshFetchTime()
          Update the time with the current time.
 void refreshReadTime()
          Update the time with the current time.
 void setContent(byte[] contentArg, java.lang.String contentTypeArg)
          Change the content of this cache item.
 void setPriority(int priorityArg)
          Set the priority
 void setRedirected(java.net.URL newURL)
          Sets a redirection to another URL which contains the page.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

CachedPage

public CachedPage(java.net.URL urlArg,
                  byte[] contentArg,
                  java.lang.String contentTypeArg,
                  Source sourceArg)
A page needs the URL and its content with meta information.

Parameters:
urlArg - url of page
contentArg - contant as byte array
contentTypeArg - type as reported by Content-Type header
sourceArg - wikipedia site

CachedPage

public CachedPage(java.net.URL urlArg,
                  Source sourceArg,
                  int priorityArg)
A page needs the URL and its content with meta information.

Parameters:
urlArg - url of page
sourceArg - Source for the url
priorityArg - fetching priority of queued page
Method Detail

setContent

public void setContent(byte[] contentArg,
                       java.lang.String contentTypeArg)
Change the content of this cache item.

Parameters:
contentArg - contant as byte array
contentTypeArg - type as reported by Content-Type header

setRedirected

public void setRedirected(java.net.URL newURL)
Sets a redirection to another URL which contains the page.

Parameters:
newURL - url as supplied from web server

isRedirected

public boolean isRedirected()
Tells if the page is a redirection to another locateion

Returns:
true if page is cached

getRedirected

public java.net.URL getRedirected()
Returns:
the redirected

refreshFetchTime

public void refreshFetchTime()
Update the time with the current time. It is good practice to do that when receiving an answer from the server that the cached page is still up to date.


refreshReadTime

public void refreshReadTime()
Update the time with the current time. It is good practice to do that when receiving an answer from the server that the cached page is still up to date.


getContent

public byte[] getContent()
Returns:
the content

extractCharset

public static java.lang.String extractCharset(java.lang.String contentType)
Determine the charset given a content type

Parameters:
contentType -
Returns:
charset

getCharset

public java.lang.String getCharset()
Return the charset part of the content type. If non is available return ISO-8859-1.

Returns:
charset

getContentAsString

public java.lang.String getContentAsString()
Convert content into a string using the specified charset. ISO-8859-1 is assumed if a charset specification is missing.

This form of the content is useful for text which is parsed of modified but should not be used on other content like images.

Returns:
content

getUrl

public java.net.URL getUrl()
Returns:
the url

getUrlAsString

public java.lang.String getUrlAsString()
Returns:
the url

getContentType

public java.lang.String getContentType()
Returns:
the encoding

getLastFetchTime

public long getLastFetchTime()
Returns:
the time

getLastReadTime

public long getLastReadTime()
Returns:
the lastReadTime

getPriority

public int getPriority()
Returns:
the priortiy

hasURL

public boolean hasURL(java.lang.String urlArg)
Tells the url of this page matches given url

Parameters:
urlArg - to compare
Returns:
true if page is cached

isHTML

public boolean isHTML()
Tells if is it an html page

Returns:
true if page is cached

isNewer

public boolean isNewer(long limit)
Tells if the was read since the specified time

Parameters:
limit -
Returns:
true if page is cached

isFetched

public boolean isFetched()
Tells if the page is not just queued but actually fetched and cached

Returns:
true if page is cached

isNotFetched

public boolean isNotFetched()
Tells if the page is not just queued but actually fetched and cached

Returns:
true if page is cached

hasPriority

public boolean hasPriority(int priorityArg)
Tells if the page has requested priority

Parameters:
priorityArg -
Returns:
true if condition met

setPriority

public void setPriority(int priorityArg)
Set the priority

Parameters:
priorityArg -

getSource

public Source getSource()
Returns:
the source

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object
See Also:
Object.toString()

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object
See Also:
Object.hashCode()

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.Object
See Also:
Object.equals(java.lang.Object)

main

public static void main(java.lang.String[] args)
Print license.

Parameters:
args - ignored