Source for file jResponseRdf.class.php

Documentation is available at jResponseRdf.class.php

  1. <?php
  2. /**
  3. @package     jelix
  4. @subpackage  core_response
  5. @author      Laurent Jouanneau
  6. @copyright   2006-2010 Laurent Jouanneau
  7. @link        http://www.jelix.org
  8. @licence     GNU Lesser General Public Licence see LICENCE file or http://www.gnu.org/licenses/lgpl.html
  9. */
  10.  
  11. /**
  12. * output RDF content.
  13. * This is a basic RDF generator, which generates content from
  14. * an array of data.
  15. @package  jelix
  16. @subpackage core_response
  17. @see jResponse
  18. */
  19.  
  20. final class jResponseRdf extends jResponse {
  21.     /**
  22.     * @var string 
  23.     */
  24.     protected $_type = 'rdf';
  25.  
  26.     /**
  27.      * List of object or array, which will be transform into RDF content
  28.      * @var array 
  29.      */
  30.     public $data;
  31.  
  32.     /**
  33.      * a template selector for complex RDF content.
  34.      * keep empty if you have a simple array of array in $data :
  35.      * RDF content will be generated by a simple generator.
  36.      * if you specify a template, you don't have to fill other
  37.      * properties (except data)
  38.      * @var string 
  39.      */
  40.     public $template;
  41.  
  42.     /**
  43.      * namespace of the attributes and elements that will content your data.
  44.      * @var string 
  45.      */
  46.     public $resNs="http://dummy/rdf#";
  47.     /**
  48.      * namespace prefix
  49.      * @var string 
  50.      */
  51.     public $resNsPrefix='row';
  52.     /**
  53.      * uri prefix of all ressources
  54.      * @var string 
  55.      */
  56.     public $resUriPrefix = "urn:data:row:";
  57.     /**
  58.      * uri of the root sequence
  59.      * @var string 
  60.      */
  61.     public $resUriRoot = "urn:data:row";
  62.     /**
  63.      * list of array values you want to put in attributes
  64.      * @var string 
  65.      */
  66.     public $asAttribute=array();
  67.     /**
  68.      * list of array values you want to put in elements
  69.      * @var string 
  70.      */
  71.     public $asElement=array();
  72.  
  73.     public function output(){
  74.         $this->_httpHeaders['Content-Type']='text/xml;charset='.$GLOBALS['gJConfig']->charset;
  75.  
  76.         if ($this->template !=''{
  77.             $tplnew jTpl();
  78.             $tpl->assign('data',$this->data);
  79.             $content $tpl->fetch($this->template);
  80.         }
  81.         else {
  82.             $content $this->generateContent();
  83.         }
  84.         
  85.         $this->sendHttpHeaders();
  86.         echo '<?xml version="1.0" encoding="'.$GLOBALS['gJConfig']->charset.'"?>';
  87.         echo $content;
  88.         return true;
  89.     }
  90.  
  91.     protected function generateContent({
  92.         ob_start();
  93.         $EOL="\n";
  94.         echo '<RDF xmlns:RDF="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#"'.$EOL;
  95.         echo '  xmlns:',$this->resNsPrefix,'="',$this->resNs,'"  xmlns:NC="http://home.netscape.com/NC-rdf#">',$EOL;
  96.  
  97.         echo '<Bag RDF:about="'.$this->resUriRoot.'">'.$EOL;
  98.         foreach($this->data as $dt){
  99.             echo "<li>\n<Description ";
  100.             // NC:parseType="Integer"
  101.             if(is_object($dt))
  102.                 $dt=get_object_vars ($dt);
  103.             if(count($this->asAttribute|| count($this->asElement)){
  104.                 foreach($this->asAttribute as $name){
  105.                     echo $this->resNsPrefix,':',$name,'="',htmlspecialchars($dt[$name]),'" ';
  106.                 }
  107.                 if(count($this->asElement)){
  108.                     echo ">\n";
  109.                     foreach($this->asElement as $name){
  110.                         echo '<',$this->resNsPrefix,':',$name,'>',htmlspecialchars($dt[$name]),'</',$this->resNsPrefix,':',$name,">\n";
  111.                     }
  112.                     echo "</Description>\n</li>\n";
  113.                 }else
  114.                     echo "/>\n</li>\n";
  115.  
  116.             }else{
  117.                 if(count($dt)){
  118.                     echo ">\n";
  119.                     foreach($dt as $name=>$val){
  120.                         echo '<',$this->resNsPrefix,':',$name,'>',htmlspecialchars($val),'</',$this->resNsPrefix,':',$name,">\n";
  121.                     }
  122.                     echo "</Description>\n</li>\n";
  123.                 }else{
  124.                     echo "/>\n</li>\n";
  125.                 }
  126.             }
  127.         }
  128.         echo "</Bag>\n</RDF>\n";
  129.         return ob_get_clean();
  130.     }
  131. }

Documentation generated on Wed, 24 Sep 2014 22:01:34 +0200 by phpDocumentor 1.4.3