1:- module(mbox, []). 2:- use_module(library(semweb/rdf_db)). 3:- use_module(library(http/http_dispatch)). 4
5:- rdf_register_ns(foaf, 'http://xmlns.com/foaf/0.1/'). 6
7
15name_mbox(Name, MBox) :-
16 rdf(X, foaf:name, literal(Name)),
17 rdf(X, foaf:mbox, MBox).
18
19
20 23
24:- http_handler('/mbox/simple', simple_mbox_table, []).
30simple_mbox_table(_Request) :-
31 format('Content-type: text/html~n~n'),
32 format('<table>~n'),
33 forall(name_mbox(Name, MBox),
34 format('<tr><td>~w<td>~w~n', [Name, MBox])),
35 format('</table>~n').
36
37
38 41
42:- use_module(library(http/html_write)). 43:- http_handler('/mbox', mbox_table, []).
51mbox_table(_Request) :-
52 findall(Name-MBox, name_mbox(Name, MBox), Pairs),
53 reply_html_page(title('Mailboxes'),
54 table(\mailboxes(Pairs))).
55
56mailboxes([]) -->
57 [].
58mailboxes([Name-MBox|T]) -->
59 html(tr([td(Name), td(MBox)])),
60 mailboxes(T).
61
62
63 66
67:- use_module(library(http/http_json)). 68:- http_handler('/mbox/json', json_mbox_table, []).
75json_mbox_table(_Request) :-
76 findall(json([ name=Name,
77 mbox=MBox
78 ]),
79 name_mbox(Name, MBox), Objects),
80 reply_json(Objects)