[ Index ] |
|
Code source de Joomla 1.0.13 |
1 <?php 2 /** 3 * DOMIT node maps are structures for storing and accessing collections of DOMIT_Nodes. 4 * @package domit-xmlparser 5 * @copyright (C) 2004 John Heinstein. All rights reserved 6 * @license http://www.gnu.org/copyleft/lesser.html LGPL License 7 * @author John Heinstein <johnkarl@nbnet.nb.ca> 8 * @link http://www.engageinteractive.com/domit/ DOMIT! Home Page 9 * DOMIT! is Free Software 10 **/ 11 12 if (!defined('DOMIT_INCLUDE_PATH')) { 13 define('DOMIT_INCLUDE_PATH', (dirname(__FILE__) . "/")); 14 } 15 16 /** 17 * A DOM NodeList implementation 18 * 19 * @package domit-xmlparser 20 * @author John Heinstein <johnkarl@nbnet.nb.ca> 21 */ 22 class DOMIT_NodeList { 23 /** @var Array A container for the nodes in the list */ 24 var $arNodeList = array(); 25 26 /** 27 * Return the node at the specified index 28 * @param int The index of the requested node 29 * @return Object A reference to the requested node, or null 30 */ 31 function &item($index) { 32 if ($index < $this->getLength()) { 33 return $this->arNodeList[$index]; 34 } 35 36 $null = null; 37 return $null; 38 } //item 39 40 /** 41 * Returns the number of nodes in the list 42 * @return int The number of nodes in the list 43 */ 44 function getLength() { 45 return count($this->arNodeList); 46 } //getLength 47 48 /** 49 * Appends a node to the list 50 * @return Object The appended node 51 */ 52 function &appendNode(&$node) { 53 $this->arNodeList[] =& $node; 54 return $node; 55 } //appendNode 56 57 /** 58 * Removes the specified node from the list 59 * @param Object A reference to the node to be removed 60 * @return Object A reference to the removed node 61 */ 62 function &removeNode(&$node) { 63 $total = $this->getLength(); 64 $returnNode = null; 65 $found = false; 66 67 for ($i = 0; $i < $total; $i++) { 68 if (!$found) { 69 if ($node->uid == $this->arNodeList[$i]->uid) { 70 $found = true; 71 $returnNode=& $node; 72 } 73 } 74 75 if ($found) { 76 if ($i == ($total - 1)) { 77 unset($this->arNodeList[$i]); 78 } 79 else { 80 $this->arNodeList[$i] =& $this->arNodeList[($i + 1)]; 81 } 82 } 83 } 84 85 return $returnNode; 86 } //$removeNode 87 88 /** 89 * Formats a string for presentation as HTML 90 * @param string The string to be formatted 91 * @param boolean True if the string is to be sent directly to output 92 * @return string The HTML formatted string 93 */ 94 function forHTML($str, $doPrint = false) { 95 require_once (DOMIT_INCLUDE_PATH . 'xml_domit_utilities.php'); 96 return DOMIT_Utilities::forHTML($str, $doPrint); 97 } //forHTML 98 99 /** 100 * Generates an array representation of the node and its children 101 * @return Array A representation of the node and its children 102 */ 103 function toArray() { 104 return $this->arNodeList; 105 } //toArray 106 107 /** 108 * Copies a node and/or its children 109 * @param boolean True if all child nodes are also to be cloned 110 * @return Object A copy of the node and/or its children 111 */ 112 function &createClone($deep = false) { 113 $className = get_class($this); 114 $clone = new $className(); 115 116 foreach ($this->arNodeList as $key => $value) { 117 $currNode =& $this->arNodeList[$key]; 118 $clone->arNodeList[$key] =& $currNode->cloneNode($deep); 119 } 120 121 return $clone; 122 } //createClone 123 124 /** 125 * Generates a string representation of the node and its children 126 * @param boolean True if HTML readable output is desired 127 * @param boolean True if illegal xml characters in text nodes and attributes should be converted to entities 128 * @return string The string representation 129 */ 130 function toString($htmlSafe = false, $subEntities=false) { 131 $result = ''; 132 133 foreach ($this->arNodeList as $key => $value) { 134 $currNode =& $this->arNodeList[$key]; 135 $result .= $currNode->toString(false, $subEntities); 136 } 137 138 if ($htmlSafe) $result = $this->forHTML($result); 139 140 return $result; 141 } //toString 142 143 /** 144 * Generates a normalized (formatted for readability) representation of the node collection 145 * @param boolean True if HTML readable output is desired 146 * @param boolean True if illegal xml characters in text nodes and attributes should be converted to entities 147 * @return string The string representation 148 */ 149 function toNormalizedString($htmlSafe = false, $subEntities=false) { 150 $result = ''; 151 152 foreach ($this->arNodeList as $key => $value) { 153 $currNode =& $this->arNodeList[$key]; 154 $result .= $currNode->toNormalizedString(false, $subEntities); 155 } 156 157 if ($htmlSafe) $result = $this->forHTML($result); 158 159 return $result; 160 } //toNormalizedString 161 } //DOMIT_NodeList 162 163 /** 164 * A DOM NamedNodeMap implementation 165 * 166 * @package domit-xmlparser 167 * @author John Heinstein <johnkarl@nbnet.nb.ca> 168 */ 169 class DOMIT_NamedNodeMap { 170 /** @var Array A container for the nodes in the map */ 171 var $arNodeMap = array(); 172 /** @var Array A numerical index to the keys of the mapped nodes */ 173 var $indexedNodeMap = array(); 174 /** @var boolean True if the list has been modified and $indexedNodeMap needs reindexing */ 175 var $isDirty = true; 176 177 /** 178 * Gets a node with the specifed name 179 * @param string The name of the node 180 * @return mixed A reference to the requested node, or null 181 */ 182 function &getNamedItem($name) { 183 if (isset($this->arNodeMap[$name])) { 184 return $this->arNodeMap[$name]; 185 } 186 187 $null = null; 188 return $null; 189 } //getNamedItem 190 191 /** 192 * Reindexes the numerical index for the named node map 193 */ 194 function reindexNodeMap() { 195 $this->indexedNodeMap = array(); 196 197 foreach ($this->arNodeMap as $key => $value) { 198 $this->indexedNodeMap[] = $key; 199 } 200 201 $this->isDirty = false; 202 } //reindexNodeMap 203 204 /** 205 * Assigns a node to the list 206 * @param Object A reference to the node to be assigned 207 * @return Object A reference to the assigned node 208 */ 209 function &setNamedItem(&$arg) { 210 $returnNode = null; 211 212 if (isset($this->arNodeMap[$arg->nodeName])) { 213 $returnNode =& $this->arNodeMap[$arg->nodeName]; 214 } 215 else { 216 $this->isDirty = true; 217 } 218 219 $this->arNodeMap[$arg->nodeName] =& $arg; 220 return $returnNode; 221 } //setNamedItem 222 223 /** 224 * Removes a node from the list, by name 225 * @param string The name of the node to be removed 226 * @return mixed A reference to the removed node, or null 227 */ 228 function &removeNamedItem($name) { 229 $returnNode = null; 230 231 if (isset($this->arNodeMap[$name])) { 232 $returnNode =& $this->arNodeMap[$name]; 233 unset($this->arNodeMap[$name]); 234 $this->isDirty = true; 235 } 236 237 return $returnNode; 238 } //removeNamedItem 239 240 /** 241 * Gets a node with the specifed name, taking into account namespaces 242 * @param string The namespaceURI of the node 243 * @param string The localName of the node 244 * @return mixed A reference to the requested node, or null 245 */ 246 function &getNamedItemNS($namespaceURI, $localName) { 247 $key = $this->getKeyNS($namespaceURI, $localName); 248 249 //check for explicit namespaces 250 if (isset($this->arNodeMap[$key])) { 251 return $this->arNodeMap[$key]; 252 } 253 254 //check for implicit namespaces too 255 //URI will be on element, but not attribute 256 if (isset($this->arNodeMap[$localName])) { 257 //get element namespace 258 $firstAttr =& $this->item(1); 259 $ownerElem =& $firstAttr->ownerElement; 260 261 if ($namespaceURI == $ownerElem->namespaceURI) { 262 return $this->arNodeMap[$localName]; 263 } 264 } 265 266 $null = null; 267 return $null; 268 } //getNamedItemNS 269 270 /** 271 * Assigns a node to the list, using its namespaceURI and localName 272 * @param Object A reference to the node to be assigned 273 * @return Object A reference to the assigned node 274 */ 275 function &setNamedItemNS(&$arg) { 276 $returnNode = null; 277 $key = $this->getKeyNS($arg->namespaceURI, $arg->localName); 278 279 if (isset($this->arNodeMap[$key])) { 280 $returnNode =& $this->arNodeMap[$key]; 281 } 282 else { 283 $this->isDirty = true; 284 } 285 286 $this->arNodeMap[$key] =& $arg; 287 return $returnNode; 288 } //setNamedItemNS 289 290 /** 291 * Removes a node from the list, by name, by local name and namespace URI 292 * @param string The namespaceURI of the node to be removed 293 * @param string The localName of the node to be removed 294 * @return mixed A reference to the removed node, or null 295 */ 296 function &removeNamedItemNS($namespaceURI, $localName) { 297 $returnNode = null; 298 $key = $this->getKeyNS($namespaceURI, $localName); 299 300 if (isset($this->arNodeMap[$key])) { 301 $returnNode =& $this->arNodeMap[$key]; 302 unset($this->arNodeMap[$key]); 303 $this->isDirty = true; 304 } 305 306 return $returnNode; 307 } //removeNamedItemNS 308 309 /** 310 * Returns the key of the NamedNodeMap, given the namespaceURI and localName 311 * @param string The namespaceURI of the node to be removed 312 * @param string The localName of the node to be removed 313 * @return string The key of the NamedNodeMap 314 */ 315 function getKeyNS($namespaceURI, $localName) { 316 if ($namespaceURI != '') { 317 return $namespaceURI . ":" . $localName; 318 } 319 320 return $localName; 321 } //getKeyNS 322 323 /** 324 * Return the node at the specified index 325 * @param int The index of the requested node 326 * @return mixed A reference to the requested node, or null 327 */ 328 function &item($index) { 329 if ($this->isDirty) $this->reindexNodeMap(); 330 return $this->arNodeMap[$this->indexedNodeMap[$index]]; 331 } //item 332 333 /** 334 * Returns the number of nodes in the map 335 * @return int The number of nodes in the map 336 */ 337 function getLength() { 338 return count($this->arNodeMap); 339 } //getLength 340 341 /** 342 * Formats a string for presentation as HTML 343 * @param string The string to be formatted 344 * @param boolean True if the string is to be sent directly to output 345 * @return string The HTML formatted string 346 */ 347 function forHTML($str, $doPrint = false) { 348 require_once (DOMIT_INCLUDE_PATH . 'xml_domit_utilities.php'); 349 return DOMIT_Utilities::forHTML($str, $doPrint); 350 } //forHTML 351 352 /** 353 * Generates an array representation of the node and its children 354 * @return Array A representation of the node and its children 355 */ 356 function toArray() { 357 return $this->arNodeMap; 358 } //toArray 359 360 /** 361 * Copies a node and/or its children 362 * @param boolean True if all child nodes are also to be cloned 363 * @return Object A copy of the node and/or its children 364 */ 365 function &createClone($deep = false) { 366 $className = get_class($this); 367 $clone = new $className(); 368 369 foreach ($this->arNodeMap as $key => $value) { 370 $currNode =& $this->arNodeMap[$key]; 371 $clone->arNodeMap[$key] =& $currNode->cloneNode($deep); 372 } 373 374 return $clone; 375 } //createClone 376 377 /** 378 * Generates a string representation of the node and its children 379 * @param boolean True if HTML readable output is desired 380 * @param boolean True if illegal xml characters in text nodes and attributes should be converted to entities 381 * @return string The string representation 382 */ 383 function toString($htmlSafe = false, $subEntities=false) { 384 $result = ''; 385 386 foreach ($this->arNodeMap as $key => $value) { 387 $currNode =& $this->arNodeMap[$key]; 388 $result .= $currNode->toString(false, $subEntities); 389 } 390 391 if ($htmlSafe) $result = $this->forHTML($result); 392 393 return $result; 394 } //toString 395 396 /** 397 * Generates a normalized (formatted for readability) representation of the node collection 398 * @param boolean True if HTML readable output is desired 399 * @param boolean True if illegal xml characters in text nodes and attributes should be converted to entities 400 * @return string The string representation 401 */ 402 function toNormalizedString($htmlSafe = false, $subEntities=false) { 403 $result = ''; 404 405 foreach ($this->arNodeMap as $key => $value) { 406 $currNode =& $this->arNodeMap[$key]; 407 $result .= $currNode->toNormalizedString(false, $subEntities); 408 } 409 410 if ($htmlSafe) $result = $this->forHTML($result); 411 412 return $result; 413 } //toNormalizedString 414 } //DOMIT_NamedNodeMap 415 416 /** 417 * A NamedNodeMap with specialized funtionality for Attribute nodes 418 * 419 * @package domit-xmlparser 420 * @author John Heinstein <johnkarl@nbnet.nb.ca> 421 */ 422 class DOMIT_NamedNodeMap_Attr extends DOMIT_NamedNodeMap { 423 /** 424 * Generates an array representation of the node and its children 425 * @return Array A representation of the node and its children 426 */ 427 function toArray() { 428 $arReturn = array(); 429 430 foreach ($this->arNodeMap as $key => $value) { 431 $arReturn[$key] = $this->arNodeMap[$key]->getValue(); 432 } 433 434 return $arReturn; 435 } //toArray 436 437 /** 438 * Generates a string representation of the node and its children 439 * @param boolean True if HTML readable output is desired 440 * @param boolean True if illegal xml characters in text nodes and attributes should be converted to entities 441 * @return string The string representation 442 */ 443 function toString($htmlSafe = false, $subEntities=false) { 444 $result = ''; 445 446 foreach ($this->arNodeMap as $key => $value) { 447 $currNode =& $this->arNodeMap[$key]; 448 $result .= $currNode->toString(false, $subEntities); 449 } 450 451 if ($htmlSafe) $result = $this->forHTML($result); 452 453 return $result; 454 } //toString 455 } //DOMIT_NamedNodeMap_Attr 456 457 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Wed Nov 21 14:43:32 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |