webaccess/commit

First package version

authorJan Wielemaker
Thu Nov 25 11:27:54 2010 +0100
committerJan Wielemaker
Thu Nov 25 11:27:54 2010 +0100
commit941891a2cbde06cb8cdd2452018d2cdde430b09d
tree32478093be8c4e7edc2651dd78554d79a68081a6
parent52a8a9f2e4d774e36d4ef857d588ef1d899e4eaf
Diff style: patch stat
diff --git a/config-available/DEFAULTS b/config-available/DEFAULTS
deleted file mode 100644
index 705b7ca..0000000
--- a/config-available/DEFAULTS
+++ /dev/null
@@ -1 +0,0 @@
-config(webaccess, link).
diff --git a/config-available/webaccess.pl b/config-available/webaccess.pl
deleted file mode 100644
index 45f816e..0000000
--- a/config-available/webaccess.pl
+++ /dev/null
@@ -1,5 +0,0 @@
-:- module(conf_webaccess, []).
-
-/** <module> Access external web-resources
-*/
-
diff --git a/lib/http/page_info.pl b/lib/http/page_info.pl
new file mode 100644
index 0000000..02ad910
--- /dev/null
+++ b/lib/http/page_info.pl
@@ -0,0 +1,69 @@
+/*  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(http_page_info,
+	  [ page_content_type/2		% +URL, -MimeType
+	  ]).
+:- use_module(library(http/http_open)).
+:- use_module(library(uri)).
+
+/** <module> Get info on external web links
+*/
+
+
+%%	page_content_type(+URL, -ContentType:atom) is semidet.
+%
+%	Query the external resource using   a =HEAD= request, extracting
+%	the content-type as an atom. Extracted  values are cached. Fails
+%	if the content-type cannot be extracted due to errors.
+%
+%	@bug	Failures shouldbe retried after some time.
+
+:- dynamic
+	content_type_cache/2.
+
+page_content_type(URL, MimeType) :-
+	content_type_cache(URL, Type), !,
+	atom(Type),
+	Type = MimeType.
+page_content_type(URL, MimeType) :-
+	uri_components(URL, Components),
+	uri_data(scheme, Components, Scheme),
+	Scheme == http,
+	catch(http_open(URL, Stream,
+			[ method(head),
+			  header(content_type, Type)
+			]), _, fail),
+	close(Stream),
+	assertz(content_type_cache(URL, Type)),
+	MimeType = Type.
+page_content_type(URL, _) :-
+	assertz(content_type_cache(URL, meta(fail))),
+	fail.
diff --git a/rdf/cpack/webaccess.ttl b/rdf/cpack/webaccess.ttl
index 03dcafa..72b7cf3 100644
--- a/rdf/cpack/webaccess.ttl
+++ b/rdf/cpack/webaccess.ttl
@@ -2,7 +2,7 @@
 @prefix rdfs:    <http://www.w3.org/2000/01/rdf-schema#> .
 @prefix dcterms: <http://purl.org/dc/terms/> .
 @prefix foaf:    <http://xmlns.com/foaf/0.1/> .
-@prefix cpack:   <http://www.swi-prolog.org/cliopatria/cpack#> .
+@prefix cpack:   <http://cliopatria.swi-prolog.org/schema/cpack#> .
 
 # This file is a Turtle-format RDF file that describes the package.  It
 # *must* be located in rdf/cpack/webaccess.ttl
@@ -11,7 +11,7 @@
 # this.  Otherwise you can specify the information inline as done below.
 # See http://xmlns.com/foaf/spec/ for defines fields.
 
-<> a cpack:Package ;
+<> a cpack:Library ;
 	cpack:packageName "webaccess" ;
 	dcterms:title "Access external web-resources" ;
 	cpack:author [ a foaf:Person ;
@@ -24,7 +24,8 @@
 	    ] ;
 	cpack:description
 
-"""The package description goes here.  You can use PlDoc Wiki markup.
+"""This library deals with accessing external web-resources: extracting
+   meta-data such as existence, manage thumbnails, etc.
 """ .