[ Index ]
 

Code source de Joomla 1.0.13

Accédez au Source d'autres logiciels libres

title

Body

[fermer]

/includes/domit/ -> dom_xmlrpc_domxml_parser.php (source)

   1  <?php
   2  /**
   3  * dom_xmlrpc_domxml_document wraps a DOM-XML DOM document in the DOM XML-RPC API
   4  * @package dom-xmlrpc
   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/dom_xmlrpc/ DOM XML-RPC Home Page
   9  * DOM XML-RPC is Free Software
  10  **/
  11  
  12  if (!defined('DOM_XMLRPC_INCLUDE_PATH')) {
  13      define('DOM_XMLRPC_INCLUDE_PATH', (dirname(__FILE__) . "/"));
  14  }
  15  
  16  require_once (DOM_XMLRPC_INCLUDE_PATH . 'dom_xmlrpc_constants.php');
  17  
  18  /**
  19  * Wraps a DOM-XML DOM document in the DOM XML-RPC API
  20  *
  21  * @package dom-xmlrpc
  22  * @author John Heinstein <johnkarl@nbnet.nb.ca>
  23  */
  24  class dom_xmlrpc_domxml_document {
  25      /** @var object A reference to the DOM-XML document */
  26      var $xmldoc = null;
  27  
  28      /**
  29      * Instantiates a DOM-XML Document
  30      * @param string The XML text to be parsed
  31      * @return boolean True if parsing has been successful
  32      */
  33  	function parseXML($xmlText) {
  34          //remove whitespace
  35          $xmlText = eregi_replace('>' . "[[:space:]]+" . '<' , '><', $xmlText);
  36  
  37          //parse document
  38          $this->xmldoc = domxml_open_mem($xmlText);
  39  
  40          if (is_object($this->xmldoc)) $success = true;
  41          else $success = false;
  42  
  43          return $success;
  44      } //parseXML
  45  
  46      /**
  47      * Returns a reference to the DOM-XML Document
  48      * @return object A reference to the DOM-XML Document
  49      */
  50  	function getDocument() {
  51          return $this->xmldoc;
  52      } //getDocument
  53  
  54      /**
  55      * Gets the method type
  56      * @return string The method type
  57      */
  58  	function getMethodType() {
  59          $root = $this->xmldoc->document_element();
  60          return $root->node_name();
  61      } //getMethodType
  62  
  63      /**
  64      * Gets the method name
  65      * @return string The method name
  66      */
  67  	function getMethodName() {
  68          if ($this->getMethodType() == DOM_XMLRPC_TYPE_METHODCALL) {
  69              $node = $this->xmldoc->document_element();
  70              $childNodes = $node->child_nodes();
  71              $node = $childNodes[0];
  72              $node = $node->first_child();
  73              return $node->node_value();
  74          }
  75          //else throw exception
  76      } //getMethodName
  77  
  78      /**
  79      * Gets a reference to the method params node
  80      * @return object A reference to the method params node
  81      */
  82  	function getParams() {
  83          switch ($this->getMethodType()) {
  84              case DOM_XMLRPC_TYPE_METHODCALL:
  85                  $node = $this->xmldoc->document_element();
  86                  $childNodes = $node->child_nodes();
  87                  return $childNodes[1];
  88                  break;
  89  
  90              case DOM_XMLRPC_TYPE_METHODRESPONSE:
  91                  if (!$this->isFault()) {
  92                      $node = $this->xmldoc->document_element();
  93                      return $node->first_child();
  94                  }
  95                  break;
  96          }
  97          //else throw exception
  98      } //getParams
  99  
 100      /**
 101      * Gets a reference to the specified param
 102      * @param int The index of the requested param
 103      * @return object A reference to the specified param
 104      */
 105  	function getParam($index) {
 106          switch ($this->getMethodType()) {
 107              case DOM_XMLRPC_TYPE_METHODCALL:
 108                  $node = $this->xmldoc->document_element();
 109                  $childNodes = $node->child_nodes();
 110                  $node = $childNodes[1];
 111                  $childNodes = $node->child_nodes();
 112                  return $childNodes[$index];
 113                  break;
 114  
 115              case DOM_XMLRPC_TYPE_METHODRESPONSE:
 116                  if (!$this->isFault()) {
 117                      $node = $this->xmldoc->document_element();
 118                      $node = $node->first_child();
 119                      $childNodes = $node->child_nodes();
 120                      return $childNodes[$index];
 121                  }
 122                  break;
 123          }
 124          //else throw exception
 125      } //getParam
 126  
 127      /**
 128      * Gets the number of existing params
 129      * @return int The number of existing params
 130      */
 131  	function getParamCount() {
 132          switch ($this->getMethodType()) {
 133              case DOM_XMLRPC_TYPE_METHODCALL:
 134                  $node = $this->xmldoc->document_element();
 135                  $childNodes = $node->child_nodes();
 136                  $node = $childNodes[1];
 137                  $childNodes = $node->child_nodes();
 138                  return count($childNodes);
 139                  break;
 140  
 141              case DOM_XMLRPC_TYPE_METHODRESPONSE:
 142                  if (!$this->isFault()) {
 143                      $node = $this->xmldoc->document_element();
 144                      $node = $node->first_child();
 145                      $childNodes = $node->child_nodes();
 146                      return count($childNodes);
 147                  }
 148                  break;
 149          }
 150          return -1; //maybe throw an exception?
 151      } //getParamCount
 152  
 153      /**
 154      * Determines whether the method response is a fault
 155      * @return boolean True if the method response is a fault
 156      */
 157  	function isFault() {
 158          $node = $this->xmldoc->document_element();
 159          $node = $node->first_child();
 160  
 161          return ($node->node_name() == DOM_XMLRPC_TYPE_FAULT);
 162      } //isFault
 163  
 164      /**
 165      * Returns the fault code, if a fault has occurred
 166      * @return int The fault code, if a fault has occurred
 167      */
 168  	function getFaultCode() {
 169          if ($this->isFault()) {
 170              $node = $this->xmldoc->document_element();
 171              $node = $node->first_child();
 172              $node = $node->first_child();
 173              $faultStruct = $node->first_child();
 174  
 175              $childNodes = $faultStruct->child_nodes();
 176              $node = $childNodes[0];
 177              $childNodes = $node->child_nodes();
 178              $node = $childNodes[1];
 179              $node = $node->first_child();
 180              $node = $node->first_child();
 181  
 182              return ($node->node_value());
 183          }
 184      } //getFaultCode
 185  
 186      /**
 187      * Returns the fault string, if a fault has occurred
 188      * @return string The fault string, if a fault has occurred
 189      */
 190  	function getFaultString() {
 191          if ($this->isFault()) {
 192              $node = $this->xmldoc->document_element();
 193              $node = $node->first_child();
 194              $node = $node->first_child();
 195              $faultStruct = $node->first_child();
 196  
 197              $childNodes = $faultStruct->child_nodes();
 198              $node = $childNodes[1];
 199              $childNodes = $node->child_nodes();
 200              $node = $childNodes[1];
 201              $node = $node->first_child();
 202              $node = $node->first_child();
 203  
 204              return ($node->nodeValue);
 205          }
 206      } //getFaultString
 207  
 208      /**
 209      * Returns the type of the specified param
 210      * @param object A reference to the param to be tested for type
 211      * @return string The type of the param
 212      */
 213  	function getParamType($node) {
 214          switch ($node->node_name()) {
 215              case DOM_XMLRPC_TYPE_PARAM:
 216                  $node = $node->first_child();
 217                  $node = $node->first_child();
 218                  return $node->node_name();
 219                  break;
 220  
 221              default:
 222                  //throw exception
 223          }
 224      } //getParamType
 225  
 226      /**
 227      * Returns an unformatted string representation of the document
 228      * @return string An unformatted string representation of the document
 229      */
 230  	function toString() {
 231          if (func_num_args() > 0) {
 232              $node = func_get_arg(0);
 233          }
 234          else {
 235              $node = $this->xmldoc->document_element();
 236          }
 237  
 238          $str = '';
 239          $str = @$this->xmldoc->dump_node($node);
 240  
 241          if ($str == '') {
 242              $str = @$node->dump_node($node);
 243          }
 244  
 245          return $str;
 246      } //toString
 247  
 248      /**
 249      * Returns a string representation of the document, formatted for readability
 250      * @return string A string representation of the document, formatted for readability
 251      */
 252  	function toNormalizedString() {
 253          //this doesn't actually normalize the string
 254          //but is here as a precaution, better
 255          //that generating an error!
 256          if (func_num_args() > 0) {
 257              return $this->toString(func_get_arg(0));
 258          }
 259          return $this->toString();
 260      } //toNormalizedString
 261  
 262  } //dom_xmlrpc_domit_document
 263  ?>


Généré le : Wed Nov 21 14:43:32 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics