[sync] last syncml command class

Anthony Mills amills at gascard.net
Sat Dec 20 03:16:12 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';

/**
 * 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.
  *
  *
  */
class Horde_RPC_syncml_command_Sync extends Horde_RPC_syncml_command {
    
    
    var $_isInSource;
    
    
    var $_targetURI;
    
    
    var $_sourceURI;

    
    var $_currentSyncElement;
    
    
    var $_syncElements;
    
    
    function outputStatus($currentCmdID, $output)
    {
        $status = &new Horde_RPC_syncml_command_Status(RESPONSE_OK, 'Sync');
        $status->setVersion(version);
        $status->setCmdRef(cmdID);
        $status->setMsgID(msgID);
        
        if ($this->_targetURI != null)
            $status->setTargetRef($this->_targetURI);
        
        if ($this->_sourceURI != null)
            $status->setSourceRef($this->_sourceURI);
        
        return $status->output($currentCmdID, $output);
    }
        
    function output($currentCmdID, $output)
    {
        attrs = array();
        
        $output->startElement(uri, 'Sync', $attrs);

        $output->startElement(uri, 'CmdID', $attrs);
        $chars = (new String(currentCmdID + '')).toCharArray();
        $output->characters(chars, 0, chars.length);
        $output->endElement(uri, 'CmdID');

        $output->startElement(uri, 'Target', $attrs);
        $output->startElement(uri, 'LocURI', $attrs);
        $chars = (new String(sourceURI + '')).toCharArray();
        $output->characters(chars, 0, chars.length);
        $output->endElement(uri, 'LocURI');
        $output->endElement(uri, 'Target');
        
        $output->startElement(uri, 'Source', $attrs);
        $output->startElement(uri, 'LocURI', $attrs);
        $chars = (new String(targetURI + '')).toCharArray();
        $output->characters(chars, 0, chars.length);
        $output->endElement(uri, 'LocURI');
        $output->endElement(uri, 'Source');
   
        $output->startElement(uri, 'NumberOfChanged', $attrs);
        $chars = (new String(syncElements.size() + '')).toCharArray();
        $output->characters(chars, 0, chars.length);
        $output->endElement(uri, 'NumberOfChanged');
   
        $output->endElement(uri, 'Sync');
        
        $currentCmdID++;
        
        return $currentCmdID;
    }

/*    
    function startSync(int currentCmdID, ContentHandler contentHandler, ErrorHandler errorHandler) throws SAXException {
        return currentCmdID;
    }
    
    function endSync(int currentCmdID, ContentHandler contentHandler, ErrorHandler errorHandler) throws SAXException {
        return currentCmdID;
    }
    
    public Iterator getSyncElements() {
        return syncElements.iterator();
    }
*/
    
    function getTargetURI() {
        return $this->_targetURI;
    }
    
    function startElement($uri, $element, $attrs)
    {            
        parent::startElement($uri, $element, $attrs);
        
        if ($this->_currentSyncElement != null)
            $this->_currentSyncElement.startElement($uri, $element, $attrs);
        
        switch ($this->_currentElementLevel) {
            case 2:                
                if ($element = 'Replace' || $element = 'Add' || $element = 'Atomic'
                    || $element = 'Copy' || $element = 'Delete' || $element = 'Sequence') {
                    $this->_currentSyncElement = SyncElementFactory::newInstance($this->_element);
                    $this->_currentSyncElement.setVersion($this->_version);
                    $this->_currentSyncElement.setCmdRef($this->_cmdID);
                    $this->_currentSyncElement.setMsgID($this->_msgID);
                    
                } else if ($element == 'Target') {
                    $this->_isInSource = false;
                } else {
                    $this->_isInSource = true;
                }
                break;
        }                
    }

    function endElement($uri, $element)
    {        
        switch ($this->_currentElementLevel) {
            case 2:
                if ($element = 'Replace' || $element = 'Add' || $element = 'Atomic'
                    || $element = 'Copy' || $element = 'Delete' || $element = 'Sequence') {
                    //syncElements.add(currentSyncElement);
                    
                }
                break;                
            case 3:
                if ($element = 'LocURI') {
                    if ($this->_isInSource)
                        $this->_sourceURI = trim($this->_chars);
                    else
                        $this->_targetURI = trim($this->_chars);
                }
                break;
        }

        if ($this->_currentSyncElement != null)
            $this->_currentSyncElement->endElement($uri, $element);

        parent::endElement($uri, $element);
    }  
    
    
    function characters($str)
    {
        if ($this->_currentSyncElement != null) {
            $this->_currentSyncElement->characters($str);
        } else {
            if (isset($this->_chars)) {
                $this->_chars = $this->_chars . $str;
            }
        }
    }

}
?>



More information about the sync mailing list