/* Part of ClioPatria SeRQL and SPARQL server Author: Jan Wielemaker E-mail: J.Wielemaker@cs.vu.nl WWW: http://www.swi-prolog.org Copyright (C): 2010, University of Amsterdam, VU University Amsterdam This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA As a special exception, if you link this library with other files, compiled with a Free Software compiler, to produce an executable, this library does not by itself cause the resulting executable to be covered by the GNU General Public License. This exception does not however invalidate any other reasons why the executable file might be covered by the GNU General Public License. */ :- module(edm_components, [ edm_display_link//2, % +URI, +Options edm_proxy_view//2, % +URI, +Options edm_result_summary//2 % +URI, +Options ]). :- use_module(cliopatria(hooks)). :- use_module(library(http/page_info)). :- use_module(library(sgml)). :- use_module(library(http/html_write)). :- use_module(library(http/html_head)). :- use_module(library(semweb/rdf_db)). :- use_module(library(semweb/rdf_label)). :- use_module(library(http/http_path)). :- use_module(components(label)). :- use_module(applications(browse)). :- use_module(library(http/http_dispatch)). :- use_module(library(http/http_wrapper)). :- use_module(user(preferences)). /** Domain-specific components for EDM models * When displaying a link to a WebResource, it either uses the referenced image as label or shows both the internal link and a link to the external resource. */ %% edm_display_link(+URI, +Options)// is semidet. % % Display EDM WebResources. If the resource is a thumbnail, % display it inline. Else put an icon behind the default link that % links to the external site. edm_display_link(R, Options) --> { \+ memberchk(edm(false), Options), rdf_has(R, rdf:type, ens:'WebResource') }, ( { page_content_type(R, Type), sub_atom(Type, 0, _, _, 'image/') } -> html(a(href(R), img([class(thumbnail), src(R)]))) ; { http_absolute_location(icons('external-link-ltr-icon.png'), External, []) }, html(span(class(no_img), [ \rdf_link(R, [edm(false)|Options]), html(a([class(img), href(R)], img(src(External)))) ])) ). %% edm_proxy_view(+URI, +Options)// is det. % % Provide a _|local view|_ for an EDM ore:Proxy object. The caller % must ensure that URI is indeed of type ore:Proxy. edm_proxy_view(URI, _Options) --> { type_styles(URI, Styles), http_current_request(Request), http_reload_with_parameters(Request, [raw(true)], FullHREF) }, html_requires(css('edm.css')), html(div(class(Styles), [ \values(div, URI, dcterms:title), \values(div, URI, ore:proxyIn -> ens:object), \values(div, URI, dcterms:creator), div(class(created), \values(span, URI, dcterms:created)), div(class(extent), \values(span, URI, dcterms:extent)), \values(div, URI, dcterms:description), div(class(owner), [ \values(span, URI, dcterms:rights), \values(span, URI, dcterms:identifier) ]), br(clear(all)), h2('Related objects'), \context_graph(URI, [style(edm(user))]), div(class(fullview), a(href(FullHREF), 'Full view')) ])). %% edm_result_summary(+URI, +Options)// is det. % % Format a search-result. edm_result_summary(URI, _Options) --> { type_styles(URI, Styles), http_link_to_id(list_resource, [r=URI], HREF) }, html_requires(css('edm.css')), html(div(class(Styles), [ a(href(HREF), \values(div, URI, dcterms:title)), \values(div, URI, ore:proxyIn -> ens:object), \values(div, URI, dcterms:creator), \values(div, URI, dcterms:description, [ resource_format(label), max_length(100), max_count(2) ]) ])). type_styles(URI, Styles) :- findall(Style, type_style(URI, Style), Styles). type_style(URI, Class) :- rdf_has(URI, rdf:type, Type), uri_css_class(Type, Class). values(Element, URI, Path) --> values(Element, URI, Path, [resource_format(label)]). values(Element, URI, Path, Options) --> { has_values(URI, Path, Pairs, Options) }, html_values(Pairs, Element, Options). html_values([], _, _) --> []. html_values([V-Classes|T], Element, Options) --> { HTML =.. [Element, class(Classes), \value(V, Options)] }, html(HTML), html_values(T, Element, Options). %% value(+Value, +Options)// is det. % % Show the actual value :- public value//2. % Called by values//3 value(Literal, Options) --> { rdf_is_literal(Literal), !, literal_text(Literal, Text0), truncate_text(Text0, Text, Options) }, html(Text). value(R, Options) --> rdf_link(R, Options). truncate_text(Text, Text, []) :- !. truncate_text(Text, Truncated, Options) :- option(max_length(Len), Options), !, truncate_atom(Text, Len, Truncated). truncate_text(Text, Text, _). %% has_values(+URI, +Path, -Pairs, +Options) is det. % % Pairs is a list of Value-Classes pairs. has_values(URI, Path, Pairs, Options) :- findall(Value-Classes, has_value(Path, URI, Classes, Value), Pairs0), partition(pair_preferred_lang, Pairs0, Preferred, NonPreferred), ( Preferred == [] -> Pairs1 = NonPreferred ; Pairs1 = Preferred ), ( option(max_count(Max), Options) -> limit(Pairs1, Max, Pairs) ; Pairs = Pairs1 ). limit([], _, []) :- !. limit(_, 0, []) :- !. limit([H|T0], N, [H|T]) :- succ(N2, N), limit(T0, N2, T). pair_preferred_lang(Value-_CSS) :- preferred_lang(Value). has_value(P0->P, URI, Classes, Value) :- !, has_value(P0, URI, Classes0, Value0), has_value(P, Value0, Classes1, Value), append(Classes0, Classes1, Classes). has_value(NS:Local, URI, Class, Value) :- !, rdf_global_id(NS:Local, P), has_value(P, URI, Class, Value). has_value(P, URI, Classes, Value) :- rdf_has(URI, P, Value, RP), p_classes(RP, P, Classes). %% p_classes(+FoundPred, +QueryPred, -CSSClasses) is det. % % @tbd Find intermediate properties p_classes(RP, RP, [RC]) :- !, uri_css_class(RP, RC). p_classes(RP, P, [RC, PC]) :- uri_css_class(P, PC), uri_css_class(RP, RC). uri_css_class(URI, Class) :- iri_xml_namespace(URI, _, Class). %% preferred_lang(+Object) % % True if Object is stated in the preferred language of the user % or language-neutral. preferred_lang(Literal) :- literal_lang(Literal, Lang), !, user_preference(user:lang, literal(PrefLang)), lang_matches(PrefLang, Lang). preferred_lang(R) :- % see bnode_label//1. rdf_label(R, Value), literal_lang(Value, Lang), !, user_preference(user:lang, literal(PrefLang)), lang_matches(PrefLang, Lang). preferred_lang(BNode) :- % see bnode_label//1. rdf_is_bnode(BNode), rdf_has(BNode, rdf:value, Value), literal_lang(Value, Lang), !, user_preference(user:lang, literal(PrefLang)), lang_matches(PrefLang, Lang). preferred_lang(_). literal_lang(literal(lang(Lang, _)), Lang).