ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
_parse_propfind.php
Go to the documentation of this file.
1<?php
2//
3// +----------------------------------------------------------------------+
4// | PHP Version 4 |
5// +----------------------------------------------------------------------+
6// | Copyright (c) 1997-2003 The PHP Group |
7// +----------------------------------------------------------------------+
8// | This source file is subject to version 2.02 of the PHP license, |
9// | that is bundled with this package in the file LICENSE, and is |
10// | available at through the world-wide-web at |
11// | http://www.php.net/license/2_02.txt. |
12// | If you did not receive a copy of the PHP license and are unable to |
13// | obtain it through the world-wide-web, please send a note to |
14// | license@php.net so we can mail you a copy immediately. |
15// +----------------------------------------------------------------------+
16// | Authors: Hartmut Holzgraefe <hholzgra@php.net> |
17// | Christian Stocker <chregu@bitflux.ch> |
18// +----------------------------------------------------------------------+
19//
20// $Id: _parse_propfind.php,v 1.2 2004/01/05 12:33:22 hholzgra Exp $
21//
22
31{
38 public $success = false;
39
46 public $props = false;
47
54 public $depth = 0;
55
56
62 public function __construct($path)
63 {
64 // success state flag
65 $this->success = true;
66
67 // property storage array
68 $this->props = array();
69
70 // internal tag depth counter
71 $this->depth = 0;
72
73 // remember if any input was parsed
74 $had_input = false;
75
76 // open input stream
77 $f_in = fopen($path, "r");
78 if (!$f_in) {
79 $this->success = false;
80 return;
81 }
82
83 // create XML parser
84 $xml_parser = xml_parser_create_ns("UTF-8", " ");
85
86 // set tag and data handlers
87 xml_set_element_handler(
88 $xml_parser,
89 array(&$this, "_startElement"),
90 array(&$this, "_endElement")
91 );
92
93 // we want a case sensitive parser
94 xml_parser_set_option(
95 $xml_parser,
96 XML_OPTION_CASE_FOLDING,
97 false
98 );
99
100
101 // parse input
102 while ($this->success && !feof($f_in)) {
103 $line = fgets($f_in);
104 if (is_string($line)) {
105 $had_input = true;
106 $this->success &= xml_parse($xml_parser, $line, false);
107 }
108 }
109
110 // finish parsing
111 if ($had_input) {
112 $this->success &= xml_parse($xml_parser, "", true);
113 }
114
115 // free parser
116 xml_parser_free($xml_parser);
117
118 // close input stream
119 fclose($f_in);
120
121 // if no input was parsed it was a request
122 if (!count($this->props)) {
123 $this->props = "all";
124 } // default
125 }
126
127
136 public function _startElement($parser, $name, $attrs)
137 {
138 // name space handling
139 if (strstr($name, " ")) {
140 list($ns, $tag) = explode(" ", $name);
141 if ($ns == "") {
142 $this->success = false;
143 }
144 } else {
145 $ns = "";
146 $tag = $name;
147 }
148
149 // special tags at level 1: <allprop> and <propname>
150 if ($this->depth == 1) {
151 if ($tag == "allprop") {
152 $this->props = "all";
153 }
154
155 if ($tag == "propname") {
156 $this->props = "names";
157 }
158 }
159
160 // requested properties are found at level 2
161 if ($this->depth == 2) {
162 $prop = array("name" => $tag);
163 if ($ns) {
164 $prop["xmlns"] = $ns;
165 }
166 $this->props[] = $prop;
167 }
168
169 // increment depth count
170 $this->depth++;
171 }
172
173
181 public function _endElement($parser, $name)
182 {
183 // here we only need to decrement the depth count
184 $this->depth--;
185 }
186}
$parser
Definition: BPMN2Parser.php:23
An exception for terminatinating execution or to throw for unit testing.
__construct($path)
constructor
_startElement($parser, $name, $attrs)
start tag handler
_endElement($parser, $name)
end tag handler
if(function_exists( 'posix_getuid') &&posix_getuid()===0) if(!array_key_exists('t', $options)) $tag
Definition: cron.php:35
if($format !==null) $name
Definition: metadata.php:146