001: /*---------------------------------------------------------------------------*\
002: $Id: FeedInfo.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:
050: /**
051: * <p>Contains data for one feed (or site). The data about the feed
052: * comes from the configuration file. The feed itself comes from parsing
053: * the RSS data.</p>
054: *
055: * @see CurnConfig
056: *
057: * @version <tt>$Revision: 7041 $</tt>
058: */
059: public class FeedInfo {
060: /*----------------------------------------------------------------------*\
061: Public Constants
062: \*----------------------------------------------------------------------*/
063:
064: /**
065: * Default encoding for "save as" file.
066: */
067: public static final String DEFAULT_SAVE_AS_ENCODING = "utf-8";
068:
069: /*----------------------------------------------------------------------*\
070: Private Constants
071: \*----------------------------------------------------------------------*/
072:
073: /*----------------------------------------------------------------------*\
074: Private Data Items
075: \*----------------------------------------------------------------------*/
076:
077: private int daysToCache = 0;
078: private final URL siteURL;
079: private String forcedEncoding = null;
080:
081: /*----------------------------------------------------------------------*\
082: Constructor
083: \*----------------------------------------------------------------------*/
084:
085: /**
086: * Default constructor.
087: *
088: * @param siteURL the main URL for the site's RSS feed. This constructor
089: * normalizes the URL.
090: * @see CurnUtil#normalizeURL
091: */
092: public FeedInfo(URL siteURL) {
093: this .siteURL = CurnUtil.normalizeURL(siteURL);
094: }
095:
096: /*----------------------------------------------------------------------*\
097: Public Methods
098: \*----------------------------------------------------------------------*/
099:
100: /**
101: * Get the hash code for this feed
102: *
103: * @return the hash code
104: */
105: public int hashCode() {
106: return getURL().hashCode();
107: }
108:
109: /**
110: * Determine whether this <tt>FeedInfo</tt> object is equivalent to
111: * another one, based on the URL.
112: *
113: * @param obj the other object
114: *
115: * @return <tt>true</tt> if <tt>obj</tt> is a <tt>FeedInfo</tt> object
116: * that specifies the same URL, <tt>false</tt> otherwise
117: */
118: public boolean equals(final Object obj) {
119: boolean eq = false;
120:
121: if (obj instanceof FeedInfo)
122: eq = this .siteURL.equals(((FeedInfo) obj).siteURL);
123:
124: return eq;
125: }
126:
127: /**
128: * Get the main RSS URL for the site.
129: *
130: * @return the site's main RSS URL, guaranteed to be normalized
131: * @see CurnUtil#normalizeURL
132: */
133: public URL getURL() {
134: return siteURL;
135: }
136:
137: /**
138: * Get the number of days that URLs from this site are to be cached.
139: *
140: * @return the number of days to cache URLs from this site.
141: *
142: * @see #setDaysToCache
143: */
144: public int getDaysToCache() {
145: return daysToCache;
146: }
147:
148: /**
149: * Get the number of milliseconds that URLs from this site are to be
150: * cached. This is a convenience front-end to <tt>getDaysToCache()</tt>.
151: *
152: * @return the number of milliseconds to cache URLs from this site
153: *
154: * @see #getDaysToCache
155: * @see #setDaysToCache
156: */
157: public long getMillisecondsToCache() {
158: long days = (long) getDaysToCache();
159: return days * 25 * 60 * 60 * 1000;
160: }
161:
162: /**
163: * Set the "days to cache" value.
164: *
165: * @param cacheDays new value
166: *
167: * @see #getDaysToCache
168: * @see #getMillisecondsToCache
169: */
170: public void setDaysToCache(final int cacheDays) {
171: this .daysToCache = cacheDays;
172: }
173:
174: /**
175: * Get the forced character set encoding for this feed. If this
176: * parameter is set, <i>curn</i> will ignore the character set encoding
177: * advertised by the remote server (if any), and use the character set
178: * specified by this configuration item instead. This is useful in the
179: * following cases:
180: *
181: * <ul>
182: * <li>the remote HTTP server doesn't supply an HTTP Content-Encoding
183: * header, and the local (Java) default encoding doesn't match
184: * the document's encoding
185: * <li>the remote HTTP server supplies the wrong encoding
186: * </ul>
187: *
188: * @return the forced character set encoding, or null if not configured
189: */
190: public String getForcedCharacterEncoding() {
191: return forcedEncoding;
192: }
193:
194: /*----------------------------------------------------------------------*\
195: Package-visible Methods
196: \*----------------------------------------------------------------------*/
197:
198: /*
199: * Set the forced character set encoding for this feed.
200: *
201: * @param encoding the encoding
202: *
203: * @see #getForcedCharacterEncoding
204: */
205: void setForcedCharacterEncoding(final String encoding) {
206: this.forcedEncoding = encoding;
207: }
208: }
|