You are here

function ARC_rdfxml_parser::handle_close in Taxonomy import/export via XML 5

Same name and namespace in other branches
  1. 5.2 arc/ARC_rdfxml_parser.php \ARC_rdfxml_parser::handle_close()
  2. 6.2 arc/ARC_rdfxml_parser.php \ARC_rdfxml_parser::handle_close()
  3. 6 arc/ARC_rdfxml_parser.php \ARC_rdfxml_parser::handle_close()

File

arc/ARC_rdfxml_parser.php, line 713

Class

ARC_rdfxml_parser

Code

function handle_close($parser, $tag) {

  /* echo "at state ".$this->state." closing ".$tag."\n"; */
  switch ($this->state) {
    case 3:

      /* p _close_ */
      $this->state = 2;
      break;
    case 2:

      /* no (more) props */
      if ($cur_s = $this->subjs[$this->s_count - 1]) {
        $cur_p = isset($cur_s["cur_p"]) ? $cur_s["cur_p"] : "";
        if ($cur_p === str_replace(" ", "", $tag) || $tag === "http://www.w3.org/1999/02/22-rdf-syntax-ns# li" && $cur_p === "http://www.w3.org/1999/02/22-rdf-syntax-ns#_" . $cur_s["li_count"]) {

          /* closing p */
        }
        else {
          $this
            ->pop_s();
          $this->state = @$this->subjs[$this->s_count - 1] ? 2 : 1;

          /* s was o of upper triple | back at root, expecting siblings */
        }
        if (@$cur_s["in_list"]) {
          $this->state = 4;
        }
      }
      break;
    case 4:

      /* empty p or p_close after cdata reading or p_close after collection */
      $cur_s =& $this->subjs[$this->s_count - 1];
      if (@$cur_s["is_list"]) {
        $this
          ->add_triple($cur_s, "http://www.w3.org/1999/02/22-rdf-syntax-ns#rest", array(
          "type" => "uri",
          "uri" => "http://www.w3.org/1999/02/22-rdf-syntax-ns#nil",
        ));

        /* back to list start */
        $coll_p = str_replace(" ", "", $tag);
        while ($cur_s["cur_p"] != $coll_p) {
          $next_s = $cur_s;
          $this
            ->pop_s();
          $cur_s =& $this->subjs[$this->s_count - 1];
        }
        if ($p_rdf_ID = $cur_s["p_rdf_ID"]) {

          /* reify */
          $this
            ->reify(array(
            "type" => "uri",
            "uri" => $this
              ->calc_uri($cur_s, $p_rdf_ID, "ID"),
          ), $cur_s, array(
            "type" => "uri",
            "uri" => $cur_s["cur_p"],
          ), $next_s);
        }
        $this->state = 2;
      }
      else {
        $this
          ->add_triple($cur_s, $cur_s["cur_p"], array(
          "type" => "literal",
          "val" => @$cur_s["o_cdata"],
          "dt" => @$cur_s["o_rdf_datatype"],
          "lang" => $this
            ->get_cur_lang($cur_s),
        ));
        if ($p_rdf_ID = @$cur_s["p_rdf_ID"]) {

          /* reify */
          $this
            ->reify(array(
            "type" => "uri",
            "uri" => $this
              ->calc_uri($cur_s, $p_rdf_ID, "ID"),
          ), $cur_s, array(
            "type" => "uri",
            "uri" => $cur_s["cur_p"],
          ), array(
            "type" => "literal",
            "val" => $cur_s["o_cdata"],
            "dt" => $cur_s["o_rdf_datatype"],
            "lang" => $this
              ->get_cur_lang($cur_s),
          ));
        }
        unset($cur_s["o_cdata"]);
        unset($cur_s["o_rdf_datatype"]);
        $this->state = 2;
      }
      break;
    case 6:

      /* expecting xml data */
      $cur_s =& $this->subjs[$this->s_count - 1];
      $data = $cur_s["o_xml_data"];
      $xml_level = $cur_s["o_xml_level"];
      if ($xml_level === 0) {

        /* p close after xml reading */
        $this
          ->add_triple($cur_s, $cur_s["cur_p"], array(
          "type" => "literal",
          "val" => trim($data),
          "dt" => "http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral",
          "lang" => $this
            ->get_cur_lang($cur_s),
        ));
        unset($cur_s["o_xml_data"]);
        $this->state = 2;
      }
      else {
        $tag_parts = explode(" ", $tag);
        if (count($tag_parts) == 1) {

          /* no qname */
          $data .= '</' . $tag . '>';
        }
        else {
          $ns_uri = $tag_parts[0];
          $local_name = $tag_parts[1];
          $nsp = $this->nsps[$ns_uri];
          $data .= strlen($nsp) ? '</' . $nsp . ":" . $local_name . '>' : '</' . $local_name . '>';
        }
        $cur_s["o_xml_data"] = $data;
        $cur_s["o_xml_level"] = $xml_level - 1;
        if (str_replace(" ", "", $tag) === $cur_s["cur_p"]) {

          /* container prop in XML */
          $cur_s["p_xml_literal_level"]--;
        }
      }
      break;
  }
}