ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
_parse_lockinfo.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_lockinfo.php,v 1.2 2004/01/05 12:32:40 hholzgra Exp $
21//
22
31{
38 public $success = false;
39
46 public $locktype = "";
47
54 public $lockscope = "";
55
62 public $owner = "";
63
70 public $collect_owner = false;
71
78 public function __construct($path)
79 {
80 // we assume success unless problems occur
81 $this->success = true;
82
83 // remember if any input was parsed
84 $had_input = false;
85
86 // open stream
87 $f_in = fopen($path, "r");
88 if (!$f_in) {
89 $this->success = false;
90 return;
91 }
92
93 // create namespace aware parser
94 $xml_parser = xml_parser_create_ns("UTF-8", " ");
95
96 // set tag and data handlers
97 xml_set_element_handler(
98 $xml_parser,
99 array(&$this, "_startElement"),
100 array(&$this, "_endElement")
101 );
102 xml_set_character_data_handler(
103 $xml_parser,
104 array(&$this, "_data")
105 );
106
107 // we want a case sensitive parser
108 xml_parser_set_option(
109 $xml_parser,
110 XML_OPTION_CASE_FOLDING,
111 false
112 );
113
114 // parse input
115 while ($this->success && !feof($f_in)) {
116 $line = fgets($f_in);
117 if (is_string($line)) {
118 $had_input = true;
119 $this->success &= xml_parse($xml_parser, $line, false);
120 }
121 }
122
123 // finish parsing
124 if ($had_input) {
125 $this->success &= xml_parse($xml_parser, "", true);
126 }
127
128 // check if required tags where found
129 $this->success &= !empty($this->locktype);
130 $this->success &= !empty($this->lockscope);
131
132 // free parser resource
133 xml_parser_free($xml_parser);
134
135 // close input stream
136 fclose($f_in);
137 }
138
139
149 public function _startElement($parser, $name, $attrs)
150 {
151 // namespace handling
152 if (strstr($name, " ")) {
153 list($ns, $tag) = explode(" ", $name);
154 } else {
155 $ns = "";
156 $tag = $name;
157 }
158
159
160 if ($this->collect_owner) {
161 // everything within the <owner> tag needs to be collected
162 $ns_short = "";
163 $ns_attr = "";
164 if ($ns) {
165 if ($ns == "DAV:") {
166 $ns_short = "D:";
167 } else {
168 $ns_attr = " xmlns='$ns'";
169 }
170 }
171 $this->owner .= "<$ns_short$tag$ns_attr>";
172 } elseif ($ns == "DAV:") {
173 // parse only the essential tags
174 switch ($tag) {
175 case "write":
176 $this->locktype = $tag;
177 break;
178 case "exclusive":
179 case "shared":
180 $this->lockscope = $tag;
181 break;
182 case "owner":
183 $this->collect_owner = true;
184 break;
185 }
186 }
187 }
188
197 public function _data($parser, $data)
198 {
199 // only the <owner> tag has data content
200 if ($this->collect_owner) {
201 $this->owner .= $data;
202 }
203 }
204
213 public function _endElement($parser, $name)
214 {
215 // namespace handling
216 if (strstr($name, " ")) {
217 list($ns, $tag) = explode(" ", $name);
218 } else {
219 $ns = "";
220 $tag = $name;
221 }
222
223 // <owner> finished?
224 if (($ns == "DAV:") && ($tag == "owner")) {
225 $this->collect_owner = false;
226 }
227
228 // within <owner> we have to collect everything
229 if ($this->collect_owner) {
230 $ns_short = "";
231 $ns_attr = "";
232 if ($ns) {
233 if ($ns == "DAV:") {
234 $ns_short = "D:";
235 } else {
236 $ns_attr = " xmlns='$ns'";
237 }
238 }
239 $this->owner .= "</$ns_short$tag$ns_attr>";
240 }
241 }
242}
$parser
Definition: BPMN2Parser.php:23
An exception for terminatinating execution or to throw for unit testing.
_endElement($parser, $name)
tag end handler
_startElement($parser, $name, $attrs)
tag start handler
_data($parser, $data)
data handler
__construct($path)
constructor
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