[ PHPXref.com ] [ Generated: Thu Jul 24 12:24:35 2008 ] [ Concerto 2.1.2 ]
[ Index ]     [ Variables ]     [ Functions ]     [ Classes ]     [ Constants ]     [ Statistics ]

title

Body

[close]

/domit/ -> xml_domit_shared.php (source)

   1  <?php
   2  /**
   3  * @package domit-xmlparser
   4  * @version 1.01
   5  * @copyright (C) 2004 John Heinstein. All rights reserved
   6  * @author John Heinstein <johnkarl@nbnet.nb.ca>
   7  * @link http://www.engageinteractive.com/domit/ DOMIT! Home Page
   8  * DOMIT! is Free Software
   9  **/
  10  
  11  if (!defined('DOMIT_INCLUDE_PATH')) {
  12      /* Path to DOMIT! files */
  13      define('DOMIT_INCLUDE_PATH', (dirname(__FILE__) . "/"));
  14  }
  15  
  16  //Nodes
  17  /** DOM Element nodeType */
  18  define('DOMIT_ELEMENT_NODE', 1);
  19  /** DOM Attr nodeType */
  20  define('DOMIT_ATTRIBUTE_NODE', 2);
  21  /** DOM Text nodeType */
  22  define('DOMIT_TEXT_NODE', 3);
  23  /** DOM CDATA Section nodeType */
  24  define('DOMIT_CDATA_SECTION_NODE', 4);
  25  /** DOM Entity Reference nodeType */
  26  define('DOMIT_ENTITY_REFERENCE_NODE', 5);
  27  /** DOM Entity nodeType */
  28  define('DOMIT_ENTITY_NODE', 6);
  29  /** DOM Processing Instruction nodeType */
  30  define('DOMIT_PROCESSING_INSTRUCTION_NODE', 7);
  31  /** DOM Comment nodeType */
  32  define('DOMIT_COMMENT_NODE', 8);
  33  /** DOM Document nodeType */
  34  define('DOMIT_DOCUMENT_NODE', 9);
  35  /** DOM DocType nodeType */
  36  define('DOMIT_DOCUMENT_TYPE_NODE', 10);
  37  /** DOM Document Fragment nodeType */
  38  define('DOMIT_DOCUMENT_FRAGMENT_NODE', 11);
  39  /** DOM Notation nodeType */
  40  define('DOMIT_NOTATION_NODE', 12);
  41  
  42  //DOM Level 1 Exceptions
  43  /** DOM error: array index out of bounds  */
  44  define('DOMIT_INDEX_SIZE_ERR', 1);
  45  /** DOM error: text doesn't fit into a DOMString */
  46  define('DOMIT_DOMSTRING_SIZE_ERR', 2); 
  47  /** DOM error: node can't be inserted at this location */
  48  define('DOMIT_HIERARCHY_REQUEST_ERR', 3);
  49  /** DOM error: node not a child of target document */
  50  define('DOMIT_WRONG_DOCUMENT_ERR', 4); 
  51  /** DOM error: invalid character specified */
  52  define('DOMIT_INVALID_CHARACTER_ERR', 5);
  53  /** DOM error: data can't be added to current node */
  54  define('DOMIT_NO_DATA_ALLOWED_ERR', 6);
  55  /** DOM error: node is read-only */
  56  define('DOMIT_NO_MODIFICATION_ALLOWED_ERR', 7);
  57  /** DOM error: node can't be found in specified context */
  58  define('DOMIT_NOT_FOUND_ERR', 8);
  59  /** DOM error: operation not supported by current implementation */
  60  define('DOMIT_NOT_SUPPORTED_ERR', 9);
  61  /** DOM error: attribute currently in use elsewhere */
  62  define('DOMIT_INUSE_ATTRIBUTE_ERR', 10);
  63  
  64  //DOM Level 2 Exceptions
  65  /** DOM error: attempt made to use an object that is no longer usable */
  66  define('DOMIT_INVALID_STATE_ERR', 11);
  67  /** DOM error: invalid or illegal string specified */
  68  define('DOMIT_SYNTAX_ERR', 12);
  69  /** DOM error: can't modify underlying type of node */
  70  define('DOMIT_INVALID_MODIFICATION_ERR', 13);
  71  /** DOM error: attempt to change node in a way incompatible with namespaces */
  72  define('DOMIT_NAMESPACE_ERR', 14);
  73  /** DOM error: operation unsupported by underlying object */
  74  define('DOMIT_INVALID_ACCESS_ERR', 15);
  75  
  76  //DOMIT! Exceptions
  77  /** DOM error: attempt to instantiate abstract class */
  78  define('DOMIT_ABSTRACT_CLASS_INSTANTIATION_ERR', 100);
  79  /** DOM error: attempt to call abstract method */
  80  define('DOMIT_ABSTRACT_METHOD_INVOCATION_ERR', 101);
  81  /** DOM error: can't perform this action on or with Document Fragment */
  82  define('DOMIT_DOCUMENT_FRAGMENT_ERR', 102);
  83  
  84  //DOMIT! Error Modes
  85  /** continue on error  */
  86  define('DOMIT_ONERROR_CONTINUE', 1);
  87  /** die on error  */
  88  define('DOMIT_ONERROR_DIE', 2);
  89  
  90  
  91  /**
  92  *@global Object Instance of the UIDGenerator class
  93  */
  94  $GLOBALS['uidFactory'] = new UIDGenerator();
  95  
  96  require_once (DOMIT_INCLUDE_PATH . 'xml_domit_nodemaps.php');
  97  
  98  /**
  99  * Generates unique ids for each node
 100  *
 101  * @package domit-xmlparser
 102  * @author John Heinstein <johnkarl@nbnet.nb.ca>
 103  */
 104  class UIDGenerator {
 105      /** @var int A seed value for generating uids */
 106      var $seed;
 107      /** @var int A tally of the number of uids generated */
 108      var $counter = 0;
 109      
 110      /**
 111      * UIDGenerator constructor
 112      */
 113  	function UIDGenerator() {
 114          $this->seed = 'node' . time();
 115      } //UIDGenerator
 116      
 117      /**
 118      * Generates a unique id
 119      * @return uid 
 120      */
 121  	function generateUID() {
 122          return ($this->seed . $this->counter++);
 123      } //generateUID
 124  } //UIDGenerator
 125  
 126  /**
 127  * @global object Reference to custom error handler for DOMException class
 128  */
 129  $GLOBALS['DOMIT_DOMException_errorHandler'] = null;
 130  /**
 131  * @global int Error mode; specifies whether to die on error or simply continue
 132  */
 133  $GLOBALS['DOMIT_DOMException_mode'] = DOMIT_ONERROR_CONTINUE;
 134  /**
 135  * @global string Log file for errors
 136  */
 137  $GLOBALS['DOMIT_DOMException_log'] = null;
 138  
 139  /**
 140  * A DOMIT! exception handling class
 141  *
 142  * @package domit-xmlparser
 143  * @author John Heinstein <johnkarl@nbnet.nb.ca>
 144  */
 145  class DOMIT_DOMException {
 146      /**
 147      * Raises the specified exception
 148      * @param int The error number
 149      * @param string A string explanation of the error
 150      */
 151  	function raiseException($errorNum, $errorString) {
 152          if ($GLOBALS['DOMIT_DOMException_errorHandler'] != null) {
 153              call_user_func($GLOBALS['DOMIT_DOMException_errorHandler'], $errorNum, $errorString);
 154          }
 155          else {
 156              $errorMessageText = $errorNum  . ' ' . $errorString;
 157              $errorMessage = 'Error: ' . $errorMessageText;
 158              
 159              if ((!isset($GLOBALS['DOMIT_ERROR_FORMATTING_HTML'])) ||
 160                  ($GLOBALS['DOMIT_ERROR_FORMATTING_HTML'] == true)) {
 161                      $errorMessage = "<p><pre>" . $errorMessage . "</pre></p>";
 162              }
 163              
 164              //log error to file
 165              if ((isset($GLOBALS['DOMIT_DOMException_log'])) &&
 166                  ($GLOBALS['DOMIT_DOMException_log'] != null)) {
 167                      require_once (DOMIT_INCLUDE_PATH . 'php_file_utilities.php');
 168                      $logItem = "\n" . date('Y-m-d H:i:s') . 'DOMIT! Error ' . $errorMessageText;
 169                      php_file_utilities::putDataToFile($GLOBALS['DOMIT_DOMException_log'], 
 170                                          $logItem, 'a');
 171              }
 172              
 173              switch ($GLOBALS['DOMIT_DOMException_mode']) {
 174                  case DOMIT_ONERROR_CONTINUE:
 175                      return;
 176                      break;
 177                      
 178                  case DOMIT_ONERROR_DIE:
 179                      die($errorMessage);
 180                      break;
 181              }            
 182          }
 183      } //raiseException
 184      
 185      /**
 186      * custom handler for DOM errors
 187      * @param object A reference to the custom error handler
 188      */
 189  	function setErrorHandler($method) {
 190          $GLOBALS['DOMIT_DOMException_errorHandler'] =& $method;
 191      } //setErrorHandler
 192      
 193      /**
 194      * Set error mode
 195      * @param int The DOM error mode
 196      */
 197  	function setErrorMode($mode) {
 198          $GLOBALS['DOMIT_DOMException_mode'] = $mode;
 199      } //setErrorMode
 200      
 201      /**
 202      * Set error mode
 203      * @param boolean True if errors should be logged
 204      * @param string Absolute or relative path to log file
 205      */
 206  	function setErrorLog($doLogErrors, $logfile) {
 207          if ($doLogErrors) {
 208              $GLOBALS['DOMIT_DOMException_log'] = $logfile;
 209          }
 210          else {
 211              $GLOBALS['DOMIT_DOMException_log'] = null;
 212          }
 213      } //setErrorLog
 214  } //DOMIT_DOMException
 215  
 216  /**
 217  * A class representing the DOM Implementation node
 218  *
 219  * @package domit-xmlparser
 220  * @author John Heinstein <johnkarl@nbnet.nb.ca>
 221  */
 222  class DOMIT_DOMImplementation {
 223  	function hasFeature($feature, $version = null) {
 224          if (strtoupper($feature) == 'XML') {
 225              if (($version == '1.0') || ($version == '2.0') || ($version == null)) {
 226                  return true;
 227              }
 228          }
 229          
 230          return false;
 231      } //hasFeature
 232      
 233      /**
 234      * Creates a new DOMIT_Document node and appends a documentElement with the specified info
 235      * @param string The namespaceURI of the documentElement
 236      * @param string The $qualifiedName of the documentElement
 237      * @param Object A document type node
 238      * @return Object The new document fragment node
 239      */
 240      function &createDocument($namespaceURI, $qualifiedName, &$docType) {
 241          $xmldoc = new DOMIT_Document();
 242          $documentElement =& $xmldoc->createElementNS($namespaceURI, $qualifiedName);
 243          
 244          $xmldoc->setDocumentElement($documentElement);
 245          
 246          if ($docType != null) {
 247              $xmldoc->doctype =& $docType;
 248          }
 249          
 250          return $xmldoc;
 251      } //createDocument
 252      
 253      /**
 254      * Creates a new DOMIT_DocumentType node (not yet implemented!)
 255      * @param string The $qualifiedName
 256      * @param string The $publicID
 257      * @param string The $systemID
 258      * @return Object The new document type node
 259      */
 260      function &createDocumentType($qualifiedName, $publicID, $systemID) {
 261          //not yet implemented
 262          DOMIT_DOMException::raiseException(DOMIT_NOT_SUPPORTED_ERROR, 
 263              ('Method createDocumentType is not yet implemented.'));
 264      } //createDocumentType
 265  } //DOMIT_DOMImplementation
 266  
 267  ?>


[ Powered by PHPXref - Served by Debian GNU/Linux ]