[BUGFIX] Typo in the Extension Manager
[Packages/TYPO3.CMS.git] / typo3 / sysext / em / classes / parser / class.tx_em_parser_mirrorxmlpullparser.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2010 Marcus Krause <marcus#exp2010@t3sec.info>
6 * Steffen Kamper <info@sk-typo3.de>
7 * All rights reserved
8 *
9 * This script is part of the TYPO3 project. The TYPO3 project is
10 * free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * The GNU General Public License can be found at
16 * http://www.gnu.org/copyleft/gpl.html.
17 *
18 * This script is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * This copyright notice MUST APPEAR in all copies of the script!
24 ***************************************************************/
25 /**
26 * class.tx_em_parser_mirrorxmlpullparser.php
27 *
28 * Module: Extension manager - mirrors.xml pull-parser
29 *
30 * @author Marcus Krause <marcus#exp2010@t3sec.info>
31 * @author Steffen Kamper <info@sk-typo3.de>
32 */
33
34
35 /**
36 * Parser for TYPO3's mirrors.xml file.
37 *
38 * Depends on PHP ext/xmlreader which should be available
39 * with PHP >= 5.1.0.
40 *
41 * @author Marcus Krause <marcus#exp2010@t3sec.info>
42 * @author Steffen Kamper <info@sk-typo3.de>
43 *
44 * @since 2010-02-19
45 * @package TYPO3
46 * @subpackage EM
47 */
48 class tx_em_Parser_MirrorXmlPullParser extends tx_em_Parser_MirrorXmlAbstractParser implements SplSubject {
49
50
51 /**
52 * Keeps list of attached observers.
53 *
54 * @var SplObserver[]
55 */
56 protected $observers = array();
57
58
59 /**
60 * Class constructor.
61 *
62 * @access public
63 * @return void
64 */
65 function __construct() {
66 $this->requiredPHPExt = 'xmlreader';
67
68 if ($this->isAvailable()) {
69 $this->objXML = new XMLReader();
70 }
71 }
72
73 /**
74 * Method parses an extensions.xml file.
75 *
76 * @access public
77 * @param string $file file resource, typically a stream
78 * @return void
79 * @throws tx_em_MirrorXmlException in case of XML parser errors
80 */
81 public function parseXML($file) {
82 if (!(is_object($this->objXML) && (get_class($this->objXML) == 'XMLReader'))) {
83 $this->throwException('Unable to create XML parser.');
84 }
85 $this->objXML->open($file, 'utf-8') || $this->throwException(sprintf('Unable to open file resource %s.', htmlspecialchars($file)));
86
87 while ($this->objXML->read()) {
88
89 if ($this->objXML->nodeType == XMLReader::ELEMENT) {
90 $this->startElement($this->objXML->name);
91 } else {
92 if ($this->objXML->nodeType == XMLReader::END_ELEMENT) {
93 $this->endElement($this->objXML->name);
94 } else {
95 continue;
96 }
97 }
98 }
99 $this->objXML->close();
100 }
101
102 /**
103 * Method is invoked when parser accesses start tag of an element.
104 *
105 * @access protected
106 * @param string $elementName element name at parser's current position
107 * @return void
108 * @see endElement()
109 */
110 protected function startElement($elementName) {
111 switch ($elementName) {
112 case 'title':
113 $this->title = $this->getElementValue($elementName);
114 break;
115 case 'host':
116 $this->host = $this->getElementValue($elementName);
117 break;
118 case 'path':
119 $this->path = $this->getElementValue($elementName);
120 break;
121 case 'country':
122 $this->country = $this->getElementValue($elementName);
123 break;
124 case 'name':
125 $this->sponsorname = $this->getElementValue($elementName);
126 break;
127 case 'link':
128 $this->sponsorlink = $this->getElementValue($elementName);
129 break;
130 case 'logo':
131 $this->sponsorlogo = $this->getElementValue($elementName);
132 break;
133 }
134 }
135
136 /**
137 * Method is invoked when parser accesses end tag of an element.
138 *
139 * @access protected
140 * @param string $elementName element name at parser's current position
141 * @return void
142 * @see startElement()
143 */
144 protected function endElement($elementName) {
145 switch ($elementName) {
146 case 'mirror':
147 $this->notify();
148 $this->resetProperties();
149 break;
150 }
151 }
152
153 /**
154 * Method returns the value of an element at XMLReader's current
155 * position.
156 *
157 * Method will read until it finds the end of the given element.
158 * If element has no value, method returns NULL.
159 *
160 * @access protected
161 * @param string $elementName name of element to retrieve it's value from
162 * @return string an element's value if it has a value, otherwise NULL
163 */
164 protected function getElementValue(&$elementName) {
165 $value = NULL;
166 if (!$this->objXML->isEmptyElement) {
167 $value = '';
168 while ($this->objXML->read()) {
169 if ($this->objXML->nodeType == XMLReader::TEXT
170 || $this->objXML->nodeType == XMLReader::CDATA
171 || $this->objXML->nodeType == XMLReader::WHITESPACE
172 || $this->objXML->nodeType == XMLReader::SIGNIFICANT_WHITESPACE) {
173 $value .= $this->objXML->value;
174 } else {
175 if ($this->objXML->nodeType == XMLReader::END_ELEMENT
176 && $this->objXML->name === $elementName) {
177 break;
178 }
179 }
180 }
181 }
182 return $value;
183 }
184
185 /**
186 * Method attaches an observer.
187 *
188 * @access public
189 * @param SplObserver $observer an observer to attach
190 * @return void
191 * @see $observers, detach(), notify()
192 */
193 public function attach(SplObserver $observer) {
194 $this->observers[] = $observer;
195 }
196
197 /**
198 * Method detaches an attached observer
199 *
200 * @access public
201 * @param SplObserver $observer an observer to detach
202 * @return void
203 * @see $observers, attach(), notify()
204 */
205 public function detach(SplObserver $observer) {
206 $key = array_search($observer, $this->observers, TRUE);
207 if (!($key === FALSE)) {
208 unset($this->observers[$key]);
209 }
210 }
211
212 /**
213 * Method notifies attached observers.
214 *
215 * @access public
216 * @return void
217 * @see $observers, attach(), detach()
218 */
219 public function notify() {
220 foreach ($this->observers as $observer) {
221 $observer->update($this);
222 }
223 }
224 }
225
226 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/sysext/em/classes/parser/class.tx_em_parser_mirrorxmlpullparser.php'])) {
227 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/sysext/em/classes/parser/class.tx_em_parser_mirrorxmlpullparser.php']);
228 }
229
230 ?>