From 8dff628b5a3e1b8397fb026903a2e72e29a61420 Mon Sep 17 00:00:00 2001 From: josch Date: Wed, 30 Apr 2008 09:57:24 +0000 Subject: [PATCH] namespace optimizations git-svn-id: http://yolanda.mister-muffin.de/svn@337 7eef14d0-6ed0-489d-bf55-20463b2d70db --- trunk/config/backend.xml | 7 +- trunk/functions.pl | 4 -- trunk/index.pl | 4 ++ trunk/search.pl | 4 ++ trunk/upload.pl | 148 +++++++++------------------------------ trunk/video.pl | 20 +++--- 6 files changed, 59 insertions(+), 128 deletions(-) diff --git a/trunk/config/backend.xml b/trunk/config/backend.xml index 13744ff..eb3c236 100644 --- a/trunk/config/backend.xml +++ b/trunk/config/backend.xml @@ -41,11 +41,16 @@ 64 120 - + http://www.w3.org/1999/XSL/Transform http://purl.org/dc/elements/1.1/ + http://purl.org/dc/terms/ http://web.resource.org/cc/ http://www.w3.org/1999/02/22-rdf-syntax-ns# + http://www.w3.org/2002/xforms + http://www.w3.org/2001/XMLSchema + http://www.w3.org/2001/XMLSchema-instance + "http://www.w3.org/1999/xhtml" diff --git a/trunk/functions.pl b/trunk/functions.pl index 1b5e0d7..7d72469 100644 --- a/trunk/functions.pl +++ b/trunk/functions.pl @@ -34,10 +34,6 @@ sub get_page_array #TODO: set namespace for each site on its own $page->setAttribute( "username", $userinfo->{'username'} ); - $page->setNamespace("http://www.w3.org/1999/xhtml", "xhtml", 0); - $page->setNamespace("http://web.resource.org/cc/", "cc", 0); - $page->setNamespace("http://purl.org/dc/elements/1.1/", "dc", 0); - $page->setNamespace("http://www.w3.org/1999/02/22-rdf-syntax-ns#", "rdf", 0); return $page; } diff --git a/trunk/index.pl b/trunk/index.pl index 35343c8..546ccbb 100644 --- a/trunk/index.pl +++ b/trunk/index.pl @@ -11,6 +11,10 @@ my $doc = XML::LibXML::Document->new( "1.0", "UTF-8" ); my $page = get_page_array(@userinfo); +$page->setNamespace( $config->{"xml_namespace_cc"}, "cc", 0); +$page->setNamespace( $config->{"xml_namespace_dc"}, "dc", 0); +$page->setNamespace( $config->{"xml_namespace_rdf"}, "rdf", 0); + #TODO: make the element unneccesary $page->appendChild(XML::LibXML::Element->new( "frontpage" )); diff --git a/trunk/search.pl b/trunk/search.pl index f6c89be..3a2a578 100644 --- a/trunk/search.pl +++ b/trunk/search.pl @@ -11,6 +11,10 @@ my $doc = XML::LibXML::Document->new( "1.0", "UTF-8" ); my $page = get_page_array(@userinfo); +$page->setNamespace( $config->{"xml_namespace_cc"}, "cc", 0); +$page->setNamespace( $config->{"xml_namespace_dc"}, "dc", 0); +$page->setNamespace( $config->{"xml_namespace_rdf"}, "rdf", 0); + #check if query is set if($query->param('query')) { diff --git a/trunk/upload.pl b/trunk/upload.pl index 6fbd2c4..61f2f59 100644 --- a/trunk/upload.pl +++ b/trunk/upload.pl @@ -11,127 +11,45 @@ my $doc = XML::LibXML::Document->new( "1.0", "UTF-8" ); my $page = get_page_array(@userinfo); -$page->setNamespace("http://www.w3.org/2002/xforms", "xforms", 0); -$page->setNamespace("http://www.w3.org/2001/XMLSchema", "xsd", 0); -$page->setNamespace("http://www.w3.org/2001/XMLSchema-instance", "xsi", 0); +$page->setNamespace( $config->{"xml_namespace_xforms"}, "xforms", 0); +$page->setNamespace( $config->{"xml_namespace_xsd"}, "xsd", 0); +$page->setNamespace( $config->{"xml_namespace_xsi"}, "xsi", 0); +$page->setNamespace( $config->{"xml_namespace_dcterms"}, "dcterms", 0 ); my $instance = XML::LibXML::Element->new( "instance" ); -$instance->setNamespace("http://www.w3.org/2002/xforms", "xforms"); +$instance->setNamespace( $config->{"xml_namespace_xforms"}, "xforms"); my $video = XML::LibXML::Element->new( "video" ); -my $node = XML::LibXML::Element->new( "abstract" ); -$node->setNamespace( "http://purl.org/dc/terms/", "dcterms" ); -$node->setNamespace( "http://www.w3.org/2001/XMLSchema-instance", "xsi", 0 ); -$node->setAttributeNS( "http://www.w3.org/2001/XMLSchema-instance", "type", "xsd:string" ); -$video->appendChild($node); +sub getElementDC +{ + my $node = XML::LibXML::Element->new( shift ); + $node->setNamespace( $config->{"xml_namespace_dcterms"}, "dcterms" ); + $node->setNamespace( $config->{"xml_namespace_xsi"}, "xsi", 0 ); + $node->setAttributeNS( $config->{"xml_namespace_xsi"}, "type", shift ); + return $node; +} -$node = XML::LibXML::Element->new( "alternative" ); -$node->setNamespace( "http://purl.org/dc/terms/", "dcterms" ); -$node->setNamespace( "http://www.w3.org/2001/XMLSchema-instance", "xsi", 0 ); -$node->setAttributeNS( "http://www.w3.org/2001/XMLSchema-instance", "type", "xsd:normalizedString" ); -$video->appendChild($node); - -$node = XML::LibXML::Element->new( "contributor" ); -$node->setNamespace( "http://purl.org/dc/terms/", "dcterms" ); -$node->setNamespace( "http://www.w3.org/2001/XMLSchema-instance", "xsi", 0 ); -$node->setAttributeNS( "http://www.w3.org/2001/XMLSchema-instance", "type", "xsd:normalizedString" ); -$video->appendChild($node); - -$node = XML::LibXML::Element->new( "created" ); -$node->setNamespace( "http://purl.org/dc/terms/", "dcterms" ); -$node->setNamespace( "http://www.w3.org/2001/XMLSchema-instance", "xsi", 0 ); -$node->setAttributeNS( "http://www.w3.org/2001/XMLSchema-instance", "type", "xsd:date" ); -$video->appendChild($node); - -$node = XML::LibXML::Element->new( "creator" ); -$node->setNamespace( "http://purl.org/dc/terms/", "dcterms" ); -$node->setNamespace( "http://www.w3.org/2001/XMLSchema-instance", "xsi", 0 ); -$node->setAttributeNS( "http://www.w3.org/2001/XMLSchema-instance", "type", "xsd:normalizedString" ); -$video->appendChild($node); - -$node = XML::LibXML::Element->new( "hasFormat" ); -$node->setNamespace( "http://purl.org/dc/terms/", "dcterms" ); -$node->setNamespace( "http://www.w3.org/2001/XMLSchema-instance", "xsi", 0 ); -$node->setAttributeNS( "http://www.w3.org/2001/XMLSchema-instance", "type", "xsd:normalizedString" ); -$video->appendChild($node); - -$node = XML::LibXML::Element->new( "isFormatOf" ); -$node->setNamespace( "http://purl.org/dc/terms/", "dcterms" ); -$node->setNamespace( "http://www.w3.org/2001/XMLSchema-instance", "xsi", 0 ); -$node->setAttributeNS( "http://www.w3.org/2001/XMLSchema-instance", "type", "xsd:normalizedString" ); -$video->appendChild($node); - -$node = XML::LibXML::Element->new( "isPartOf" ); -$node->setNamespace( "http://purl.org/dc/terms/", "dcterms" ); -$node->setNamespace( "http://www.w3.org/2001/XMLSchema-instance", "xsi", 0 ); -$node->setAttributeNS( "http://www.w3.org/2001/XMLSchema-instance", "type", "xsd:normalizedString" ); -$video->appendChild($node); - -$node = XML::LibXML::Element->new( "language" ); -$node->setNamespace( "http://purl.org/dc/terms/", "dcterms" ); -$node->setNamespace( "http://www.w3.org/2001/XMLSchema-instance", "xsi", 0 ); -$node->setAttributeNS( "http://www.w3.org/2001/XMLSchema-instance", "type", "xsd:language" ); -$video->appendChild($node); - -$node = XML::LibXML::Element->new( "license" ); -$node->setNamespace( "http://purl.org/dc/terms/", "dcterms" ); -$node->setNamespace( "http://www.w3.org/2001/XMLSchema-instance", "xsi", 0 ); -$node->setAttributeNS( "http://www.w3.org/2001/XMLSchema-instance", "type", "xsd:normalizedString" ); -$video->appendChild($node); - -$node = XML::LibXML::Element->new( "references" ); -$node->setNamespace( "http://purl.org/dc/terms/", "dcterms" ); -$node->setNamespace( "http://www.w3.org/2001/XMLSchema-instance", "xsi", 0 ); -$node->setAttributeNS( "http://www.w3.org/2001/XMLSchema-instance", "type", "xsd:normalizedString" ); -$video->appendChild($node); - -$node = XML::LibXML::Element->new( "replaces" ); -$node->setNamespace( "http://purl.org/dc/terms/", "dcterms" ); -$node->setNamespace( "http://www.w3.org/2001/XMLSchema-instance", "xsi", 0 ); -$node->setAttributeNS( "http://www.w3.org/2001/XMLSchema-instance", "type", "xsd:normalizedString" ); -$video->appendChild($node); - -$node = XML::LibXML::Element->new( "rightsHolder" ); -$node->setNamespace( "http://purl.org/dc/terms/", "dcterms" ); -$node->setNamespace( "http://www.w3.org/2001/XMLSchema-instance", "xsi", 0 ); -$node->setAttributeNS( "http://www.w3.org/2001/XMLSchema-instance", "type", "xsd:normalizedString" ); -$video->appendChild($node); - -$node = XML::LibXML::Element->new( "source" ); -$node->setNamespace( "http://purl.org/dc/terms/", "dcterms" ); -$node->setNamespace( "http://www.w3.org/2001/XMLSchema-instance", "xsi", 0 ); -$node->setAttributeNS( "http://www.w3.org/2001/XMLSchema-instance", "type", "xsd:normalizedString" ); -$video->appendChild($node); - -$node = XML::LibXML::Element->new( "spatial" ); -$node->setNamespace( "http://purl.org/dc/terms/", "dcterms" ); -$node->setNamespace( "http://www.w3.org/2001/XMLSchema-instance", "xsi", 0 ); -$node->setAttributeNS( "http://www.w3.org/2001/XMLSchema-instance", "type", "xsd:normalizedString" ); -$video->appendChild($node); - -$node = XML::LibXML::Element->new( "subject" ); -$node->setNamespace( "http://purl.org/dc/terms/", "dcterms" ); -$node->setNamespace( "http://www.w3.org/2001/XMLSchema-instance", "xsi", 0 ); -$node->setAttributeNS( "http://www.w3.org/2001/XMLSchema-instance", "type", "xsd:normalizedString" ); -$video->appendChild($node); - -$node = XML::LibXML::Element->new( "temporal" ); -$node->setNamespace( "http://purl.org/dc/terms/", "dcterms" ); -$node->setNamespace( "http://www.w3.org/2001/XMLSchema-instance", "xsi", 0 ); -$node->setAttributeNS( "http://www.w3.org/2001/XMLSchema-instance", "type", "xsd:date" ); -$video->appendChild($node); - -$node = XML::LibXML::Element->new( "title" ); -$node->setNamespace( "http://purl.org/dc/terms/", "dcterms" ); -$node->setNamespace( "http://www.w3.org/2001/XMLSchema-instance", "xsi", 0 ); -$node->setAttributeNS( "http://www.w3.org/2001/XMLSchema-instance", "type", "xsd:normalizedString" ); -$video->appendChild($node); - -$node = XML::LibXML::Element->new( "data" ); -$node->setNamespace( "http://www.w3.org/2001/XMLSchema-instance", "xsi", 0 ); -$node->setAttributeNS( "http://www.w3.org/2001/XMLSchema-instance", "type", "xsd:base64Binary" ); -$video->appendChild($node); +$video->appendChild( getElementDC( "abstract", "xsd:string") ); +$video->appendChild( getElementDC( "alternative", "xsd:normalizedString") ); +$video->appendChild( getElementDC( "contributor", "xsd:normalizedString") ); +$video->appendChild( getElementDC( "created", "xsd:date") ); +$video->appendChild( getElementDC( "creator", "xsd:normalizedString") ); +$video->appendChild( getElementDC( "hasFormat", "xsd:normalizedString") ); +$video->appendChild( getElementDC( "hasPart", "xsd:normalizedString") ); +$video->appendChild( getElementDC( "isFormatOf", "xsd:normalizedString") ); +$video->appendChild( getElementDC( "isPartOf", "xsd:normalizedString") ); +$video->appendChild( getElementDC( "language", "xsd:language") ); +$video->appendChild( getElementDC( "license", "xsd:normalizedString") ); +$video->appendChild( getElementDC( "references", "xsd:normalizedString") ); +$video->appendChild( getElementDC( "replaces", "xsd:normalizedString") ); +$video->appendChild( getElementDC( "rightsHolder", "xsd:normalizedString") ); +$video->appendChild( getElementDC( "source", "xsd:normalizedString") ); +$video->appendChild( getElementDC( "spatial", "xsd:normalizedString") ); +$video->appendChild( getElementDC( "subject", "xsd:normalizedString") ); +$video->appendChild( getElementDC( "temporal", "xsd:date") ); +$video->appendChild( getElementDC( "title", "xsd:normalizedString") ); +$video->appendChild( getElementDC( "data", "xsd:base64Binary") ); $instance->appendChild($video); diff --git a/trunk/video.pl b/trunk/video.pl index 885c031..3f293ab 100644 --- a/trunk/video.pl +++ b/trunk/video.pl @@ -11,6 +11,10 @@ my $doc = XML::LibXML::Document->new( "1.0", "UTF-8" ); my $page = get_page_array(@userinfo); +$page->setNamespace( $config->{"xml_namespace_cc"}, "cc", 0); +$page->setNamespace( $config->{"xml_namespace_dc"}, "dc", 0); +$page->setNamespace( $config->{"xml_namespace_rdf"}, "rdf", 0); + #check if id or title is passed if($query->url_param('id')) { @@ -69,6 +73,14 @@ if($query->url_param('id')) $page->setAttribute( "embed", "preview" ); } + #if there was a single result, display the video + my ($id, $title, $description, $publisher, $timestamp, $creator, $subject, + $source, $language, $coverage, $rights, $license, + $filesize, $duration, $width, $height, $fps, $viewcount, $downloadcount) = $sth->fetchrow_array(); + + #finish query + $sth->finish() or die $dbh->errstr; + #if user is logged in if($userinfo->{'username'}) { @@ -180,14 +192,6 @@ if($query->url_param('id')) } } } - - #if there was a single result, display the video - my ($id, $title, $description, $publisher, $timestamp, $creator, $subject, - $source, $language, $coverage, $rights, $license, - $filesize, $duration, $width, $height, $fps, $viewcount, $downloadcount) = $sth->fetchrow_array(); - - #finish query - $sth->finish() or die $dbh->errstr; #construct video xml my $video = XML::LibXML::Element->new( "video" );