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