Source for file GRDDLParser.php

Documentation is available at GRDDLParser.php

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

Documentation generated on Fri, 13 Jan 2006 07:48:14 +0100 by phpDocumentor 1.3.0RC4