29
30:- module(flint, []). 31:- use_module(library(semweb/rdf_db)). 32:- use_module(library(http/http_dispatch)). 33:- use_module(library(http/http_files)). 34:- use_module(library(http/html_write)). 35:- use_module(library(http/html_head)). 36:- use_module(library(http/json)). 37:- use_module(cliopatria(hooks)). 38
39:- http_handler(flint('index.html'), sparql_editor, []). 40:- http_handler(flint('config.js'), flint_config, []). 41:- http_handler(flint(.), http_reply_from_files(flint(.), []), [prefix]). 42
43:- html_resource(flint('config.js'),
44 [ requires([ flint('flint-editor.js'),
45
46 flint('css/sparqlcolors.css'),
47 flint('css/docs.css')
48 ])
49 ]). 50
51
52:- html_resource(flint('lib/codemirror.js'),
53 [ requires([ flint('jquery-1.5.2.min.js'),
54 flint('lib/codemirror.css')
55 ])
56 ]). 57
58:- html_resource(flint('flint-editor.js'),
59 [ requires([ flint('lib/codemirror.js'),
60 flint('sparql10querymode_ll1.js'),
61 flint('sparql11querymode_ll1.js'),
62 flint('sparql11updatemode_ll1.js')
63 ])
64 ]).
70sparql_editor(_Request) :-
71 \+ absolute_file_name(flint('flint-editor.js'), _,
72 [ access(read),
73 file_errors(fail)
74 ]), !,
75 reply_html_page(cliopatria(default),
76 title('No Flint installed'),
77 \no_flint).
78sparql_editor(_Request) :-
79 reply_html_page(
80 cliopatria(plain),
81 title('Flint SPARQL Editor'),
82 \flint_page).
83
84flint_page -->
85 html_requires(flint('config.js')),
86 html(div(id(flint), [])).
93flint_config(_Request) :-
94 config(Config),
95 format('Content-type: text/javascript~n~n'),
96 format('$(document).ready(function() {~n'),
97 write_config(Config),
98 write_init,
99 format('});~n').
100
101write_config(Config) :-
102 format(' var flintConfig = '),
103 json_write(current_output, Config, [width(72)]),
104 format(';').
105
106write_init :-
107 format(' var fint = new FlintEditor("flint", "images", flintConfig);~n').
113config(json([ interface = json([ toolbar=true,
114 menu=true
115 ]),
116 namespaces = NameSpaces,
117 defaultEndpointParameters = EndpointParameters,
118 endpoints = EndPoints,
119 defaultModes = Modes
120 ])) :-
121 namespaces(NameSpaces),
122 endpoint_parameters(EndpointParameters),
123 endpoints(EndPoints),
124 modes(Modes).
125
126namespaces(NameSpaces) :-
127 setof(NameSpace, namespace(NameSpace), NameSpaces).
128
129namespace(json([ name(Prefix),
130 prefix(Prefix),
131 uri(URI)
132 ])) :-
133 rdf_current_ns(Prefix, URI).
134
135:- if(\+current_predicate(rdf_current_ns/2)). 136rdf_current_ns(Prefix, URI) :- rdf_current_prefix(Prefix, URI).
137:- endif. 138
139endpoint_parameters(
140 json([ queryParameters =
141 json([ format(output),
142 query(query),
143 update(update)
144 ]),
145 selectFormats =
146 [ json([ name('Plain text'),
147 format(text),
148 type('text/plain')
149 ]),
150 json([ name('SPARQL-XML'),
151 format(sparql),
152 type('application/sparql-results+xml')
153 ]),
154 json([ name('JSON'),
155 format(json),
156 type('application/sparql-results+json')
157 ])
158 ],
159 constructFormats =
160 [ json([ name('Plain text'),
161 format(text),
162 type('text/plain')
163 ]),
164 json([ name('RDF/XML'),
165 format(rdfxml),
166 type('application/rdf+xml')
167 ]),
168 json([ name('Turtle'),
169 format(turtle),
170 type('application/turtle')
171 ])
172 ]
173 ])).
174
175
176endpoints([ json([ name('ClioPatria'),
177 uri(EndPoint),
178 modes([ sparql11query, sparql10 ])
179 ]),
180 json([ name('Update'),
181 uri(UpdateEndPoint),
182 modes([ sparql11update ])
183 ])
184 ]) :-
185 http_link_to_id(sparql_query, [], EndPoint),
186 http_link_to_id(sparql_update, [], UpdateEndPoint).
187
188
189modes([ json([ name('SPARQL 1.1 Query'),
190 mode(sparql11query)
191 ]),
192 json([ name('SPARQL 1.1 Update'),
193 mode(sparql11update)
194 ]),
195 json([ name('SPARQL 1.0'),
196 mode(sparql10)
197 ])
198 ]).
205no_flint -->
206 { absolute_file_name(cliopatria(.), CD0,
207 [ file_type(directory),
208 access(read)
209 ]),
210 prolog_to_os_filename(CD0, ClioHome)
211 },
212 html_requires(pldoc),
213 html([ h1('Flint SPARQL Editor is not installed'),
214 p([ 'Please run the following command in the ClioPatria ',
215 'installation directory "~w" to install Flint.'-[ClioHome]
216 ]),
217 pre(class(code),
218 [ 'git submodule update --init web/FlintSparqlEditor'
219 ])
220 ]).
221
222
223 226
227cliopatria:(150=query/sparql_editor, 'Flint SPARQL Editor')