+++ /dev/null
-/*TK make sure the items go somewhere! */
-
-/*
- * Copyright (C) 2001-2006 The Mir-coders group
- *
- * This file is part of Mir.
- *
- * Mir 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; either version 2 of the License, or
- * (at your option) any later version.
- *
- * Mir 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 Mir; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * In addition, as a special exception, The Mir-coders gives permission to link
- * the code of this program with any library licensed under the Apache Software License,
- * and distribute linked combinations including the two. You must obey the
- * GNU General Public License in all respects for all of the code used other than
- * the above mentioned libraries. If you modify this file, you may extend this
- * exception to your version of the file, but you are not obligated to do so.
- * If you do not wish to do so, delete this exception statement from your version.
- */
-package mir.rss;
-
-import mir.log.LoggerWrapper;
-import mir.util.HTTPClientHelper;
-
-import org.apache.commons.feedparser.*;
-import org.apache.commons.feedparser.impl.*;
-import org.apache.commons.feedparser.network.*;
-
-
-import java.io.InputStream;
-import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.LinkedList;
-import java.util.Map;
-
-/**
- *
- * <p>Title: </p>
- * <p>Description: </p>
- * <p>Copyright: Copyright (c) 2007</p>
- * <p>Company: </p>
- * @author not attributable
- * @version 1.0
- */
-
-public class RSS2Reader {
- private FeedParser parser;
- private FeedParserListener listener;
- private RSSData result;
- private List items;
- private RDFResource channel;
- static final LoggerWrapper logger =
- new LoggerWrapper("rss.rss2reader");
-
-
- private RDFResource currentItem(){
- try{
- return (RDFResource) items.get(items.size()-1);
- }
- catch (IndexOutOfBoundsException i){
- logger.debug( "Something screwy happened!");
- return new RDFResource("nonexistent","entity");
- }
- }
-
-
- public RSS2Reader() throws org.apache.commons.feedparser.FeedParserException {
- parser = FeedParserFactory.newFeedParser();
-
- result = new RSSData();
- items = new ArrayList();
- channel = new RDFResource("rss:channel");
-
-
- listener = new DefaultFeedParserListener() {
-
-
- public void onItem( FeedParserState state,
- String title,
- String link,
- String description,
- String permalink ) throws FeedParserException {
- logger.debug( "Found a new published article: " + permalink );
- RDFResource item = new RDFResource("rss:item", link);
- item.set("rss:link",permalink);
- item.set("rss:title",title);
- item.set("rss:description",description);
- items.add(item);
- }
-
- public void onAuthor(FeedParserState state, java.lang.String name, java.lang.String email, java.lang.String resource){
- currentItem().set("dc:creator",name);
- }
-
- public void onContent(FeedParserState state, java.lang.String type, java.lang.String format, java.lang.String encoding, java.lang.String mode, java.lang.String value, boolean isSummary) {
- currentItem().set("content.encoded",value);
- }
-
- public void onCreated(FeedParserState state,java.util.Date date){
- SimpleDateFormat formatter = new SimpleDateFormat("yyyy-mm-ddThh:mm:ssTZ");
- currentItem().set("dc:date",formatter.format(date));
- }
-
- public void onItemEnd(){
- result.addResource(currentItem());
- logger.debug( "Finished processing article" );
- }
-
-
-
-
-
- };
- }
-
- public RSSData parseInputStream(InputStream aStream) throws RSSExc, RSSFailure {
- try {
- parser.parse( listener, aStream, "" );
- return result;
- }
- catch (Throwable t) {
- throw new RSSFailure(t);
- }
- }
-
- public RSSData parseInputStream(InputStream aStream, String anEncoding) throws RSSExc, RSSFailure {
- try {
- return parseInputStream(aStream);
- }
- catch (Throwable t) {
- throw new RSSFailure(t);
- }
- }
-
- public RSSData parseUrl(String anUrl) throws RSSExc, RSSFailure {
- try {
- ResourceRequest request = ResourceRequestFactory.getResourceRequest( anUrl );
- InputStream is = request.getInputStream();
- return parseInputStream(is);
-
- }
- catch (Throwable t) {
- throw new RSSFailure(t);
- }
- }
-
- public RSSData parseUrl(String anUrl, String anEncoding) throws RSSExc, RSSFailure {
- try {
- return parseUrl(anUrl);
- }
-
- catch (Throwable t) {
- throw new RSSFailure(t);
- }
- }
-
-}