001: /*---------------------------------------------------------------------------*\
002: $Id: FeedCacheEntry.java 7041 2007-09-09 01:04:47Z bmc $
003: ---------------------------------------------------------------------------
004: This software is released under a BSD-style license:
005:
006: Copyright (c) 2004-2007 Brian M. Clapper. All rights reserved.
007:
008: Redistribution and use in source and binary forms, with or without
009: modification, are permitted provided that the following conditions are
010: met:
011:
012: 1. Redistributions of source code must retain the above copyright notice,
013: this list of conditions and the following disclaimer.
014:
015: 2. The end-user documentation included with the redistribution, if any,
016: must include the following acknowlegement:
017:
018: "This product includes software developed by Brian M. Clapper
019: (bmc@clapper.org, http://www.clapper.org/bmc/). That software is
020: copyright (c) 2004-2007 Brian M. Clapper."
021:
022: Alternately, this acknowlegement may appear in the software itself,
023: if wherever such third-party acknowlegements normally appear.
024:
025: 3. Neither the names "clapper.org", "curn", nor any of the names of the
026: project contributors may be used to endorse or promote products
027: derived from this software without prior written permission. For
028: written permission, please contact bmc@clapper.org.
029:
030: 4. Products derived from this software may not be called "curn", nor may
031: "clapper.org" appear in their names without prior written permission
032: of Brian M. Clapper.
033:
034: THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
035: WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
036: MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
037: NO EVENT SHALL BRIAN M. CLAPPER BE LIABLE FOR ANY DIRECT, INDIRECT,
038: INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
039: NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
040: DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
041: THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
042: (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
043: THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
044: \*---------------------------------------------------------------------------*/
045:
046: package org.clapper.curn;
047:
048: import java.net.URL;
049: import java.util.Date;
050:
051: /**
052: * <p>Defines the contents of a cache entry. There is one cache entry
053: * per feed item.</p>
054: *
055: * @see CurnConfig
056: * @see FeedInfo
057: *
058: * @version <tt>$Revision: 7041 $</tt>
059: */
060: public class FeedCacheEntry {
061: /*----------------------------------------------------------------------*\
062: Private Static Variables
063: \*----------------------------------------------------------------------*/
064:
065: /*----------------------------------------------------------------------*\
066: Private Data Items
067: \*----------------------------------------------------------------------*/
068:
069: private long timestamp = 0;
070: private final String entryID;
071: private final URL entryURL;
072: private final URL channelURL;
073: private final Date publicationDate;
074: private boolean sticky = false;
075:
076: /*----------------------------------------------------------------------*\
077: Constructor
078: \*----------------------------------------------------------------------*/
079:
080: /**
081: * Construct a new <tt>FeedCacheEntry</tt>.
082: *
083: * @param entryID the entry's unique ID.
084: * @param channelURL the main URL for the site's RSS feed
085: * @param entryURL the URL to be cached. May be an individual item URL,
086: * or the channel URL (again).
087: * @param pubDate the publication date of the item, or null if unknown
088: * @param timestamp the timestamp (milliseconds) to be cached
089: */
090: public FeedCacheEntry(String entryID, URL channelURL, URL entryURL,
091: Date pubDate, long timestamp) {
092: this .entryID = entryID;
093: this .channelURL = channelURL;
094: this .entryURL = entryURL;
095: this .timestamp = timestamp;
096: this .publicationDate = pubDate;
097: }
098:
099: /*----------------------------------------------------------------------*\
100: Public Methods
101: \*----------------------------------------------------------------------*/
102:
103: /**
104: * Get the unique ID (i.e., cache key) associated with this item.
105: *
106: * @return the unique ID
107: */
108: public String getUniqueID() {
109: return entryID;
110: }
111:
112: /**
113: * Get the main (channel) RSS URL for the site. This URL is the main
114: * feed URL, not the item's specific URL.
115: *
116: * @return the site's main RSS URL
117: */
118: public URL getChannelURL() {
119: return channelURL;
120: }
121:
122: /**
123: * Determine whether this entry is a channel entry or not. A channel
124: * entry has the same entry URL and channel URL. This method is really
125: * just convenient shorthand for:
126: *
127: * <blockquote>
128: * <pre>entry.getChannelURL().sameFile(entry.getEntryURL())</pre>
129: * </blockquote>
130: *
131: * @return <tt>true</tt> if this entry is a channel (a.k.a., feed) entry,
132: * <tt>false</tt> if it is an item entry
133: */
134: public boolean isChannelEntry() {
135: return channelURL.sameFile(entryURL);
136: }
137:
138: /**
139: * Get the URL for this entry.
140: *
141: * @return the entry URL
142: */
143: public URL getEntryURL() {
144: return entryURL;
145: }
146:
147: /**
148: * Get the publication date associated with the cached item. This value
149: * is typically from within the parsed RSS item.
150: *
151: * @return the publication date, or null if not known
152: */
153: public Date getPublicationDate() {
154: return publicationDate;
155: }
156:
157: /**
158: * Get the timestamp associated with this entry. The timestamp
159: * represents the last time (in milliseconds) that the URL was read.
160: *
161: * @return the timestamp
162: */
163: public long getTimestamp() {
164: return timestamp;
165: }
166:
167: /**
168: * Set the timestamp associated with this entry. The timestamp
169: * represents the last time (in milliseconds) that the URL was read.
170: *
171: * @param timestamp the timestamp
172: */
173: public void setTimestamp(final long timestamp) {
174: this .timestamp = timestamp;
175: }
176:
177: /**
178: * Determine whether this entry is "sticky" (i.e., should be shown even
179: * though it's already been seen.
180: *
181: * @return <tt>true</tt> if the item is marked "sticky",
182: * <tt>false</tt> if not
183: */
184: public boolean isSticky() {
185: return sticky;
186: }
187:
188: /**
189: * Set or clear the "sticky" flag. If an item is marked sticky, it will
190: * be shown even though it's already in the cache. NOTE: Stickiness is
191: * not automatically persisted to the disk store. It's intended to be
192: * calculated at runtime, based on other criteria.
193: *
194: * @param sticky whether or not the entry is to be marked sticky
195: */
196: public void setSticky(boolean sticky) {
197: this.sticky = sticky;
198: }
199: }
|