ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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
4include_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
25
26
33 function __construct($a_top_entity, $a_schema_version, $a_xml, $a_ds, $a_mapping)
34 {
35 $this->ds = $a_ds;
36 $this->mapping = $a_mapping;
37 $this->top_entity = $a_top_entity;
38 $this->schema_version = $a_schema_version;
39 $this->dspref = ($this->ds->getDSPrefix() != "")
40 ? $this->ds->getDSPrefix().":"
41 : "";
42
43 parent::ilSaxParser();
44 $this->setXMLContent($a_xml);
45 $this->startParsing();
46
47
48 }
49
57 {
59 }
60
61
68 function setHandlers($a_xml_parser)
69 {
70 xml_set_object($a_xml_parser,$this);
71 xml_set_element_handler($a_xml_parser, 'handleBeginTag', 'handleEndTag');
72 xml_set_character_data_handler($a_xml_parser, 'handleCharacterData');
73 }
74
75
79 function startParsing()
80 {
81 parent::startParsing();
82 }
83
87 function handleBeginTag($a_xml_parser, $a_name, $a_attribs)
88 {
89 switch ($a_name)
90 {
91 case $this->dspref."DataSet":
92// $this->import->initDataset($this->ds_component, $a_attribs["top_entity"]);
93 $this->current_installation_id = $a_attribs["InstallationId"];
94 $this->ds->setCurrentInstallationId($a_attribs["InstallationId"]);
95 break;
96
97 case $this->dspref."Types":
98 $this->current_entity = $a_attribs["Entity"];
99 $this->current_version = $a_attribs["Version"];
100 break;
101
102 case $this->dspref."FieldType":
103 $this->current_ftypes[$a_attribs["Name"]] =
104 $a_attribs["Type"];
105 break;
106
107 case $this->dspref."Rec":
108 $this->current_entity = $a_attribs["Entity"];
109 $this->in_record = true;
110 $this->current_field_values = array();
111 break;
112
113 default:
114 if ($this->in_record)
115 {
116 $field = explode(":", $a_name); // remove namespace
117 $field = $field[count($field) - 1];
118 $this->current_field = $field;
119 }
120 }
121 }
122
126 function handleEndTag($a_xml_parser, $a_name)
127 {
128 switch ($a_name)
129 {
130 case $this->dspref."Types":
131 $this->entities[$this->current_entity] =
132 array(
133 "version" => $this->current_version,
134 "types" => $this->current_ftypes
135 );
136 $this->current_ftypes = array();
137 $this->current_entity = "";
138 $this->current_version = "";
139 break;
140
141 case $this->dspref."Rec":
142 $this->ds->importRecord($this->current_entity,
143 $this->entities[$this->current_entity]["types"],
144 $this->current_field_values,
145 $this->mapping,
146 $this->schema_version);
147 $this->in_record = false;
148 $this->current_entity = "";
149 $this->current_field_values = array();
150 break;
151
152 default:
153 if ($this->in_record && $this->current_field != "")
154 {
155 $this->current_field_values[$this->current_field] =
156 $this->chr_data;
157 }
158 $this->current_field = "";
159 break;
160 }
161
162 $this->chr_data = "";
163 }
164
168 function handleCharacterData($a_xml_parser,$a_data)
169 {
170 //$a_data = str_replace("<","&lt;",$a_data);
171 //$a_data = str_replace(">","&gt;",$a_data);
172 // DELETE WHITESPACES AND NEWLINES OF CHARACTER DATA
173 //$a_data = preg_replace("/\n/","",$a_data);
174 //$a_data = preg_replace("/\t+/","",$a_data);
175
176 $this->chr_data .= $a_data;
177 }
178
179}
180?>
Manifest parser for ILIAS standard export files.
__construct($a_top_entity, $a_schema_version, $a_xml, $a_ds, $a_mapping)
Constructor.
handleBeginTag($a_xml_parser, $a_name, $a_attribs)
Begin Tag.
handleEndTag($a_xml_parser, $a_name)
End Tag.
setHandlers($a_xml_parser)
Set event handlers.
getCurrentInstallationId()
Get current installation id.
handleCharacterData($a_xml_parser, $a_data)
End Tag.
Base class for sax-based expat parsing extended classes need to overwrite the method setHandlers and ...
setXMLContent($a_xml_content)