2005-06-19 21:00:58 +02:00
|
|
|
<?php
|
|
|
|
/**
|
2009-07-15 21:31:25 +02:00
|
|
|
* eGroupWare - SyncML based on Horde 3
|
|
|
|
*
|
|
|
|
* The SyncML_Command class provides a base class for handling all <SyncBody>
|
|
|
|
* commands.
|
2005-06-19 21:00:58 +02:00
|
|
|
*
|
2009-07-15 21:31:25 +02:00
|
|
|
* A SyncML command is a protocol primitive. Each SyncML command specifies to
|
|
|
|
* a recipient an individual operation that is to be performed.
|
2005-06-19 21:00:58 +02:00
|
|
|
*
|
2009-07-15 21:31:25 +02:00
|
|
|
* The SyncML_Command objects are hooked into the XML parser of the
|
|
|
|
* SyncML_ContentHandler class and are reponsible for parsing a single command
|
|
|
|
* inside the SyncBody section of a SyncML message. All actions that must be
|
|
|
|
* executed for a single SyncML command are handled by these objects, by means
|
|
|
|
* of the handleCommand() method.
|
2005-06-19 21:00:58 +02:00
|
|
|
*
|
|
|
|
*
|
2009-07-15 21:31:25 +02:00
|
|
|
* Using the PEAR Log class (which need to be installed!)
|
|
|
|
*
|
|
|
|
* @link http://www.egroupware.org
|
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
|
|
|
* @package api
|
|
|
|
* @subpackage horde
|
|
|
|
* @author Anthony Mills <amills@pyramid6.com>
|
|
|
|
* @author Jan Schneider <jan@horde.org>
|
|
|
|
* @author Joerg Lehrke <jlehrke@noc.de>
|
|
|
|
* @copyright (c) The Horde Project (http://www.horde.org/)
|
|
|
|
* @version $Id$
|
2005-06-19 21:00:58 +02:00
|
|
|
*/
|
2009-07-15 21:31:25 +02:00
|
|
|
include_once 'Horde/SyncML/State_egw.php';
|
|
|
|
|
2005-06-19 21:00:58 +02:00
|
|
|
class Horde_SyncML_Command {
|
|
|
|
|
2009-07-15 21:31:25 +02:00
|
|
|
/**
|
|
|
|
* Name of the command, like 'Put'.
|
|
|
|
*
|
|
|
|
* Must be overwritten by a sub class.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
var $_cmdName;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The command ID (<CmdID>).
|
|
|
|
*
|
|
|
|
* @var integer
|
|
|
|
*/
|
2005-06-19 21:00:58 +02:00
|
|
|
var $_cmdID;
|
|
|
|
|
2009-07-15 21:31:25 +02:00
|
|
|
/**
|
|
|
|
* Stack for holding the XML elements during creation of the object from
|
|
|
|
* the XML event flow.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
var $_stack = array();
|
2005-06-19 21:00:58 +02:00
|
|
|
|
2009-07-15 21:31:25 +02:00
|
|
|
/**
|
|
|
|
* Buffer for the parsed character data.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
var $_chars = '';
|
2005-06-19 21:00:58 +02:00
|
|
|
|
2009-07-15 21:31:25 +02:00
|
|
|
/**
|
|
|
|
* Start element handler for the XML parser, delegated from
|
|
|
|
* SyncML_ContentHandler::startElement().
|
|
|
|
*
|
|
|
|
* @param string $uri The namespace URI of the element.
|
|
|
|
* @param string $element The element tag name.
|
|
|
|
* @param array $attrs A hash with the element's attributes.
|
|
|
|
*/
|
|
|
|
function startElement($uri, $element, $attrs)
|
2005-06-19 21:00:58 +02:00
|
|
|
{
|
2009-07-15 21:31:25 +02:00
|
|
|
$this->_stack[] = $element;
|
2005-06-19 21:00:58 +02:00
|
|
|
}
|
|
|
|
|
2009-07-15 21:31:25 +02:00
|
|
|
/**
|
|
|
|
* End element handler for the XML parser, delegated from
|
|
|
|
* SyncML_ContentHandler::endElement().
|
|
|
|
*
|
|
|
|
* @param string $uri The namespace URI of the element.
|
|
|
|
* @param string $element The element tag name.
|
|
|
|
*/
|
2005-06-19 21:00:58 +02:00
|
|
|
function endElement($uri, $element)
|
|
|
|
{
|
2009-07-15 21:31:25 +02:00
|
|
|
if (count($this->_stack) == 2 &&
|
|
|
|
$element == 'CmdID') {
|
|
|
|
$this->_cmdID = intval(trim($this->_chars));
|
2005-06-19 21:00:58 +02:00
|
|
|
}
|
|
|
|
|
2009-07-15 21:31:25 +02:00
|
|
|
if (strlen($this->_chars)) {
|
|
|
|
$this->_chars = '';
|
2005-06-19 21:00:58 +02:00
|
|
|
}
|
|
|
|
|
2009-07-15 21:31:25 +02:00
|
|
|
array_pop($this->_stack);
|
2005-06-19 21:00:58 +02:00
|
|
|
}
|
|
|
|
|
2009-07-15 21:31:25 +02:00
|
|
|
/**
|
|
|
|
* Character data handler for the XML parser, delegated from
|
|
|
|
* SyncML_ContentHandler::characters().
|
|
|
|
*
|
|
|
|
* @param string $str The data string.
|
|
|
|
*/
|
2005-06-19 21:00:58 +02:00
|
|
|
function characters($str)
|
|
|
|
{
|
|
|
|
if (isset($this->_chars)) {
|
2009-07-15 21:31:25 +02:00
|
|
|
$this->_chars .= $str;
|
2005-06-19 21:00:58 +02:00
|
|
|
} else {
|
|
|
|
$this->_chars = $str;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-15 21:31:25 +02:00
|
|
|
/**
|
|
|
|
* Returns the command name this instance is reponsible for.
|
|
|
|
*
|
|
|
|
* @return string The command name this object is handling.
|
|
|
|
*/
|
|
|
|
function getCommandName()
|
|
|
|
{
|
|
|
|
return $this->_cmdName;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This method is supposed to implement the actual business logic of the
|
|
|
|
* command once the XML parsing is complete.
|
|
|
|
*
|
|
|
|
* @abstract
|
|
|
|
*/
|
|
|
|
function output($currentCmdID, &$output)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Attempts to return a concrete Horde_SyncML_Command instance based on
|
|
|
|
* $command.
|
|
|
|
*
|
|
|
|
* @param string $command The type of the concrete
|
|
|
|
* SyncML_Comment subclass to
|
|
|
|
* return.
|
|
|
|
* @param $params Optional Parameter.
|
|
|
|
*
|
|
|
|
* @return SyncML_Command The newly created concrete SyncML_Command
|
|
|
|
* instance, or false on error.
|
|
|
|
*/
|
|
|
|
function &factory($command, $params = null)
|
|
|
|
{
|
|
|
|
$command = basename($command);
|
|
|
|
$class = 'Horde_SyncML_Command_' . $command;
|
|
|
|
|
|
|
|
if (!class_exists($class)) {
|
|
|
|
include_once 'Horde/SyncML/Command/' . $command . '.php';
|
|
|
|
}
|
|
|
|
if (class_exists($class)) {
|
|
|
|
$cmd = new $class($params);
|
|
|
|
} else {
|
|
|
|
$msg = 'SyncML: Class definition of ' . $class . ' not found.';
|
|
|
|
Horde::logMessage($msg, __FILE__, __LINE__, PEAR_LOG_ERR);
|
|
|
|
require_once 'PEAR.php';
|
|
|
|
$cmd = PEAR::raiseError($msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $cmd;
|
|
|
|
}
|
|
|
|
|
2005-06-19 21:00:58 +02:00
|
|
|
}
|