[ Index ]
 

Code source de Horde 3.1.3

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

title

Body

[fermer]

/lib/SyncML/Command/ -> SyncElement.php (source)

   1  <?php
   2  
   3  include_once  'SyncML/Command.php';
   4  
   5  /**
   6   * The class SyncML_Command_SyncElement stores information from the Add,
   7   * Delete and Replace elements found inside a sync command.
   8   *
   9   * $Horde: framework/SyncML/SyncML/Command/SyncElement.php,v 1.3.2.3 2006/01/01 21:28:36 jan Exp $
  10   *
  11   * Copyright 2005-2006 The horde project (www.horde.org)
  12   *
  13   * See the enclosed file COPYING for license information (LGPL). If you
  14   * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
  15   *
  16   * @author  Karsten Fourmont <karsten@horde.org>
  17   * @since   Horde 3.0
  18   * @package SyncML
  19   */
  20  class SyncML_Command_SyncElement extends SyncML_Command {
  21  
  22      /**
  23       * Add, Delete or Replace.
  24       */
  25      var $_elementType;
  26  
  27      /**
  28       * Array of SyncML_SyncItem entries.
  29       */
  30      var $_items = array();
  31  
  32      /**
  33       * Mimetype for all items.
  34       */
  35      var $_contentType;
  36  
  37      /**
  38       * Temp data for creation of individual items.
  39       */
  40      var $_content;
  41  
  42      var $_cuid;
  43  
  44      /**
  45       * Mimetype for individual item.
  46       */
  47      var $_itemConentType;
  48  
  49      /**
  50       * Creates a Sync Element.
  51       *
  52       * @param string elementType either Add, Delete or Replace
  53       */
  54      function SyncML_Command_SyncElement($elementType)
  55      {
  56          $this->_elementType = $elementType;
  57      }
  58  
  59      function output($currentCmdID, &$output)
  60      {
  61          switch ($this->_elementType) {
  62          case 'Add':
  63              $response = RESPONSE_ITEM_ADDED;
  64              break;
  65  
  66          case 'Delete':
  67              $response = RESPONSE_OK;
  68              break;
  69  
  70          case 'Replace':
  71              $response = RESPONSE_OK;
  72              break;
  73          }
  74  
  75          $status = &new SyncML_Command_Status($response,
  76                                               $this->_elementType);
  77          $status->setCmdRef($this->_cmdID);
  78  
  79          return $status->output($currentCmdID, $output);
  80      }
  81  
  82      function startElement($uri, $element, $attrs)
  83      {
  84          parent::startElement($uri, $element, $attrs);
  85          switch (count($this->_Stack)) {
  86          case 2:
  87              $this->_cuid = null;
  88              $this->_content = null;
  89              $this->_itemContentType = null;
  90              break;
  91          }
  92      }
  93  
  94      function endElement($uri, $element)
  95      {
  96          switch (count($this->_Stack)) {
  97          case 1:
  98              break;
  99  
 100          case 2:
 101              if ($element == 'Item') {
 102                  if (empty($this->_itemContentType)
 103                      && !empty($this->_contentType)) {
 104                      $this->_itemContentType = $this->_contentType;
 105                  }
 106  
 107                  $this->_items[] = &new SyncML_SyncItem($this->_elementType,
 108                                                         $this->_content,
 109                                                         $this->_itemContentType,
 110                                                         $this->_cuid);
 111              }
 112  
 113          case 3:
 114              if ($element == 'Type') {
 115                  $this->_contentType = trim($this->_chars);
 116              } elseif ($element == 'Data') {
 117                  $this->_content = trim($this->_chars);
 118              }
 119              break;
 120  
 121          case 4:
 122              if ($element == 'LocURI') {
 123                  if ($this->_Stack[2] == 'Source') {
 124                      $this->_cuid = trim($this->_chars);
 125                  } elseif ($this->_Stack[2] == 'Target') {
 126                      // Not used: we ignore "suid proposals" from
 127                      // client.
 128                  }
 129              }
 130              break;
 131  
 132          case 5:
 133              if ($element == 'Type') {
 134                  $this->_itemContentType = trim($this->_chars);
 135              }
 136              break;
 137          }
 138  
 139          parent::endElement($uri, $element);
 140      }
 141  
 142      function getItems()
 143      {
 144          return $this->_items;
 145      }
 146  
 147      function getContentType()
 148      {
 149          return $this->_contentType;
 150      }
 151  
 152  }
 153  
 154  /**
 155   * The class SyncML_Command_SyncElement stores information about
 156   * the items inside a sync element (Add|Delete|Replace).
 157   *
 158   * A single SyncElement can contain multiple items.
 159   *
 160   * Instances of this class are created during the XML parsing by
 161   * SyncML_Command_SyncElement.
 162   *
 163   * @package SyncML
 164   */
 165  class SyncML_SyncItem {
 166  
 167      /**
 168       * Add, Delete or Replace, inherited from
 169       * SyncML_Command_SyncElement.
 170       */
 171      var $_elementType;
 172  
 173      var $_cuid;
 174  
 175      /**
 176       * Optional, may be provided by parent element or even not at all.
 177       */
 178      var $_contentType;
 179  
 180      var $_content;
 181  
 182      function SyncML_SyncItem($elementType, $content = null,
 183                               $contentType = null, $cuid = null)
 184      {
 185          $this->_elementType = $elementType;
 186          $this->_cuid = $cuid;
 187          $this->_contentType = $contentType;
 188          $this->_content = $content;
 189      }
 190  
 191      function getCuid()
 192      {
 193          return $this->_cuid;
 194      }
 195  
 196      function getContent()
 197      {
 198          return $this->_content;
 199      }
 200  
 201      function getContentType()
 202      {
 203          return $this->_contentType;
 204      }
 205  
 206      function getElementType()
 207      {
 208          return $this->_elementType;
 209      }
 210  
 211  }


Généré le : Sun Feb 25 18:01:28 2007 par Balluche grâce à PHPXref 0.7