source: trunk/www.guidonia.net/wp/wp-content/plugins/webtv/Drivers/Zend/Gdata/App/Entry.php@ 44

Last change on this file since 44 was 44, checked in by luciano, 14 years ago
File size: 11.2 KB
Line 
1<?php
2
3/**
4 * Zend Framework
5 *
6 * LICENSE
7 *
8 * This source file is subject to the new BSD license that is bundled
9 * with this package in the file LICENSE.txt.
10 * It is also available through the world-wide-web at this URL:
11 * http://framework.zend.com/license/new-bsd
12 * If you did not receive a copy of the license and are unable to
13 * obtain it through the world-wide-web, please send an email
14 * to license@zend.com so we can send you a copy immediately.
15 *
16 * @category Zend
17 * @package Zend_Gdata
18 * @subpackage App
19 * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
20 * @license http://framework.zend.com/license/new-bsd New BSD License
21 */
22
23/**
24 * @see Zend_Gdata_App_FeedEntryParent
25 */
26require_once 'Zend/Gdata/App/FeedEntryParent.php';
27
28/**
29 * @see Zend_Gdata_App_Extension_Content
30 */
31require_once 'Zend/Gdata/App/Extension/Content.php';
32
33/**
34 * @see Zend_Gdata_App_Extension_Edited
35 */
36require_once 'Zend/Gdata/App/Extension/Edited.php';
37
38/**
39 * @see Zend_Gdata_App_Extension_Published
40 */
41require_once 'Zend/Gdata/App/Extension/Published.php';
42
43/**
44 * @see Zend_Gdata_App_Extension_Source
45 */
46require_once 'Zend/Gdata/App/Extension/Source.php';
47
48/**
49 * @see Zend_Gdata_App_Extension_Summary
50 */
51require_once 'Zend/Gdata/App/Extension/Summary.php';
52
53/**
54 * @see Zend_Gdata_App_Extension_Control
55 */
56require_once 'Zend/Gdata/App/Extension/Control.php';
57
58/**
59 * Concrete class for working with Atom entries.
60 *
61 * @category Zend
62 * @package Zend_Gdata
63 * @subpackage App
64 * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
65 * @license http://framework.zend.com/license/new-bsd New BSD License
66 */
67class Zend_Gdata_App_Entry extends Zend_Gdata_App_FeedEntryParent
68{
69
70 /**
71 * Root XML element for Atom entries.
72 *
73 * @var string
74 */
75 protected $_rootElement = 'entry';
76
77 /**
78 * Class name for each entry in this feed*
79 *
80 * @var string
81 */
82 protected $_entryClassName = 'Zend_Gdata_App_Entry';
83
84 /**
85 * atom:content element
86 *
87 * @var Zend_Gdata_App_Extension_Content
88 */
89 protected $_content = null;
90
91 /**
92 * atom:published element
93 *
94 * @var Zend_Gdata_App_Extension_Published
95 */
96 protected $_published = null;
97
98 /**
99 * atom:source element
100 *
101 * @var Zend_Gdata_App_Extension_Source
102 */
103 protected $_source = null;
104
105 /**
106 * atom:summary element
107 *
108 * @var Zend_Gdata_App_Extension_Summary
109 */
110 protected $_summary = null;
111
112 /**
113 * app:control element
114 *
115 * @var Zend_Gdata_App_Extension_Control
116 */
117 protected $_control = null;
118
119 /**
120 * app:edited element
121 *
122 * @var Zend_Gdata_App_Extension_Edited
123 */
124 protected $_edited = null;
125
126 public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
127 {
128 $element = parent::getDOM($doc, $majorVersion, $minorVersion);
129 if ($this->_content != null) {
130 $element->appendChild($this->_content->getDOM($element->ownerDocument));
131 }
132 if ($this->_published != null) {
133 $element->appendChild($this->_published->getDOM($element->ownerDocument));
134 }
135 if ($this->_source != null) {
136 $element->appendChild($this->_source->getDOM($element->ownerDocument));
137 }
138 if ($this->_summary != null) {
139 $element->appendChild($this->_summary->getDOM($element->ownerDocument));
140 }
141 if ($this->_control != null) {
142 $element->appendChild($this->_control->getDOM($element->ownerDocument));
143 }
144 if ($this->_edited != null) {
145 $element->appendChild($this->_edited->getDOM($element->ownerDocument));
146 }
147 return $element;
148 }
149
150 protected function takeChildFromDOM($child)
151 {
152 $absoluteNodeName = $child->namespaceURI . ':' . $child->localName;
153 switch ($absoluteNodeName) {
154 case $this->lookupNamespace('atom') . ':' . 'content':
155 $content = new Zend_Gdata_App_Extension_Content();
156 $content->transferFromDOM($child);
157 $this->_content = $content;
158 break;
159 case $this->lookupNamespace('atom') . ':' . 'published':
160 $published = new Zend_Gdata_App_Extension_Published();
161 $published->transferFromDOM($child);
162 $this->_published = $published;
163 break;
164 case $this->lookupNamespace('atom') . ':' . 'source':
165 $source = new Zend_Gdata_App_Extension_Source();
166 $source->transferFromDOM($child);
167 $this->_source = $source;
168 break;
169 case $this->lookupNamespace('atom') . ':' . 'summary':
170 $summary = new Zend_Gdata_App_Extension_Summary();
171 $summary->transferFromDOM($child);
172 $this->_summary = $summary;
173 break;
174 case $this->lookupNamespace('app') . ':' . 'control':
175 $control = new Zend_Gdata_App_Extension_Control();
176 $control->transferFromDOM($child);
177 $this->_control = $control;
178 break;
179 case $this->lookupNamespace('app') . ':' . 'edited':
180 $edited = new Zend_Gdata_App_Extension_Edited();
181 $edited->transferFromDOM($child);
182 $this->_edited = $edited;
183 break;
184 default:
185 parent::takeChildFromDOM($child);
186 break;
187 }
188 }
189
190 /**
191 * Uploads changes in this entry to the server using Zend_Gdata_App
192 *
193 * @param string|null $uri The URI to send requests to, or null if $data
194 * contains the URI.
195 * @param string|null $className The name of the class that should we
196 * deserializing the server response. If null, then
197 * 'Zend_Gdata_App_Entry' will be used.
198 * @param array $extraHeaders Extra headers to add to the request, as an
199 * array of string-based key/value pairs.
200 * @return Zend_Gdata_App_Entry The updated entry.
201 * @throws Zend_Gdata_App_Exception
202 */
203 public function save($uri = null, $className = null, $extraHeaders = array())
204 {
205 return $this->getService()->updateEntry($this,
206 $uri,
207 $className,
208 $extraHeaders);
209 }
210
211 /**
212 * Deletes this entry to the server using the referenced
213 * Zend_Http_Client to do a HTTP DELETE to the edit link stored in this
214 * entry's link collection.
215 *
216 * @return void
217 * @throws Zend_Gdata_App_Exception
218 */
219 public function delete()
220 {
221 $this->getService()->delete($this);
222 }
223
224 /**
225 * Reload the current entry. Returns a new copy of the entry as returned
226 * by the server, or null if no changes exist. This does not
227 * modify the current entry instance.
228 *
229 * @param string|null The URI to send requests to, or null if $data
230 * contains the URI.
231 * @param string|null The name of the class that should we deserializing
232 * the server response. If null, then 'Zend_Gdata_App_Entry' will
233 * be used.
234 * @param array $extraHeaders Extra headers to add to the request, as an
235 * array of string-based key/value pairs.
236 * @return mixed A new instance of the current entry with updated data, or
237 * null if the server reports that no changes have been made.
238 * @throws Zend_Gdata_App_Exception
239 */
240 public function reload($uri = null, $className = null, $extraHeaders = array())
241 {
242 // Get URI
243 $editLink = $this->getEditLink();
244 if (($uri === null) && $editLink != null) {
245 $uri = $editLink->getHref();
246 }
247
248 // Set classname to current class, if not otherwise set
249 if ($className === null) {
250 $className = get_class($this);
251 }
252
253 // Append ETag, if present (Gdata v2 and above, only) and doesn't
254 // conflict with existing headers
255 if ($this->_etag != null
256 && !array_key_exists('If-Match', $extraHeaders)
257 && !array_key_exists('If-None-Match', $extraHeaders)) {
258 $extraHeaders['If-None-Match'] = $this->_etag;
259 }
260
261 // If an HTTP 304 status (Not Modified)is returned, then we return
262 // null.
263 $result = null;
264 try {
265 $result = $this->service->importUrl($uri, $className, $extraHeaders);
266 } catch (Zend_Gdata_App_HttpException $e) {
267 if ($e->getResponse()->getStatus() != '304')
268 throw $e;
269 }
270
271 return $result;
272 }
273
274 /**
275 * Gets the value of the atom:content element
276 *
277 * @return Zend_Gdata_App_Extension_Content
278 */
279 public function getContent()
280 {
281 return $this->_content;
282 }
283
284 /**
285 * Sets the value of the atom:content element
286 *
287 * @param Zend_Gdata_App_Extension_Content $value
288 * @return Zend_Gdata_App_Entry Provides a fluent interface
289 */
290 public function setContent($value)
291 {
292 $this->_content = $value;
293 return $this;
294 }
295
296 /**
297 * Sets the value of the atom:published element
298 * This represents the publishing date for an entry
299 *
300 * @return Zend_Gdata_App_Extension_Published
301 */
302 public function getPublished()
303 {
304 return $this->_published;
305 }
306
307 /**
308 * Sets the value of the atom:published element
309 * This represents the publishing date for an entry
310 *
311 * @param Zend_Gdata_App_Extension_Published $value
312 * @return Zend_Gdata_App_Entry Provides a fluent interface
313 */
314 public function setPublished($value)
315 {
316 $this->_published = $value;
317 return $this;
318 }
319
320 /**
321 * Gets the value of the atom:source element
322 *
323 * @return Zend_Gdata_App_Extension_Source
324 */
325 public function getSource()
326 {
327 return $this->_source;
328 }
329
330 /**
331 * Sets the value of the atom:source element
332 *
333 * @param Zend_Gdata_App_Extension_Source $value
334 * @return Zend_Gdata_App_Entry Provides a fluent interface
335 */
336 public function setSource($value)
337 {
338 $this->_source = $value;
339 return $this;
340 }
341
342 /**
343 * Gets the value of the atom:summary element
344 * This represents a textual summary of this entry's content
345 *
346 * @return Zend_Gdata_App_Extension_Summary
347 */
348 public function getSummary()
349 {
350 return $this->_summary;
351 }
352
353 /**
354 * Sets the value of the atom:summary element
355 * This represents a textual summary of this entry's content
356 *
357 * @param Zend_Gdata_App_Extension_Summary $value
358 * @return Zend_Gdata_App_Entry Provides a fluent interface
359 */
360 public function setSummary($value)
361 {
362 $this->_summary = $value;
363 return $this;
364 }
365
366 /**
367 * Gets the value of the app:control element
368 *
369 * @return Zend_Gdata_App_Extension_Control
370 */
371 public function getControl()
372 {
373 return $this->_control;
374 }
375
376 /**
377 * Sets the value of the app:control element
378 *
379 * @param Zend_Gdata_App_Extension_Control $value
380 * @return Zend_Gdata_App_Entry Provides a fluent interface
381 */
382 public function setControl($value)
383 {
384 $this->_control = $value;
385 return $this;
386 }
387
388}
Note: See TracBrowser for help on using the repository browser.