Source for file GRDDLParser.php

Documentation is available at GRDDLParser.php

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

Documentation generated on Fri, 17 Dec 2004 16:14:59 +0100 by phpDocumentor 1.3.0RC3