syntax
[ class tree: syntax ] [ index: syntax ] [ all elements ]

Source for file Parser.php

Documentation is available at Parser.php

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

Documentation generated on Mon, 11 Mar 2019 15:39:29 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.