diff options
-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 |