ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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 public 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
44 $this->setXMLContent($a_xml);
45 $this->startParsing();
46 }
47
54 public function getCurrentInstallationId()
55 {
57 }
58
59
66 public function setHandlers($a_xml_parser)
67 {
68 xml_set_object($a_xml_parser, $this);
69 xml_set_element_handler($a_xml_parser, 'handleBeginTag', 'handleEndTag');
70 xml_set_character_data_handler($a_xml_parser, 'handleCharacterData');
71 }
72
73
77 public function startParsing()
78 {
79 parent::startParsing();
80 }
81
85 public function handleBeginTag($a_xml_parser, $a_name, $a_attribs)
86 {
87 switch ($a_name) {
88 case $this->dspref . "DataSet":
89// $this->import->initDataset($this->ds_component, $a_attribs["top_entity"]);
90 $this->current_installation_id = $a_attribs["InstallationId"];
91 $this->ds->setCurrentInstallationId($a_attribs["InstallationId"]);
92 break;
93
94 case $this->dspref . "Types":
95 $this->current_entity = $a_attribs["Entity"];
96 $this->current_version = $a_attribs["Version"];
97 break;
98
99 case $this->dspref . "FieldType":
100 $this->current_ftypes[$a_attribs["Name"]] =
101 $a_attribs["Type"];
102 break;
103
104 case $this->dspref . "Rec":
105 $this->current_entity = $a_attribs["Entity"];
106 $this->in_record = true;
107 $this->current_field_values = array();
108 break;
109
110 default:
111 if ($this->in_record) {
112 $field = explode(":", $a_name); // remove namespace
113 $field = $field[count($field) - 1];
114 $this->current_field = $field;
115 }
116 }
117 }
118
122 public function handleEndTag($a_xml_parser, $a_name)
123 {
124 switch ($a_name) {
125 case $this->dspref . "Types":
126 $this->entities[$this->current_entity] =
127 array(
128 "version" => $this->current_version,
129 "types" => $this->current_ftypes
130 );
131 $this->current_ftypes = array();
132 $this->current_entity = "";
133 $this->current_version = "";
134 break;
135
136 case $this->dspref . "Rec":
137 $this->ds->importRecord(
138 $this->current_entity,
139 $this->entities[$this->current_entity]["types"],
140 $this->current_field_values,
141 $this->mapping,
142 $this->schema_version
143 );
144 $this->in_record = false;
145 $this->current_entity = "";
146 $this->current_field_values = array();
147 break;
148
149 default:
150 if ($this->in_record && $this->current_field != "") {
151 $this->current_field_values[$this->current_field] =
152 $this->chr_data;
153 }
154 $this->current_field = "";
155 break;
156 }
157
158 $this->chr_data = "";
159 }
160
164 public function handleCharacterData($a_xml_parser, $a_data)
165 {
166 //$a_data = str_replace("<","&lt;",$a_data);
167 //$a_data = str_replace(">","&gt;",$a_data);
168 // DELETE WHITESPACES AND NEWLINES OF CHARACTER DATA
169 //$a_data = preg_replace("/\n/","",$a_data);
170 //$a_data = preg_replace("/\t+/","",$a_data);
171
172 $this->chr_data .= $a_data;
173 }
174}
An exception for terminatinating execution or to throw for unit testing.
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)
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc