Changeset 17

Show
Ignore:
Timestamp:
08/27/06 23:26:39 (2 years ago)
Author:
schst
Message:

Fixed XInclude extension

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/XJConf/DefinitionParser.php

    r14 r17  
    218218        } 
    219219 
    220 //        if ($defHandler->needsEnd() == true) { 
    221             array_push($this->defHandlerStack, $defHandler); 
    222 //        } 
     220        array_push($this->defHandlerStack, $defHandler); 
    223221        } 
    224222 
  • trunk/XJConf/XmlParser.php

    r9 r17  
    3939     * a listof defined namespaces 
    4040     * 
    41      * @var  NamespaceDefinitions  
     41     * @var  NamespaceDefinitions 
    4242     */ 
    4343    private $tagDefs; 
     
    7878     */ 
    7979    private $nodeTypes   = array(); 
    80      
     80 
    8181    /** 
    8282     * constructor 
    83      *  
     83     * 
    8484     * Sets the node types depending on your PHP version using the constants 
    8585     * defined by the XMLReader PHP extension. 
     
    9999        } 
    100100    } 
    101      
     101 
    102102    /** 
    103103     * set the list of namespace defintions 
     
    109109        $this->tagDefs = $tagDefs; 
    110110    } 
    111      
     111 
    112112    /** 
    113113     * add some more namespace definitions 
     
    124124        $this->tagDefs->appendNamespaceDefinitions($tagDefs); 
    125125    } 
    126      
     126 
    127127    /** 
    128128     * add an extension that handles all tags in given namespace 
     
    131131     * @param  Extension  $ext        use this extension to handle all tags in given namespace 
    132132     */ 
    133     public function addExtension($namespace, Extension $ext) 
    134     { 
     133    public function addExtension(Extension $ext, $namespace = null) 
     134    { 
     135        if ($namespace == null) { 
     136            $namespace = $ext->getNamespace(); 
     137        } 
    135138        $this->extensions[$namespace] = $ext; 
    136139    } 
    137      
     140 
    138141    /** 
    139142     * parses a given file and creates the data structure described in this file 
     
    143146    public function parse($filename) 
    144147    { 
    145         $this->initParser(); 
     148        $reader = $this->initParser(); 
    146149        array_push($this->openFiles, $filename); 
    147         $this->reader->open($filename); 
    148         while ($this->reader->read()) { 
    149             switch ($this->reader->nodeType) { 
     150        $reader->open($filename); 
     151        while ($reader->read()) { 
     152            switch ($reader->nodeType) { 
    150153                case $this->nodeTypes['startTag']: 
    151                     $nameSpaceURI = $this->reader->namespaceURI; 
    152                     $elementName  = $this->reader->localName; 
     154                    $empty = $reader->isEmptyElement; 
     155                    $nameSpaceURI = $reader->namespaceURI; 
     156                    $elementName  = $reader->localName; 
    153157                    $attributes   = array(); 
    154                     if (TRUE == $this->reader->hasAttributes) { 
     158                    if (TRUE == $reader->hasAttributes) { 
    155159                                // go to first attribute 
    156                                 $attribute = $this->reader->moveToFirstAttribute(); 
     160                                $attribute = $reader->moveToFirstAttribute(); 
    157161                                // save data of all attributes 
    158162                                while (TRUE == $attribute) { 
    159                                         $attributes[$this->reader->localName] = $this->reader->value; 
    160                                     $attribute = $this->reader->moveToNextAttribute(); 
     163                                        $attributes[$reader->localName] = $reader->value; 
     164                                    $attribute = $reader->moveToNextAttribute(); 
    161165                                } 
    162166                            } 
    163167 
    164168                    $this->startElement($nameSpaceURI, $elementName, $attributes); 
     169                    if (true === $empty) { 
     170                        $this->endElement($nameSpaceURI, $elementName); 
     171                    } 
    165172                    break; 
    166173 
    167174                case $this->nodeTypes['text']: 
    168                     $this->characters($this->reader->value); 
     175                    $this->characters($reader->value); 
    169176                    break; 
    170177 
    171178                case $this->nodeTypes['endTag']: 
    172                     $this->endElement($this->reader->namespaceURI, $this->reader->localName); 
     179                    $this->endElement($reader->namespaceURI, $reader->localName); 
    173180                    break; 
    174181            } 
    175182        } 
    176183 
    177         $this->reader->close($filename); 
     184        $reader->close($filename); 
    178185        array_pop($this->openFiles); 
    179186 
    180187    } 
    181      
     188 
    182189    /** 
    183190     * returns the data structure associated with this name 
     
    190197        return $this->config[$name]; 
    191198    } 
    192      
     199 
    193200    /** 
    194201     * returns the name of the file that is currently parsed 
     
    200207        return end($this->openFiles); 
    201208    } 
    202      
     209 
    203210    /** 
    204211     * initializes the parser 
     
    206213    private function initParser() 
    207214    { 
    208         if (null == $this->reader) { 
    209             $this->reader = new XMLReader(); 
    210         } 
     215        $reader = new XMLReader(); 
     216        return $reader; 
    211217    } 
    212218 
     
    290296        // get the last tag from the stack 
    291297        $tag = array_pop($this->tagStack); 
    292          
     298 
    293299        // This tag needs to be handled by an extension 
    294300        if (isset($this->extensions[$namespaceURI]) == true) { 
     
    323329     * Fetches the current tag from the stack and 
    324330     * appends the data. 
    325      *  
     331     * 
    326332     * @param  string  $buf 
    327333     */