1 | (in-package :rest-interface) |
---|
2 | |
---|
3 | (defgeneric publish-feed (feed) |
---|
4 | (:documentation "Register feed urls with hunchentoot")) |
---|
5 | |
---|
6 | (defmacro as-feed (feed) |
---|
7 | `(setf (content-type) "application/atom+xml; charset=UTF-8") |
---|
8 | `(cxml:with-xml-output (cxml:make-string-sink :canonical t) |
---|
9 | (atom:feed-to-elem ,feed))) |
---|
10 | |
---|
11 | (defun overview-feed () |
---|
12 | "Interface function to the corresponding Atom method" |
---|
13 | (setf (content-type) "application/atom+xml; charset=UTF-8") |
---|
14 | (as-feed atom:*tm-feed*)) |
---|
15 | |
---|
16 | |
---|
17 | (defmethod publish-feed ((feed atom:feed)) |
---|
18 | (push |
---|
19 | (create-regex-dispatcher |
---|
20 | (format nil "~a~a" (path feed) "/?$") #'overview-feed) |
---|
21 | hunchentoot:*dispatch-table*) |
---|
22 | (mapc #'publish-feed (atom:subfeeds feed))) |
---|
23 | |
---|
24 | (defmethod publish-feed ((feed atom:collection-feed)) |
---|
25 | (push |
---|
26 | (create-regex-dispatcher |
---|
27 | (format nil "~a~a" (path feed) "/?$") |
---|
28 | (lambda () |
---|
29 | (setf (content-type) "application/atom+xml; charset=UTF-8") |
---|
30 | (as-feed feed))) |
---|
31 | hunchentoot:*dispatch-table*) |
---|
32 | (mapc #'publish-feed (atom:subfeeds feed))) |
---|
33 | |
---|
34 | (defmethod publish-feed ((feed atom:fragments-feed)) |
---|
35 | (push |
---|
36 | (create-regex-dispatcher |
---|
37 | (format nil "~a~a" (path feed) "/?$") |
---|
38 | (lambda () |
---|
39 | (setf (content-type) "application/atom+xml; charset=UTF-8") |
---|
40 | (as-feed feed))) |
---|
41 | hunchentoot:*dispatch-table*) |
---|
42 | ;and now register the general fragments method |
---|
43 | (push |
---|
44 | (create-regex-dispatcher |
---|
45 | (format nil "~a~a" (path feed) "/([0-9]+)$") |
---|
46 | (lambda (&optional unique-id) |
---|
47 | (setf (content-type) "application/x-tm+xml;version=1.0; charset=utf-8") |
---|
48 | (let |
---|
49 | ((fragment |
---|
50 | (d:get-fragment (parse-integer unique-id)))) |
---|
51 | (if fragment |
---|
52 | (exporter:export-xtm-fragment fragment :xtm-format '1.0) |
---|
53 | (format nil "<t:topicMap xmlns:t=\"http://www.topicmaps.org/xtm/1.0/\" xmlns:xlink=\"http://www.w3.org/1999/xlink\"/>"))))) |
---|
54 | hunchentoot:*dispatch-table*)) |
---|
55 | |
---|
56 | (defmethod publish-feed ((feed snapshots-feed)) |
---|
57 | (push |
---|
58 | (create-regex-dispatcher |
---|
59 | (format nil "~a~a" (path feed) "/?$") |
---|
60 | (lambda () |
---|
61 | (setf (content-type) "application/atom+xml; charset=UTF-8") |
---|
62 | (as-feed feed))) |
---|
63 | hunchentoot:*dispatch-table*) |
---|
64 | ;and now register the general snapshots method |
---|
65 | (push |
---|
66 | (create-regex-dispatcher |
---|
67 | (format nil "~a~a" (path feed) "/([0-9]+)$") |
---|
68 | (lambda (&optional revision) |
---|
69 | (setf (content-type) "application/x-tm+xml;version=1.0; charset=utf-8") |
---|
70 | (exporter:export-xtm-to-string |
---|
71 | :revision (parse-integer revision) |
---|
72 | :tm-id (atom:tm-id feed) |
---|
73 | :xtm-format '1.0))) |
---|
74 | hunchentoot:*dispatch-table*)) |
---|
75 | |
---|
76 | |
---|
77 | |
---|
78 | |
---|