Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/lib/pear/HTTP/WebDAV/Tools/_parse_lockinfo.php
Go to the documentation of this file.
00001 <?php // $Id: _parse_lockinfo.php,v 1.2 2010/12/14 17:36:02 moodlerobot Exp $
00002 /*
00003    +----------------------------------------------------------------------+
00004    | Copyright (c) 2002-2007 Christian Stocker, Hartmut Holzgraefe        |
00005    | All rights reserved                                                  |
00006    |                                                                      |
00007    | Redistribution and use in source and binary forms, with or without   |
00008    | modification, are permitted provided that the following conditions   |
00009    | are met:                                                             |
00010    |                                                                      |
00011    | 1. Redistributions of source code must retain the above copyright    |
00012    |    notice, this list of conditions and the following disclaimer.     |
00013    | 2. Redistributions in binary form must reproduce the above copyright |
00014    |    notice, this list of conditions and the following disclaimer in   |
00015    |    the documentation and/or other materials provided with the        |
00016    |    distribution.                                                     |
00017    | 3. The names of the authors may not be used to endorse or promote    |
00018    |    products derived from this software without specific prior        |
00019    |    written permission.                                               |
00020    |                                                                      |
00021    | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS  |
00022    | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT    |
00023    | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS    |
00024    | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE       |
00025    | COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,  |
00026    | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
00027    | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;     |
00028    | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER     |
00029    | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT   |
00030    | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN    |
00031    | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE      |
00032    | POSSIBILITY OF SUCH DAMAGE.                                          |
00033    +----------------------------------------------------------------------+
00034 */
00035 
00036 
00044 class _parse_lockinfo 
00045 {
00052     var $success = false;
00053 
00060     var $locktype = "";
00061 
00068     var $lockscope = "";
00069 
00076     var $owner = "";
00077 
00084     var $collect_owner = false;
00085     
00092     function _parse_lockinfo($path) 
00093     {
00094         // we assume success unless problems occur
00095         $this->success = true;
00096 
00097         // remember if any input was parsed
00098         $had_input = false;
00099         
00100         // open stream
00101         $f_in = fopen($path, "r");
00102         if (!$f_in) {
00103             $this->success = false;
00104             return;
00105         }
00106 
00107         // create namespace aware parser
00108         $xml_parser = xml_parser_create_ns("UTF-8", " ");
00109 
00110         // set tag and data handlers
00111         xml_set_element_handler($xml_parser,
00112                                 array(&$this, "_startElement"),
00113                                 array(&$this, "_endElement"));
00114         xml_set_character_data_handler($xml_parser,
00115                                        array(&$this, "_data"));
00116 
00117         // we want a case sensitive parser
00118         xml_parser_set_option($xml_parser,
00119                               XML_OPTION_CASE_FOLDING, false);
00120 
00121         // parse input
00122         while ($this->success && !feof($f_in)) {
00123             $line = fgets($f_in);
00124             if (is_string($line)) {
00125                 $had_input = true;
00126                 $this->success &= xml_parse($xml_parser, $line, false);
00127             }
00128         } 
00129 
00130         // finish parsing
00131         if ($had_input) {
00132             $this->success &= xml_parse($xml_parser, "", true);
00133         }
00134 
00135         // check if required tags where found
00136         $this->success &= !empty($this->locktype);
00137         $this->success &= !empty($this->lockscope);
00138 
00139         // free parser resource
00140         xml_parser_free($xml_parser);
00141 
00142         // close input stream
00143         fclose($f_in);      
00144     }
00145     
00146 
00156     function _startElement($parser, $name, $attrs) 
00157     {
00158         // namespace handling
00159         if (strstr($name, " ")) {
00160             list($ns, $tag) = explode(" ", $name);
00161         } else {
00162             $ns  = "";
00163             $tag = $name;
00164         }
00165         
00166   
00167         if ($this->collect_owner) {
00168             // everything within the <owner> tag needs to be collected
00169             $ns_short = "";
00170             $ns_attr  = "";
00171             if ($ns) {
00172                 if ($ns == "DAV:") {
00173                     $ns_short = "D:";
00174                 } else {
00175                     $ns_attr = " xmlns='$ns'";
00176                 }
00177             }
00178             $this->owner .= "<$ns_short$tag$ns_attr>";
00179         } else if ($ns == "DAV:") {
00180             // parse only the essential tags
00181             switch ($tag) {
00182             case "write":
00183                 $this->locktype = $tag;
00184                 break;
00185             case "exclusive":
00186             case "shared":
00187                 $this->lockscope = $tag;
00188                 break;
00189             case "owner":
00190                 $this->collect_owner = true;
00191                 break;
00192             }
00193         }
00194     }
00195     
00204     function _data($parser, $data) 
00205     {
00206         // only the <owner> tag has data content
00207         if ($this->collect_owner) {
00208             $this->owner .= $data;
00209         }
00210     }
00211 
00220     function _endElement($parser, $name) 
00221     {
00222         // namespace handling
00223         if (strstr($name, " ")) {
00224             list($ns, $tag) = explode(" ", $name);
00225         } else {
00226             $ns  = "";
00227             $tag = $name;
00228         }
00229 
00230         // <owner> finished?
00231         if (($ns == "DAV:") && ($tag == "owner")) {
00232             $this->collect_owner = false;
00233         }
00234 
00235         // within <owner> we have to collect everything
00236         if ($this->collect_owner) {
00237             $ns_short = "";
00238             $ns_attr  = "";
00239             if ($ns) {
00240                 if ($ns == "DAV:") {
00241                     $ns_short = "D:";
00242                 } else {
00243                     $ns_attr = " xmlns='$ns'";
00244                 }
00245             }
00246             $this->owner .= "</$ns_short$tag$ns_attr>";
00247         }
00248     }
00249 }
00250 
00251 ?>
 All Data Structures Namespaces Files Functions Variables Enumerations