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

Last change on this file since 44 was 44, checked in by luciano, 14 years ago
File size: 7.5 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 Gdata
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
25 */
26require_once 'Zend/Gdata.php';
27
28/**
29 * @see Zend_Gdata_App_Feed
30 */
31require_once 'Zend/Gdata/App/Feed.php';
32
33/**
34 * @see Zend_Gdata_Entry
35 */
36require_once 'Zend/Gdata/Entry.php';
37
38/**
39 * @see Zend_Gdata_Extension_OpenSearchTotalResults
40 */
41require_once 'Zend/Gdata/Extension/OpenSearchTotalResults.php';
42
43/**
44 * @see Zend_Gdata_Extension_OpenSearchStartIndex
45 */
46require_once 'Zend/Gdata/Extension/OpenSearchStartIndex.php';
47
48/**
49 * @see Zend_Gdata_Extension_OpenSearchItemsPerPage
50 */
51require_once 'Zend/Gdata/Extension/OpenSearchItemsPerPage.php';
52
53/**
54 * The Gdata flavor of an Atom Feed
55 *
56 * @category Zend
57 * @package Zend_Gdata
58 * @subpackage Gdata
59 * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
60 * @license http://framework.zend.com/license/new-bsd New BSD License
61 */
62class Zend_Gdata_Feed extends Zend_Gdata_App_Feed
63{
64
65 /**
66 * The classname for individual feed elements.
67 *
68 * @var string
69 */
70 protected $_entryClassName = 'Zend_Gdata_Entry';
71
72 /**
73 * The openSearch:totalResults element
74 *
75 * @var Zend_Gdata_Extension_OpenSearchTotalResults|null
76 */
77 protected $_totalResults = null;
78
79 /**
80 * The openSearch:startIndex element
81 *
82 * @var Zend_Gdata_Extension_OpenSearchStartIndex|null
83 */
84 protected $_startIndex = null;
85
86 /**
87 * The openSearch:itemsPerPage element
88 *
89 * @var Zend_Gdata_Extension_OpenSearchItemsPerPage|null
90 */
91 protected $_itemsPerPage = null;
92
93 public function __construct($element = null)
94 {
95 $this->registerAllNamespaces(Zend_Gdata::$namespaces);
96 parent::__construct($element);
97 }
98
99 public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
100 {
101 $element = parent::getDOM($doc, $majorVersion, $minorVersion);
102 if ($this->_totalResults != null) {
103 $element->appendChild($this->_totalResults->getDOM($element->ownerDocument));
104 }
105 if ($this->_startIndex != null) {
106 $element->appendChild($this->_startIndex->getDOM($element->ownerDocument));
107 }
108 if ($this->_itemsPerPage != null) {
109 $element->appendChild($this->_itemsPerPage->getDOM($element->ownerDocument));
110 }
111
112 // ETags are special. We only support them in protocol >= 2.X.
113 // This will be duplicated by the HTTP ETag header.
114 if ($majorVersion >= 2) {
115 if ($this->_etag != null) {
116 $element->setAttributeNS($this->lookupNamespace('gd'),
117 'gd:etag',
118 $this->_etag);
119 }
120 }
121
122 return $element;
123 }
124
125 /**
126 * Creates individual Entry objects of the appropriate type and
127 * stores them in the $_entry array based upon DOM data.
128 *
129 * @param DOMNode $child The DOMNode to process
130 */
131 protected function takeChildFromDOM($child)
132 {
133 $absoluteNodeName = $child->namespaceURI . ':' . $child->localName;
134 switch ($absoluteNodeName) {
135 case $this->lookupNamespace('openSearch') . ':' . 'totalResults':
136 $totalResults = new Zend_Gdata_Extension_OpenSearchTotalResults();
137 $totalResults->transferFromDOM($child);
138 $this->_totalResults = $totalResults;
139 break;
140 case $this->lookupNamespace('openSearch') . ':' . 'startIndex':
141 $startIndex = new Zend_Gdata_Extension_OpenSearchStartIndex();
142 $startIndex->transferFromDOM($child);
143 $this->_startIndex = $startIndex;
144 break;
145 case $this->lookupNamespace('openSearch') . ':' . 'itemsPerPage':
146 $itemsPerPage = new Zend_Gdata_Extension_OpenSearchItemsPerPage();
147 $itemsPerPage->transferFromDOM($child);
148 $this->_itemsPerPage = $itemsPerPage;
149 break;
150 default:
151 parent::takeChildFromDOM($child);
152 break;
153 }
154 }
155
156 /**
157 * Given a DOMNode representing an attribute, tries to map the data into
158 * instance members. If no mapping is defined, the name and value are
159 * stored in an array.
160 *
161 * @param DOMNode $attribute The DOMNode attribute needed to be handled
162 */
163 protected function takeAttributeFromDOM($attribute)
164 {
165 switch ($attribute->localName) {
166 case 'etag':
167 // ETags are special, since they can be conveyed by either the
168 // HTTP ETag header or as an XML attribute.
169 $etag = $attribute->nodeValue;
170 if ($this->_etag === null) {
171 $this->_etag = $etag;
172 }
173 elseif ($this->_etag != $etag) {
174 require_once('Zend/Gdata/App/IOException.php');
175 throw new Zend_Gdata_App_IOException("ETag mismatch");
176 }
177 break;
178 default:
179 parent::takeAttributeFromDOM($attribute);
180 break;
181 }
182 }
183
184 /**
185 * Set the value of the totalResults property.
186 *
187 * @param Zend_Gdata_Extension_OpenSearchTotalResults|null $value The
188 * value of the totalResults property. Use null to unset.
189 * @return Zend_Gdata_Feed Provides a fluent interface.
190 */
191 function setTotalResults($value) {
192 $this->_totalResults = $value;
193 return $this;
194 }
195
196 /**
197 * Get the value of the totalResults property.
198 *
199 * @return Zend_Gdata_Extension_OpenSearchTotalResults|null The value of
200 * the totalResults property, or null if unset.
201 */
202 function getTotalResults() {
203 return $this->_totalResults;
204 }
205
206 /**
207 * Set the start index property for feed paging.
208 *
209 * @param Zend_Gdata_Extension_OpenSearchStartIndex|null $value The value
210 * for the startIndex property. Use null to unset.
211 * @return Zend_Gdata_Feed Provides a fluent interface.
212 */
213 function setStartIndex($value) {
214 $this->_startIndex = $value;
215 return $this;
216 }
217
218 /**
219 * Get the value of the startIndex property.
220 *
221 * @return Zend_Gdata_Extension_OpenSearchStartIndex|null The value of the
222 * startIndex property, or null if unset.
223 */
224 function getStartIndex() {
225 return $this->_startIndex;
226 }
227
228 /**
229 * Set the itemsPerPage property.
230 *
231 * @param Zend_Gdata_Extension_OpenSearchItemsPerPage|null $value The
232 * value for the itemsPerPage property. Use nul to unset.
233 * @return Zend_Gdata_Feed Provides a fluent interface.
234 */
235 function setItemsPerPage($value) {
236 $this->_itemsPerPage = $value;
237 return $this;
238 }
239
240 /**
241 * Get the value of the itemsPerPage property.
242 *
243 * @return Zend_Gdata_Extension_OpenSearchItemsPerPage|null The value of
244 * the itemsPerPage property, or null if unset.
245 */
246 function getItemsPerPage() {
247 return $this->_itemsPerPage;
248 }
249
250}
Note: See TracBrowser for help on using the repository browser.