annotate classical/urispace/urispace.pl @ 14:91b5145fff34

Classical dataset
author Chris Cannam
date Tue, 07 Nov 2017 11:22:37 +0000
parents
children d95e683fbd35
rev   line source
Chris@14 1 :- module(urispace,[init/0]).
Chris@14 2
Chris@14 3
Chris@14 4 :- use_module(library('http/thread_httpd')).
Chris@14 5 :- use_module(library('semweb/rdf_db')).
Chris@14 6 :- use_module(log).
Chris@14 7 :- use_module(config).
Chris@14 8 :- use_module(mapping).
Chris@14 9
Chris@14 10 server(Port, Options) :-
Chris@14 11 http_server(reply,[ port(Port),timeout(20)| Options]).
Chris@14 12
Chris@14 13
Chris@14 14
Chris@14 15 /**
Chris@14 16 * Closes the servlet
Chris@14 17 */
Chris@14 18 reply(Request) :-
Chris@14 19 log:log(Request),
Chris@14 20 member(path('/quit'), Request), !,
Chris@14 21 format('Connection: close~n', []),
Chris@14 22 format('Content-type: text/html~n~n', []),
Chris@14 23 format('Bye Bye~n').
Chris@14 24
Chris@14 25
Chris@14 26 /**
Chris@14 27 * Sends back 303 to RDF document describing the resource
Chris@14 28 */
Chris@14 29 reply(Request) :-
Chris@14 30 member(path(Path),Request),
Chris@14 31 member(accept(AcceptHeader),Request),
Chris@14 32 format(user_error,'Accept header: ~w ',[AcceptHeader]),
Chris@14 33 %accept_rdf(AcceptHeader),
Chris@14 34 concat_atom(PatternX,'/',Path),
Chris@14 35 delete(PatternX,'',Pattern),
Chris@14 36 mapping:see_other_rdf(requested_pattern(Pattern),redirect_pattern(RedirectP)),
Chris@14 37 !,
Chris@14 38 concat_atom(RedirectP,Redirect),
Chris@14 39 log:log('Sending a 303 towards ~w',Redirect),
Chris@14 40 throw(http_reply(see_other(Redirect),[])).
Chris@14 41
Chris@14 42 accept_rdf('application/rdf+xml').
Chris@14 43 %accept_rdf('text/xml').
Chris@14 44 accept_rdf(AcceptHeader) :-
Chris@14 45 sub_atom(AcceptHeader,_,_,_,'application/rdf+xml').
Chris@14 46 %accept_rdf(AcceptHeader) :-
Chris@14 47 % sub_atom(AcceptHeader,_,_,_,'text/xml').
Chris@14 48
Chris@14 49 /**
Chris@14 50 * Sends back towards the default representation of the resource
Chris@14 51 * (usually html)
Chris@14 52 */
Chris@14 53 reply(Request) :-
Chris@14 54 member(path(Path),Request),
Chris@14 55 concat_atom(PatternX,'/',Path),
Chris@14 56 delete(PatternX,'',Pattern),
Chris@14 57 mapping:see_other(requested_pattern(Pattern),redirect_pattern(RedirectP)),
Chris@14 58 !,
Chris@14 59 concat_atom(RedirectP,Redirect),
Chris@14 60 log:log('Sending a 303 towards ~w',Redirect),
Chris@14 61 throw(http_reply(see_other(Redirect),[])).
Chris@14 62
Chris@14 63 init :-
Chris@14 64 config:port(P),
Chris@14 65 server(P,[]),
Chris@14 66 nl,
Chris@14 67 writeln(' - Server launched'),nl.
Chris@14 68
Chris@14 69 :-
Chris@14 70 nl,writeln('----------------'),nl,
Chris@14 71 writeln(' - Launch the server by running ?-init.'),
Chris@14 72 writeln(' - To change the port, change config.pl'),nl,writeln('----------------'),nl.
Chris@14 73
Chris@14 74