[ Index ]
 

Code source de SPIP Agora 1.4

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/Agora1-4/ecrire/include/dxs/ -> dxs_object.php (source)

   1  <?php
   2  /*****************************************************
   3  * This file is part of Agora, web based content management system.
   4  *
   5  * Agora is free software; you can redistribute it and/or modify
   6  * it under the terms of the GNU General Public License as published by
   7  * the Free Software Foundation; version 2 of the License.
   8  *
   9  * Agora is distributed in the hope that it will be useful,
  10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12  * GNU General Public License for more details (file "COPYING").
  13  *
  14  * Copyright © Arnaud Martin, Antoine Pitrou et Philippe Rivière.
  15  * List of authors detailed in "copyright_fr.html" file.
  16  * E-mail : agora@sig.premier-ministre.gouv.fr
  17  * Web site : http://www.agora.gouv.fr
  18  *****************************************************/
  19  //we are waiting for a solution of the bug:
  20  //    http://pear.php.net/bugs/bug.php?id=1238
  21  require_once  'PEARTree.php';
  22  
  23  class DXS_TrivialValidatorData {
  24      var $_namespace;
  25      var $_rootElement;
  26  
  27  	function DXS_TrivialValidatorData ($space, $root) {
  28          $this->_namespace = $space;
  29          $this->_rootElement = $root;
  30      }
  31  }
  32  
  33  /**
  34   * Clever-Age XMLTree class is a base class for every XML representation 
  35   * of Agora data (through DXS).
  36   * @package    XML
  37   * @author Maciek Borowka <maciek@clever-age.com>
  38   * @access    public
  39   */
  40  class DXS_Object {
  41      // {{{ properties
  42  
  43      /**
  44      * The PEAR xml tree.
  45      * @var     XML_Tree
  46      * @access  private
  47      */
  48      var $xmlTree;
  49  
  50      /**
  51      * The raw xml content. Can contain garbage if initOK is not true.
  52      * @var     String
  53      * @access  private
  54      */
  55      var $content;
  56  
  57      /**
  58      * If true, the xmlTree contains a valid XML Tree
  59      * @var     Boolean
  60      * @access  private
  61      */
  62      var $initOK;
  63  
  64      /**
  65      * If true, the xmlTree contains a valid XML Tree
  66      * @var     Boolean
  67      * @access  private
  68      */
  69      var $debugLastError;
  70  
  71      // }}}
  72  
  73      // {{{ constructor
  74  
  75      /**
  76      * DXS_Object constructor.
  77      *
  78      * @access public
  79      */
  80  	function DXS_Object () { }
  81  
  82      // }}}
  83  
  84      // {{{ getInitOK()
  85      /** @access public
  86      */
  87  	function getInitOK () {
  88          if (!isset($this->xmlTree)) {
  89              //echo "<p>DXS_Object::xmlTree unset</p>\n";
  90              return FALSE;
  91          }
  92          else {
  93              //echo "<p>DXS_Object::xmlTree SET:".var_dump($this->initOK)." :+)))</p>\n";
  94              return $this->initOK;
  95          }
  96      }
  97  
  98      // }}}
  99  
 100      // {{{ getXMLTree()
 101      /** @access public
 102      */
 103  	function getXMLTree () {
 104          return $this->xmlTree;
 105      }
 106  
 107      // }}}
 108  
 109      // {{{ handleCDATA()
 110  
 111      /** There is a special feature in the DXS project: in any CDATA tags, if an "escape"
 112      * argument is present, every occurence of the value
 113      * of this argument is replaced by "]]>" (the end of the CDATA section).
 114      * That means it is possible to send virtually EVERY string
 115      * using that class, even those that contain the "]]>" substring (normally
 116      * forbidden in the CDATA sections, of course). <br/>
 117      * For performance reasons, this treatement is not made automaticaly
 118      * (and what's more, from time to time, one needs to avoid that).
 119      * That's why this method exists. It takes a tag and if needed (if "escape"
 120      * is present), it handles the content of the tag. No treatment is performed
 121      * on the children.
 122      * <b>Remember to pass the $xmlCDATATag by reference</b>
 123      * @access public
 124      */
 125  	function handleCDATA ($xmlCDATATag) {
 126          $escapeStr = $xmlCDATATag->getAttribute("escape");
 127  
 128          if ($escapeStr != "") {
 129              $content = str_replace($escapeStr, "]]>", $xmlCDATATag->content);
 130              $xmlCDATATag->content = $content;
 131          }
 132      }
 133  
 134      // }}}
 135  
 136      // {{{ initFromString()
 137  
 138      /** Initializes this object from an xml string.
 139      * This version of xml tree is only able to verify
 140      * whether the root element and namespace are those specified 
 141          * by TrivialValidatorData $validatorData.
 142      * Future versions will hopefully support the full XMLSchema validation.
 143      * @access public
 144      */
 145  	function initFromString ($xmlContent, $validatorData) {
 146          if (isset($this->xmlTree))
 147              unset($this->xmlTree);
 148  
 149          $this->initOK = FALSE;
 150  
 151          $this->debugLastError = "100/INIT OK";
 152          //echo "<pre>".$xmlContent."</p>\n";
 153  
 154          $this->xmlTree = new XML_Tree();
 155          $this->content = $xmlContent;
 156  
 157          $err = $this->xmlTree->getTreeFromString($this->content);
 158  
 159          if (!PEAR::isError($err)) {
 160              //very simple validation...
 161              if (($this->xmlTree->root->name == $validatorData->_rootElement) && ($this->xmlTree->root->getAttribute(
 162                                                                                       'xmlns')
 163                                                                                      == $validatorData->_namespace)) {
 164                  $this->initOK = TRUE;
 165              }
 166              else {
 167                  $this->debugLastError
 168                      = '200/Bad root element ' . $this->xmlTree->root->name . ' instead of ' . $validatorData->_rootElement . ' or namespace ' . $this->xmlTree->root->getAttribute(
 169                                                                                                                                                      'xmlns'). ' instead of ' . $validatorData->_namespace;
 170              }
 171          }
 172          else
 173              $this->debugLastError = "200/Error in xml parser";
 174  
 175          return $this->initOK;
 176      }
 177  
 178      // }}}
 179  
 180      // {{{ init()
 181  
 182      /**  This function behaves like initFromString, but
 183      * reads the data to parse from the file $fileName.
 184      * If allow_url_fopen is On in php.ini, you can also use URLs.
 185      * @access public
 186      */
 187  	function initFromFile ($fileName, $validatorData) {
 188          //reading the file
 189          $this->content = "";
 190          $fp = @fopen($fileName, "r");
 191  
 192          if (!is_resource($fp)) {
 193              //echo "<p>DXS_Object: Bad file : $fileName. (Or allow_url_fopen is off in php.ini)</p>";
 194              $this->initOK = FALSE;
 195              return FALSE;
 196          }
 197  
 198          while (!feof($fp)) {
 199              $this->content .= fgets($fp, 1024);
 200          }
 201  
 202          fclose($fp);
 203  
 204          return $this->initFromString($this->content, $validatorData);
 205      }
 206  
 207      // }}}
 208  
 209      // {{{ getAgoraEntity()
 210  
 211      /**
 212      * Fetches, parses and constructs an object "metier"
 213      * using the data found at the URL $url.
 214      * @access public    
 215      */
 216  	function getAgoraEntity ($url) { /* PSEUDO ABSTRACT */ }
 217  
 218  // }}}
 219  
 220  }
 221  ?>


Généré le : Sat Feb 24 14:40:03 2007 par Balluche grâce à PHPXref 0.7