[ Index ]
 

Code source de Horde 3.1.3

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

title

Body

[fermer]

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

   1  <?php
   2  
   3  include_once  'SyncML/Command.php';
   4  include_once 'SyncML/Command/SyncElement.php';
   5  
   6  /**
   7   * $Horde: framework/SyncML/SyncML/Command/Sync.php,v 1.17.10.8 2006/01/11 18:39:28 selsky Exp $
   8   *
   9   * Copyright 2005-2006 Karsten Fourmont <karsten@horde.org>
  10   *
  11   * The command handler for the &gt;Sync&lt; command is the central
  12   * class to dispatch sync messages.
  13   *
  14   * During parsing of the received XML, the actual sync commands (Add,
  15   * Replace, Delete) from the client are stored in the _syncElements
  16   * attribute.  When the output method of SyncML_Command_Sync is
  17   * called, these elements are processed and the resulting status
  18   * messages created.
  19   *
  20   * Then the server modifications are sent back to the client by the
  21   * handleSync method which is called from within the output method.
  22   *
  23   * See the enclosed file COPYING for license information (LGPL). If you
  24   * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
  25   *
  26   * @author  Karsten Fourmont <karsten@horde.org>
  27   * @since   Horde 3.0
  28   * @package SyncML
  29   */
  30  class SyncML_Command_Sync extends Syncml_Command
  31  {
  32      /**
  33       * @var SyncML_Command_SyncElement
  34       */
  35      var $_currentSyncElement;
  36  
  37      /**
  38       * @var array
  39       */
  40      var $_syncElements = array();
  41  
  42      /**
  43       * contacts, calendar, tasks or notes
  44       *
  45       * @var string
  46       */
  47      var $_targetURI;
  48  
  49      /**
  50       * Creates a response to a sync command.
  51       * Currently that's the place where we also create
  52       * the &lt;sync&gt; with the server changes that
  53       * needs to be send to the client.
  54       */
  55      function output($currentCmdID, &$output)
  56      {
  57          $state =& $_SESSION['SyncML.state'];
  58          $sync =& $state->getSync($this->_targetURI);
  59          if (!is_object($sync)) {
  60              $GLOBALS['backend']->logMessage('No sync object found for URI = ' . $this->_targetURI,
  61                                              __FILE__, __LINE__, PEAR_LOG_ERR);
  62              // @TODO: create meaningful status code here.
  63          }
  64  
  65          // Here's where client modifications are processed:
  66          foreach ($this->_syncElements as $element) {
  67              foreach ($element->getItems() as $item) {
  68                  $result = $sync->handleSyncItem($item);
  69              }
  70              $currentCmdID = $element->output($currentCmdID, $output);
  71          }
  72  
  73          /* Now send client changes to server: this will precede the
  74           * <sync> response: */
  75          $currentCmdID = $sync->createSyncOutput($currentCmdID, $output);
  76  
  77          $status = &new SyncML_Command_Status(RESPONSE_OK, 'Sync');
  78          $status->setCmdRef($this->_cmdID);
  79  
  80          if ($this->_targetURI != null) {
  81              $status->setTargetRef($this->_targetURI);
  82          }
  83  
  84          if ($this->_sourceURI != null) {
  85              $status->setSourceRef($this->_sourceURI);
  86          }
  87  
  88          return $status->output($currentCmdID, $output);
  89      }
  90  
  91      function getTargetURI()
  92      {
  93          return $this->_targetURI;
  94      }
  95  
  96      function startElement($uri, $element, $attrs)
  97      {
  98          parent::startElement($uri, $element, $attrs);
  99  
 100          switch (count($this->_Stack)) {
 101          case 2:
 102              if ($element == 'Replace' || $element == 'Add' || $element == 'Delete') {
 103                  $this->_currentSyncElement = &new SyncML_Command_SyncElement($element);
 104              }
 105              break;
 106          }
 107  
 108          if (isset($this->_currentSyncElement)) {
 109              $this->_currentSyncElement->startElement($uri, $element, $attrs);
 110          }
 111      }
 112  
 113      function endElement($uri, $element)
 114      {
 115          if (isset($this->_currentSyncElement)) {
 116              $this->_currentSyncElement->endElement($uri, $element);
 117          }
 118  
 119          switch (count($this->_Stack)) {
 120          case 2:
 121              if ($element == 'Replace' || $element == 'Add' || $element == 'Delete') {
 122                  $this->_syncElements[] = $this->_currentSyncElement;
 123                  unset($this->_currentSyncElement);
 124              }
 125              break;
 126  
 127          case 3:
 128              if ($element = 'LocURI' && !isset($this->_currentSyncElement)) {
 129                  if ($this->_Stack[1] == 'Source') {
 130                      $this->_sourceURI = trim($this->_chars);
 131                  } elseif ($this->_Stack[1] == 'Target') {
 132                      $this->_targetURI = basename(preg_replace('/\?.*$/', '', trim($this->_chars)));
 133                  }
 134              }
 135              break;
 136          }
 137  
 138          parent::endElement($uri, $element);
 139      }
 140  
 141      function characters($str)
 142      {
 143          if (isset($this->_currentSyncElement)) {
 144              $this->_currentSyncElement->characters($str);
 145          } else {
 146              if (isset($this->_chars)) {
 147                  $this->_chars = $this->_chars . $str;
 148              } else {
 149                  $this->_chars = $str;
 150              }
 151          }
 152      }
 153  
 154  }


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