Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 5 commits
  • 4 files changed
  • 0 comments
  • 3 contributors
2  README.md
Source Rendered
@@ -4,6 +4,7 @@ A simple Clojure wrapper for the ROME feed parsing and manipulation library. Rig
4 4
5 5 ## Usage
6 6
  7 +```clojure
7 8 ;; build-feed will automaticaly dispatch on an xml string, a filepath or an url
8 9 ;; returns a SyndFeedImpl object
9 10 (def feed (build-feed "test/clj_rome/test/feeds/lacuisinededoria.xml"))
@@ -16,6 +17,7 @@ A simple Clojure wrapper for the ROME feed parsing and manipulation library. Rig
16 17 (def same-title (:title (entry2map (first (get-entries feed)))))
17 18 ;; contains :contents :authors :title :link :description :categories :updated-date :published-date
18 19 ;; the dates are in clj-time format
  20 +```
19 21
20 22 For more documentation on ROME, see the [ROME javadocs](http://www.jarvana.com/jarvana/view/net/java/dev/rome/rome/1.0.0/rome-1.0.0-javadoc.jar!/index.html).
21 23
3  project.clj
@@ -3,4 +3,5 @@
3 3 :dependencies [[org.clojure/clojure "1.2.1"]
4 4 [org.clojure/clojure-contrib "1.2.0"]
5 5 [clj-time "0.3.1"]
6   - [net.java.dev.rome/rome "1.0.0"]])
  6 + [net.java.dev.rome/rome "1.0.0"]
  7 + [net.java.dev.rome/rome-fetcher "1.0.0"]])
59 src/clj_rome/fetcher.clj
... ... @@ -0,0 +1,59 @@
  1 +(ns clj-rome.fetcher
  2 + (:import (com.sun.syndication.fetcher.impl HttpURLFeedFetcher)
  3 + (com.sun.syndication.fetcher FetcherListener)
  4 + (java.net URL))
  5 + (:require [clojure.contrib.string]))
  6 +
  7 +(def *fetcher*)
  8 +
  9 +(defn build-url-fetcher
  10 + "builds an HttpURLFeedFetcher with or without caching."
  11 + (
  12 + []
  13 + (HttpURLFeedFetcher.))
  14 + (
  15 + [cache]
  16 + (HttpURLFeedFetcher. cache)
  17 + ))
  18 +
  19 +(defn retrieve-feed
  20 + "retrieves a feed from a fetcher or the default one.
  21 + Returns a SyndFeedImpl object"
  22 + (
  23 + [fetcher url]
  24 + (.retrieveFeed fetcher (URL. (str url))))
  25 + (
  26 + [url]
  27 + (retrieve-feed *fetcher* url)
  28 + ))
  29 +
  30 +
  31 +(defn add-listener
  32 + "adds a listener to the given fetcher object.
  33 + Returns a FetcherListener object. Use it with
  34 + remove-listener."
  35 + ( [fetcher cb]
  36 + (let [listener (proxy [FetcherListener] []
  37 + (fetcherEvent [event] (cb event)))]
  38 + (.addFetcherEventListener fetcher listener)
  39 + listener))
  40 + ( [cb]
  41 + (add-listener *fetcher* cb)
  42 + ))
  43 +
  44 +(defn remove-listener
  45 + "removes a listener from the given fetcher"
  46 + (
  47 + [fetcher listener]
  48 + (.removeFetcherEventListener fetcher listener)
  49 + )
  50 + (
  51 + [listener]
  52 + (remove-listener *fetcher* listener)
  53 + ))
  54 +
  55 +(defmacro with-fetcher
  56 + [fetcher & body]
  57 + `(binding [clj-rome.fetcher/*fetcher* fetcher]
  58 + ~@body))
  59 +
8 src/clj_rome/reader.clj
@@ -20,9 +20,15 @@
20 20 [str]
21 21 (cond
22 22 (re-find #"^https?://" str) (XmlReader. (URL. str))
23   - (re-find #"^\s*<" str) (StringReader. str)
  23 + (re-find #"^\s*<" str) (StringReader. str)
24 24 :else (FileReader. str))))
25 25
  26 +(extend-type java.io.Reader
  27 + Feedable
  28 + (make-reader
  29 + [reader]
  30 + reader))
  31 +
26 32 (defn build-feed
27 33 "builds a SyndFeedImpl from an url, a filepath or a XML string"
28 34 [arg]

No commit comments for this range

Something went wrong with that request. Please try again.