001: /**********************************************************************************
002:
003: Feedzeo!
004: A free and open source RSS/Atom/RDF feed aggregator
005:
006: Copyright (C) 2005-2006 Anand Rao (anandrao@users.sourceforge.net)
007:
008: This library is free software; you can redistribute it and/or
009: modify it under the terms of the GNU Lesser General Public
010: License as published by the Free Software Foundation; either
011: version 2.1 of the License, or (at your option) any later version.
012:
013: This library is distributed in the hope that it will be useful,
014: but WITHOUT ANY WARRANTY; without even the implied warranty of
015: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
016: Lesser General Public License for more details.
017:
018: You should have received a copy of the GNU Lesser General Public
019: License along with this library; if not, write to the Free Software
020: Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
021:
022: ************************************************************************************/package data;
023:
024: import java.util.*;
025: import util.*;
026:
027: public class CategoryData {
028: private String name; /* Name of the Category */
029: private Hashtable ChnlHashtbl; /* hash table providing fast
030: linkname -to-> ChannelData retreival */
031:
032: public CategoryData(String name) {
033: ChnlHashtbl = new Hashtable();
034: this .name = name;
035: }
036:
037: /* add/update channel data and return 0 on success, -1 on failure */
038: public synchronized int addChannel(ChannelData chnl) {
039: String link = chnl.getFeedSourceURL();
040: try {
041: /* adds a new channel if not already present in the HashTable,
042: else updates the old entry with new ChannelData object */
043: ChnlHashtbl.put(link, chnl);
044: } catch (Exception e) {
045: ExceptionUtil.reportException(e);
046: return -1;
047: }
048: return 0;
049: }
050:
051: public synchronized int removeChannel(String FeedSourceURL) {
052: if (FeedSourceURL == null)
053: return -1;
054: if (ChnlHashtbl.remove(FeedSourceURL) == null) {
055: System.out
056: .println("Channel remove failed in hastable for channels:"
057: + FeedSourceURL);
058: return -1;
059: }
060: return 0;
061: }
062:
063: public synchronized int getNumChannels() {
064: return (ChnlHashtbl.size());
065: }
066:
067: public synchronized Vector getFeedNames() {
068: Vector feeds = new Vector();
069: Iterator i = ChnlHashtbl.values().iterator();
070: while (i.hasNext()) {
071: ChannelData c = (ChannelData) i.next();
072: feeds.addElement(c.getTitle());
073: }
074: return feeds;
075: }
076:
077: public synchronized String getFeedName(String feedSourceLink) {
078: ChannelData chd = (ChannelData) ChnlHashtbl.get(feedSourceLink);
079: if (chd != null)
080: return chd.getTitle();
081: return null;
082: }
083:
084: public synchronized String getFeedTableDataPageLink(
085: String feedSourceLink) {
086: ChannelData chd = (ChannelData) ChnlHashtbl.get(feedSourceLink);
087: if (chd != null)
088: return chd.getHTMLTableDatafilename();
089: return null;
090: }
091:
092: public synchronized Vector getFeedPageLinks() {
093: Vector pageLinks = new Vector();
094: Iterator i = ChnlHashtbl.values().iterator();
095: while (i.hasNext()) {
096: ChannelData c = (ChannelData) i.next();
097: pageLinks.addElement(c.getHTMLfilename());
098: }
099: return pageLinks;
100: }
101:
102: public synchronized Vector getFeedSourceLinks() {
103: Vector sourceLinks = new Vector();
104: Iterator i = ChnlHashtbl.values().iterator();
105: while (i.hasNext()) {
106: ChannelData c = (ChannelData) i.next();
107: sourceLinks.addElement(c.getFeedSourceURL());
108: }
109: return sourceLinks;
110: }
111:
112: public synchronized Vector getFeedTableDataPageLinks() {
113: Vector tablePageLinks = new Vector();
114: Iterator i = ChnlHashtbl.values().iterator();
115: while (i.hasNext()) {
116: ChannelData c = (ChannelData) i.next();
117: tablePageLinks.addElement(c.getHTMLTableDatafilename());
118: }
119: return tablePageLinks;
120: }
121:
122: public synchronized boolean isChannelContentChanged(
123: String feedSourceLink) {
124: ChannelData chd = (ChannelData) ChnlHashtbl.get(feedSourceLink);
125: if (chd == null)
126: return false;
127:
128: long lastUpdateTime = chd.getFeedSourceLastModified();
129: System.out.println("Checking link:" + feedSourceLink);
130:
131: if (HttpUtil.hasURLContentChanged(feedSourceLink,
132: lastUpdateTime))
133: return true;
134: return false;
135: }
136:
137: public synchronized void setChannelHTMLfilename(
138: String feedSourceLink, String filename) {
139: ChannelData chd = (ChannelData) ChnlHashtbl.get(feedSourceLink);
140: if (chd == null)
141: return;
142: chd.setHTMLfilename(filename);
143: }
144:
145: public synchronized String getChannelHTMLfilename(
146: String feedSourceLink) {
147: ChannelData chd = (ChannelData) ChnlHashtbl.get(feedSourceLink);
148: if (chd == null)
149: return ("");
150: return chd.getHTMLfilename();
151: }
152:
153: public synchronized void setChannelHTMLTableDatafilename(
154: String feedSourceLink, String filename) {
155: ChannelData chd = (ChannelData) ChnlHashtbl.get(feedSourceLink);
156: if (chd == null)
157: return;
158: chd.setHTMLTableDatafilename(filename);
159: }
160:
161: public synchronized String getChannelHTMLTableDatafilename(
162: String feedSourceLink) {
163: ChannelData chd = (ChannelData) ChnlHashtbl.get(feedSourceLink);
164: if (chd == null)
165: return ("");
166: return chd.getHTMLTableDatafilename();
167: }
168:
169: public synchronized String getChannelData(String DataType,
170: String feedSourceLink) {
171: ChannelData chd = (ChannelData) ChnlHashtbl.get(feedSourceLink);
172: if (chd == null)
173: return ("");
174: return chd.getData(DataType);
175: }
176:
177: public synchronized String getChannelItemData(String DataType,
178: String feedSourceLink, int ItemIndex) {
179: ChannelData chd = (ChannelData) ChnlHashtbl.get(feedSourceLink);
180: if (chd == null)
181: return ("");
182: return chd.getItemData(DataType, ItemIndex);
183: }
184:
185: public String getCategoryName() {
186: return name;
187: }
188:
189: public String getData(String Type) {
190: if (Type.equalsIgnoreCase(DataElement.CATEGORY_TITLE_ELEM))
191: if (name != null)
192: return name;
193: return "";
194: }
195: };
|