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

Last change on this file since 44 was 44, checked in by luciano, 14 years ago
File size: 20.7 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_Extension_Element
25*/
26require_once 'Zend/Gdata/App/Extension/Element.php';
27
28/**
29 * @see Zend_Gdata_App_Extension_Author
30*/
31require_once 'Zend/Gdata/App/Extension/Author.php';
32
33/**
34 * @see Zend_Gdata_App_Extension_Category
35*/
36require_once 'Zend/Gdata/App/Extension/Category.php';
37
38/**
39 * @see Zend_Gdata_App_Extension_Contributor
40*/
41require_once 'Zend/Gdata/App/Extension/Contributor.php';
42
43/**
44 * @see Zend_Gdata_App_Extension_Id
45 */
46require_once 'Zend/Gdata/App/Extension/Id.php';
47
48/**
49 * @see Zend_Gdata_App_Extension_Link
50 */
51require_once 'Zend/Gdata/App/Extension/Link.php';
52
53/**
54 * @see Zend_Gdata_App_Extension_Rights
55 */
56require_once 'Zend/Gdata/App/Extension/Rights.php';
57
58/**
59 * @see Zend_Gdata_App_Extension_Title
60 */
61require_once 'Zend/Gdata/App/Extension/Title.php';
62
63/**
64 * @see Zend_Gdata_App_Extension_Updated
65 */
66require_once 'Zend/Gdata/App/Extension/Updated.php';
67
68/**
69 * Zend_Version
70 */
71require_once 'Zend/Version.php';
72
73/**
74 * Abstract class for common functionality in entries and feeds
75 *
76 * @category Zend
77 * @package Zend_Gdata
78 * @subpackage App
79 * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
80 * @license http://framework.zend.com/license/new-bsd New BSD License
81 */
82abstract class Zend_Gdata_App_FeedEntryParent extends Zend_Gdata_App_Base
83{
84 /**
85 * Service instance used to make network requests.
86 *
87 * @see setService(), getService()
88 */
89 protected $_service = null;
90
91 /**
92 * The HTTP ETag associated with this entry. Used for optimistic
93 * concurrency in protoco v2 or greater.
94 *
95 * @var string|null
96 */
97 protected $_etag = NULL;
98
99 protected $_author = array();
100 protected $_category = array();
101 protected $_contributor = array();
102 protected $_id = null;
103 protected $_link = array();
104 protected $_rights = null;
105 protected $_title = null;
106 protected $_updated = null;
107
108 /**
109 * Indicates the major protocol version that should be used.
110 * At present, recognized values are either 1 or 2. However, any integer
111 * value >= 1 is considered valid.
112 *
113 * @see setMajorProtocolVersion()
114 * @see getMajorProtocolVersion()
115 */
116 protected $_majorProtocolVersion = 1;
117
118 /**
119 * Indicates the minor protocol version that should be used. Can be set
120 * to either an integer >= 0, or NULL if no minor version should be sent
121 * to the server.
122 *
123 * @see setMinorProtocolVersion()
124 * @see getMinorProtocolVersion()
125 */
126 protected $_minorProtocolVersion = null;
127
128 /**
129 * Constructs a Feed or Entry
130 */
131 public function __construct($element = null)
132 {
133 if (!($element instanceof DOMElement)) {
134 if ($element) {
135 $this->transferFromXML($element);
136 }
137 } else {
138 $this->transferFromDOM($element);
139 }
140 }
141
142 /**
143 * Set the HTTP client instance
144 *
145 * Sets the HTTP client object to use for retrieving the feed.
146 *
147 * @deprecated Deprecated as of Zend Framework 1.7. Use
148 * setService() instead.
149 * @param Zend_Http_Client $httpClient
150 * @return Zend_Gdata_App_Feed Provides a fluent interface
151 */
152 public function setHttpClient(Zend_Http_Client $httpClient)
153 {
154 if (!$this->_service) {
155 $this->_service = new Zend_Gdata_App();
156 }
157 $this->_service->setHttpClient($httpClient);
158 return $this;
159 }
160
161 /**
162 * Gets the HTTP client object. If none is set, a new Zend_Http_Client
163 * will be used.
164 *
165 * @deprecated Deprecated as of Zend Framework 1.7. Use
166 * getService() instead.
167 * @return Zend_Http_Client_Abstract
168 */
169 public function getHttpClient()
170 {
171 if (!$this->_service) {
172 $this->_service = new Zend_Gdata_App();
173 }
174 $client = $this->_service->getHttpClient();
175 return $client;
176 }
177
178 /**
179 * Set the active service instance for this object. This will be used to
180 * perform network requests, such as when calling save() and delete().
181 *
182 * @param Zend_Gdata_App $instance The new service instance.
183 * @return Zend_Gdata_App_FeedEntryParent Provides a fluent interface.
184 */
185 public function setService($instance)
186 {
187 $this->_service = $instance;
188 return $this;
189 }
190
191 /**
192 * Get the active service instance for this object. This will be used to
193 * perform network requests, such as when calling save() and delete().
194 *
195 * @return Zend_Gdata_App|null The current service instance, or null if
196 * not set.
197 */
198 public function getService()
199 {
200 return $this->_service;
201 }
202
203 public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
204 {
205 $element = parent::getDOM($doc, $majorVersion, $minorVersion);
206 foreach ($this->_author as $author) {
207 $element->appendChild($author->getDOM($element->ownerDocument));
208 }
209 foreach ($this->_category as $category) {
210 $element->appendChild($category->getDOM($element->ownerDocument));
211 }
212 foreach ($this->_contributor as $contributor) {
213 $element->appendChild($contributor->getDOM($element->ownerDocument));
214 }
215 if ($this->_id != null) {
216 $element->appendChild($this->_id->getDOM($element->ownerDocument));
217 }
218 foreach ($this->_link as $link) {
219 $element->appendChild($link->getDOM($element->ownerDocument));
220 }
221 if ($this->_rights != null) {
222 $element->appendChild($this->_rights->getDOM($element->ownerDocument));
223 }
224 if ($this->_title != null) {
225 $element->appendChild($this->_title->getDOM($element->ownerDocument));
226 }
227 if ($this->_updated != null) {
228 $element->appendChild($this->_updated->getDOM($element->ownerDocument));
229 }
230 return $element;
231 }
232
233 protected function takeChildFromDOM($child)
234 {
235 $absoluteNodeName = $child->namespaceURI . ':' . $child->localName;
236 switch ($absoluteNodeName) {
237 case $this->lookupNamespace('atom') . ':' . 'author':
238 $author = new Zend_Gdata_App_Extension_Author();
239 $author->transferFromDOM($child);
240 $this->_author[] = $author;
241 break;
242 case $this->lookupNamespace('atom') . ':' . 'category':
243 $category = new Zend_Gdata_App_Extension_Category();
244 $category->transferFromDOM($child);
245 $this->_category[] = $category;
246 break;
247 case $this->lookupNamespace('atom') . ':' . 'contributor':
248 $contributor = new Zend_Gdata_App_Extension_Contributor();
249 $contributor->transferFromDOM($child);
250 $this->_contributor[] = $contributor;
251 break;
252 case $this->lookupNamespace('atom') . ':' . 'id':
253 $id = new Zend_Gdata_App_Extension_Id();
254 $id->transferFromDOM($child);
255 $this->_id = $id;
256 break;
257 case $this->lookupNamespace('atom') . ':' . 'link':
258 $link = new Zend_Gdata_App_Extension_Link();
259 $link->transferFromDOM($child);
260 $this->_link[] = $link;
261 break;
262 case $this->lookupNamespace('atom') . ':' . 'rights':
263 $rights = new Zend_Gdata_App_Extension_Rights();
264 $rights->transferFromDOM($child);
265 $this->_rights = $rights;
266 break;
267 case $this->lookupNamespace('atom') . ':' . 'title':
268 $title = new Zend_Gdata_App_Extension_Title();
269 $title->transferFromDOM($child);
270 $this->_title = $title;
271 break;
272 case $this->lookupNamespace('atom') . ':' . 'updated':
273 $updated = new Zend_Gdata_App_Extension_Updated();
274 $updated->transferFromDOM($child);
275 $this->_updated = $updated;
276 break;
277 default:
278 parent::takeChildFromDOM($child);
279 break;
280 }
281 }
282
283 /**
284 * @return Zend_Gdata_App_Extension_Author
285 */
286 public function getAuthor()
287 {
288 return $this->_author;
289 }
290
291 /**
292 * Sets the list of the authors of this feed/entry. In an atom feed, each
293 * author is represented by an atom:author element
294 *
295 * @param array $value
296 * @return Zend_Gdata_App_FeedEntryParent Provides a fluent interface
297 */
298 public function setAuthor($value)
299 {
300 $this->_author = $value;
301 return $this;
302 }
303
304 /**
305 * Returns the array of categories that classify this feed/entry. Each
306 * category is represented in an atom feed by an atom:category element.
307 *
308 * @return array Array of Zend_Gdata_App_Extension_Category
309 */
310 public function getCategory()
311 {
312 return $this->_category;
313 }
314
315 /**
316 * Sets the array of categories that classify this feed/entry. Each
317 * category is represented in an atom feed by an atom:category element.
318 *
319 * @param array $value Array of Zend_Gdata_App_Extension_Category
320 * @return Zend_Gdata_App_FeedEntryParent Provides a fluent interface
321 */
322 public function setCategory($value)
323 {
324 $this->_category = $value;
325 return $this;
326 }
327
328 /**
329 * Returns the array of contributors to this feed/entry. Each contributor
330 * is represented in an atom feed by an atom:contributor XML element
331 *
332 * @return array An array of Zend_Gdata_App_Extension_Contributor
333 */
334 public function getContributor()
335 {
336 return $this->_contributor;
337 }
338
339 /**
340 * Sets the array of contributors to this feed/entry. Each contributor
341 * is represented in an atom feed by an atom:contributor XML element
342 *
343 * @param array $value
344 * @return Zend_Gdata_App_FeedEntryParent Provides a fluent interface
345 */
346 public function setContributor($value)
347 {
348 $this->_contributor = $value;
349 return $this;
350 }
351
352 /**
353 * @return Zend_Gdata_App_Extension_Id
354 */
355 public function getId()
356 {
357 return $this->_id;
358 }
359
360 /**
361 * @param Zend_Gdata_App_Extension_Id $value
362 * @return Zend_Gdata_App_FeedEntryParent Provides a fluent interface
363 */
364 public function setId($value)
365 {
366 $this->_id = $value;
367 return $this;
368 }
369
370 /**
371 * Given a particular 'rel' value, this method returns a matching
372 * Zend_Gdata_App_Extension_Link element. If the 'rel' value
373 * is not provided, the full array of Zend_Gdata_App_Extension_Link
374 * elements is returned. In an atom feed, each link is represented
375 * by an atom:link element. The 'rel' value passed to this function
376 * is the atom:link/@rel attribute. Example rel values include 'self',
377 * 'edit', and 'alternate'.
378 *
379 * @param string $rel The rel value of the link to be found. If null,
380 * the array of Zend_Gdata_App_Extension_link elements is returned
381 * @return mixed Either a single Zend_Gdata_App_Extension_link element,
382 * an array of the same or null is returned depending on the rel value
383 * supplied as the argument to this function
384 */
385 public function getLink($rel = null)
386 {
387 if ($rel == null) {
388 return $this->_link;
389 } else {
390 foreach ($this->_link as $link) {
391 if ($link->rel == $rel) {
392 return $link;
393 }
394 }
395 return null;
396 }
397 }
398
399 /**
400 * Returns the Zend_Gdata_App_Extension_Link element which represents
401 * the URL used to edit this resource. This link is in the atom feed/entry
402 * as an atom:link with a rel attribute value of 'edit'.
403 *
404 * @return Zend_Gdata_App_Extension_Link The link, or null if not found
405 */
406 public function getEditLink()
407 {
408 return $this->getLink('edit');
409 }
410
411 /**
412 * Returns the Zend_Gdata_App_Extension_Link element which represents
413 * the URL used to retrieve the next chunk of results when paging through
414 * a feed. This link is in the atom feed as an atom:link with a
415 * rel attribute value of 'next'.
416 *
417 * @return Zend_Gdata_App_Extension_Link The link, or null if not found
418 */
419 public function getNextLink()
420 {
421 return $this->getLink('next');
422 }
423
424 /**
425 * Returns the Zend_Gdata_App_Extension_Link element which represents
426 * the URL used to retrieve the previous chunk of results when paging
427 * through a feed. This link is in the atom feed as an atom:link with a
428 * rel attribute value of 'previous'.
429 *
430 * @return Zend_Gdata_App_Extension_Link The link, or null if not found
431 */
432 public function getPreviousLink()
433 {
434 return $this->getLink('previous');
435 }
436
437 /**
438 * @return Zend_Gdata_App_Extension_Link
439 */
440 public function getLicenseLink()
441 {
442 return $this->getLink('license');
443 }
444
445 /**
446 * Returns the Zend_Gdata_App_Extension_Link element which represents
447 * the URL used to retrieve the entry or feed represented by this object
448 * This link is in the atom feed/entry as an atom:link with a
449 * rel attribute value of 'self'.
450 *
451 * @return Zend_Gdata_App_Extension_Link The link, or null if not found
452 */
453 public function getSelfLink()
454 {
455 return $this->getLink('self');
456 }
457
458 /**
459 * Returns the Zend_Gdata_App_Extension_Link element which represents
460 * the URL for an alternate view of the data represented by this feed or
461 * entry. This alternate view is commonly a user-facing webpage, blog
462 * post, etc. The MIME type for the data at the URL is available from the
463 * returned Zend_Gdata_App_Extension_Link element.
464 * This link is in the atom feed/entry as an atom:link with a
465 * rel attribute value of 'self'.
466 *
467 * @return Zend_Gdata_App_Extension_Link The link, or null if not found
468 */
469 public function getAlternateLink()
470 {
471 return $this->getLink('alternate');
472 }
473
474 /**
475 * @param array $value The array of Zend_Gdata_App_Extension_Link elements
476 * @return Zend_Gdata_App_FeedEntryParent Provides a fluent interface
477 */
478 public function setLink($value)
479 {
480 $this->_link = $value;
481 return $this;
482 }
483
484 /**
485 * @return Zend_Gdata_AppExtension_Rights
486 */
487 public function getRights()
488 {
489 return $this->_rights;
490 }
491
492 /**
493 * @param Zend_Gdata_App_Extension_Rights $value
494 * @return Zend_Gdata_App_FeedEntryParent Provides a fluent interface
495 */
496 public function setRights($value)
497 {
498 $this->_rights = $value;
499 return $this;
500 }
501
502 /**
503 * Returns the title of this feed or entry. The title is an extremely
504 * short textual representation of this resource and is found as
505 * an atom:title element in a feed or entry
506 *
507 * @return Zend_Gdata_App_Extension_Title
508 */
509 public function getTitle()
510 {
511 return $this->_title;
512 }
513
514 /**
515 * Returns a string representation of the title of this feed or entry.
516 * The title is an extremely short textual representation of this
517 * resource and is found as an atom:title element in a feed or entry
518 *
519 * @return string
520 */
521 public function getTitleValue()
522 {
523 if (($titleObj = $this->getTitle()) != null) {
524 return $titleObj->getText();
525 } else {
526 return null;
527 }
528 }
529
530 /**
531 * Returns the title of this feed or entry. The title is an extremely
532 * short textual representation of this resource and is found as
533 * an atom:title element in a feed or entry
534 *
535 * @param Zend_Gdata_App_Extension_Title $value
536 * @return Zend_Gdata_App_Feed_Entry_Parent Provides a fluent interface
537 */
538 public function setTitle($value)
539 {
540 $this->_title = $value;
541 return $this;
542 }
543
544 /**
545 * @return Zend_Gdata_App_Extension_Updated
546 */
547 public function getUpdated()
548 {
549 return $this->_updated;
550 }
551
552 /**
553 * @param Zend_Gdata_App_Extension_Updated $value
554 * @return Zend_Gdata_App_Feed_Entry_Parent Provides a fluent interface
555 */
556 public function setUpdated($value)
557 {
558 $this->_updated = $value;
559 return $this;
560 }
561
562 /**
563 * Set the Etag for the current entry to $value. Setting $value to null
564 * unsets the Etag.
565 *
566 * @param string|null $value
567 * @return Zend_Gdata_App_Entry Provides a fluent interface
568 */
569 public function setEtag($value) {
570 $this->_etag = $value;
571 return $this;
572 }
573
574 /**
575 * Return the Etag for the current entry, or null if not set.
576 *
577 * @return string|null
578 */
579 public function getEtag() {
580 return $this->_etag;
581 }
582
583 /**
584 * Set the major protocol version that should be used. Values < 1
585 * (excluding NULL) will cause a Zend_Gdata_App_InvalidArgumentException
586 * to be thrown.
587 *
588 * @see _majorProtocolVersion
589 * @param (int|NULL) $value The major protocol version to use.
590 * @throws Zend_Gdata_App_InvalidArgumentException
591 */
592 public function setMajorProtocolVersion($value)
593 {
594 if (!($value >= 1) && ($value !== null)) {
595 require_once('Zend/Gdata/App/InvalidArgumentException.php');
596 throw new Zend_Gdata_App_InvalidArgumentException(
597 'Major protocol version must be >= 1');
598 }
599 $this->_majorProtocolVersion = $value;
600 }
601
602 /**
603 * Get the major protocol version that is in use.
604 *
605 * @see _majorProtocolVersion
606 * @return (int|NULL) The major protocol version in use.
607 */
608 public function getMajorProtocolVersion()
609 {
610 return $this->_majorProtocolVersion;
611 }
612
613 /**
614 * Set the minor protocol version that should be used. If set to NULL, no
615 * minor protocol version will be sent to the server. Values < 0 will
616 * cause a Zend_Gdata_App_InvalidArgumentException to be thrown.
617 *
618 * @see _minorProtocolVersion
619 * @param (int|NULL) $value The minor protocol version to use.
620 * @throws Zend_Gdata_App_InvalidArgumentException
621 */
622 public function setMinorProtocolVersion($value)
623 {
624 if (!($value >= 0)) {
625 require_once('Zend/Gdata/App/InvalidArgumentException.php');
626 throw new Zend_Gdata_App_InvalidArgumentException(
627 'Minor protocol version must be >= 0 or null');
628 }
629 $this->_minorProtocolVersion = $value;
630 }
631
632 /**
633 * Get the minor protocol version that is in use.
634 *
635 * @see _minorProtocolVersion
636 * @return (int|NULL) The major protocol version in use, or NULL if no
637 * minor version is specified.
638 */
639 public function getMinorProtocolVersion()
640 {
641 return $this->_minorProtocolVersion;
642 }
643
644 /**
645 * Get the full version of a namespace prefix
646 *
647 * Looks up a prefix (atom:, etc.) in the list of registered
648 * namespaces and returns the full namespace URI if
649 * available. Returns the prefix, unmodified, if it's not
650 * registered.
651 *
652 * The current entry or feed's version will be used when performing the
653 * namespace lookup unless overridden using $majorVersion and
654 * $minorVersion. If the entry/fee has a null version, then the latest
655 * protocol version will be used by default.
656 *
657 * @param string $prefix The namespace prefix to lookup.
658 * @param integer $majorVersion The major protocol version in effect.
659 * Defaults to null (auto-select).
660 * @param integer $minorVersion The minor protocol version in effect.
661 * Defaults to null (auto-select).
662 * @return string
663 */
664 public function lookupNamespace($prefix,
665 $majorVersion = null,
666 $minorVersion = null)
667 {
668 // Auto-select current version
669 if ($majorVersion === null) {
670 $majorVersion = $this->getMajorProtocolVersion();
671 }
672 if ($minorVersion === null) {
673 $minorVersion = $this->getMinorProtocolVersion();
674 }
675
676 // Perform lookup
677 return parent::lookupNamespace($prefix, $majorVersion, $minorVersion);
678 }
679
680}
Note: See TracBrowser for help on using the repository browser.