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.net.*;
025: import java.io.*;
026: import java.util.*;
027:
028: import de.nava.informa.parsers.*;
029: import de.nava.informa.impl.basic.*;
030: import de.nava.informa.core.*;
031: import util.ExceptionUtil;
032: import util.StringUtil;
033: import util.HttpUtil;
034:
035: /**
036: *
037: * @author Anand Rao
038: */
039: public class FeedRetriever {
040:
041: private ChannelBuilder cb;
042: private FeedParser fp;
043: private Channel chnl;
044: private Collection items;
045: private String FeedSource;
046:
047: /** Creates a new instance of FeedRetriever */
048: public FeedRetriever(String FeedSource) {
049: cb = new ChannelBuilder();
050: fp = new FeedParser();
051: this .FeedSource = FeedSource;
052: try {
053: chnl = (Channel) fp.parse(cb, new URL(FeedSource));
054: } catch (Exception e) {
055: ExceptionUtil.reportException(e);
056: }
057: }
058:
059: public ChannelData getChannelData() {
060:
061: if (chnl == null) { // in cases where the site is down, Channel object
062: // could be returned as null
063: return null;
064: }
065:
066: Object[] itemobjs;
067: ChannelData ch = new ChannelData();
068:
069: ch.setCopyright(chnl.getCopyright());
070: ch.setCreator(chnl.getCreator());
071: if (chnl.getTitle().length() > 0) {
072: String TitlewoTabs = StringUtil.replaceTabsNewLine(chnl
073: .getTitle());
074: ch.setTitle(TitlewoTabs);
075: } else {
076: System.out.println("Feedretriever: no title in "
077: + FeedSource);
078: String domainname = HttpUtil.getDomainName(FeedSource);
079: ch.setTitle(domainname);
080: }
081: ch.setFeedSourceURL(FeedSource);
082: long lastModified = HttpUtil.getURLLastModified(FeedSource);
083: ch.setFeedSourceLastModified(lastModified);
084: ch.setDescription(chnl.getDescription());
085: if (chnl.getImage() != null)
086: ch.setImageLink(((Image) chnl.getImage()).getLink());
087: ch.setPublishDate(chnl.getPubDate());
088: ch.setPublisher(chnl.getPublisher());
089:
090: items = chnl.getItems();
091: itemobjs = items.toArray();
092: for (int i = 0; i < itemobjs.length; i++) {
093:
094: Item newsItem = (Item) itemobjs[i];
095: ItemData id = new ItemData();
096:
097: id.setCreator(newsItem.getCreator());
098: id.setTitle(newsItem.getTitle());
099: id.setDescription(newsItem.getDescription());
100: id.setCreationDate(newsItem.getDate());
101: id.setLink(newsItem.getLink());
102: ch.addItem(id);
103: }
104: return ch;
105: }
106:
107: };
|