#!/usr/bin/perl -Tw # # demo.pl - Redland CGI database and query demo Perl program # # Copyright (C) 2000-2004, David Beckett http://www.dajobe.org/ # Copyright (C) 2000-2004, University of Bristol, UK http://www.bristol.ac.uk/ # # This package is Free Software and part of Redland http://librdf.org/ # # It is licensed under the following three licenses as alternatives: # 1. GNU Lesser General Public License (LGPL) V2.1 or any newer version # 2. GNU General Public License (GPL) V2 or any newer version # 3. Apache License, V2.0 or any newer version # # You may not use this file except in compliance with at least one of # the above three licenses. # # See LICENSE.html or LICENSE.txt at the top of this package for the # complete terms and further detail along with the license texts for # the licenses in COPYING.LIB, COPYING and LICENSE-2.0.txt respectively. # # # # CHANGE THIS FOR YOUR CONFIGURATION $::ROOT_DIR='/somewhere'; use strict; # Helps with broken web requests (missing headers) $ENV{'Content-Length'}||=0; # Tainting, dontcha know $ENV{'PATH'}="/bin:/usr/bin:/usr/local/bin"; # Standard perl modules use CGI; use LWP::Simple; use URI::URL; # Configuration my(@commands)=qw(destroy query parse add print), my(%command_labels)=('destroy' =>'Delete database', 'query' =>'Find triples', 'add', =>'Add a triple', 'parse', =>'Parse RDF', 'print', =>'Print database'); my(%command_needs_write)=('destroy' =>1, 'query' =>0, 'add', =>1, 'parse', =>1, 'print', =>0); my(@parsers)=qw(raptor ntriples); my(%parser_labels)=('raptor' => 'RDF/XML', 'ntriples' => 'N-Triples' ); my(%parser_just_file_uris)=('raptor' => 1, 'ntriples' => 1 ); my $default_command='parse'; my $db_dir="$::ROOT_DIR/db"; my $tmp_dir="$::ROOT_DIR/tmp"; my $log_file="$::ROOT_DIR/logs/demo.log"; # Used for deleting databases my @suffixes=qw(po2s so2p sp2o); my $db_format="%s-%s.db"; # args: db suffix # 1: Use stream parsing (print as it goes) or # 0: parse into model (prints resulting model) my $use_parse_stream=1; my $max_stream_size=200; my(%namespaces)=( 'rdf' => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#', 'rdfs' => 'http://www.w3.org/2000/01/rdf-schema#', 'rss' => 'http://purl.org/rss/1.0/', 'synd' => 'http://purl.org/rss/1.0/modules/syndication/', 'dc' => 'http://purl.org/dc/elements/1.1/', 'owl' => 'http://www.w3.org/2002/07/owl#', 'xsd' => 'http://www.w3.org/2001/XMLSchema#', ); # Redland perl modules use RDF::Redland; ###################################################################### # Subroutines sub log_action ($$$;$) { my($host, $db, $message, $now)=@_; $now ||= time; return unless open (LOG, ">>$log_file"); my($sec,$min,$hour,$mday,$mon,$year)=gmtime $now; my $date=sprintf("%04d-%02d-%02dT%02d:%02d:%02dZ",1900+$year,$mon+1,$mday,$hour,$min,$sec); print LOG "$host $date $db $message\n"; close(LOG); } sub end_page($) { my $q=shift; print <<'EOT';
The source code of this demonstration is available in the Redland distribution as demos/demo.pl or from the Redland website
EOT print qq{