PageRenderTime 70ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/DevApp/library/ServerLibraries/ZendFramework/1.7/library/Zend/Gdata/Feed.php

http://firephp.googlecode.com/
PHP | 250 lines | 103 code | 25 blank | 122 comment | 13 complexity | 026963370de9e647003cb44f4f00e13b MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.0, MIT, Apache-2.0
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Gdata
  17. * @subpackage Gdata
  18. * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. */
  21. /**
  22. * @see Zend_Gdata
  23. */
  24. require_once 'Zend/Gdata.php';
  25. /**
  26. * @see Zend_Gdata_App_Feed
  27. */
  28. require_once 'Zend/Gdata/App/Feed.php';
  29. /**
  30. * @see Zend_Gdata_Entry
  31. */
  32. require_once 'Zend/Gdata/Entry.php';
  33. /**
  34. * @see Zend_Gdata_Extension_OpenSearchTotalResults
  35. */
  36. require_once 'Zend/Gdata/Extension/OpenSearchTotalResults.php';
  37. /**
  38. * @see Zend_Gdata_Extension_OpenSearchStartIndex
  39. */
  40. require_once 'Zend/Gdata/Extension/OpenSearchStartIndex.php';
  41. /**
  42. * @see Zend_Gdata_Extension_OpenSearchItemsPerPage
  43. */
  44. require_once 'Zend/Gdata/Extension/OpenSearchItemsPerPage.php';
  45. /**
  46. * The Gdata flavor of an Atom Feed
  47. *
  48. * @category Zend
  49. * @package Zend_Gdata
  50. * @subpackage Gdata
  51. * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
  52. * @license http://framework.zend.com/license/new-bsd New BSD License
  53. */
  54. class Zend_Gdata_Feed extends Zend_Gdata_App_Feed
  55. {
  56. /**
  57. * The classname for individual feed elements.
  58. *
  59. * @var string
  60. */
  61. protected $_entryClassName = 'Zend_Gdata_Entry';
  62. /**
  63. * The openSearch:totalResults element
  64. *
  65. * @var Zend_Gdata_Extension_OpenSearchTotalResults|null
  66. */
  67. protected $_totalResults = null;
  68. /**
  69. * The openSearch:startIndex element
  70. *
  71. * @var Zend_Gdata_Extension_OpenSearchStartIndex|null
  72. */
  73. protected $_startIndex = null;
  74. /**
  75. * The openSearch:itemsPerPage element
  76. *
  77. * @var Zend_Gdata_Extension_OpenSearchItemsPerPage|null
  78. */
  79. protected $_itemsPerPage = null;
  80. public function __construct($element = null)
  81. {
  82. $this->registerAllNamespaces(Zend_Gdata::$namespaces);
  83. parent::__construct($element);
  84. }
  85. public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
  86. {
  87. $element = parent::getDOM($doc, $majorVersion, $minorVersion);
  88. if ($this->_totalResults != null) {
  89. $element->appendChild($this->_totalResults->getDOM($element->ownerDocument));
  90. }
  91. if ($this->_startIndex != null) {
  92. $element->appendChild($this->_startIndex->getDOM($element->ownerDocument));
  93. }
  94. if ($this->_itemsPerPage != null) {
  95. $element->appendChild($this->_itemsPerPage->getDOM($element->ownerDocument));
  96. }
  97. // ETags are special. We only support them in protocol >= 2.X.
  98. // This will be duplicated by the HTTP ETag header.
  99. if ($majorVersion >= 2) {
  100. if ($this->_etag != null) {
  101. $element->setAttributeNS($this->lookupNamespace('gd'),
  102. 'gd:etag',
  103. $this->_etag);
  104. }
  105. }
  106. return $element;
  107. }
  108. /**
  109. * Creates individual Entry objects of the appropriate type and
  110. * stores them in the $_entry array based upon DOM data.
  111. *
  112. * @param DOMNode $child The DOMNode to process
  113. */
  114. protected function takeChildFromDOM($child)
  115. {
  116. $absoluteNodeName = $child->namespaceURI . ':' . $child->localName;
  117. switch ($absoluteNodeName) {
  118. case $this->lookupNamespace('openSearch') . ':' . 'totalResults':
  119. $totalResults = new Zend_Gdata_Extension_OpenSearchTotalResults();
  120. $totalResults->transferFromDOM($child);
  121. $this->_totalResults = $totalResults;
  122. break;
  123. case $this->lookupNamespace('openSearch') . ':' . 'startIndex':
  124. $startIndex = new Zend_Gdata_Extension_OpenSearchStartIndex();
  125. $startIndex->transferFromDOM($child);
  126. $this->_startIndex = $startIndex;
  127. break;
  128. case $this->lookupNamespace('openSearch') . ':' . 'itemsPerPage':
  129. $itemsPerPage = new Zend_Gdata_Extension_OpenSearchItemsPerPage();
  130. $itemsPerPage->transferFromDOM($child);
  131. $this->_itemsPerPage = $itemsPerPage;
  132. break;
  133. default:
  134. parent::takeChildFromDOM($child);
  135. break;
  136. }
  137. }
  138. /**
  139. * Given a DOMNode representing an attribute, tries to map the data into
  140. * instance members. If no mapping is defined, the name and value are
  141. * stored in an array.
  142. *
  143. * @param DOMNode $attribute The DOMNode attribute needed to be handled
  144. */
  145. protected function takeAttributeFromDOM($attribute)
  146. {
  147. switch ($attribute->localName) {
  148. case 'etag':
  149. // ETags are special, since they can be conveyed by either the
  150. // HTTP ETag header or as an XML attribute.
  151. $etag = $attribute->nodeValue;
  152. if (is_null($this->_etag)) {
  153. $this->_etag = $etag;
  154. }
  155. elseif ($this->_etag != $etag) {
  156. require_once('Zend/Gdata/App/IOException.php');
  157. throw new Zend_Gdata_App_IOException("ETag mismatch");
  158. }
  159. break;
  160. default:
  161. parent::takeAttributeFromDOM($attribute);
  162. break;
  163. }
  164. }
  165. /**
  166. * Set the value of the totalResults property.
  167. *
  168. * @param Zend_Gdata_Extension_OpenSearchTotalResults|null $value The
  169. * value of the totalResults property. Use null to unset.
  170. * @return Zend_Gdata_Feed Provides a fluent interface.
  171. */
  172. function setTotalResults($value) {
  173. $this->_totalResults = $value;
  174. return $this;
  175. }
  176. /**
  177. * Get the value of the totalResults property.
  178. *
  179. * @return Zend_Gdata_Extension_OpenSearchTotalResults|null The value of
  180. * the totalResults property, or null if unset.
  181. */
  182. function getTotalResults() {
  183. return $this->_totalResults;
  184. }
  185. /**
  186. * Set the start index property for feed paging.
  187. *
  188. * @param Zend_Gdata_Extension_OpenSearchStartIndex|null $value The value
  189. * for the startIndex property. Use null to unset.
  190. * @return Zend_Gdata_Feed Provides a fluent interface.
  191. */
  192. function setStartIndex($value) {
  193. $this->_startIndex = $value;
  194. return $this;
  195. }
  196. /**
  197. * Get the value of the startIndex property.
  198. *
  199. * @return Zend_Gdata_Extension_OpenSearchStartIndex|null The value of the
  200. * startIndex property, or null if unset.
  201. */
  202. function getStartIndex() {
  203. return $this->_startIndex;
  204. }
  205. /**
  206. * Set the itemsPerPage property.
  207. *
  208. * @param Zend_Gdata_Extension_OpenSearchItemsPerPage|null $value The
  209. * value for the itemsPerPage property. Use nul to unset.
  210. * @return Zend_Gdata_Feed Provides a fluent interface.
  211. */
  212. function setItemsPerPage($value) {
  213. $this->_itemsPerPage = $value;
  214. return $this;
  215. }
  216. /**
  217. * Get the value of the itemsPerPage property.
  218. *
  219. * @return Zend_Gdata_Extension_OpenSearchItemsPerPage|null The value of
  220. * the itemsPerPage property, or null if unset.
  221. */
  222. function getItemsPerPage() {
  223. return $this->_itemsPerPage;
  224. }
  225. }