ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilExportFileParser.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("./classes/class.ilSaxParser.php");
5 include_once "./Services/Xml/classes/class.ilXmlWriter.php";
6 
15 {
16  protected $item_xml = "";
17 
24  function __construct($a_file, $a_callback_obj, $a_callback_func)
25  {
26  $this->callback_obj = $a_callback_obj;
27  $this->callback_func = $a_callback_func;
28 
29  parent::ilSaxParser($a_file, true);
30  $this->startParsing();
31  }
32 
39  function setHandlers($a_xml_parser)
40  {
41  xml_set_object($a_xml_parser,$this);
42  xml_set_element_handler($a_xml_parser, 'handleBeginTag', 'handleEndTag');
43  xml_set_character_data_handler($a_xml_parser, 'handleCharacterData');
44  }
45 
46 
50  function startParsing()
51  {
53  }
54 
58  function handleBeginTag($a_xml_parser, $a_name, $a_attribs)
59  {
60  if ($this->in_export_item)
61  {
62  $this->export_item_writer->xmlStartTag($a_name, $a_attribs);
63  }
64 
65 
66  switch ($a_name)
67  {
68  case "exp:Export":
69  $this->entity = $a_attribs["Entity"];
70  $this->install_id = $a_attribs["InstallationId"];
71  $this->install_url = $a_attribs["InstallationUrl"];
72  $this->schema_version = $a_attribs["SchemaVersion"];
73  break;
74 
75  case "exp:ExportItem":
76  $this->in_export_item = true;
77  $this->current_id = $a_attribs["Id"];
78 
79  $this->export_item_writer = new ilXmlWriter();
80 
81  $this->item_xml = "";
82  $this->expfiles[] = array("component" => $a_attribs["Component"],
83  "path" => $a_attribs["Path"]);
84  break;
85  }
86  }
87 
91  function handleEndTag($a_xml_parser, $a_name)
92  {
93  switch ($a_name)
94  {
95  case "exp:ExportItem":
96  $this->in_export_item = false;
97  $cf = $this->callback_func;
98  $this->callback_obj->$cf($this->entity, $this->schema_version, $this->current_id,
99  $this->export_item_writer->xmlDumpMem(false), $this->install_id,
100  $this->install_url);
101  break;
102 
103  }
104 
105  if ($this->in_export_item)
106  {
107  $this->export_item_writer->xmlEndTag($a_name);
108  }
109 
110 
111  $this->chr_data = "";
112  }
113 
117  function handleCharacterData($a_xml_parser,$a_data)
118  {
119  //$a_data = str_replace("<","&lt;",$a_data);
120  //$a_data = str_replace(">","&gt;",$a_data);
121  // DELETE WHITESPACES AND NEWLINES OF CHARACTER DATA
122  //$a_data = preg_replace("/\n/","",$a_data);
123  //$a_data = preg_replace("/\t+/","",$a_data);
124 
125  $this->chr_data .= $a_data;
126 
127  if ($this->in_export_item)
128  {
129  $this->export_item_writer->xmlData($a_data);
130  }
131 
132  }
133 
134 }
135 ?>