Updated 'core'.
[hub.git] / application / hub / main / template / answer / announcement / class_XmlAnnouncementAnswerTemplateEngine.php
1 <?php
2 /**
3  * An AnnouncementAnswer 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 XmlAnnouncementAnswerTemplateEngine extends BaseXmlAnswerTemplateEngine implements CompileableTemplate, Registerable {
26         /**
27          * Some XML nodes must be available for later data extraction
28          */
29         const ANNOUNCEMENT_DATA_NODE_ID          = 'my-node-id';
30         const ANNOUNCEMENT_DATA_SESSION_ID       = 'my-session-id';
31         const ANNOUNCEMENT_DATA_PRIVATE_KEY_HASH = 'my-private-key-hash';
32         const ANNOUNCEMENT_DATA_NODE_STATUS      = 'my-status';
33         const ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS = 'my-external-address';
34         const ANNOUNCEMENT_DATA_INTERNAL_ADDRESS = 'my-internal-address';
35
36         /**
37          * Protected constructor
38          *
39          * @return      void
40          */
41         protected function __construct () {
42                 // Call parent constructor
43                 parent::__construct(__CLASS__);
44
45                 // Init sub-nodes array
46                 $this->setSubNodes(array(
47                         // These nodes don't contain any data
48                         'my-data',
49                         'your-data',
50                         // Data from *this* node
51                         self::ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS,
52                         self::ANNOUNCEMENT_DATA_INTERNAL_ADDRESS,
53                         self::ANNOUNCEMENT_DATA_NODE_STATUS,
54                         self::ANNOUNCEMENT_DATA_NODE_ID,
55                         self::ANNOUNCEMENT_DATA_SESSION_ID,
56                         self::ANNOUNCEMENT_DATA_PRIVATE_KEY_HASH,
57                         // Data from other node
58                         'your-external-address',
59                         'your-internal-address',
60                         'your-node-id',
61                         'your-session-id',
62                         'your-private-key-hash',
63                         // Answer status (generic field)
64                         self::ANSWER_STATUS,
65                 ));
66         }
67
68         /**
69          * Creates an instance of the class TemplateEngine and prepares it for usage
70          *
71          * @return      $templateInstance               An instance of TemplateEngine
72          * @throws      BasePathIsEmptyException                If the provided $templateBasePath is empty
73          * @throws      InvalidBasePathStringException  If $templateBasePath is no string
74          * @throws      BasePathIsNoDirectoryException  If $templateBasePath is no
75          *                                                                                      directory or not found
76          * @throws      BasePathReadProtectedException  If $templateBasePath is
77          *                                                                                      read-protected
78          */
79         public static final function createXmlAnnouncementAnswerTemplateEngine () {
80                 // Get a new instance
81                 $templateInstance = new XmlAnnouncementAnswerTemplateEngine();
82
83                 // Init instance
84                 $templateInstance->initXmlTemplateEngine('node', 'announcement_answer');
85
86                 // Return the prepared instance
87                 return $templateInstance;
88         }
89
90         /**
91          * Currently not used
92          *
93          * @param       $resource               XML parser resource (currently ignored)
94          * @param       $characters             Characters to handle
95          * @return      void
96          * @todo        Find something useful with this!
97          */
98         public function characterHandler ($resource, $characters) {
99                 // Trim all spaces away
100                 $characters = trim($characters);
101
102                 // Is this string empty?
103                 if (empty($characters)) {
104                         // Then skip it silently
105                         return;
106                 } // END - if
107
108                 /*
109                  * Assign the found characters to variable and use the last entry from
110                  * stack as the name.
111                  */
112                 parent::assignVariable($this->getStackInstance()->getNamed('node_announcement_answer'), $characters);
113         }
114
115         /**
116          * Getter for cache file (FQFN)
117          *
118          * @return      $fqfn   Full-qualified file name of the menu cache
119          */
120         public function getAnnouncementAnswerCacheFqfn () {
121                 $this->partialStub('Please implement this method.');
122         }
123
124         /**
125          * Starts the announcement-answer
126          *
127          * @return      void
128          */
129         protected function startAnnouncementAnswer () {
130                 // Push the node name on the stacker
131                 $this->getStackInstance()->pushNamed('node_announcement_answer', 'announcement-answer');
132         }
133
134         /**
135          * Starts the my-data
136          *
137          * @return      void
138          */
139         protected function startMyData () {
140                 // Push the node name on the stacker
141                 $this->getStackInstance()->pushNamed('node_announcement_answer', 'my-data');
142         }
143
144         /**
145          * Starts the my-external-address
146          *
147          * @return      void
148          */
149         protected function startMyExternalAddress () {
150                 // Push the node name on the stacker
151                 $this->getStackInstance()->pushNamed('node_announcement_answer', self::ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS);
152         }
153
154         /**
155          * Starts the my-internal-address
156          *
157          * @return      void
158          */
159         protected function startMyInternalAddress () {
160                 // Push the node name on the stacker
161                 $this->getStackInstance()->pushNamed('node_announcement_answer', self::ANNOUNCEMENT_DATA_INTERNAL_ADDRESS);
162         }
163
164         /**
165          * Starts the my-node-id
166          *
167          * @return      void
168          */
169         protected function startMyNodeId () {
170                 // Push the node name on the stacker
171                 $this->getStackInstance()->pushNamed('node_announcement_answer', self::ANNOUNCEMENT_DATA_NODE_ID);
172         }
173
174         /**
175          * Starts the my-session-id
176          *
177          * @return      void
178          */
179         protected function startMySessionId () {
180                 // Push the node name on the stacker
181                 $this->getStackInstance()->pushNamed('node_announcement_answer', self::ANNOUNCEMENT_DATA_SESSION_ID);
182         }
183
184         /**
185          * Starts the my-private-key-hash
186          *
187          * @return      void
188          */
189         protected function startMyPrivateKeyHash () {
190                 // Push the node name on the stacker
191                 $this->getStackInstance()->pushNamed('node_announcement_answer', self::ANNOUNCEMENT_DATA_PRIVATE_KEY_HASH);
192         }
193
194         /**
195          * Starts the my-status
196          *
197          * @return      void
198          */
199         protected function startMyStatus () {
200                 // Push the node name on the stacker
201                 $this->getStackInstance()->pushNamed('node_announcement_answer', self::ANNOUNCEMENT_DATA_NODE_STATUS);
202         }
203
204         /**
205          * Finishes the my-status
206          *
207          * @return      void
208          */
209         protected function finishMyStatus () {
210                 // Pop the last entry
211                 $this->getStackInstance()->popNamed('node_announcement_answer');
212         }
213
214         /**
215          * Finishes the my-private-key-hash
216          *
217          * @return      void
218          */
219         protected function finishMyPrivateKeyhash () {
220                 // Pop the last entry
221                 $this->getStackInstance()->popNamed('node_announcement_answer');
222         }
223
224         /**
225          * Finishes the my-session-id
226          *
227          * @return      void
228          */
229         protected function finishMySessionId () {
230                 // Pop the last entry
231                 $this->getStackInstance()->popNamed('node_announcement_answer');
232         }
233
234         /**
235          * Finishes the my-node-id
236          *
237          * @return      void
238          */
239         protected function finishMyNodeId () {
240                 // Pop the last entry
241                 $this->getStackInstance()->popNamed('node_announcement_answer');
242         }
243
244         /**
245          * Finishes the my-internal-address
246          *
247          * @return      void
248          */
249         protected function finishMyInternalAddress () {
250                 // Pop the last entry
251                 $this->getStackInstance()->popNamed('node_announcement_answer');
252         }
253
254         /**
255          * Finishes the my-external-address
256          *
257          * @return      void
258          */
259         protected function finishMyExternalAddress () {
260                 // Pop the last entry
261                 $this->getStackInstance()->popNamed('node_announcement_answer');
262         }
263
264         /**
265          * Finishes the my-data
266          *
267          * @return      void
268          */
269         protected function finishMyData () {
270                 // Pop the last entry
271                 $this->getStackInstance()->popNamed('node_announcement_answer');
272         }
273
274         /**
275          * Starts the your-data
276          *
277          * @return      void
278          */
279         protected function startYourData () {
280                 // Push the node name on the stacker
281                 $this->getStackInstance()->pushNamed('node_announcement_answer', 'your-data');
282         }
283
284         /**
285          * Starts the your-external-address
286          *
287          * @return      void
288          */
289         protected function startYourExternalAddress () {
290                 // Push the node name on the stacker
291                 $this->getStackInstance()->pushNamed('node_announcement_answer', 'your-external-address');
292         }
293
294         /**
295          * Starts the your-internal-address
296          *
297          * @return      void
298          */
299         protected function startYourInternalAddress () {
300                 // Push the node name on the stacker
301                 $this->getStackInstance()->pushNamed('node_announcement_answer', 'your-internal-address');
302         }
303
304         /**
305          * Starts the your-session-id
306          *
307          * @return      void
308          */
309         protected function startYourSessionId () {
310                 // Push the node name on the stacker
311                 $this->getStackInstance()->pushNamed('node_announcement_answer', 'your-session-id');
312         }
313
314         /**
315          * Starts the your-node-id
316          *
317          * @return      void
318          */
319         protected function startYourNodeId () {
320                 // Push the node name on the stacker
321                 $this->getStackInstance()->pushNamed('node_announcement_answer', 'your-node-id');
322         }
323
324         /**
325          * Starts the your-private-key-hash
326          *
327          * @return      void
328          */
329         protected function startYourPrivateKeyHash () {
330                 // Push the node name on the stacker
331                 $this->getStackInstance()->pushNamed('node_announcement_answer', 'your-private-key-hash');
332         }
333
334         /**
335          * Finishes the your-private-key-hash
336          *
337          * @return      void
338          */
339         protected function finishYourPrivateKeyHash () {
340                 // Pop the last entry
341                 $this->getStackInstance()->popNamed('node_announcement_answer');
342         }
343
344         /**
345          * Finishes the your-node-id
346          *
347          * @return      void
348          */
349         protected function finishYourNodeId () {
350                 // Pop the last entry
351                 $this->getStackInstance()->popNamed('node_announcement_answer');
352         }
353
354         /**
355          * Finishes the your-session-id
356          *
357          * @return      void
358          */
359         protected function finishYourSessionId () {
360                 // Pop the last entry
361                 $this->getStackInstance()->popNamed('node_announcement_answer');
362         }
363
364         /**
365          * Finishes the your-internal-address
366          *
367          * @return      void
368          */
369         protected function finishYourInternalAddress () {
370                 // Pop the last entry
371                 $this->getStackInstance()->popNamed('node_announcement_answer');
372         }
373
374         /**
375          * Finishes the your-external-address
376          *
377          * @return      void
378          */
379         protected function finishYourExternalAddress () {
380                 // Pop the last entry
381                 $this->getStackInstance()->popNamed('node_announcement_answer');
382         }
383
384         /**
385          * Finishes the your-data
386          *
387          * @return      void
388          */
389         protected function finishYourData () {
390                 // Pop the last entry
391                 $this->getStackInstance()->popNamed('node_announcement_answer');
392         }
393
394         /**
395          * Finishes the announcement-answer
396          *
397          * @return      void
398          */
399         protected function finishAnnouncementAnswer () {
400                 // Pop the last entry
401                 $this->getStackInstance()->popNamed('node_announcement_answer');
402         }
403 }
404
405 // [EOF]
406 ?>