diff options
author | christoph <christoph@debian.uxul.homelinux.org> | 2009-02-21 02:26:59 +0100 |
---|---|---|
committer | christoph <christoph@debian.uxul.homelinux.org> | 2009-02-21 02:26:59 +0100 |
commit | 2c2e8de50c5b362891a40a1a727262d742b97c21 (patch) | |
tree | 90c463fa6343055b7e5773b5d0915e1b206a19c4 | |
parent | 5b3fac97c77c5c9945d08d98cb19251ca7736980 (diff) |
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.
-rw-r--r-- | cljssss-g.clj | 74 | ||||
-rw-r--r-- | opml.st | 17 | ||||
-rw-r--r-- | opmlclass.clj | 18 |
3 files changed, 100 insertions, 9 deletions
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 "<?xml version=\"1.0\" encoding=\"utf-8\"?><opml version=\"1.0\"><head>" + "<dateCreated>blah</dateCreated>" + "<title>Gödel-Gentzen Clojure Syndication Services Super System Feed Export</title></head><body>" + (loop [clstr "" r results] + (if (first r) + (recur + (str clstr + "<outline text=\"" + (:title (first r)) + "\" xmlUrl=\"" + (:uri (first r)) + "\" htmlUrl=\"" + (:link (first r)) + "\" />") + (rest r)) + clstr)) + "</body></opml>")))) +; (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 @@ -0,0 +1,17 @@ +<?xml version="1.0" encoding="utf-8"?> +<opml version="1.0"> + <head> + <dateCreated>$date$</dateCreated> + <title>Gödel-Gentzen Clojure Syndication Services Super System Feed Export</title> + </head> + <body> + $feeds:{f | + <outline + text="$f.text$" + xmlUrl="$f.xmlurl$" + htmlUrl="$f.htmlurl$" + /> }$ + </body> +</opml> + + 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 |