source: Dev/branches/rest-dojo-ui/server/rdfapi/syntax/GRDDLParser.php @ 256

Last change on this file since 256 was 256, checked in by hendrikvanantwerpen, 13 years ago

Reworked project structure based on REST interaction and Dojo library. As
soon as this is stable, the old jQueryUI branch can be removed (it's
kept for reference).

File size: 2.5 KB
Line 
1<?php
2// ----------------------------------------------------------------------------------
3// Class: RdfParser
4// ----------------------------------------------------------------------------------
5
6
7/**
8 * A GRDDLParser.
9 * This class extracts rdf data from xhtml documents. It uses the PHP xsltprocessor.
10 * Gleaning Resource Descriptions from Dialects of Languages (GRDDL):
11 * (http://www.w3.org/TR/grddl/)
12 *
13 * @version  $Id: GRDDLParser.php 320 2006-11-21 09:38:51Z tgauss $
14 * @author Tobias Gauß <tobias.gauss@web.de>,
15 *
16 * @package syntax
17 * @access      public
18 *
19 */   
20class GRDDLParser extends Object{
21       
22       
23        /**
24        * Document link
25        *
26        *
27        * @var     String
28        * @access       private
29        */
30        var $doclink;
31       
32       
33        /**
34        * Stylesheet link
35        *
36        *
37        * @var     String[]
38        * @access       private
39        */
40        var $stylelinks;
41       
42       
43        /**
44        * DomDocument
45        *
46        * @var     DomDocument
47        * @access       private
48        */
49        var $domdoc;
50       
51       
52        /**
53        * generates a MemModel and creates the DomDocument.
54        *
55        * @param String $doc
56        * @access public
57        * @return MemModel $model
58        */
59        function generateModel($doc){
60                $model = new MemModel();
61                $this->doclink=$doc;
62                $this->domdoc = new DomDocument;
63                $this->domdoc->load($doc);
64                $this->_getStyles();
65                $model = $this->_generateRDF();
66                return $model;
67        }
68       
69
70        /**
71        * gets the used xsl stylesheets.
72        *
73        * @access private
74        */
75        function _getStyles(){
76                $link=$this->domdoc->getElementsByTagName('link');
77                $i=0;
78                while($link->item($i)!=''){
79                        $item = $link->item($i);
80                        if($item->getAttributeNode('rel')->value=='transformation'){
81                                $temp = $item->getAttributeNode('href')->value;
82                                if(substr($temp,0,1)=='/'){
83                                        $pos = strrpos($this->doclink,'/');
84                                        $part = substr($this->doclink,0,$pos);
85                                        $this->stylelink[]=$part.$temp;
86                                }else{
87                                        $this->stylelink[]=$temp;
88                                }
89                        }
90                        $i++;
91                }
92        }
93       
94        /*
95        * uses the PHP build in xslt processor to
96        * generate the RDF statements and uses the
97        * RDF- Parser to generate the model
98        *
99        * @access private
100        * @return MemModel $model
101        */
102        function _generateRDF(){
103                $model=new MemModel();
104                $model->setBaseURI($this->doclink);
105                $proc = new xsltprocessor;
106                include_once(RDFAPI_INCLUDE_DIR.PACKAGE_SYNTAX_RDF);
107                $pars=new RdfParser();
108                foreach($this->stylelink as $key => $value){
109                        $xsl = new DomDocument;
110                        $xsl->load($value);
111                        $proc->importStyleSheet($xsl);
112                        $model->addModel($pars->generateModel($proc->transformToXML($this->domdoc),$this->doclink));
113                }
114                return $model;
115        }
116
117       
118       
119}
120?>
Note: See TracBrowser for help on using the repository browser.