ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilDataSetImportParser.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 include_once("./Services/Xml/classes/class.ilSaxParser.php");
5 
14 {
15  protected $import = null; // import object
16  protected $entities = array(); // types array
17  protected $current_entity = ""; // current entity
18  protected $current_version = ""; // current version
19  protected $current_ftypes = array(); // current field types
20  protected $entities_sent = false; // sent entities to import class?
21  protected $in_record = false; // are we currently in a rec tag?
22  protected $current_field = ""; // current field
23  protected $current_field_values = array(); // current field values
24 
25 
32  function __construct($a_top_entity, $a_schema_version, $a_xml, $a_ds, $a_mapping)
33  {
34  $this->ds = $a_ds;
35  $this->mapping = $a_mapping;
36  $this->top_entity = $a_top_entity;
37  $this->schema_version = $a_schema_version;
38  $this->dspref = ($this->ds->getDSPrefix() != "")
39  ? $this->ds->getDSPrefix().":"
40  : "";
41 
43  $this->setXMLContent($a_xml);
44  $this->startParsing();
45 
46 
47  }
48 
55  function setHandlers($a_xml_parser)
56  {
57  xml_set_object($a_xml_parser,$this);
58  xml_set_element_handler($a_xml_parser, 'handleBeginTag', 'handleEndTag');
59  xml_set_character_data_handler($a_xml_parser, 'handleCharacterData');
60  }
61 
62 
66  function startParsing()
67  {
69  }
70 
74  function handleBeginTag($a_xml_parser, $a_name, $a_attribs)
75  {
76  switch ($a_name)
77  {
78  case $this->dspref."Dataset":
79 // $this->import->initDataset($this->ds_component, $a_attribs["top_entity"]);
80  break;
81 
82  case $this->dspref."Types":
83  $this->current_entity = $a_attribs["Entity"];
84  $this->current_version = $a_attribs["Version"];
85  break;
86 
87  case $this->dspref."FieldType":
88  $this->current_ftypes[$a_attribs["Name"]] =
89  $a_attribs["Type"];
90  break;
91 
92  case $this->dspref."Rec":
93  $this->current_entity = $a_attribs["Entity"];
94  $this->in_record = true;
95  $this->current_field_values = array();
96  break;
97 
98  default:
99  if ($this->in_record)
100  {
101  $field = explode(":", $a_name); // remove namespace
102  $field = $field[count($field) - 1];
103  $this->current_field = $field;
104  }
105  }
106  }
107 
111  function handleEndTag($a_xml_parser, $a_name)
112  {
113  switch ($a_name)
114  {
115  case $this->dspref."Types":
116  $this->entities[$this->current_entity] =
117  array(
118  "version" => $this->current_version,
119  "types" => $this->current_ftypes
120  );
121  $this->current_ftypes = array();
122  $this->current_entity = "";
123  $this->current_version = "";
124  break;
125 
126  case $this->dspref."Rec":
127  $this->ds->importRecord($this->current_entity,
128  $this->entities[$this->current_entity]["types"],
129  $this->current_field_values,
130  $this->mapping,
131  $this->schema_version);
132  $this->in_record = false;
133  $this->current_entity = "";
134  $this->current_field_values = array();
135  break;
136 
137  default:
138  if ($this->in_record && $this->current_field != "")
139  {
140  $this->current_field_values[$this->current_field] =
141  $this->chr_data;
142  }
143  $this->current_field = "";
144  break;
145  }
146 
147  $this->chr_data = "";
148  }
149 
153  function handleCharacterData($a_xml_parser,$a_data)
154  {
155  //$a_data = str_replace("<","&lt;",$a_data);
156  //$a_data = str_replace(">","&gt;",$a_data);
157  // DELETE WHITESPACES AND NEWLINES OF CHARACTER DATA
158  //$a_data = preg_replace("/\n/","",$a_data);
159  //$a_data = preg_replace("/\t+/","",$a_data);
160 
161  $this->chr_data .= $a_data;
162  }
163 
164 }
165 ?>