From 2c2e8de50c5b362891a40a1a727262d742b97c21 Mon Sep 17 00:00:00 2001 From: christoph Date: Sat, 21 Feb 2009 02:26:59 +0100 Subject: Adding an OPML-Export /feedlist.opml which is session-aware. Unfortunately I couldnt create a class fitting to StringTemplate's needs, unfortunately Clojure seems not to be able to create Interfaces on-the-fly and one has to compile them before using them. I couldnt manage to do so, so I decided to create an OPML-String directly. So far, this works. Anyway, added opml.st and opmlclass.clj - which somehow reflect my trial of doing this. --- cljssss-g.clj | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++-------- opml.st | 17 ++++++++++++++ opmlclass.clj | 18 +++++++++++++++ 3 files changed, 100 insertions(+), 9 deletions(-) create mode 100644 opml.st create mode 100644 opmlclass.clj diff --git a/cljssss-g.clj b/cljssss-g.clj index d9f2149..03856e1 100644 --- a/cljssss-g.clj +++ b/cljssss-g.clj @@ -26,6 +26,69 @@ (sql/transaction ~@body))) +(defn opml-init [text xmlurl htmlurl] + (ref {:text text :xmlurl xmlurl :htmlurl htmlurl})) + +(defn opml-getText [this] + (this :text)) +(defn opml-getXmlurl [this] + (this :xmlurl)) +(defn opml-getHtmlurl [this] + (this :htmlurl)) + +;(gen-interface +; :name opmliface +; :prefix "opml-" +; :init init +; :methods [[getXmlurl [] String] +; [getHtmlurl [] String] +; [getText [] String]]) + +;;; FIXME: clojure has no way of creating interfaces on-the-fly. So I +;;; cannot use stringtemplate here. +(defn opml-string [id] + (with-dbt + (sql/with-query-results + results + ["SELECT feed.uri, feed.link, user_feed_link.title FROM feed, user_feed_link WHERE user_feed_link.feed=feed.id AND user_feed_link.user=?" id] + (str "" + "blah" + "Gödel-Gentzen Clojure Syndication Services Super System Feed Export" + (loop [clstr "" r results] + (if (first r) + (recur + (str clstr + "") + (rest r)) + clstr)) + "")))) +; (let [template-object (.getInstanceOf templates "opml"), +; feeds +; (to-array +; (loop [clst '() r results] +; (if (first r) +; (recur +; (concat +; clst +; (list (proxy [Object] [] +; (getText [] +; ((first r) :title)) +; (getXmlurl [] +; ((first r) :uri)) +; (getHtmlurl [] +; ((first r) :link))))) +; (rest r)) + clst)))] +; (. template-object setAttribute "date" "heute") +; (. template-object setAttribute "feeds" feeds) +; (.toString template-object))))) + (defservlet cljssss-g (GET "/login" (if (= (params :valuesofbetawillgiverisetodom) "true") @@ -46,17 +109,10 @@ (alter session assoc :id id) (redirect-to "/")) (redirect-to "/login?valuesofbetawillgiverisetodom=true")))))) - (GET "/bare_feedlist" + (GET "/feedlist.opml" (if (not (session :id)) (redirect-to "/login") - (with-dbt - (sql/with-query-results - [results] - ["SELECT feed.link FROM feed, user_feed_link WHERE user_feed_link.feed=feed.id AND user_feed_link.user=?" 1] - (loop [cstr "" r results] - (if (rest r) - (recur (str cstr (first r) "\n") (rest r)) - (str cstr (first r) "\n"))))))) + (opml-string (session :id)))) (GET "/" (if (session :id) (.toString diff --git a/opml.st b/opml.st new file mode 100644 index 0000000..3fd6360 --- /dev/null +++ b/opml.st @@ -0,0 +1,17 @@ + + + + $date$ + Gödel-Gentzen Clojure Syndication Services Super System Feed Export + + + $feeds:{f | + }$ + + + + diff --git a/opmlclass.clj b/opmlclass.clj new file mode 100644 index 0000000..4486580 --- /dev/null +++ b/opmlclass.clj @@ -0,0 +1,18 @@ +(ns cljssss-g + (require [clojure.xml :as xml] + [clojure.contrib.sql :as sql] + compojure) + (import (org.antlr.stringtemplate StringTemplateGroup) + (com.sun.syndication.io SyndFeedInput XmlReader) + (com.sun.syndication.feed.synd SyndFeed SyndEntry) + (java.net URL)) + (use compojure)) + + +(gen-interface + :name opmliface + :prefix "opml-" + :init init + :methods [[getXmlurl [] String] + [getHtmlurl [] String] + [getText [] String]]) \ No newline at end of file -- cgit v1.2.3