Updated 'core'.
[hub.git] / application / hub / main / template / announcement / class_XmlAnnouncementTemplateEngine.php
1 <?php
2 /**
3  * An Announcement template engine class for XML templates
4  *
5  * @author              Roland Haeder <webmaster@shipsimu.org>
6  * @version             0.0.0
7  * @copyright   Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
8  * @license             GNU GPL 3.0 or any newer version
9  * @link                http://www.shipsimu.org
10  * @todo                This template engine does not make use of setTemplateType()
11  *
12  * This program is free software: you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation, either version 3 of the License, or
15  * (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program. If not, see <http://www.gnu.org/licenses/>.
24  */
25 class XmlAnnouncementTemplateEngine extends BaseXmlTemplateEngine implements CompileableTemplate, Registerable {
26         /**
27          * Some XML nodes must be available for later data extraction
28          */
29         const ANNOUNCEMENT_DATA_SESSION_ID       = 'session-id';
30         const ANNOUNCEMENT_DATA_NODE_ID          = 'node-id';
31         const ANNOUNCEMENT_DATA_PRIVATE_KEY_HASH = 'private-key-hash';
32         const ANNOUNCEMENT_DATA_NODE_STATUS      = 'node-status';
33         const ANNOUNCEMENT_DATA_NODE_MODE        = 'node-mode';
34         const ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS = 'external-address';
35         const ANNOUNCEMENT_DATA_INTERNAL_ADDRESS = 'internal-address';
36
37         /**
38          * Protected constructor
39          *
40          * @return      void
41          */
42         protected function __construct () {
43                 // Call parent constructor
44                 parent::__construct(__CLASS__);
45
46                 // Init array
47                 $this->setSubNodes(array(
48                         'announcement-data',
49                         'listener',
50                         self::ANNOUNCEMENT_DATA_NODE_STATUS,
51                         self::ANNOUNCEMENT_DATA_NODE_MODE,
52                         self::ANNOUNCEMENT_DATA_NODE_ID,
53                         self::ANNOUNCEMENT_DATA_SESSION_ID,
54                         self::ANNOUNCEMENT_DATA_PRIVATE_KEY_HASH,
55                         self::ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS,
56                         self::ANNOUNCEMENT_DATA_INTERNAL_ADDRESS,
57                         'object-type-list',
58                 ));
59         }
60
61         /**
62          * Creates an instance of the class TemplateEngine and prepares it for usage
63          *
64          * @return      $templateInstance               An instance of TemplateEngine
65          * @throws      BasePathIsEmptyException                If the provided $templateBasePath is empty
66          * @throws      InvalidBasePathStringException  If $templateBasePath is no string
67          * @throws      BasePathIsNoDirectoryException  If $templateBasePath is no
68          *                                                                                      directory or not found
69          * @throws      BasePathReadProtectedException  If $templateBasePath is
70          *                                                                                      read-protected
71          */
72         public static final function createXmlAnnouncementTemplateEngine () {
73                 // Get a new instance
74                 $templateInstance = new XmlAnnouncementTemplateEngine();
75
76                 // Init template instance
77                 $templateInstance->initXmlTemplateEngine('node', 'announcement');
78
79                 // Return the prepared instance
80                 return $templateInstance;
81         }
82
83         /**
84          * Currently not used
85          *
86          * @param       $resource               XML parser resource (currently ignored)
87          * @param       $characters             Characters to handle
88          * @return      void
89          */
90         public function characterHandler ($resource, $characters) {
91                 // Trim all spaces away
92                 $characters = trim($characters);
93
94                 // Is this string empty?
95                 if (empty($characters)) {
96                         // Then skip it silently
97                         return;
98                 } // END - if
99
100                 /*
101                  * Assign the found characters to variable and use the last entry from
102                  * stack as the name.
103                  */
104                 parent::assignVariable($this->getStackInstance()->getNamed('node_announcement'), $characters);
105         }
106
107         /**
108          * Getter for cache file (FQFN)
109          *
110          * @return      $fqfn   Full-qualified file name of the menu cache
111          */
112         public function getMenuCacheFqfn () {
113                 $this->partialStub('Please implement this method.');
114         }
115
116         /**
117          * Starts the announcement
118          *
119          * @return      void
120          */
121         protected function startAnnouncement () {
122                 // Push the node name on the stacker
123                 $this->getStackInstance()->pushNamed('node_announcement', 'announcement');
124         }
125
126         /**
127          * Starts the announcement data
128          *
129          * @return      void
130          */
131         protected function startAnnouncementData () {
132                 // Push the node name on the stacker
133                 $this->getStackInstance()->pushNamed('node_announcement', 'announcement-data');
134         }
135
136         /**
137          * Starts the node status
138          *
139          * @return      void
140          */
141         protected function startNodeStatus () {
142                 // Push the node name on the stacker
143                 $this->getStackInstance()->pushNamed('node_announcement', self::ANNOUNCEMENT_DATA_NODE_STATUS);
144         }
145
146         /**
147          * Starts the node-mode
148          *
149          * @return      void
150          */
151         protected function startNodeMode () {
152                 // Push the node name on the stacker
153                 $this->getStackInstance()->pushNamed('node_announcement', self::ANNOUNCEMENT_DATA_NODE_MODE);
154         }
155
156         /**
157          * Starts the listener
158          *
159          * @return      void
160          */
161         protected function startListener () {
162                 // Push the node name on the stacker
163                 $this->getStackInstance()->pushNamed('node_announcement', 'listener');
164         }
165
166         /**
167          * Starts the session id
168          *
169          * @return      void
170          */
171         protected function startSessionId () {
172                 // Push the node name on the stacker
173                 $this->getStackInstance()->pushNamed('node_announcement', self::ANNOUNCEMENT_DATA_SESSION_ID);
174         }
175
176         /**
177          * Starts the node id
178          *
179          * @return      void
180          */
181         protected function startNodeId () {
182                 // Push the node name on the stacker
183                 $this->getStackInstance()->pushNamed('node_announcement', self::ANNOUNCEMENT_DATA_NODE_ID);
184         }
185
186         /**
187          * Starts the private key hash
188          *
189          * @return      void
190          */
191         protected function startPrivateKeyHash () {
192                 // Push the node name on the stacker
193                 $this->getStackInstance()->pushNamed('node_announcement', self::ANNOUNCEMENT_DATA_PRIVATE_KEY_HASH);
194         }
195
196         /**
197          * Starts the public ip
198          *
199          * @return      void
200          */
201         protected function startExternalAddress () {
202                 // Push the node name on the stacker
203                 $this->getStackInstance()->pushNamed('node_announcement', self::ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS);
204         }
205
206         /**
207          * Starts the private ip
208          *
209          * @return      void
210          */
211         protected function startInternalAddress () {
212                 // Push the node name on the stacker
213                 $this->getStackInstance()->pushNamed('node_announcement', self::ANNOUNCEMENT_DATA_INTERNAL_ADDRESS);
214         }
215
216         /**
217          * Starts the object type list
218          *
219          * @return      void
220          */
221         protected function startObjectTypeList () {
222                 // Push the node name on the stacker
223                 $this->getStackInstance()->pushNamed('node_announcement', 'object-type-list');
224         }
225
226         /**
227          * Starts the object type
228          *
229          * @return      void
230          */
231         protected function startObjectType () {
232                 // Push the node name on the stacker
233                 $this->getStackInstance()->pushNamed('node_announcement', 'object-type');
234         }
235
236         /**
237          * Finishes the object type
238          *
239          * @return      void
240          */
241         protected function finishObjectType () {
242                 // Pop the last entry
243                 $this->getStackInstance()->popNamed('node_announcement');
244         }
245
246         /**
247          * Finishes the object type list
248          *
249          * @return      void
250          */
251         protected function finishObjectTypeList () {
252                 // Pop the last entry
253                 $this->getStackInstance()->popNamed('node_announcement');
254         }
255
256         /**
257          * Finishes the private key hash
258          *
259          * @return      void
260          */
261         protected function finishPrivateKeyHash () {
262                 // Pop the last entry
263                 $this->getStackInstance()->popNamed('node_announcement');
264         }
265
266         /**
267          * Finishes the node id
268          *
269          * @return      void
270          */
271         protected function finishNodeId () {
272                 // Pop the last entry
273                 $this->getStackInstance()->popNamed('node_announcement');
274         }
275
276         /**
277          * Finishes the session id
278          *
279          * @return      void
280          */
281         protected function finishSessionId () {
282                 // Pop the last entry
283                 $this->getStackInstance()->popNamed('node_announcement');
284         }
285
286         /**
287          * Finishes the private ip
288          *
289          * @return      void
290          */
291         protected function finishInternalAddress () {
292                 // Pop the last entry
293                 $this->getStackInstance()->popNamed('node_announcement');
294         }
295
296         /**
297          * Finishes the public ip
298          *
299          * @return      void
300          */
301         protected function finishExternalAddress () {
302                 // Pop the last entry
303                 $this->getStackInstance()->popNamed('node_announcement');
304         }
305
306         /**
307          * Finishes the listener
308          *
309          * @return      void
310          */
311         protected function finishListener () {
312                 // Pop the last entry
313                 $this->getStackInstance()->popNamed('node_announcement');
314         }
315
316         /**
317          * Finishes the node mode
318          *
319          * @return      void
320          */
321         protected function finishNodeMode () {
322                 // Pop the last entry
323                 $this->getStackInstance()->popNamed('node_announcement');
324         }
325
326         /**
327          * Finishes the node status
328          *
329          * @return      void
330          */
331         protected function finishNodeStatus () {
332                 // Pop the last entry
333                 $this->getStackInstance()->popNamed('node_announcement');
334         }
335
336         /**
337          * Finishes the announcement data
338          *
339          * @return      void
340          */
341         protected function finishAnnouncementData () {
342                 // Pop the last entry
343                 $this->getStackInstance()->popNamed('node_announcement');
344         }
345
346         /**
347          * Finishes the announcement
348          *
349          * @return      void
350          */
351         protected function finishAnnouncement () {
352                 // Pop the last entry
353                 $this->getStackInstance()->popNamed('node_announcement');
354         }
355 }
356
357 // [EOF]
358 ?>