From 614c4aa723972ecbdb86f08cc1881463bd6b241f Mon Sep 17 00:00:00 2001 From: allo Date: Fri, 8 Jun 2007 09:36:00 +0000 Subject: [PATCH] first version of FeedReader git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@3829 6c8d7289-2bf4-0310-a012-ef5d649a1542 --- htroot/FeedReader_p.html | 24 +++++++++++ htroot/FeedReader_p.java | 92 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 116 insertions(+) create mode 100644 htroot/FeedReader_p.html create mode 100644 htroot/FeedReader_p.java diff --git a/htroot/FeedReader_p.html b/htroot/FeedReader_p.html new file mode 100644 index 000000000..2d95a1c27 --- /dev/null +++ b/htroot/FeedReader_p.html @@ -0,0 +1,24 @@ + +#(page)# +please select your feed with ?url=Feedurl&max=5&offset=1 (to be implemented in html ;)) +:: +
+
Title
+
#[title]#
+ #(hasAuthor)#::
Author
+
#[author]#
#(/hasAuthor)# +
Description
+
#[description]#
+
+ +
+#{items}# +
#[title]#
+
#[description]#
+#{/items}# +
+:: +Error +#(/page)# \ No newline at end of file diff --git a/htroot/FeedReader_p.java b/htroot/FeedReader_p.java new file mode 100644 index 000000000..7524fb73f --- /dev/null +++ b/htroot/FeedReader_p.java @@ -0,0 +1,92 @@ +//FeedReader_p.java +//------------ +// part of YACY +// +// (C) 2007 Alexander Schier +// +// last change: $LastChangedDate: $ by $LastChangedBy: $ +// $LastChangedRevision: $ +// +// This program 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. +// +// This program 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 this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.Collection; +import java.util.Iterator; + +import de.anomic.http.httpHeader; +import de.anomic.server.serverObjects; +import de.anomic.server.serverSwitch; +import de.anomic.server.servletProperties; +import de.nava.informa.core.ChannelIF; +import de.nava.informa.core.ParseException; +import de.nava.informa.impl.basic.ChannelBuilder; +import de.nava.informa.impl.basic.Item; +import de.nava.informa.parsers.FeedParser; + +public class FeedReader_p { + + + public static servletProperties respond(httpHeader header, serverObjects post, serverSwitch env) { + servletProperties prop = new servletProperties(); + prop.put("SUPERTEMPLATE", "/env/page.html"); + + URL url; + try { + if(post!=null){ + url = new URL((String) post.get("url")); + int maxitems=Integer.parseInt(post.get("max", "0")); + int offset=Integer.parseInt(post.get("offset", "0")); //offset to the first displayed item + ChannelBuilder builder=new ChannelBuilder(); + ChannelIF channel=FeedParser.parse(builder, url); + prop.put("page_title", channel.getTitle()); + if(channel.getCreator()!=null){ + prop.put("page_hasAuthor", 1); + prop.put("page_hasAuthor_author", channel.getCreator()); + }else + prop.put("page_hasAuthor", 0); + prop.put("page_description", channel.getDescription()); + + Collection feedItems=channel.getItems(); + if(!feedItems.isEmpty()){ + Iterator it=feedItems.iterator(); + int count=0; + while(it.hasNext() && (maxitems==0 || count0)) //first check, if there still is an offset. if yes, skip count++, so the next item will overwrite this item. then decrement offset. + count++; + } + prop.put("page_items", count); + } + prop.put("page", 1); + } + } catch (MalformedURLException e) { + prop.put("page", 2); + } catch (IOException e) { + prop.put("page", 2); + } catch (ParseException e) { + prop.put("page", 2); + } + + // return rewrite properties + return prop; + } +}