25 require_once dirname(__FILE__).
'/class.ilBMFBase.php';
26 require_once dirname(__FILE__).
'/class.ilBMFValue.php';
56 var
$entities = array (
'&' =>
'&',
'<' =>
'<',
'>' =>
'>',
"'" =>
''',
'"' =>
'"' );
76 $this->attachments = $attachments;
79 if (preg_match(
'/<\?xml[^>]+encoding\s*?=\s*?(\'([^\']*)\'|"([^"]*)")[^>]*?[\?]>/', $xml, $m)) {
80 $encoding = strtoupper($m[2] ? $m[2] : $m[3]);
88 $parser = xml_parser_create($encoding);
89 xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
90 xml_set_object($parser, $this);
91 xml_set_element_handler($parser,
'startElement',
'endElement');
92 xml_set_character_data_handler($parser,
'characterData');
96 if ($xml[strlen($xml) - 1] == 0) {
101 if (!xml_parse($parser, $xml,
true)) {
102 $err = sprintf(
'XML error on line %d col %d byte %d %s',
103 xml_get_current_line_number($parser),
104 xml_get_current_column_number($parser),
105 xml_get_current_byte_index($parser),
106 xml_error_string(xml_get_error_code($parser)));
109 xml_parser_free($parser);
123 $this->
domulti(
$d-1, $ar, $r[$ar[$ad]], $v, $ad+1);
141 if (isset($this->message[$pos][
'children'])) {
142 $children = explode(
'|', $this->message[$pos][
'children']);
144 foreach ($children as $c => $child_pos) {
145 if ($this->message[$child_pos][
'type'] != null) {
149 if (array_key_exists(
'arraySize', $this->message[$pos])) {
150 $ardepth = count($this->message[$pos][
'arraySize']);
152 $ar = array_pad(array(), $ardepth, 0);
153 if (array_key_exists(
'arrayOffset', $this->message[$pos])) {
154 for ($i = 0; $i < $ardepth; $i++) {
155 $ar[$i] += $this->message[$pos][
'arrayOffset'][$i];
158 $elc = count($response);
159 for ($i = 0; $i < $elc; $i++) {
161 $this->
domulti($ardepth, $ar, $newresp, $response[$i]);
166 while ($ad > 0 && $ar[$ad] >= $this->message[$pos][
'arraySize'][$ad]) {
172 $response = $newresp;
173 }
elseif (isset($this->message[$pos][
'arrayOffset']) &&
174 $this->message[$pos][
'arrayOffset'][0] > 0) {
176 $pad = $this->message[$pos][
'arrayOffset'][0] + count($response) * -1;
177 $response = array_pad($response, $pad, null);
184 foreach ($this->message[$pos][
'attrs'] as $atn => $atv) {
185 if (!strstr($atn,
'xmlns') &&
186 !strpos($atn,
':')) {
193 $nqn =&
new Qname($this->message[$pos][
'name'], $this->message[$pos][
'namespace']);
194 $tqn =&
new Qname($this->message[$pos][
'type'], $this->message[$pos][
'type_namespace']);
195 $response =&
new ilBMFValue($nqn->fqn(), $tqn->fqn(), $response, $attrs);
196 if (isset($this->message[$pos][
'arrayType'])) {
197 $response->arrayType = $this->message[$pos][
'arrayType'];
200 $nqn =&
new Qname($this->message[$pos][
'name'], $this->message[$pos][
'namespace']);
201 $tqn =&
new Qname($this->message[$pos][
'type'], $this->message[$pos][
'type_namespace']);
202 $response =&
new ilBMFValue($nqn->fqn(), $tqn->fqn(), $this->message[$pos][
'cdata'], $attrs);
206 if (array_key_exists(
'actor', $this->message[$pos])) {
207 $response->actor = $this->message[$pos][
'actor'];
209 if (array_key_exists(
'mustUnderstand', $this->message[$pos])) {
210 $response->mustunderstand = $this->message[$pos][
'mustUnderstand'];
225 $pos = $this->position++;
228 $this->message[$pos] = array();
229 $this->message[$pos][
'type'] =
'';
230 $this->message[$pos][
'type_namespace'] =
'';
231 $this->message[$pos][
'cdata'] =
'';
232 $this->message[$pos][
'pos'] = $pos;
233 $this->message[$pos][
'id'] =
'';
239 $this->message[$pos][
'depth'] = $this->depth++;
243 if (isset($this->message[$this->parent][
'children']))
255 $this->parent = $pos;
258 if (strcasecmp(
'envelope', $qname->name) == 0) {
259 $this->status =
'envelope';
260 }
elseif (strcasecmp(
'header', $qname->name) == 0) {
261 $this->status =
'header';
262 $this->header_struct_name[] = $this->curent_root_struct_name = $qname->name;
263 $this->header_struct[] = $this->curent_root_struct = $pos;
264 $this->message[$pos][
'type'] =
'Struct';
265 }
elseif (strcasecmp(
'body', $qname->name) == 0) {
266 $this->status =
'body';
270 }
elseif ($this->status ==
'body') {
273 $can_root = $this->depth == $this->bodyDepth + 1;
275 foreach ($attrs as
$key => $value) {
276 if (stristr(
$key,
':root') && !$value) {
283 $this->status =
'method';
284 $this->root_struct_name[] = $this->curent_root_struct_name = $qname->name;
285 $this->root_struct[] = $this->curent_root_struct = $pos;
286 $this->message[$pos][
'type'] =
'Struct';
294 $this->message[$pos][
'name'] = htmlspecialchars($qname->name);
297 $this->message[$pos][
'attrs'] = $attrs;
300 foreach ($attrs as
$key => $value) {
304 if ($kqn->ns ==
'xmlns') {
305 $prefix = $kqn->name;
307 if (in_array($value, $this->_XMLSchema)) {
311 $this->_namespaces[$value] = $prefix;
316 $qname->namespace = $value;
317 }
elseif ($kqn->name ==
'actor') {
318 $this->message[$pos][
'actor'] = $value;
319 }
elseif ($kqn->name ==
'mustUnderstand') {
320 $this->message[$pos][
'mustUnderstand'] = $value;
323 }
elseif ($kqn->name ==
'type') {
324 $vqn =&
new QName($value);
325 $this->message[$pos][
'type'] = $vqn->name;
330 }
elseif ($kqn->name ==
'arrayType') {
331 $vqn =&
new QName($value);
332 $this->message[$pos][
'type'] =
'Array';
333 if (isset($vqn->arraySize)) {
334 $this->message[$pos][
'arraySize'] = $vqn->arraySize;
336 $this->message[$pos][
'arrayType'] = $vqn->name;
338 }
elseif ($kqn->name ==
'offset') {
339 $this->message[$pos][
'arrayOffset'] = split(
',', substr($value, 1, strlen($value) - 2));
341 }
elseif ($kqn->name ==
'id') {
343 $this->references[$value] = $pos;
344 $this->message[$pos][
'id'] = $value;
346 }
elseif ($kqn->name ==
'href') {
347 if ($value[0] ==
'#') {
348 $ref = substr($value, 1);
349 if (isset($this->references[$ref])) {
351 $ref_pos = $this->references[$ref];
352 $this->message[$pos][
'children'] = &$this->message[$ref_pos][
'children'];
353 $this->message[$pos][
'cdata'] = &$this->message[$ref_pos][
'cdata'];
354 $this->message[$pos][
'type'] = &$this->message[$ref_pos][
'type'];
355 $this->message[$pos][
'arraySize'] = &$this->message[$ref_pos][
'arraySize'];
356 $this->message[$pos][
'arrayType'] = &$this->message[$ref_pos][
'arrayType'];
359 if (!isset($this->need_references[$ref])) {
360 $this->need_references[$ref] = array();
362 $this->need_references[$ref][] = $pos;
364 }
elseif (isset($this->attachments[$value])) {
365 $this->message[$pos][
'cdata'] = $this->attachments[$value];
370 if (array_key_exists(
'xmlns:' . $qname->ns, $attrs)) {
372 }
elseif ($qname->ns && !$qname->namespace) {
378 $this->message[$pos][
'namespace'] =
$namespace;
400 if ($this->message[$pos][
'type'] ==
'') {
401 if (isset($this->message[$pos][
'children'])) {
410 $this->message[$pos][
'type'] =
'Struct';
412 $parent = $this->message[$pos][
'parent'];
413 if ($this->message[
$parent][
'type'] ==
'Array' &&
414 array_key_exists(
'arrayType', $this->message[
$parent])) {
415 $this->message[$pos][
'type'] = $this->message[
$parent][
'arrayType'];
417 $this->message[$pos][
'type'] =
'string';
423 if ($pos == $this->curent_root_struct) {
424 $this->status =
'body';
425 }
elseif ($qname->name ==
'Body' || $qname->name ==
'Header') {
426 $this->status =
'envelope';
430 $this->parent = $this->message[$pos][
'parent'];
433 $idref = $this->message[$pos][
'id'];
435 if ($idref !=
'' && array_key_exists($idref, $this->need_references)) {
436 foreach ($this->need_references[$idref] as $ref_pos) {
438 $this->message[$ref_pos][
'children'] = &$this->message[$pos][
'children'];
439 $this->message[$ref_pos][
'cdata'] = &$this->message[$pos][
'cdata'];
440 $this->message[$ref_pos][
'type'] = &$this->message[$pos][
'type'];
441 $this->message[$ref_pos][
'arraySize'] = &$this->message[$pos][
'arraySize'];
442 $this->message[$ref_pos][
'arrayType'] = &$this->message[$pos][
'arrayType'];
456 if (isset($this->message[$pos][
'cdata'])) {
457 $this->message[$pos][
'cdata'] .=
$data;
459 $this->message[$pos][
'cdata'] =
$data;
473 if (isset($this->root_struct[0]) &&
474 $this->root_struct[0]) {
492 if (isset($this->header_struct[0]) &&
493 $this->header_struct[0]) {
514 $trans_tbl = array_flip($this->entities);
515 return strtr($text, $trans_tbl);