#!/usr/local/bin/xotclsh #$Id: UNIVERSAL.xotcl,v 1.1 2004/05/23 22:50:39 neumann Exp $ package require XOTcl; namespace import -force xotcl::* array set opts { -ssl 0 -instanceFile UNIVERSAL.rdf -cssFile UNIVERSAL.css -root . -pkgdir .} array set opts $argv @ @File { description { This is a demo of a Webserver that presents the contents of an RDF source file in a friendly and easy readable manner.
The RDF file is parsed first into triples which are added to the resource database RDFdb. This RDFdb used in this example replaces the standard triple database of xoRDF by an application specific version, which is easier to process. The triple database is the source of the Catalog, which displays a short, easy to read summary of the entries. The database is used as well for the "detailed view", which presents all the data of the triples through nested HTML tables.
The demo program uses either HTTP or HTTPS (in which case you will require the SSL/TLS extension of Tcl). } } lappend auto_path $opts(-pkgdir) if {$opts(-ssl)} { package require xotcl::actiweb::secureHtmlPlace SecureHtmlPlace ::receiver -port 443 -root $opts(-root) } else { package require xotcl::actiweb::htmlPlace HtmlPlace ::receiver -port 8095 -root $opts(-root) -allowExit exit } package require xotcl::actiweb::webDocument # load RDF processing components package require xotcl::rdf::parser package require xotcl::rdf::triple package require xotcl::xml::printVisitor proc loadFile filename { set F [open $filename r]; set c [read $F]; close $F return $c } # # instantiate parser and parser an example text into a node tree # RDFParser R R parse [loadFile $opts(-instanceFile)] # # load the nodetree from the parser into the triple database # #section Triples TripleVisitor tv -parser R tv proc interprete {} { my instvar topNode parser if {![my exists topNode]} {set topNode ${parser}::topNode0} my reset my interpretNodeTree $topNode } #### Define a simple Resource Database Class RDFdb -superclass RDFTripleDB RDFdb instproc isContainer c { regexp ^[self]::rdfdoc\# $c } RDFdb instproc add {predicate subject object} { set s [self]::$subject if {[my info children $s] == ""} { #puts stderr "create new resource $s" Resource create $s } $s set $predicate $object next ;# for passing to RDFTripleDB (which provides e.g. prettyTriples) } RDFdb instproc reset {} { foreach c [my info children] { $c destroy } next } RDFdb instproc resources {} { set result "" foreach c [my info children] { if {![my isContainer $c] && [$c info class] != "::RDFTriple"} {lappend result $c} } return $result } RDFdb instproc querySubject {subject} { set s [self]::$subject set result "" if {[my info children $s] != ""} { foreach att [lsort [$s info vars]] { lappend result $att [$s set $att] } } return $result } # create an Instance of the Resource Database RDFdb tv::db # define Resources with its methods Class Resource Resource instproc dump {} { foreach att [lsort [my info vars]] { puts stderr "\t$att = [my set $att]" } } Resource instproc substitute {lines} { set result "" foreach line [split $lines \n] { if {[regexp {^ *http:} $line]} { set value "" set o [self] set line [string trim $line] foreach step $line { set value [$o set $step] set o tv::db::$value } append result $value } else { append result $line } } return $result } Resource instproc pretty {} { set q [univ selfAction "details [namespace tail [self]]"] my substitute " http://nm.wu-wien.ac.at/universal/rdf-lifecycle#Contribute \ http://nm.wu-wien.ac.at/universal/rdf-lifecycle#Entity : http://nm.wu-wien.ac.at/universal/rdf-general#Title , http://nm.wu-wien.ac.at/universal/rdf-education#LearningResourceType , http://nm.wu-wien.ac.at/universal/rdf-education#TypicalLearningTime , http://nm.wu-wien.ac.at/universal/rdf-lifecycle#Contribute \ http://nm.wu-wien.ac.at/universal/rdf-lifecycle#Date ([my pretty-access])" } Resource instproc pretty-title {} { my substitute "http://nm.wu-wien.ac.at/universal/rdf-general#Title" } Resource instproc pretty-access {} { set tech http://nm.wu-wien.ac.at/universal/rdf-technical set format [my substitute "$tech#Format"] set location [my substitute "$tech#Location"] if {$format == "text/html"} { set label "go" } else { set label "Download [my substitute $tech#Size] bytes" } return "$label" } ### Definition of the Learning Resource Manager: Class LrManager -superclass WebDocument -parameter { {defaultUrl http://nm.wu-wien.ac.at/Lehre/oo2/} } LrManager instproc html-title {t} { my contentType text/html return "
\n" append result [my attributeTable $subject outer] "" } LrManager instproc attributeTable {subject cls} { set result "" set lastns "" foreach {attr value} [tv::db querySubject $subject] { if {[tv::db isContainer $value]} { #set q [univ selfAction "details $value"]; set value "$value" set value [my attributeTable $value inner] } regexp {^(.*)\#(.*)$} $attr _ ns property if {$ns != $lastns} { if {$lastns != ""} { append result
\n } append result "Attributes from namespace $ns:\n
$property | " \ "$value | "