[sync] syncml command classes
Anthony Mills
amills at gascard.net
Sat Dec 20 03:13:24 PST 2003
I put these files in this directory horde/framework/RPC/RPC/syncml_command.
Feel free to move them around. The factory can be rewritten to use file names
instead of a switch statement. The elements are case sensitive.
Anthony
-------------- next part --------------
<?php
include_once 'Horde/RPC/syncml_state.php';
include_once 'Horde/RPC/syncml_status.php';
include_once 'Horde/RPC/syncml_command/command.php';
/**
* The Horde_RPC_syncml class provides a SyncML implementation of the
* Horde RPC system.
*
* $Horde: framework/RPC/RPC/syncml.php,v 1.6 2003/12/17 16:02:44 chuck Exp $
*
* Copyright 2003 Anthony Mills <amills at pyramid6.com>
*
* See the enclosed file COPYING for license information (LGPL). If you
* did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
*
* @author Anthony Mills <amills at pyramid6.com>
* @version $Revision: 1.6 $
* @since Horde 3.0
* @package Horde_RPC
*/
/**
* All variables are from the client standpoint.
*
*
*/
class Horde_RPC_syncml_command_Alert extends Horde_RPC_syncml_command {
var $_alert;
var $_sourceURI;
var $_targetURI;
var $_metaAnchorNext;
var $_metaAnchorLast;
var $_outputMetaAnchorNext;
var $_outputMetaAnchorLast;
//var $_sync;
//SAX stack
var $_isInSource;
/** Creates a new instance of Alert */
function alert($alert = null)
{
if ($alert != null) {
$this->_alert = $alert;
}
}
function output($currentCmdID, $output)
{
$attrs = array();
$status = &new Horde_RPC_syncml_command_status((($isAuthorized) ? RESPONSE_OK : RESPONSE_INVALID_CREDENTIALS), 'Alert');
$status->setVersion($this->_version);
$status->setCmdRef($this->_cmdID);
$status->setMsgID($this->_msgID);
if ($this->_targetURI != null)
$status->setTargetRef($this->_targetURI);
if ($this->_sourceURI != null)
$status->setSourceRef($this->_sourceURI);
if ($this->_metaAnchorNext != null)
$status->setItemDataAnchorNext($this->_metaAnchorNext);
$currentCmdID = $status.output($currentCmdID, $output);
if ($this->_isAuthorized) {
$output->startElement($this->_uri, 'Alert', $attrs);
$output->startElement($this->_uri, 'CmdID', $attrs);
$chars = $this->_currentCmdID;
$output->characters($chars);
$output->endElement($this->_uri, 'CmdID');
$output->startElement($this->_uri, 'Data', $attrs);
$chars = $this->_alert;
$output->characters($chars);
$output->endElement($this->_uri, 'Data');
$output->startElement($this->_uri, 'Item', $attrs);
if ($this->_sourceURI != null) {
$output->startElement($this->_uri, 'Target', $attrs);
$output->startElement($this->_uri, 'LocURI', $attrs);
$chars = $this->_sourceURI;
$output->characters($chars);
$output->endElement($this->_uri, 'LocURI');
$output->endElement($this->_uri, 'Target');
}
if ($this->_targetURI != null) {
$output->startElement($this->_uri, 'Source', $attrs);
$output->startElement($this->_uri, 'LocURI', $attrs);
$chars = $this->_targetURI;
$output->characters($chars);
$output->endElement($this->_uri, 'LocURI');
$output->endElement($this->_uri, 'Source');
}
$output->startElement($this->_uri, 'Meta', $attrs);
$metainf$this->_uri = ($this->_version == 0) ? SyncMLState.NAME_SPACE_URI_METINF : SyncMLState.NAME_SPACE_URI_METINF_1_1;
$output->startElement($metainfuri, 'Anchor', $attrs);
if ($this->_outputMetaAnchorLast != null) {
$output->startElement(metainf$this->_uri, 'Last', $attrs);
$chars = $this->_outputMetaAnchorLast;
$output->characters($chars);
$output->endElement(metainf$this->_uri, 'Last');
}
if ($this->_outputMetaAnchorNext != null) {
$output->startElement($metainfuri, 'Next', $attrs);
$chars = $this->_outputMetaAnchorNext;
$output->characters($chars);
$output->endElement($metainfuri, 'Next');
}
$output->endElement($metainfuri, 'Anchor');
$output->endElement($this->_uri, 'Meta');
$output->endElement($this->_uri, 'Item');
$output->endElement($this->_uri, 'Alert');
$currentCmdID++;
}
return $currentCmdID;
}
/** Setter for property sourceURI.
* @param sourceURI New value of property sourceURI.
*
*/
function setSourceURI($sourceURI)
{
$this->_sourceURI = $sourceURI;
}
function getTargetURI()
{
return $this->_targetURI;
}
/** Setter for property targetURI.
* @param targetURI New value of property targetURI.
*
*/
function setTargetURI($targetURI)
{
$this->_targetURI = $targetURI;
}
function startElement($uri, $element, $attrs)
{
parent::startElement($uri, $element, $attrs);
switch ($this->_xmlStack) {
case 3:
if ($element = 'Target') {
$this->_isInSource = false;
} else {
$this->_isInSource = true;
}
break;
}
}
function endElement($uri, $element)
{
switch ($this->_xmlStack) {
case 2:
if ($element = 'Data') {
$this->_alert = intval(trim($this->_chars));
//sync = SyncFactory::newInstance(alert);
}
break;
case 4:
if ($element = 'LocURI')) {
if ($this->_isInSource)
$this->_sourceURI = trim($this->_chars);
else
$this->_targetURI = trim($this->_chars);
}
break;
case 5:
if ($element = 'Next')) {
metaAnchorNext = trim($this->_chars);
outputMetaAnchorNext = metaAnchorNext;
}
break;
}
parent::endElement($uri, $element);
}
function getAlert()
{
return $this->_alert;
}
function setAlet($alert)
{
$this->_alert = $alert;
}
}
?>
-------------- next part --------------
<?php
include_once 'Horde/RPC/syncml_state.php';
/**
* The Horde_RPC_syncml_command class provides a SyncML implementation of the
* Horde RPC system.
*
* $Horde: framework/RPC/RPC/syncml.php,v 1.6 2003/12/17 16:02:44 chuck Exp $
*
* Copyright 2003 Anthony Mills <amills at pyramid6.com>
*
* See the enclosed file COPYING for license information (LGPL). If you
* did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
*
* @author Anthony Mills <amills at pyramid6.com>
* @version $Revision: 1.6 $
* @since Horde 3.0
* @package Horde_RPC
*/
/**
* All variables are from the client standpoint.
*
*
*/
function Horde_RPC_syncml_command {
var $_cmdID;
var $_msgID;
var $_version;
var $_isAuthorized;
var $_uri;
var $_xmlStack;
var $_chars;
//var $devinf;
function output($currentCmdID, $output) {}
/** Setter for property msgID.
* @param msgID New value of property msgID.
*
*/
function setMsgID($msgID) {
$this->_msgID = $msgID;
}
function setVersion($version) {
$this->_version = $version;
if ($version == 0)
$this->_uri = NAME_SPACE_URI_SYNCML;
else
$this->_uri = NAME_SPACE_URI_SYNCML_1_1;
}
function setIsAuthorized($isAuthorized) {
$this->_isAuthorized = $isAuthorized;
}
function startElement($uri, $localName, $attrs)
{
$this->_xmlStack++;
}
function endElement($uri, $element)
{
switch ($this->_xmlStack) {
case 2:
if ($this->_localName == 'CmdID') {
$this->_cmdID = intval($this->_chars);
}
break;
}
if (isset($this->_chars)) {
unset($this->_chars);
}
$this->_xmlStack--;
}
function characters($str)
{
if (isset($this->_chars)) {
$this->_chars = $this->_chars . $str;
}
}
}
?>
-------------- next part --------------
<?php
include_once 'Horde/RPC/syncml_state.php';
include_once 'Horde/RPC/syncml_status.php';
include_once 'Horde/RPC/syncml_command/command.php';
/**
* The Horde_RPC_syncml class provides a SyncML implementation of the
* Horde RPC system.
*
* $Horde: framework/RPC/RPC/syncml.php,v 1.6 2003/12/17 16:02:44 chuck Exp $
*
* Copyright 2003 Anthony Mills <amills at pyramid6.com>
*
* See the enclosed file COPYING for license information (LGPL). If you
* did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
*
* @author Anthony Mills <amills at pyramid6.com>
* @version $Revision: 1.6 $
* @since Horde 3.0
* @package Horde_RPC
*/
/**
* All variables are from the client standpoint.
*
*
*/
class Horde_RPC_syncml_command_CommandFactory {
function createInstance($cmd) {
if ($cmd == 'Status')
return &new Horde_RPC_syncml_command_Status();
else if ($cmd == 'Get')
return &new Horde_RPC_syncml_command_Get();
else if ($cmd == 'Put')
return &new Horde_RPC_syncml_command_Put();
else if ($cmd == 'Alert')
return &new Horde_RPC_syncml_command_Alert();
else if ($cmd == 'Final')
return &new Horde_RPC_syncml_command_Final();
else if ($cmd == 'Sync')
return &new Horde_RPC_syncml_command_Sync();
else if ($cmd == 'Replace')
return &new Horde_RPC_syncml_command_Replace();
else
return null;
}
}
More information about the sync
mailing list