Source for file RdfParser.php

Documentation is available at RdfParser.php

  1. <?php
  2.  
  3. // ----------------------------------------------------------------------------------
  4. // Class: RdfParser
  5. // ----------------------------------------------------------------------------------
  6.  
  7.  
  8. /**
  9.  * An RDF paser.
  10.  * This class reads RDF data from files or URIs and generates models out of it. All valid
  11.  * RDF XML syntaxes defined by the W3C in RDF/XML Syntax Specification (Revised)
  12.  * - W3C Working Draft 10 October 2003
  13.  * (http://www.w3.org/TR/2003/WD-rdf-syntax-grammar-20031010/) are supported.
  14.  * The parser is based on the PHP version of repat
  15.  * (http://phpxmlclasses.sourceforge.net/show_doc.php?class=class_rdf_parser.html)
  16.  * by Luis Argerich (lrargerich@yahoo.com).
  17.  * 
  18.  * @version  $Id: fsource_syntax__syntaxRdfParser.php.html 443 2007-06-01 16:25:38Z cax $
  19.  * @author Luis Argerich <lrargerich@yahoo.com>,
  20.  *          Chris Bizer <chris@bizer.de>,
  21.  *          Radoslaw Oldakowski <radol@gmx.de>
  22.  *            Daniel Westphal <mail@d-westphal.de>
  23.  * @package syntax
  24.  * @access    public
  25.  *
  26.  */   
  27.   
  28. class RdfParser extends Object {
  29.  
  30. var $model;
  31.  
  32. /* Private Methods */
  33.  
  34.  
  35. /**
  36. * converts a string to its unicode NFC form (e.g. \uHHHH or \UHHHHHHHH).
  37. @param String $str 
  38. @return String 
  39. @access private
  40. *
  41. */
  42. function str2unicode_nfc($str=""){
  43.     $result="";
  44.     /* try to detect encoding */
  45.     $tmp=str_replace("?"""$str);
  46.     if(strpos(utf8_decode($tmp)"?")===false){
  47.         $str=utf8_decode($str);
  48.     }
  49.     for($i=0,$i_max=strlen($str);$i<$i_max;$i++){
  50.         $nr=0;/* unicode dec nr */
  51.         /* char */
  52.         $char=$str[$i];
  53.         /* utf8 binary */
  54.         $utf8_char=utf8_encode($char);
  55.         $bytes=strlen($utf8_char);
  56.         if($bytes==1){
  57.             /* 0####### (0-127) */
  58.             $nr=ord($utf8_char);
  59.         }
  60.         elseif($bytes==2){
  61.             /* 110##### 10###### = 192+x 128+x */
  62.             $nr=((ord($utf8_char[0])-192)*64(ord($utf8_char[1])-128);
  63.         }
  64.         elseif($bytes==3){
  65.             /* 1110#### 10###### 10###### = 224+x 128+x 128+x */
  66.             $nr=((ord($utf8_char[0])-224)*4096((ord($utf8_char[1])-128)*64(ord($utf8_char[2])-128);
  67.         }
  68.         elseif($bytes==4){
  69.             /* 1111#### 10###### 10###### 10###### = 240+x 128+x 128+x 128+x */
  70.             $nr=((ord($utf8_char[0])-240)*262144((ord($utf8_char[1])-128)*4096((ord($utf8_char[2])-128)*64(ord($utf8_char[3])-128);
  71.         }
  72.         /* result (see http://www.w3.org/TR/rdf-testcases/#ntrip_strings) */
  73.         if($nr<9){/* #x0-#x8 (0-8) */
  74.             $result.="\\u".sprintf("%04X",$nr);
  75.         }
  76.         elseif($nr==9){/* #x9 (9) */
  77.             $result.='\t';
  78.         }
  79.         elseif($nr==10){/* #xA (10) */
  80.             $result.='\n';
  81.         }
  82.         elseif($nr<13){/* #xB-#xC (11-12) */
  83.             $result.="\\u".sprintf("%04X",$nr);
  84.         }
  85.         elseif($nr==13){/* #xD (13) */
  86.             $result.='\t';
  87.         }
  88.         elseif($nr<32){/* #xE-#x1F (14-31) */
  89.             $result.="\\u".sprintf("%04X",$nr);
  90.         }
  91.         elseif($nr<34){/* #x20-#x21 (32-33) */
  92.             $result.=$char;
  93.         }
  94.         elseif($nr==34){/* #x22 (34) */
  95.             $result.='\"';
  96.         }
  97.         elseif($nr<92){/* #x23-#x5B (35-91) */
  98.             $result.=$char;
  99.         }
  100.         elseif($nr==92){/* #x5C (92) */
  101.             $result.='\\';
  102.         }
  103.         elseif($nr<127){/* #x5D-#x7E (93-126) */
  104.             $result.=$char;
  105.         }
  106.         elseif($nr<65536){/* #x7F-#xFFFF (128-65535) */
  107.             $result.="\\u".sprintf("%04X",$nr);
  108.         }
  109.         elseif($nr<1114112){/* #x10000-#x10FFFF (65536-1114111) */
  110.             $result.="\\U".sprintf("%08X",$nr);
  111.         }
  112.         else{
  113.             /* other chars are not defined => ignore */
  114.         }
  115.     }
  116.     return $result;
  117. }
  118.  
  119.  
  120.  
  121.  
  122. /**
  123.  * @access    private
  124.  */  
  125. function _new_element()
  126. {
  127.     $e['parent']=Array();  // Parent is a blank Array
  128.     $e['state']=0;
  129.     $e['has_property_atributes']=0;
  130.     $e['has_member_attributes']=0;
  131.     $e['subject_type']=0;
  132.     $e['subject']='';
  133.     $e['predicate']='';
  134.     $e['ordinal']=0;
  135.     $e['members']=0;
  136.     $e['data']='';
  137.     $e['xml_lang']='';
  138.     $e['bag_id']='';
  139.     $e['statements']=0;
  140.     $e['statement_id']='';
  141.     $e['datatype']='';
  142.     $e['element_base_uri''';
  143.    
  144.     return $e;
  145. }
  146.  
  147. /**
  148.  
  149.  * @param string $source 
  150.  * @param string &$destination 
  151.  *
  152.  * @access    private
  153.  */  
  154. function _copy_element($source&$destination )
  155. {
  156.     if$source )
  157.     {
  158.         $destination['parent'$source;
  159.         $destination['state'$source['state'];
  160.         $destination['xml_lang'$source['xml_lang'];
  161.         $destination['element_base_uri'$source['element_base_uri'];       
  162.     }
  163. }
  164.  
  165.   /**
  166.    * @param string &$e 
  167.    * @access    private
  168.    */  
  169. function _clear_element(&$e)
  170. {
  171.         $e['subject']='';
  172.         $e['predicate']='';
  173.         $e['data']='';
  174.         $e['bag_id']='';
  175.         $e['statement_id']='';
  176.  
  177.         if(isset($e['parent'])) {
  178.           if$e['parent')
  179.           {
  180.               if$e['parent']['xml_lang'!= $e['xml_lang')
  181.               {
  182.                   $e['xml_lang']='';
  183.               }
  184.           }
  185.           else
  186.           {
  187.               $e['xml_lang']='';
  188.           }
  189.         else {
  190.             $e['xml_lang']='';
  191.         }
  192.  
  193.         $e['parent']=Array();
  194.         $e['state']=0;
  195.         $e['has_property_attributes']=0;
  196.         $e['has_member_attributes']=0;
  197.         $e['subject_type']=0;
  198.         $e['subject']='';
  199.         $e['predicate']='';
  200.         $e['ordinal']=0;
  201.         $e['members']=0;
  202.         $e['data']='';
  203.         $e['xml_lang']='';
  204.         $e['bag_id']='';
  205.         $e['statements']=0;
  206.         $e['statement_id']='';
  207.         $e['datatype']='';
  208.         $e['element_base_uri''';
  209. }
  210.  
  211.   /**
  212.    * @access    private
  213.    */  
  214. function _push_element()
  215. {
  216.     if(!isset($this->rdf_parser['free'])) {
  217.         $this->rdf_parser['free']=Array();
  218.     }
  219.     if(count($this->rdf_parser['free'])>0)
  220.     {
  221.         $e $this->rdf_parser['free'];
  222.         if(isset($e['parent'])) {
  223.           $this->rdf_parser['free'$e['parent'];
  224.         else {
  225.           $this->rdf_parser['free']=$this->_new_element();
  226.         }
  227.     }
  228.     else
  229.     {
  230.         $e $this->_new_element();
  231.     }
  232.     if(!isset($this->rdf_parser['top'])) {
  233.       $this->rdf_parser['top']=Array();
  234.     }
  235.     $this->_copy_element$this->rdf_parser['top']$e );
  236.     $this->rdf_parser['top'$e;
  237. }
  238.  
  239.   /**
  240.    * @access    private
  241.    */  
  242. function _pop_element()
  243. {
  244.     $e $this->rdf_parser['top'];
  245.     $this->rdf_parser['top'$e['parent'];
  246.     $this->_clear_element$e );
  247.     $this->rdf_parser['free'$e;
  248. }
  249.  
  250.   /**
  251.    * @param string $local_name 
  252.    * @access    private
  253.    */  
  254. function _is_rdf_property_attribute_resource($local_name )
  255. {
  256.     return $local_name == RDF_TYPE );    
  257. }
  258.  
  259.   /**
  260.    * @param string $local_name 
  261.    * @access    private
  262.    */  
  263. function _is_rdf_property_attribute_literal($local_name )
  264. {
  265.     return $local_name == RDF_VALUE )           
  266.         || $local_name == RDF_BAG )
  267.         || $local_name == RDF_SEQ )
  268.         || $local_name == RDF_ALT )
  269.         || $local_name == RDF_STATEMENT )
  270.         || $local_name == RDF_PROPERTY )
  271.         || $local_name == RDF_LIST );      
  272. }
  273.  
  274.   /**
  275.    * @param string $local_name 
  276.    * @access    private
  277.    */  
  278. function _is_rdf_ordinal$local_name )
  279. {
  280.     $ordinal = -1;
  281.  
  282.     if$local_name{0==  '_'  )
  283.     {
  284.         $ordinal =  substr($local_name,1;
  285.     }
  286.  
  287.     return $ordinal $ordinal 0;
  288. }
  289.  
  290.   /**
  291.    * @param string $local_name 
  292.    * @access    private
  293.    */  
  294. function _is_rdf_property_attribute$local_name )
  295. {
  296.     return $this->_is_rdf_property_attribute_resource$local_name )
  297.         || $this->_is_rdf_property_attribute_literal$local_name );
  298. }
  299.  
  300. {
  301.     return $local_name == RDF_RDF )
  302.         || $local_name == RDF_DESCRIPTION)
  303.         || $local_name == RDF_ID)                 
  304.         || $local_name == RDF_ABOUT )
  305.         || $local_name == RDF_BAG_ID )
  306.         || $local_name == RDF_PARSE_TYPE )
  307.         || $local_name == RDF_RESOURCE )        
  308.         || $local_name == RDF_NODEID )
  309.         || $local_name == RDF_LI )
  310.         || $local_name == RDF_ABOUT_EACH )
  311.         || $local_name == RDF_ABOUT_EACH_PREFIX )
  312.         || $local_name == RDF_DATATYPE );
  313. }
  314.  
  315.   /**
  316.    * @param string $local_name 
  317.    * @access    private
  318.    */  
  319. function _is_rdf_property_element$local_name )
  320. {
  321.     return (  $local_name == RDF_TYPE )
  322.         || (  $local_name == RDF_SUBJECT )
  323.         || (  $local_name == RDF_PREDICATE )
  324.         || (  $local_name == RDF_OBJECT )
  325.         || (  $local_name == RDF_VALUE )
  326.         || (  $local_name == RDF_LI )
  327.         || (  $local_name == RDF_SEEALSO )             
  328.         || $local_name == RDF_BAG )
  329.         || $local_name == RDF_SEQ )
  330.         || $local_name == RDF_ALT )
  331.         || $local_name == RDF_STATEMENT )
  332.         || $local_name == RDF_PROPERTY )
  333.         || $local_name == RDF_LIST )
  334.         || $local_name == RDF_FIRST )        
  335.         || $local_name == RDF_REST )
  336.         || (  $local_name{0== '_'  );
  337. }
  338.  
  339.   /**
  340.    * @param string $local_name 
  341.    * @access    private
  342.    */  
  343. function _is_forbidden_rdf_property_element ($local_name)
  344. {
  345.     return $local_name == RDF_RDF )
  346.         || $local_name == RDF_DESCRIPTION)
  347.         || $local_name == RDF_ID)                 
  348.         || $local_name == RDF_ABOUT )
  349.         || $local_name == RDF_BAG_ID )
  350.         || $local_name == RDF_PARSE_TYPE )
  351.         || $local_name == RDF_RESOURCE )        
  352.         || $local_name == RDF_NODEID )
  353.         || $local_name == RDF_ABOUT_EACH )
  354.         || $local_name == RDF_ABOUT_EACH_PREFIX )
  355.         || $local_name == RDF_DATATYPE );
  356. }
  357.                 
  358.  
  359.   /**
  360.    * @param string $local_name 
  361.    * @access    private
  362.    */  
  363. function _is_rdf_node_element$local_name )
  364. {
  365.     return $local_name == RDF_DESCRIPTION )                 
  366.         || $local_name == RDF_STATEMENT )
  367.         || $local_name == RDF_SUBJECT )
  368.         || $local_name == RDF_PREDICATE )
  369.         || $local_name == RDF_OBJECT )        
  370.         || $local_name == RDF_PROPERTY )
  371.         || $local_name == RDF_TYPE )
  372.         || $local_name == RDF_VALUE )
  373.         || $local_name == RDF_BAG )
  374.         || $local_name == RDF_SEQ )
  375.         || $local_name == RDF_ALT )        
  376.         || $local_name == RDF_SEEALSO )        
  377.         || $local_name == RDF_LIST )
  378.         || $local_name == RDF_FIRST )        
  379.         || $local_name == RDF_REST )        
  380.         || $local_name == RDF_NIL )                
  381.         || $local_name{0== '_'  );
  382. }
  383.  
  384.   /**
  385.    * @param string $local_name 
  386.    * @access    private
  387.    */  
  388. function _is_forbidden_rdf_node_element ($local_name)
  389. {
  390.     return $local_name == RDF_RDF )
  391.         || $local_name == RDF_ID)                 
  392.         || $local_name == RDF_ABOUT )
  393.         || $local_name == RDF_BAG_ID )
  394.         || $local_name == RDF_PARSE_TYPE )
  395.         || $local_name == RDF_RESOURCE )        
  396.         || $local_name == RDF_NODEID )
  397.         || $local_name == RDF_LI )
  398.         || $local_name == RDF_ABOUT_EACH )
  399.         || $local_name == RDF_ABOUT_EACH_PREFIX )
  400.         || $local_name == RDF_DATATYPE );
  401. }
  402.  
  403.   /**
  404.    * @param string $val 
  405.    * @access    private
  406.    */  
  407. function _istalnum($val{
  408.   return ereg("[A-Za-z0-9]",$val);
  409. }
  410.   /**
  411.    * @param string $val 
  412.    * @access    private
  413.    */  
  414. function _istalpha($val{
  415.   return ereg("[A-Za-z]",$val);
  416. }
  417.  
  418.   /**
  419.    * @param string $uri 
  420.    * @access    private
  421.    */  
  422. function _is_absolute_uri($uri )
  423. {
  424.     $result false;
  425.         $uri_p=0;
  426.     if$uri && $this->_istalpha$uri{$uri_p) )
  427.     {
  428.         ++$uri_p;
  429.  
  430.         while( ($uri_p<strlen($uri))
  431.             && $this->_istalnum$uri{$uri_p)
  432.                 || $uri{$uri_p==  '+'  )
  433.                 || $uri{$uri_p== '-'  )
  434.                 || $uri{$uri_p==  '.'  ) ) )
  435.         {
  436.                 ++$uri_p;
  437.         }
  438.  
  439.         $result $uri{$uri_p== ':'  );
  440.     }
  441.     return $result;
  442. }
  443.  
  444.  
  445. /*
  446.    * This function returns an associative array returning any of the various components of the URL that are present. This includes the
  447.    * $arr=parse_url($url)
  448.    * scheme - e.g. http
  449.    * host
  450.    * port
  451.    * user
  452.    * pass
  453.    * path
  454.    * query - after the question mark ?
  455.    * fragment - after the hashmark #
  456.    *
  457.    * @param string $uri
  458.    * @param string $buffer
  459.    * @param string &$scheme
  460.    * @param string &$authority
  461.    * @param string &$path
  462.    * @param string &$query
  463.    * @param string &$fragment
  464.    * @access    private 
  465. */  
  466. function _parse_uri($uri,$buffer,&$scheme,&$authority,&$path,&$query,&$fragment {
  467.     
  468.   $parsed=parse_url($uri);
  469.   if(isset($parsed['scheme'])) {
  470.     $scheme=$parsed['scheme'];
  471.   else {
  472.     $scheme='';
  473.   }
  474.   if(isset($parsed['host'])) {
  475.     $host=$parsed['host'];
  476.   else {
  477.     $host='';
  478.   }
  479.   if(isset($parsed['host'])) {
  480.     $authority=$parsed['host'];
  481.   else {
  482.     $authority='';
  483.   }
  484.   if(isset($parsed['path'])) {
  485.     $path=$parsed['path'];
  486.   else {
  487.     $path='';
  488.   }
  489.   if(isset($parsed['query'])) {
  490.     $query=$parsed['query'];
  491.   else {
  492.     $query='';
  493.   }
  494.   if(isset($parsed['fragment'])) {
  495.     $fragment=$parsed['fragment'];
  496.   else {
  497.     $fragment='';
  498.   }
  499.  
  500. }
  501.  
  502. /**
  503.    * @param string $base_uri 
  504.    * @param string $reference_uri 
  505.    * @param string &$buffer 
  506.    * @access    private
  507. */ 
  508. function _resolve_uri_reference($base_uri,$reference_uri,&$buffer )
  509. {
  510.     if ($reference_uri == '')
  511.         return ($buffer preg_replace("/\#[^\/\\\]*$/"''$base_uri));
  512.             
  513.     $base_buffer='';
  514.     $reference_buffer='';
  515.     $path_buffer='';
  516.  
  517.     $buffer '';
  518.  
  519.     $this->_parse_uri($reference_uri,
  520.                       $reference_buffer,
  521.                       $reference_scheme,
  522.                       $reference_authority,
  523.                       $reference_path,
  524.                       $reference_query,
  525.                       $reference_fragment );
  526.                
  527.     $this->_parse_uri($base_uri,
  528.                       $base_buffer,
  529.                       $base_scheme,
  530.                       $base_authority,
  531.                       $base_path,
  532.                       $base_query,
  533.                       $base_fragment );     
  534.         
  535.     if$reference_scheme == ''
  536.         && $reference_authority == ''
  537.         && $reference_path == ''
  538.         && $reference_query == '' )
  539.     {
  540.         $buffer=$base_uri;
  541.  
  542.         if$reference_fragment != '' )        
  543.         {
  544.             if ($base_path == '' || $base_path == '/' || $base_path == "\\"{
  545.                $buffer $this->rdf_parser['document_base_uri'];    
  546.             }
  547.             else 
  548.             {
  549.                 $buffer preg_replace("/\#[^\/\\\]*$/"''$base_uri);
  550.             }
  551.            
  552.             // CB: Changed for base URI
  553.             $c substr($bufferstrlen($buffer)-,1);
  554.             if (!($c=='#' || $c==':' || $c=='/' || $c=="\\"))
  555.                    $buffer.= '#' ;
  556.             $buffer.=$reference_fragment;               
  557.             
  558.         }
  559.     }
  560.     else if$reference_scheme != '' )
  561.     {
  562.         $buffer=$reference_uri;
  563.     }
  564.     else
  565.     {                    
  566.         $result_scheme $base_scheme;
  567.         $result_path '';
  568.         
  569.         if$reference_authority != '' )
  570.         {
  571.             $result_authority $reference_authority;            
  572.         }
  573.         else
  574.         {
  575.             $result_authority $base_authority;
  576.            
  577.             if ($reference_path != '')
  578.             {
  579.                 if ($reference_path{0== '/' || $reference_path{0== "\\")
  580.                 {
  581.                     if ($reference_path{1== '/' || $reference_path{1== "\\")
  582.                     {
  583.                         $result_authority '';
  584.                         $result_path $reference_path;    
  585.                     }
  586.                     else
  587.                         $result_path $reference_path;
  588.                 }
  589.                 elseif (substr($reference_path03== '../' ||
  590.                         substr($reference_path03== '..\\')
  591.                 {
  592.                     $slash $reference_path{2};                        
  593.                     while($base_path != '' && substr($reference_path03== '../' 
  594.                                              || substr($reference_path03== '..\\'))
  595.                     {                        
  596.                           $base_path preg_replace("/((\/)|(\\\))[^\/\\\]*$/"''$base_path);                                                    
  597.                           if ($base_path != ''{
  598.                              $base_path preg_replace("/((\/)|(\\\))[^\/\\\]*$/"''$base_path);                                                       
  599.                              $reference_path substr($reference_path3);
  600.                           }
  601.                     }
  602.                            
  603.                     $result_path $base_path .$slash .$reference_path;
  604.                 }
  605.                 else 
  606.                 {   
  607.                     if ($base_path)
  608.                         $result_path preg_replace("/[^\/\\\]*$/"$reference_path$base_path1);
  609.                     else 
  610.                         $result_path '/' .$reference_path;                        
  611.                 
  612.             }
  613.             
  614.         }
  615.                                                 
  616.         if$result_scheme != '' )
  617.         {
  618.             $buffer=$result_scheme;
  619.             $buffer.=':';
  620.         }
  621.  
  622.         if$result_authority != '' )
  623.         {
  624.             $buffer.="//";
  625.             $buffer.=$result_authority;
  626.         }
  627.  
  628.         if$result_path != '' )
  629.         {
  630.             $buffer.=$result_path;
  631.         }
  632.  
  633.         if$reference_query != '' )
  634.         {
  635.             $buffer.='?';
  636.             $buffer.=$reference_query;
  637.         }
  638.  
  639.         if$reference_fragment != '' )
  640.         {
  641.             $buffer.='#';
  642.             $buffer.=$reference_fragment;
  643.         }
  644.     }  
  645. }
  646.  
  647.  
  648. /**
  649.    * IDs which contain CombiningChars or Extenders
  650.    * (see http://www.w3.org/TR/REC-xml-names/#NT-NCName) are assumed to be invalid.
  651.    * If you want to use IDs containing these characters you can turn off
  652.    * the validating by setting the constant VALIDATE_IDS to FALSE (see constants.php).
  653.    *
  654.    * @param string $id 
  655.    * @access    private
  656. */ 
  657. function is_valid_id($id )
  658. {
  659.     if (!VALIDATE_IDS)
  660.         return TRUE;
  661.     
  662.     $result FALSE;
  663.     
  664.     if$id )
  665.     {
  666.         if$this->_istalpha($id{0}|| $id{0== '_')
  667.         {
  668.             $result TRUE;
  669.             $i=0;
  670.             $len strlen($id);
  671.             while$result != FALSE && ++$i $len )
  672.             {
  673.                 if!($this->_istalnum$id{$i})
  674.                       || $id{$i== '.'
  675.                       || $id{$i== '-'
  676.                       || $id{$i== '_'))
  677.                 {
  678.                    $result FALSE
  679.                 }
  680.             }
  681.         }
  682.     }
  683.     
  684.     if (!$result)
  685.         $this->_report_error('illegal ID, nodeID or bagID attribute value');
  686.     else    
  687.         return TRUE;
  688. }
  689.  
  690. /**
  691.    * @param string $id 
  692.    * @param string &$buffer 
  693.    * @access    private
  694. */ 
  695. function _resolve_id($id,&$buffer )
  696. {
  697.     $id_buffer='';
  698.  
  699.     if$this->is_valid_id($id) )
  700.     {
  701.         $id_buffer="#$id";
  702.     }
  703.  
  704.     $this->_resolve_uri_reference$this->rdf_get_base()$id_buffer$buffer );
  705.        
  706. }
  707.  
  708. /**
  709.    * @param string $name 
  710.    * @param string &$buffer 
  711.    * @param string &$namespace_uri 
  712.    * @param string &$local_name 
  713.    * @access    private
  714. */ 
  715. function _split_name($name&$buffer&$namespace_uri&$local_name )
  716. {
  717.     static $nul 0;
  718.     $buffer=$name;
  719.  
  720.         if(  strstr$bufferNAMESPACE_SEPARATOR_CHAR ) )
  721.         {
  722.             $cosas=explode(NAMESPACE_SEPARATOR_CHAR,$buffer);
  723.             $namespace_uri $cosas[0];
  724.             $local_name $cosas[1];
  725.         }
  726.         else
  727.         {
  728.             if( ( $buffer==  'x'  )
  729.                 && $buffer==  'm'  )
  730.                 && $buffer==  'l'  )
  731.                 && $buffer==  ':'  ) )
  732.             {
  733.                 $namespace_uri XML_NAMESPACE_URI;
  734.                 $local_name substr($buffer,4);
  735.             }
  736.             else
  737.             {
  738.                 $namespace_uri '';
  739.                 $local_name $buffer;
  740.             }
  741.         }
  742. }
  743. /**
  744.    * @param string &$buf 
  745.    * @access    private
  746. */ 
  747. function _generate_anonymous_uri(&$buf )
  748. {
  749.     $id='';
  750.     if(!isset($this->rdf_parser['anonymous_id'])) {
  751.       $this->rdf_parser['anonymous_id']=0;
  752.     }
  753.     $this->rdf_parser['anonymous_id']++;
  754.  
  755.     $bufBNODE_PREFIX $this->rdf_parser['anonymous_id'];
  756.  
  757. }
  758. /**
  759.    * @param string $subject_type 
  760.    * @param string $subject 
  761.    * @param string $predicate 
  762.    * @param string $ordinal 
  763.    * @param string $object_type 
  764.    * @param string $object 
  765.    * @param string $xml_lang 
  766.    * @param string $bag_id 
  767.    * @param string $statements 
  768.    * @param string $statement_id 
  769.    * @access    private
  770. */ 
  771. function _report_statement$subject_type$subject$predicate$ordinal$object_type,  $object$xml_lang$bag_id$statements$statement_id$datatype )
  772. {
  773.     $statement_id_type RDF_SUBJECT_TYPE_URI;
  774.     $statement_id_buffer='';
  775.     $predicate_buffer='';
  776.     if (!$xml_lang && $object_type == RDF_OBJECT_TYPE_LITERAL && isset($this->rdf_parser['document_xml_lang']))
  777.         $xml_lang $this->rdf_parser['document_xml_lang'];
  778.     
  779.      // call add statement
  780.      $this->add_statement_to_model($this->rdf_parser['user_data'],$subject_type,$subject,$predicate,$ordinal,$object_type,$object,$xml_lang$datatype );
  781.  
  782.         if$bag_id )
  783.         {
  784.             if$statements == '' )
  785.             {
  786.                 $this->_report_statement(RDF_SUBJECT_TYPE_URI,
  787.                     $bag_id,
  788.                     RDF_NAMESPACE_URI.RDF_TYPE,
  789.                     0,
  790.                     RDF_OBJECT_TYPE_RESOURCE,
  791.                     RDF_NAMESPACE_URI.RDF_BAG,
  792.                     '',
  793.                     '',
  794.                     '',
  795.                     '',
  796.                     $datatype );
  797.             }
  798.  
  799.             if$statement_id )
  800.             {
  801.                 $statement_id_type RDF_SUBJECT_TYPE_BNODE;
  802.                 $this->_generate_anonymous_uri$statement_id_buffer );
  803.                 $statement_id $statement_id_buffer;
  804.             }
  805.             $statements++;
  806.             $predicate_buffer='RDF_NAMESPACE_URI_'.$statements;
  807.  
  808.             $this->_report_statement(
  809.                 RDF_SUBJECT_TYPE_URI,
  810.                 $bag_id,
  811.                 $predicate_buffer,
  812.                 $statements,
  813.                 RDF_OBJECT_TYPE_BNODE,
  814.                 $statement_id,
  815.                 '',
  816.                 '',
  817.                 '',
  818.                 '',
  819.                 $datatype );
  820.         }
  821.  
  822.         if$statement_id )
  823.         {
  824.             // rdf:type = rdf:Statement
  825.             $this->_report_statement(
  826.                 $statement_id_type,
  827.                 $statement_id,
  828.                 RDF_NAMESPACE_URI.RDF_TYPE,
  829.                 0,
  830.                 RDF_OBJECT_TYPE_RESOURCE,
  831.                 RDF_NAMESPACE_URI.RDF_STATEMENT,
  832.                 '',
  833.                 '',
  834.                 '',
  835.                 '',
  836.                 $datatype );
  837.         
  838.             if ($subject_type == RDF_SUBJECT_TYPE_BNODE)
  839.                $obj_type RDF_OBJECT_TYPE_BNODE;
  840.             else 
  841.                $obj_type RDF_OBJECT_TYPE_RESOURCE;                              
  842.                 
  843.                 
  844.             // rdf:subject
  845.             $this->_report_statement(
  846.                 $statement_id_type,
  847.                 $statement_id,
  848.                 RDF_NAMESPACE_URI.RDF_SUBJECT,
  849.                 0,               
  850.                 $obj_type,                              
  851.                 $subject,
  852.                 '',
  853.                 '',
  854.                 '',
  855.                 '',
  856.                 $datatype );
  857.  
  858.             // rdf:predicate
  859.             $this->_report_statement(
  860.                 $statement_id_type,
  861.                 $statement_id,
  862.                 RDF_NAMESPACE_URI.RDF_PREDICATE,
  863.                 0,
  864.                 RDF_OBJECT_TYPE_RESOURCE,
  865.                 $predicate,
  866.                 '',
  867.                 '',
  868.                 '',
  869.                 '',
  870.                 $datatype );
  871.  
  872.             // rdf:object
  873.             $this->_report_statement(
  874.                 $statement_id_type,
  875.                 $statement_id,
  876.                 RDF_NAMESPACE_URI.RDF_OBJECT,
  877.                 0,
  878.                 $object_type,
  879.                 $object,
  880.                 '',
  881.                 '',
  882.                 '',
  883.                 '',
  884.                 $datatype );
  885.         }
  886. }
  887. /**
  888.    * @param string $subject_type 
  889.    * @param string $subject 
  890.    * @param string $attributes 
  891.    * @param string $xml_lang 
  892.    * @param string $bag_id 
  893.    * @param string $statements 
  894.  * @access    private
  895. */ 
  896. function _handle_property_attributes($subject_type$subject$attributes$xml_lang$bag_id$statements )
  897. {
  898.     $i=0;
  899.  
  900.     $attribute='';
  901.     $predicate='';
  902.  
  903.     $attribute_namespace_uri='';
  904.     $attribute_local_name='';
  905.     $attribute_value='';
  906.  
  907.     $ordinal=0;
  908.  
  909.     for$i 0isset($attributes$i ])$i += )
  910.     {
  911.         $this->_split_name(
  912.             $attributes$i ],
  913.             $attribute,
  914.             $attribute_namespace_uri,
  915.             $attribute_local_name );
  916.  
  917.         $attribute_value $attributes$i ];
  918.  
  919.         $predicate=$attribute_namespace_uri;
  920.         $predicate.=$attribute_local_name;
  921.  
  922.         ifRDF_NAMESPACE_URI == $attribute_namespace_uri )
  923.         {
  924.             if$this->_is_rdf_property_attribute_literal$attribute_local_name ) )
  925.             {
  926.                 $this->_report_statement(
  927.                     $subject_type,
  928.                     $subject,
  929.                     $predicate,
  930.                     0,
  931.                     RDF_OBJECT_TYPE_LITERAL,
  932.                     $attribute_value,
  933.                     $xml_lang,
  934.                     $bag_id,
  935.                     $statements,
  936.                     '',
  937.                     '');
  938.             }
  939.             else if$this->_is_rdf_property_attribute_resource$attribute_local_name ) )
  940.             {
  941.                 $this->_report_statement(
  942.                     $subject_type,
  943.                     $subject,
  944.                     $predicate,
  945.                     0,
  946.                     RDF_OBJECT_TYPE_RESOURCE,
  947.                     $attribute_value,
  948.                     '',
  949.                     $bag_id,
  950.                     $statements,
  951.                     '',
  952.                     '');
  953.             }
  954.             else if( ( $ordinal $this->_is_rdf_ordinal$attribute_local_name ) ) != )
  955.             {
  956.                 $this->_report_statement(
  957.                     $subject_type,
  958.                     $subject,
  959.                     $predicate,
  960.                     $ordinal,
  961.                     RDF_OBJECT_TYPE_LITERAL,
  962.                     $attribute_value,
  963.                     $xml_lang,
  964.                     $bag_id,
  965.                     $statements,
  966.                     '',
  967.                     '' );
  968.             }
  969.             else if (   ($attribute_local_name != RDF_ABOUT)
  970.                      && ($attribute_local_name != RDF_RDF)
  971.                      && ($attribute_local_name != RDF_DESCRIPTION)
  972.                      && ($attribute_local_name != RDF_ID)
  973.                      && ($attribute_local_name != RDF_ABOUT_EACH)
  974.                      && ($attribute_local_name != RDF_ABOUT_EACH_PREFIX)
  975.                      && ($attribute_local_name != RDF_BAG_ID)
  976.                      && ($attribute_local_name != RDF_RESOURCE)
  977.                      && ($attribute_local_name != RDF_PARSE_TYPE)
  978.                      && ($attribute_local_name != RDF_PARSE_TYPE_LITERAL)   
  979.                      && ($attribute_local_name != RDF_PARSE_TYPE_RESOURCE)
  980.                      && ($attribute_local_name != RDF_LI)
  981.                      && ($attribute_local_name != RDF_SUBJECT)
  982.                      && ($attribute_local_name != RDF_PREDICATE)
  983.                      && ($attribute_local_name != RDF_OBJECT)
  984.                      && ($attribute_local_name != RDF_NODEID)
  985.                      && ($attribute_local_name != RDF_DATATYPE)
  986.                      && ($attribute_local_name != RDF_SEEALSO)
  987.                      && ($attribute_local_name != RDF_NIL)
  988.                      && ($attribute_local_name != RDF_REST)
  989.                      && ($attribute_local_name != RDF_FIRST)
  990.                     
  991.             {
  992.                 $this->_report_statement(
  993.                     $subject_type,
  994.                     $subject,
  995.                     $predicate,
  996.                     0,
  997.                     RDF_OBJECT_TYPE_LITERAL,
  998.                     $attribute_value,
  999.                     $xml_lang,
  1000.                     $bag_id,
  1001.                     $statements,
  1002.                     '',
  1003.                     '' );
  1004.             }         
  1005.         }
  1006.         else ifXML_NAMESPACE_URI == $attribute_namespace_uri )
  1007.         {
  1008.             if ($attribute_local_name == 'base')
  1009.             {
  1010.                 $this->rdf_parser['top']['element_base_uri'$attribute_value;
  1011.             }              
  1012.         }
  1013.         else if$attribute_namespace_uri )
  1014.         {
  1015.             // is it required that property attributes be in an explicit namespace?
  1016.  
  1017.             $this->_report_statement(
  1018.                 $subject_type,
  1019.                 $subject,
  1020.                 $predicate,
  1021.                 0,
  1022.                 RDF_OBJECT_TYPE_LITERAL,
  1023.                 $attribute_value,
  1024.                 $xml_lang,
  1025.                 $bag_id,
  1026.                 $statements,
  1027.                 '',
  1028.                 '' );
  1029.         }
  1030.     }
  1031. }
  1032.  
  1033.  
  1034.  
  1035. /**
  1036.    * @param string $warning 
  1037.  * @access    private
  1038. */ 
  1039. function _report_warning($warning)
  1040. {
  1041.     $errmsg RDFAPI_ERROR '(class: parser): ' $warning .'.';
  1042.     trigger_error($errmsgE_USER_WARNING)
  1043. }
  1044.  
  1045.  
  1046. function _report_error($error)
  1047. {
  1048.     $errmsg RDFAPI_ERROR '(class: parser): ' $error .'.';
  1049.     trigger_error($errmsgE_USER_ERROR)
  1050. }
  1051.  
  1052.  
  1053. /**
  1054.    * @param string $namespace_uri 
  1055.    * @param string $local_name 
  1056.    * @param string $attributes 
  1057.    * @param string $parent 
  1058.  * @access    private
  1059. */ 
  1060. function _handle_resource_element$namespace_uri$local_name$attributes$parent )
  1061. {
  1062.     $subjects_found 0;
  1063.     $aux=$attributes;
  1064.     $aux2=Array();
  1065.     foreach($attributes as $atkey=>$atvalue{
  1066.       $aux2[]=$atkey;
  1067.       $aux2[]=$atvalue;
  1068.     }
  1069.     $attributes=$aux2;
  1070.     $id '';
  1071.     $about '';
  1072.  
  1073.     $bag_id '';
  1074.     $node_id '';
  1075.     $datatype '';
  1076.  
  1077.     $i=0;
  1078.  
  1079.     $attribute='';
  1080.  
  1081.     $attribute_namespace_uri='';
  1082.     $attribute_local_name='';
  1083.     $attribute_value='';
  1084.  
  1085.     $id_buffer='';
  1086.  
  1087.     $type='';
  1088.  
  1089.     $this->rdf_parser['top']['has_property_attributes'false;
  1090.     $this->rdf_parser['top']['has_member_attributes'false;
  1091.  
  1092.     
  1093.     if$namespace_uri == RDF_NAMESPACE_URI )
  1094.     {
  1095.        if$this->_is_rdf_node_element$local_name ) )
  1096.        {           
  1097.           $msg 'unknown or out of context rdf node element: '.$local_name;    
  1098.           
  1099.           if ($this->_is_forbidden_rdf_node_element($local_name))
  1100.                $this->_report_error($msg);
  1101.           else 
  1102.                $this->_report_warning($msg);                  
  1103.        }             
  1104.     }
  1105.  
  1106.     // examine each attribute for the standard RDF "keywords"
  1107.     for$i 0isset($attributes[$i])$i += )
  1108.     {
  1109.         $this->_split_name(
  1110.             $attributes$i ],
  1111.             $attribute,
  1112.             $attribute_namespace_uri,
  1113.             $attribute_local_name );
  1114.  
  1115.         $attribute_value $attributes$i ];
  1116.  
  1117.         // if the attribute is not in any namespace
  1118.         //   or the attribute is in the RDF namespace
  1119.         if( ( $attribute_namespace_uri == '' )
  1120.             || (  $attribute_namespace_uri == RDF_NAMESPACE_URI  ))
  1121.         {
  1122.             if$attribute_local_name == RDF_ID )
  1123.             {
  1124.                 $id $attribute_value;
  1125.                 ++$subjects_found;
  1126.             else if$attribute_local_name == RDF_ABOUT {
  1127.                 $about '_'.$attribute_value;            
  1128.                 ++$subjects_found;
  1129.             else if$attribute_local_name == RDF_NODEID{
  1130.                 $node_id $attribute_value;
  1131.                 ++$subjects_found;
  1132.             else if(  $attribute_local_name == RDF_ABOUT_EACH {
  1133.                 $error 'aboutEach has been removed from the RDF specifications';
  1134.                 $this->_report_error($error);               
  1135.             else if$attribute_local_name == RDF_ABOUT_EACH_PREFIX {
  1136.                 $error 'aboutEachPrefix has been removed from the RDF specifications';
  1137.                 $this->_report_error($error);
  1138.             else if$attribute_local_name == RDF_BAG_ID{
  1139.                 $bag_id $attribute_value;
  1140.             else if$attribute_local_name == RDF_DATATYPE{
  1141.                 $datatype $attribute_value;
  1142.             else if$this->_is_rdf_property_attribute$attribute_local_name )) {
  1143.                 $this->rdf_parser['top']['has_property_attributes'true;
  1144.             else if$this->_is_rdf_ordinal$attribute_local_name )) {
  1145.                 $this->rdf_parser['top']['has_property_attributes'true;
  1146.                 $this->rdf_parser['top']['has_member_attributes'true;
  1147.             else {
  1148.                 $this->rdf_parser['top']['has_property_attributes'true;
  1149.                 $msg 'unknown or out of context rdf attribute: '.$attribute_local_name;    
  1150.           
  1151.                   if ($this->_is_forbidden_rdf_property_attribute($attribute_local_name))
  1152.                       $this->_report_error($msg);
  1153.                   else 
  1154.                       $this->_report_warning($msg);            
  1155.             }
  1156.         }
  1157.         else if(  $attribute_namespace_uri == XML_NAMESPACE_URI )
  1158.         {
  1159.             if$attribute_local_name == XML_LANG )
  1160.             {
  1161.                 $this->rdf_parser['top']['xml_lang'$attribute_value;
  1162.             }
  1163.             elseif ($attribute_local_name == 'base')
  1164.             {
  1165.                 $this->rdf_parser['top']['element_base_uri'$attribute_value;
  1166.             }                         
  1167.         }
  1168.         else if$attribute_namespace_uri )
  1169.         {
  1170.             $this->rdf_parser['top']['has_property_attributes'true;
  1171.         }
  1172.     }
  1173.  
  1174.     // if no subjects were found, generate one.
  1175.     if$subjects_found == )
  1176.     {
  1177.         $this->_generate_anonymous_uri$id_buffer );
  1178.         $this->rdf_parser['top']['subject']=$id_buffer;
  1179.         $this->rdf_parser['top']['subject_type'RDF_SUBJECT_TYPE_BNODE;
  1180.     }
  1181.     else if$subjects_found )
  1182.     {
  1183.          $this->_report_error('ID, about and nodeID are mutually exclusive');      
  1184.     }
  1185.     else if$id )
  1186.     {
  1187.         $this->_resolve_id$id$id_buffer );
  1188.         $this->rdf_parser['top']['subject_type'RDF_SUBJECT_TYPE_URI;
  1189.         $this->rdf_parser['top']['subject']=$id_buffer;
  1190.     }
  1191.     else if$about )
  1192.     {       
  1193.         $this->_resolve_uri_reference$this->rdf_get_base()substr($about,1)$id_buffer );        
  1194.         $this->rdf_parser['top']['subject_type'RDF_SUBJECT_TYPE_URI;
  1195.         $this->rdf_parser['top']['subject']=$id_buffer;
  1196.     }       
  1197.     else if$node_id )
  1198.     {
  1199.         $this->is_valid_id($node_id);
  1200.         $this->rdf_parser['top']['subject_type'RDF_SUBJECT_TYPE_BNODE;
  1201.         $this->rdf_parser['top']['subject']=$node_id;
  1202.     }
  1203.     
  1204.     // if the subject is empty, assign it the document uri
  1205.     if$this->rdf_parser['top']['subject'== '' )
  1206.     {
  1207.         $this->rdf_parser['top']['subject']=$this->rdf_get_base();                
  1208.     }
  1209.  
  1210.     if$bag_id )
  1211.     {
  1212.         $this->_resolve_id$bag_id$id_buffer );
  1213.         $this->rdf_parser['top']['bag_id']=$id_buffer;
  1214.     }
  1215.  
  1216.     // only report the type for non-rdf:Description elements.
  1217.     if( ($local_name != RDF_DESCRIPTION )
  1218.         || $namespace_uri != RDF_NAMESPACE_URI ) )
  1219.     {
  1220.         $type=$namespace_uri;
  1221.         $type.=$local_name;
  1222.  
  1223.         $this->_report_statement(
  1224.             $this->rdf_parser['top']['subject_type'],
  1225.             $this->rdf_parser['top']['subject'],
  1226.             RDF_NAMESPACE_URI.RDF_TYPE,
  1227.             0,
  1228.             RDF_OBJECT_TYPE_RESOURCE,
  1229.             $type,
  1230.             '',
  1231.             $this->rdf_parser['top']['bag_id'],
  1232.             $this->rdf_parser['top']['statements'],
  1233.             ''
  1234.             $datatype);
  1235.  
  1236.     }
  1237.  
  1238.     // if this element is the child of some property,
  1239.     //   report the appropriate statement.
  1240.     if$parent )
  1241.     {
  1242.         if ($this->rdf_parser['top']['subject_type'== RDF_SUBJECT_TYPE_BNODE)
  1243.             $objtype RDF_OBJECT_TYPE_BNODE
  1244.         else
  1245.             $objtype RDF_OBJECT_TYPE_RESOURCE;       
  1246.         
  1247.         $this->_report_statement(
  1248.             $parent['parent']['subject_type'],
  1249.             $parent['parent']['subject'],
  1250.             $parent['predicate'],
  1251.             $parent['ordinal'],
  1252.             $objtype,
  1253.             $this->rdf_parser['top']['subject'],
  1254.             '',
  1255.             $parent['parent']['bag_id'],
  1256.             $parent['parent']['statements'],
  1257.             $parent['statement_id']
  1258.             $parent['datatype']);
  1259.  
  1260.     }
  1261.  
  1262.     if$this->rdf_parser['top']['has_property_attributes')
  1263.     {
  1264.         $this->_handle_property_attributes(
  1265.             $this->rdf_parser['top']['subject_type'],
  1266.             $this->rdf_parser['top']['subject'],
  1267.             $attributes,
  1268.             $this->rdf_parser['top']['xml_lang'],
  1269.             $this->rdf_parser['top']['bag_id'],
  1270.             $this->rdf_parser['top']['statements');
  1271.     }
  1272. }
  1273.  
  1274. /**
  1275.    * @param string &$namespace_uri 
  1276.    * @param string &$local_name 
  1277.    * @param string &$attributes 
  1278.  * @access    private
  1279. */ 
  1280. function _handle_property_element&$namespace_uri&$local_name&$attributes )
  1281. {
  1282.     $buffer='';
  1283.  
  1284.     $i=0;
  1285.  
  1286.     $aux=$attributes;
  1287.     $aux2=Array();
  1288.     foreach($attributes as $atkey=>$atvalue{
  1289.       $aux2[]=$atkey;
  1290.       $aux2[]=$atvalue;
  1291.     }
  1292.     $attributes=$aux2;
  1293.  
  1294.     $attribute_namespace_uri='';
  1295.     $attribute_local_name='';
  1296.     $attribute_value '';
  1297.  
  1298.     $resource NULL;
  1299.     $statement_id '';
  1300.     $bag_id '';
  1301.     $parse_type '';
  1302.     $node_id '';
  1303.     $datatype ''
  1304.  
  1305.     $this->rdf_parser['top']['ordinal'0;
  1306.  
  1307.     if$namespace_uri == RDF_NAMESPACE_URI )
  1308.     {
  1309.        if$this->_is_rdf_property_element$local_name ) )
  1310.         {
  1311.             $msg 'unknown or out of context rdf property element: '.$local_name;    
  1312.           
  1313.               if ($this->_is_forbidden_rdf_property_element($local_name))
  1314.                   $this->_report_error($msg);
  1315.               else 
  1316.                   $this->_report_warning($msg);
  1317.         }
  1318.              
  1319.     }
  1320.  
  1321.     $buffer=$namespace_uri;
  1322.  
  1323.     if( ( $namespace_uri == RDF_NAMESPACE_URI )
  1324.         &&  $local_name == RDF_LI ) )
  1325.     {
  1326.         $this->rdf_parser['top']['parent']['members']++;
  1327.         $this->rdf_parser['top']['ordinal'$this->rdf_parser['top']['parent']['members'];
  1328.  
  1329.         $this->rdf_parser['top']['ordinal']=$this->rdf_parser['top']['ordinal'];
  1330.  
  1331.         $buffer.='_'.$this->rdf_parser['top']['ordinal'];
  1332.         
  1333.     }
  1334.     else
  1335.     {
  1336.         $buffer.=$local_name;
  1337.     }
  1338.  
  1339.     $this->rdf_parser['top']['predicate']=$buffer;
  1340.  
  1341.     $this->rdf_parser['top']['has_property_attributes'false;
  1342.     $this->rdf_parser['top']['has_member_attributes'false;
  1343.  
  1344.           
  1345.     for$i 0isset($attributes[$i])$i += )
  1346.     {
  1347.         $this->_split_name(
  1348.             $attributes[$i],
  1349.             $buffer,
  1350.             $attribute_namespace_uri,
  1351.             $attribute_local_name );
  1352.  
  1353.         $attribute_value $attributes[$i 1];
  1354.  
  1355.         // if the attribute is not in any namespace
  1356.         //   or the attribute is in the RDF namespace
  1357.         if( ( $attribute_namespace_uri == '' )
  1358.             || (  $attribute_namespace_uri == RDF_NAMESPACE_URI ) )
  1359.         {
  1360.             if( ( $attribute_local_name == RDF_ID )  )
  1361.             {
  1362.                 $statement_id $attribute_value;                               
  1363.             }
  1364.             else if$attribute_local_name == RDF_PARSE_TYPE )
  1365.             {               
  1366.                 $parse_type $attribute_value;
  1367.             }
  1368.             else if(  $attribute_local_name == RDF_RESOURCE )
  1369.             {
  1370.                 $resource $attribute_value;                                
  1371.             }
  1372.             else if(  $attribute_local_name == RDF_NODEID )
  1373.             {                                
  1374.                 $node_id $attribute_value;        
  1375.             }
  1376.             else if(  $attribute_local_name == RDF_BAG_ID )
  1377.             {
  1378.                 $bag_id $attribute_value;
  1379.             }
  1380.             else if(  $attribute_local_name == RDF_DATATYPE )
  1381.             {
  1382.                 $datatype $attribute_value;
  1383.                 $this->rdf_parser['top']['datatype'$attribute_value;
  1384.             }
  1385.             else if$this->_is_rdf_property_attribute$attribute_local_name ) )
  1386.             {
  1387.                 $this->rdf_parser['top']['has_property_attributes'true;
  1388.             }
  1389.             else
  1390.             {
  1391.                 $this->_report_warning('unknown rdf attribute: '.$attribute_local_name );
  1392.                 return;
  1393.             }            
  1394.         }
  1395.         else if(  $attribute_namespace_uri == XML_NAMESPACE_URI  )
  1396.         {
  1397.             if$attribute_local_name == XML_LANG  )
  1398.             {
  1399.                 $this->rdf_parser['top']['xml_lang'$attribute_value;
  1400.             }
  1401.             elseif ($attribute_local_name == 'base')
  1402.             {
  1403.                 $this->rdf_parser['top']['element_base_uri'$attribute_value;
  1404.             }                         
  1405.         }
  1406.         else if$attribute_namespace_uri )
  1407.         {
  1408.             $this->rdf_parser['top']['has_property_attributes'true;
  1409.         }
  1410.     }    
  1411.  
  1412.     if$statement_id )
  1413.     {
  1414.         $this->_resolve_id($statement_id$buffer );
  1415.         $this->rdf_parser['top']['statement_id']=$buffer;
  1416.     }
  1417.     
  1418.     if ($node_id)
  1419.     {
  1420.         $this->is_valid_id($node_id);
  1421.         
  1422.         if ($resource)
  1423.         {
  1424.             $this->_report_error('nodeID and resource are mutually exclusive');
  1425.         }                
  1426.            if ($statement_id
  1427.            {
  1428.                // reify statement
  1429.                $this->_report_statement(
  1430.                 $this->rdf_parser['top']['parent']['subject_type'],
  1431.                 $this->rdf_parser['top']['parent']['subject'],
  1432.                 $this->rdf_parser['top']['predicate'],
  1433.                 $this->rdf_parser['top']['ordinal'],
  1434.                 RDF_OBJECT_TYPE_BNODE
  1435.                 $node_id
  1436.                 '',
  1437.                 $this->rdf_parser['top']['parent']['bag_id'],
  1438.                 $this->rdf_parser['top']['parent']['statements'],
  1439.                 $this->rdf_parser['top']['statement_id']
  1440.                 '')
  1441.             $statement_id '';         
  1442.            
  1443.            else 
  1444.            {                             
  1445.             $this->_report_statement(
  1446.                $this->rdf_parser['top']['parent']['subject_type'],
  1447.                $this->rdf_parser['top']['parent']['subject'],
  1448.                $this->rdf_parser['top']['predicate'],
  1449.                $this->rdf_parser['top']['ordinal'],
  1450.                RDF_OBJECT_TYPE_BNODE,
  1451.                $node_id,
  1452.                '',
  1453.                $this->rdf_parser['top']['parent']['bag_id'],
  1454.                $this->rdf_parser['top']['parent']['statements'],
  1455.                '',
  1456.                $datatype );    
  1457.            }    
  1458.            
  1459.            $this->rdf_parser['top']['state'IN_PROPERTY_EMPTY_RESOURCE;      
  1460.     }
  1461.     
  1462.     if$parse_type )
  1463.     {
  1464.         if$resource {
  1465.             $this->_report_error('property elements with rdf:parseType do not allow rdf:resource' );
  1466.         }
  1467.  
  1468.         if$bag_id {
  1469.             $this->_report_warning('property elements with rdf:parseType do not allow rdf:bagID' );
  1470.             return;
  1471.         }
  1472.  
  1473.         if$this->rdf_parser['top']['has_property_attributes')
  1474.         {
  1475.                 $this->_report_error('property elements with rdf:parseType do not allow property attributes');
  1476.             return;
  1477.         }
  1478.                 
  1479.         if(  $attribute_value == RDF_PARSE_TYPE_RESOURCE )
  1480.         {
  1481.             $this->_generate_anonymous_uri$buffer );
  1482.             // since we are sure that this is now a resource property we can report it
  1483.             $this->_report_statement(
  1484.                 $this->rdf_parser['top']['parent']['subject_type'],
  1485.                 $this->rdf_parser['top']['parent']['subject'],
  1486.                 $this->rdf_parser['top']['predicate'],
  1487.                 0,
  1488.                 RDF_OBJECT_TYPE_BNODE,
  1489.                 $buffer,
  1490.                 '',
  1491.                 $this->rdf_parser['top']['parent']['bag_id'],
  1492.                 $this->rdf_parser['top']['parent']['statements'],
  1493.                 $this->rdf_parser['top']['statement_id'],
  1494.                 $datatype );
  1495.  
  1496.             $this->_push_element);
  1497.  
  1498.             $this->rdf_parser['top']['state'IN_PROPERTY_PARSE_TYPE_RESOURCE;
  1499.             $this->rdf_parser['top']['subject_type'RDF_SUBJECT_TYPE_BNODE;
  1500.             $this->rdf_parser['top']['subject']=$buffer;
  1501.             $this->rdf_parser['top']['bag_id']='';
  1502.             $this->rdf_parser['top']['datatype']$datatype;
  1503.             
  1504.         }     
  1505.            elseif (  $attribute_value == RDF_PARSE_TYPE_LITERAL )
  1506.            {
  1507.                $this->rdf_parser['top']['state'IN_PROPERTY_PARSE_TYPE_LITERAL;
  1508.                $this->rdf_parser['top']['datatype']RDF_NAMESPACE_URI .RDF_XMLLITERAL;
  1509.                $this->rdf_parser['xml_literal']['buffer''';       
  1510.                $this->rdf_parser['xml_literal']['depth'0;        
  1511.            }
  1512.         elseif ($attribute_value == RDF_PARSE_TYPE_COLLECTION)        
  1513.         {
  1514.             $this->_generate_anonymous_uri$buffer );            
  1515.             $this->_report_statement(
  1516.                 $this->rdf_parser['top']['parent']['subject_type'],
  1517.                 $this->rdf_parser['top']['parent']['subject'],
  1518.                 $this->rdf_parser['top']['predicate'],
  1519.                 0,
  1520.                 RDF_OBJECT_TYPE_BNODE,
  1521.                 $buffer,
  1522.                 '',
  1523.                 $this->rdf_parser['top']['parent']['bag_id'],
  1524.                 $this->rdf_parser['top']['parent']['statements'],
  1525.                 $this->rdf_parser['top']['statement_id'],
  1526.                 $datatype );
  1527.                 
  1528.             $this->rdf_parser['top']['state'IN_PROPERTY_PARSE_TYPE_COLLECTION;
  1529.             $this->rdf_parser['top']['collection']['first_blank_node_id'$buffer;
  1530.         }      
  1531.        
  1532.         else
  1533.         {
  1534.                    
  1535.             $this->_report_statement(
  1536.                 $this->rdf_parser['top']['parent']['subject_type'],
  1537.                 $this->rdf_parser['top']['parent']['subject'],
  1538.                 $this->rdf_parser['top']['predicate'],
  1539.                 0,
  1540.                 RDF_OBJECT_TYPE_XML,
  1541.                 '',
  1542.                 '',
  1543.                 $this->rdf_parser['top']['parent']['bag_id'],
  1544.                 $this->rdf_parser['top']['parent']['statements'],
  1545.                 $this->rdf_parser['top']['statement_id'],
  1546.                 $datatype );
  1547.  
  1548.             $this->rdf_parser['top']['state'IN_PROPERTY_PARSE_TYPE_LITERAL;
  1549.         }
  1550.     }
  1551.     else if$resource !== NULL || $bag_id || $this->rdf_parser['top']['has_property_attributes')
  1552.         {
  1553.         if$resource !== NULL )
  1554.         {
  1555.             $subject_type RDF_SUBJECT_TYPE_URI;
  1556.             $this->_resolve_uri_reference$this->rdf_get_base()$resource$buffer );
  1557.             $object_type=RDF_OBJECT_TYPE_RESOURCE;
  1558.         }
  1559.         else
  1560.         {
  1561.             $subject_type RDF_SUBJECT_TYPE_BNODE;
  1562.             $this->_generate_anonymous_uri$buffer );
  1563.             $object_type=RDF_OBJECT_TYPE_BNODE;
  1564.         }
  1565.         $this->rdf_parser['top']['state'IN_PROPERTY_EMPTY_RESOURCE;
  1566.  
  1567.         // since we are sure that this is now a resource property we can report it.
  1568.         $this->_report_statement(
  1569.             $this->rdf_parser['top']['parent']['subject_type'],
  1570.             $this->rdf_parser['top']['parent']['subject'],
  1571.             $this->rdf_parser['top']['predicate'],
  1572.             $this->rdf_parser['top']['ordinal'],
  1573.             $object_type,
  1574.             $buffer,
  1575.             '',
  1576.             $this->rdf_parser['top']['parent']['bag_id'],
  1577.             $this->rdf_parser['top']['parent']['statements'],
  1578.             $this->rdf_parser['top']['statement_id'],
  1579.             $datatype )// should we allow IDs?
  1580.             
  1581.         if$bag_id )
  1582.         {
  1583.             $this->_resolve_id$bag_id$buffer );
  1584.             $this->rdf_parser['top']['bag_id']=$buffer;            
  1585.         }
  1586.  
  1587.         if$this->rdf_parser['top']['has_property_attributes')
  1588.         {
  1589.             $this->_handle_property_attributes(
  1590.                 $subject_type,
  1591.                 $buffer,
  1592.                 $attributes,
  1593.                 $this->rdf_parser['top']['xml_lang'],
  1594.                 $this->rdf_parser['top']['bag_id'],
  1595.                 $this->rdf_parser['top']['statements');                
  1596.         }
  1597.     
  1598. }
  1599.        
  1600. /**
  1601.    * @param string &$namespace_uri 
  1602.    * @param string &$local_name 
  1603.    * @param string &$attributes 
  1604.    * @access    private
  1605. */ 
  1606. function _handle_collection_element(&$namespace_uri&$local_name&$attributes)
  1607. {
  1608.     $aux2=Array();
  1609.     foreach($attributes as $atkey=>$atvalue{
  1610.       $aux2[]=$atkey;
  1611.       $aux2[]=$atvalue;
  1612.     }
  1613.     $attributes=$aux2;
  1614. /* collection construction site
  1615. // old:    
  1616.     if (   ($namespace_uri == RDF_NAMESPACE_URI || $namespace_uri == '')
  1617.         && ($local_name == RDF_DESCRIPTION || $local_name == RDF_LI) )
  1618.     {
  1619.         for( $i = 0; isset($attributes[$i]); $i += 2 )
  1620.         {
  1621.             $this->_split_name(
  1622.                 $attributes[ $i ],
  1623.                 $attribute,
  1624.                 $attribute_namespace_uri,
  1625.                 $attribute_local_name );
  1626.  
  1627.             $attribute_value = $attributes[ $i + 1 ];
  1628.             
  1629.             if( $attribute_namespace_uri == '' || $attribute_namespace_uri == RDF_NAMESPACE_URI  )
  1630.             {
  1631.                 if( $attribute_local_name == RDF_ABOUT || 
  1632.                     $attribute_local_name == RDF_RESOURCE) 
  1633.                 {
  1634.                     $this->rdf_parser['top']['parent']['collection']['object_type'][] = RDF_OBJECT_TYPE_RESOURCE;                    
  1635.                 }
  1636.                 elseif ( $attribute_local_name == RDF_NODEID ) {
  1637.                     $this->rdf_parser['top']['parent']['collection']['object_type'][] = RDF_OBJECT_TYPE_BNODE;
  1638.                 }
  1639.                 $this->rdf_parser['top']['parent']['collection']['object_label'][] = $attribute_value;
  1640.             }
  1641.         }
  1642.     }
  1643. */
  1644. // new
  1645.  
  1646.         for$i 0isset($attributes[$i])$i += )
  1647.         {
  1648.             $this->_split_name(
  1649.                 $attributes$i ],
  1650.                 $attribute,
  1651.                 $attribute_namespace_uri,
  1652.                 $attribute_local_name );
  1653.  
  1654.             $attribute_value $attributes$i ];
  1655.             
  1656.             if$attribute_namespace_uri == '' || $attribute_namespace_uri == RDF_NAMESPACE_URI  )
  1657.             {
  1658.                 $tmp_subject_type RDF_SUBJECT_TYPE_URI;
  1659.                 if$attribute_local_name == RDF_ABOUT || 
  1660.                     $attribute_local_name == RDF_RESOURCE
  1661.                 {
  1662.                     $this->rdf_parser['top']['parent']['collection']['object_type'][RDF_OBJECT_TYPE_RESOURCE;                                        
  1663.                 }
  1664.                 elseif $attribute_local_name == RDF_NODEID {
  1665.                     $this->rdf_parser['top']['parent']['collection']['object_type'][RDF_OBJECT_TYPE_BNODE;
  1666.                     $tmp_subject_type RDF_SUBJECT_TYPE_BNODE;
  1667.                 }
  1668.                 $id_buffer '';
  1669.                 $this->_resolve_uri_reference$this->rdf_get_base()$attribute_value$id_buffer );        
  1670.                 $this->rdf_parser['top']['parent']['collection']['object_label'][$id_buffer;
  1671.                 
  1672.                    if (!(   ($namespace_uri == RDF_NAMESPACE_URI || $namespace_uri == '')
  1673.                        && ($local_name == RDF_DESCRIPTION || $local_name == RDF_LI) ))
  1674.                    {                
  1675.                       $this->_report_statement(
  1676.                             $tmp_subject_type,
  1677.                             $id_buffer,                            
  1678.                             RDF_NAMESPACE_URI.RDF_TYPE,                                                    
  1679.                             '',
  1680.                             RDF_OBJECT_TYPE_RESOURCE,
  1681.                             $namespace_uri.$local_name,
  1682.                             '',
  1683.                             '',
  1684.                             '',
  1685.                             '',
  1686.                             '');
  1687.                    }
  1688.             }
  1689.         }
  1690.  
  1691.  
  1692. // collection construction site    
  1693. }
  1694.  
  1695. /**
  1696.    * @param string &$namespace_uri 
  1697.    * @param string &$local_name 
  1698.    * @param string &$attributes 
  1699.    * @access    private
  1700. */ 
  1701. function _handle_xml_start_element(&$namespace_uri&$local_name&$attributes)
  1702. {
  1703.     $aux2=Array();
  1704.     foreach($attributes as $atkey=>$atvalue{
  1705.       $aux2[]=$atkey;
  1706.       $aux2[]=$atvalue;
  1707.     }
  1708.     $attributes=$aux2;
  1709.     
  1710.     $element '<' .$this->_join_name_and_declare_prefix($namespace_uri$local_name);        
  1711.     
  1712.     for$i 0isset($attributes[$i])$i += )
  1713.         {
  1714.             $this->_split_name(
  1715.                 $attributes$i ],
  1716.                 $attribute,
  1717.                 $attribute_namespace_uri,
  1718.                 $attribute_local_name );
  1719.  
  1720.             $attribute_value $attributes$i ];
  1721.  
  1722.             $element .= ' ' .$this->_join_name_and_declare_prefix($attribute_namespace_uri$attribute_local_name);
  1723.             $element .= '=\"' .$attribute_value .'\"';     
  1724.         }
  1725.     $element .= '>';
  1726.     
  1727.     $this->rdf_parser['xml_literal']['buffer'.= $element;
  1728. }
  1729.  
  1730. /**
  1731.    * @param string $name 
  1732.    * @access    private
  1733. */ 
  1734. function _handle_xml_end_element($name)
  1735. {
  1736.     $buffer='';
  1737.     $namespace_uri='';
  1738.     $local_name='';
  1739.     
  1740.     $this->_split_name(
  1741.         $name,
  1742.            $buffer,
  1743.            $namespace_uri,
  1744.            $local_name );
  1745.         
  1746.     $element '</';    
  1747.             
  1748.     if ($namespace_uri && isset($this->rdf_parser['default_namespace']
  1749.         &&$namespace_uri != $this->rdf_parser['default_namespace'])
  1750.     {
  1751.          $element .= $this->rdf_parser['namespaces'][$namespace_uri.':';                 
  1752.     }
  1753.         
  1754.     $element .= $local_name .'>';
  1755.         
  1756.     $this->rdf_parser['xml_literal']['buffer'.= $element
  1757.     $depth $this->rdf_parser['xml_literal']['depth']--;
  1758.         
  1759.     if (isset($this->rdf_parser['xml_literal']['declared_ns']))
  1760.           foreach ($this->rdf_parser['xml_literal']['declared_ns'as $prefix => $_depth)
  1761.     {
  1762.         if ($depth == $_depth)
  1763.             unset($this->rdf_parser['xml_literal']['declared_ns'][$prefix]);
  1764.     }
  1765. }
  1766.  
  1767. /**
  1768.    * @param string $namespace_uri 
  1769.    * @param string $local_name 
  1770.    * @access    private
  1771. */ 
  1772. function _join_name_and_declare_prefix($namespace_uri$local_name{
  1773.     
  1774.     $name '';
  1775.     
  1776.     if ($namespace_uri)
  1777.     {                
  1778.         if (isset($this->rdf_parser['default_namespace'])
  1779.             && $namespace_uri == $this->rdf_parser['default_namespace'])
  1780.         {    
  1781.             $name .= $local_name;
  1782.                     
  1783.             if (!isset($this->rdf_parser['xml_literal']['declared_ns']['_DEFAULT_'])
  1784.                 && $namespace_uri != XML_NAMESPACE_URI)
  1785.             {
  1786.                 $name .= ' xmlns=' '\"' .$namespace_uri .'\"';
  1787.                 
  1788.                 $this->rdf_parser['xml_literal']['declared_ns']['_DEFAULT_'
  1789.                     = $this->rdf_parser['xml_literal']['depth'];
  1790.             }
  1791.         }
  1792.         else
  1793.         {
  1794.             $ns_prefix $this->rdf_parser['namespaces'][$namespace_uri]
  1795.             $name .= $ns_prefix .':' .$local_name;                 
  1796.         
  1797.             if (!isset($this->rdf_parser['xml_literal']['declared_ns'][$ns_prefix])
  1798.                 && $namespace_uri != XML_NAMESPACE_URI)
  1799.             {
  1800.                 $name .= " xmlns:$ns_prefix='\"' .$namespace_uri .'\"';
  1801.                 
  1802.                 $this->rdf_parser['xml_literal']['declared_ns'][$ns_prefix
  1803.                     = $this->rdf_parser['xml_literal']['depth'];
  1804.             }
  1805.         }
  1806.             
  1807.     }
  1808.     else
  1809.         $name .= $local_name;
  1810.     
  1811.     return $name;
  1812.     
  1813. }
  1814.  
  1815. /**
  1816.   * @access    private
  1817. */ 
  1818. function _end_collection({
  1819.     
  1820.     if (isset($this->rdf_parser['top']['collection']))
  1821.     {            
  1822.                 
  1823.         $subject $this->rdf_parser['top']['collection']['first_blank_node_id'];
  1824.             
  1825.         for ($i=0isset($this->rdf_parser['top']['collection']['object_label'][$i])$i++
  1826.         {            
  1827.                         
  1828.             $this->_report_statement(
  1829.                 RDF_SUBJECT_TYPE_BNODE
  1830.                 $subject,
  1831.                 RDF_NAMESPACE_URI.RDF_FIRST,
  1832.                 '',
  1833.                 $this->rdf_parser['top']['collection']['object_type'][$i],
  1834.                 $this->rdf_parser['top']['collection']['object_label'][$i],
  1835.                 '',
  1836.                 '',
  1837.                 '',
  1838.                 '',
  1839.                 '');
  1840.  
  1841.             if (!isset($this->rdf_parser['top']['collection']['object_label'][$i+1]))
  1842.             {
  1843.                 $obj_type_2 RDF_OBJECT_TYPE_RESOURCE;
  1844.                 $object_2 RDF_NAMESPACE_URI.RDF_NIL;                
  1845.             }
  1846.             else     
  1847.             {
  1848.                 $obj_type_2RDF_OBJECT_TYPE_BNODE;
  1849.                 $this->_generate_anonymous_uri($object_2);
  1850.             }                
  1851.                 
  1852.                 
  1853.             $this->_report_statement(
  1854.                 RDF_SUBJECT_TYPE_BNODE
  1855.                 $subject,
  1856.                 RDF_NAMESPACE_URI.RDF_REST,
  1857.                 '',
  1858.                 $obj_type_2,
  1859.                 $object_2,
  1860.                 '',
  1861.                 '',
  1862.                 '',
  1863.                 '',
  1864.                 '');    
  1865.  
  1866.             $subject $object_2;        
  1867.         }        
  1868.     }
  1869. }
  1870.  
  1871. /**
  1872.    * @param string $parser 
  1873.    * @param string $name 
  1874.    * @param string $attributes 
  1875.    * @access    private
  1876. */ 
  1877. function _start_element_handler($parser$name$attributes )
  1878. {
  1879.     $buffer='';
  1880.  
  1881.     $namespace_uri='';
  1882.     $local_name='';
  1883.  
  1884.     $this->_push_element();
  1885.  
  1886.  
  1887.     $this->_split_name(
  1888.         $name,
  1889.         $buffer,
  1890.         $namespace_uri,
  1891.         $local_name );
  1892.  
  1893.     switch$this->rdf_parser['top']['state')
  1894.     {
  1895.     case IN_TOP_LEVEL:
  1896.         // set base_uri, if possible 
  1897.         foreach ($attributes as $key => $value{
  1898.              if($key == XML_NAMESPACE_URI NAMESPACE_SEPARATOR_CHAR 'base'
  1899.                      $this->rdf_parser['base_uri'$value;
  1900.                     $this->rdf_parser['document_base_uri'$value;                                 
  1901.                     
  1902.                     $c substr($valuestrlen($value)-,1);
  1903.                     if (!($c=='#' || $c==':' || $c=='/' || $c=="\\"))
  1904.                          $this->rdf_parser['normalized_base_uri'$value '#';
  1905.                     else
  1906.                         $this->rdf_parser['normalized_base_uri'$value
  1907.                     
  1908.               }
  1909.               elseif ($key == XML_NAMESPACE_URI NAMESPACE_SEPARATOR_CHAR .'lang')
  1910.                   $this->rdf_parser['document_xml_lang'$value;
  1911. echo "";
  1912.         }
  1913.                       
  1914.             
  1915.         ifRDF_NAMESPACE_URI.NAMESPACE_SEPARATOR_STRING.RDF_RDF == $name )
  1916.         {            
  1917.             $this->rdf_parser['top']['state'IN_RDF;
  1918.  
  1919.             break;            
  1920.         }        
  1921.     case IN_RDF:
  1922.         $this->rdf_parser['top']['state'IN_DESCRIPTION;
  1923.         $this->_handle_resource_element$namespace_uri$local_name$attributes'' );
  1924.         break;
  1925.     case IN_DESCRIPTION:
  1926.          $this->rdf_parser['top']['state'IN_PROPERTY_UNKNOWN_OBJECT;
  1927.         $this->_handle_property_element$namespace_uri$local_name$attributes );
  1928.         break;
  1929.         $this->_handle_collection_element($namespace_uri$local_name$attributes);
  1930.         break;
  1931.         /* if we're in a property with an unknown object type and we encounter
  1932.            an element, the object must be a resource, */
  1933.         $this->rdf_parser['top']['data']='';
  1934.         $this->rdf_parser['top']['parent']['state'IN_PROPERTY_RESOURCE;
  1935.         $this->rdf_parser['top']['state'IN_DESCRIPTION;
  1936.         $this->_handle_resource_element(
  1937.             $namespace_uri,
  1938.             $local_name,
  1939.             $attributes,
  1940.             $this->rdf_parser['top']['parent');
  1941.         break;
  1942.     case IN_PROPERTY_LITERAL:
  1943.         $this->_report_warning'no markup allowed in literals' );
  1944.         break;
  1945.         $this->rdf_parser['top']['state'IN_XML;
  1946.         /* fall through */
  1947.     case IN_XML:
  1948.         $this->rdf_parser['xml_literal']['depth']++;
  1949.         $this->_handle_xml_start_element($namespace_uri$local_name$attributes);    
  1950.         break;
  1951.     case IN_PROPERTY_RESOURCE:
  1952.         $this->_report_warning(
  1953.                      'only one element allowed inside a property element' );
  1954.         break;
  1955.         $this->_report_warning(
  1956.                     'no content allowed in property with rdf:resource, rdf:bagID, or property attributes' );
  1957.         break;
  1958.     case IN_UNKNOWN:
  1959.         break;
  1960.     }
  1961. }
  1962.  
  1963. /**
  1964.     property elements with text only as content set the state to
  1965.     IN_PROPERTY_LITERAL. as character data is received from expat,
  1966.     it is saved in a buffer and reported when the end tag is
  1967.     received.
  1968.   * @access    private
  1969. */ 
  1970. function _end_literal_property()
  1971. {
  1972.     if(!isset($this->rdf_parser['top']['statement_id'])) {
  1973.       $this->rdf_parser['top']['statement_id']='';
  1974.     }
  1975.     if(!isset($this->rdf_parser['top']['parent']['subject_type'])) {
  1976.       $this->rdf_parser['top']['parent']['subject_type']='';
  1977.     }
  1978.     if(!isset($this->rdf_parser['top']['parent']['subject'])) {
  1979.       $this->rdf_parser['top']['parent']['subject']='';
  1980.     }
  1981.     if(!isset($this->rdf_parser['top']['parent']['bag_id'])) {
  1982.       $this->rdf_parser['top']['parent']['bag_id']='';
  1983.     }
  1984.     if(!isset($this->rdf_parser['top']['parent']['statements'])) {
  1985.       $this->rdf_parser['top']['parent']['statements']=0;
  1986.     }
  1987.     if(!isset($this->rdf_parser['top']['predicate'])) {
  1988.       $this->rdf_parser['top']['predicate']='';
  1989.     }
  1990.     if(!isset($this->rdf_parser['top']['datatype'])) {
  1991.       $this->rdf_parser['top']['datatype']='';
  1992.     }
  1993.     if(!isset($this->rdf_parser['top']['ordinal'])) {
  1994.       $this->rdf_parser['top']['ordinal']=0;
  1995.     }
  1996.     $this->_report_statement(
  1997.         $this->rdf_parser['top']['parent']['subject_type'],
  1998.         $this->rdf_parser['top']['parent']['subject'],
  1999.         $this->rdf_parser['top']['predicate'],
  2000.         $this->rdf_parser['top']['ordinal'],
  2001.         RDF_OBJECT_TYPE_LITERAL,
  2002.         $this->rdf_parser['top']['data'],
  2003.         $this->rdf_parser['top']['xml_lang'],
  2004.         $this->rdf_parser['top']['parent']['bag_id'],
  2005.         $this->rdf_parser['top']['parent']['statements'],
  2006.         $this->rdf_parser['top']['statement_id']
  2007.         $this->rdf_parser['top']['datatype']);
  2008.  
  2009. }
  2010.  
  2011. /**
  2012.    * @param string $parser 
  2013.    * @param string $name 
  2014.    * @access    private
  2015. */ 
  2016. function _end_element_handler$parser$name )
  2017. {
  2018.     switch$this->rdf_parser['top']['state')
  2019.     {
  2020.     case IN_TOP_LEVEL:
  2021.         break;     
  2022.     case IN_XML:
  2023.         $this->_handle_xml_end_element($name);                
  2024.         break;
  2025.     case IN_PROPERTY_UNKNOWN_OBJECT:        
  2026.     case IN_PROPERTY_LITERAL:
  2027.         $this->_end_literal_property);
  2028.         break;
  2029.         $this->_pop_element(  );
  2030.         break;
  2031. //        $search =  array((0) => chr(10), (1) => chr(13), (2) => chr(9));
  2032. //        $replace = array((0) => '\n'   , (1) => '\r'   , (2) => '\t');
  2033. //        $this->rdf_parser["xml_literal"]["buffer"] 
  2034. //            = str_replace($search, $replace, $this->rdf_parser["xml_literal"]["buffer"]);
  2035.  
  2036.         $this->rdf_parser['top']['data'$this->rdf_parser['xml_literal']['buffer'];
  2037.         $this->_end_literal_property();     
  2038.         $this->rdf_parser['xml_literal']['buffer''';    
  2039.        
  2040.         break;
  2041.         $this->_end_collection();
  2042.         break;      
  2043.     case IN_RDF:
  2044.     case IN_DESCRIPTION:
  2045.     case IN_PROPERTY_RESOURCE:
  2046.     case IN_UNKNOWN:
  2047.         break;
  2048.     }
  2049.  
  2050.     $this->_pop_element();
  2051. }
  2052.  
  2053. /**
  2054.    * @param string $parser 
  2055.    * @param string $s 
  2056.    * @access    private
  2057. */ 
  2058. function _character_data_handler$parser,$s)
  2059. {
  2060.     $len=strlen($s);
  2061.     switch$this->rdf_parser['top']['state')
  2062.     {
  2063.     case IN_PROPERTY_LITERAL:  
  2064.         ifisset($this->rdf_parser['top']['data']) )
  2065.         {
  2066.             $n strlen$this->rdf_parser['top']['data');
  2067.             $this->rdf_parser['top']['data'].= $s;
  2068.  
  2069.         }
  2070.         else
  2071.         {
  2072.             $this->rdf_parser['top']['data']=$s;
  2073.         }
  2074.  
  2075.         if$this->rdf_parser['top']['state'== IN_PROPERTY_UNKNOWN_OBJECT )
  2076.         {
  2077.             /* look for non-whitespace */
  2078.             for$i 0(( $i $len && (  ereg(" |\n|\t",$s$i }) ))$i++ );            
  2079.             /* if we found non-whitespace, this is a literal */
  2080.             if$i $len )
  2081.             {
  2082.                 $this->rdf_parser['top']['state'IN_PROPERTY_LITERAL;
  2083.             }
  2084.         }
  2085.  
  2086.         break;
  2087.     case IN_TOP_LEVEL:  
  2088.         break;
  2089.     case IN_PROPERTY_PARSE_TYPE_LITERAL:     
  2090.     case IN_XML:                 
  2091.         $this->rdf_parser['xml_literal']['buffer'.= $s;
  2092.         break;           
  2093.     case IN_RDF:
  2094.     case IN_DESCRIPTION:
  2095.     case IN_PROPERTY_RESOURCE:
  2096.     case IN_UNKNOWN:
  2097.         break;
  2098.     }
  2099. }
  2100.  
  2101.  
  2102.   /**
  2103.    * Adds a new statement to the model
  2104.    * This method is called by generateModel().
  2105.    *
  2106.    * @access    private
  2107.    * @param    string    &$user_data 
  2108.    * @param    string    $subject_type 
  2109.    * @param    string    $subject 
  2110.    * @param    string    $predicate 
  2111.    * @param    string    $ordinal 
  2112.    * @param    string    $object_type 
  2113.    * @param    string    $object 
  2114.    * @param    string    $xml_lang )
  2115.    * @return    object MemModel 
  2116.    */  
  2117. function add_statement_to_model(
  2118.     &$user_data,
  2119.     $subject_type,
  2120.     $subject,
  2121.     $predicate,
  2122.     $ordinal,
  2123.     $object_type,
  2124.     $object,
  2125.     $xml_lang,
  2126.     $datatype )
  2127. {
  2128.  
  2129.     // ParseUnicode
  2130.     if(UNIC_RDF){
  2131.         $subject=$this->str2unicode_nfc($subject);
  2132.         $predicate=$this->str2unicode_nfc($predicate);
  2133.         $object=$this->str2unicode_nfc($object);
  2134.     }
  2135.     
  2136.     //create subject
  2137.     if ($subject_type == RDF_SUBJECT_TYPE_BNODE
  2138.             $objsub new BlankNode($subject);
  2139.         else
  2140.             $objsub new Resource($subject);
  2141.          
  2142.     // create predicate    
  2143.     $objpred new Resource($predicate);
  2144.     
  2145.     // create object
  2146.     if (($object_type == RDF_OBJECT_TYPE_RESOURCE|| ($object_type == RDF_OBJECT_TYPE_BNODE)) {
  2147.             if ($object_type == RDF_OBJECT_TYPE_BNODE
  2148.                     $objobj new BlankNode($object);
  2149.                 else
  2150.                     $objobj new Resource($object);        
  2151.     else {
  2152.    
  2153.         $objobj new Literal($object);
  2154.         if ($datatype != ''{
  2155.             $objobj->setDatatype($datatype);
  2156.         }    
  2157.         elseif ($xml_lang !=''{
  2158.             $objobj->setLanguage($xml_lang);
  2159.         }     
  2160.     }
  2161.  
  2162.     // create statement
  2163.     $statement new Statement($objsub$objpred$objobj);
  2164.     
  2165.     // add statement to model
  2166.     if(CREATE_MODEL_WITHOUT_DUPLICATES == TRUE){
  2167.         $this->model->addWithoutDuplicates($statement);
  2168.     }else 
  2169.         $this->model->add($statement);
  2170.     }
  2171.  
  2172.  
  2173. /* public functions */
  2174.  
  2175.   /**
  2176.    * Generates a new MemModel from a URI, a file or from memory.
  2177.    * If you want to parse an RDF document, pass the URI or location in the filesystem
  2178.    * of the RDF document. You can also pass RDF code direct to the function. If you pass
  2179.    * RDF code directly to the parser and there is no xml:base included, you should set
  2180.    * the base URI manually using the optional second parameter $rdfBaseURI.
  2181.    * Make sure that here are proper namespace declarations in your input document.
  2182.    *
  2183.    * @access    public
  2184.    * @param        string     $base 
  2185.    * @param     boolean  $rdfBaseURI 
  2186.    * @return    object MemModel 
  2187.    */  
  2188. function generateModel($base,$rdfBaseURI false$model false{
  2189.  
  2190.     // Check if $base is a URI or filename or a string containing RDF code.
  2191.     if (substr(ltrim($base),,1!= '<'{
  2192.     
  2193.     // $base is URL or filename
  2194.     $this->model $model?$model:new MemModel($base);
  2195.     
  2196.     $input fopen($base,'r'or die("RDF ParserCould not open File$baseStopped parsing.");
  2197.     $this->rdf_parser_createNULL );
  2198.     $this->rdf_set_base($base);
  2199.     $done=false;
  2200.     while(!$done)
  2201.     {
  2202.       $buf fread$input512 );
  2203.       $done feof($input);
  2204.     
  2205.       if $this->rdf_parse$buffeof($input) ) )
  2206.       {
  2207.         $err_code xml_get_error_code$this->rdf_get_xml_parser());
  2208.         $line xml_get_current_line_number($this->rdf_get_xml_parser() );
  2209.         $errmsg RDFAPI_ERROR '(class: parser; method: generateModel): XML-parser-error ' $err_code .' in Line ' $line .' of input document.';
  2210.         trigger_error($errmsgE_USER_ERROR);
  2211.       }
  2212.     
  2213.     /* close file. */
  2214.     fclose$input );
  2215.     
  2216.     else {
  2217.     // $base is RDF string
  2218.     $this->model $model?$model:new MemModel($base);
  2219.     
  2220.     $this->rdf_parser_createNULL );
  2221.     
  2222.     if ($rdfBaseURI!==false)
  2223.     {
  2224.         $this->rdf_set_base($rdfBaseURI);
  2225.     else
  2226.     {
  2227.         $this->rdf_set_baseNULL );
  2228.     }
  2229.     
  2230.       if $this->rdf_parse$baseTRUE ) )
  2231.       {
  2232.         $err_code xml_get_error_code$this->rdf_get_xml_parser());
  2233.         $line xml_get_current_line_number($this->rdf_get_xml_parser() );
  2234.         $errmsg RDFAPI_ERROR '(class: parser; method: generateModel): XML-parser-error ' $err_code .' in Line ' $line .' of input document.';
  2235.         trigger_error($errmsgE_USER_ERROR)
  2236.       }
  2237.     }
  2238.     // base_uri could have changed while parsing
  2239.     $this->model->setBaseURI($this->rdf_parser['base_uri']);
  2240.  
  2241.     if(isset($this->rdf_parser['namespaces'])){
  2242.         $this->model->addParsedNamespaces($this->rdf_parser['namespaces']);
  2243.     }
  2244.     
  2245.     $this->rdf_parser_free();
  2246.     
  2247.     return $this->model;    
  2248.  
  2249. }
  2250.  
  2251. /**
  2252.  * @param        string     $encoding 
  2253.  
  2254.  * @access    private
  2255. */ 
  2256. function rdf_parser_create$encoding )
  2257. {
  2258.  
  2259.     $parser xml_parser_create_ns$encodingNAMESPACE_SEPARATOR_CHAR );
  2260.  
  2261.     xml_parser_set_option($parser,XML_OPTION_CASE_FOLDING,0)
  2262.     $this->rdf_parser['xml_parser'$parser;
  2263.  
  2264.     xml_set_object($this->rdf_parser['xml_parser']$this);
  2265.     xml_set_element_handler$this->rdf_parser['xml_parser']'_start_element_handler''_end_element_handler' );
  2266.     xml_set_character_data_handler$this->rdf_parser['xml_parser']'_character_data_handler' );
  2267.     xml_set_start_namespace_decl_handler($this->rdf_parser['xml_parser']'_start_ns_declaration_handler');
  2268.  
  2269.     return $this->rdf_parser;
  2270. }
  2271.  
  2272. /**
  2273.  * @param    resource    &$parser 
  2274.  * @param   string        $ns_prefix 
  2275.  * @param    string        $ns_uri 
  2276.  * @access    private
  2277. */ 
  2278. function _start_ns_declaration_handler(&$parser$ns_prefix$ns_uri)
  2279. {
  2280.     if (!$ns_prefix
  2281.         $this->rdf_parser['default_namespace'$ns_uri;
  2282.     else        
  2283.         $this->rdf_parser['namespaces'][$ns_uri$ns_prefix;
  2284. }
  2285.  
  2286.  
  2287. /**
  2288.  * @access    private
  2289. */ 
  2290. function rdf_parser_free)
  2291. {
  2292.     $z=3;
  2293.  
  2294.     $this->rdf_parser['base_uri']='';
  2295.     $this->rdf_parser['document_base_uri''';                    
  2296.  
  2297.     unset$this->rdf_parser );
  2298. }
  2299.  
  2300. /**
  2301.    * @param        string     $s 
  2302.    * @param        string     $is_final 
  2303.  * @access    private
  2304. */ 
  2305. function rdf_parse$s$is_final )
  2306. {
  2307.     return XML_Parse$this->rdf_parser['xml_parser']$s$is_final );
  2308. }
  2309.  
  2310. /**
  2311.  * @access    private
  2312. */ 
  2313. function rdf_get_xml_parser()
  2314. {
  2315.     return $this->rdf_parser['xml_parser']);
  2316. }
  2317.  
  2318. /**
  2319.    * @param        string     $base 
  2320.  * @access    private
  2321. */ 
  2322. function rdf_set_base($base )
  2323. {
  2324.     
  2325.     $this->rdf_parser['base_uri']=$base;
  2326.     
  2327.     $c substr($basestrlen($base)-,1);
  2328.     if (!($c=='#' || $c==':' || $c=='/' || $c=="\\"))
  2329.          $this->rdf_parser['normalized_base_uri'$base '#';
  2330.     else
  2331.         $this->rdf_parser['normalized_base_uri'$base
  2332.  
  2333.     return 0;
  2334. }
  2335.  
  2336. /**
  2337.  * @access    private
  2338. */ 
  2339. function rdf_get_base()
  2340. {
  2341.         if ($this->rdf_parser['top']['element_base_uri'])
  2342.             return $this->rdf_parser['top']['element_base_uri'];
  2343.         else 
  2344.             return $this->rdf_parser['base_uri'];                          
  2345. }
  2346.  
  2347.  
  2348. // end: rdf_parser
  2349.  
  2350. ?>

Documentation generated on Fri, 1 Jun 2007 16:50:45 +0200 by phpDocumentor 1.3.2