]> git.mxchange.org Git - hub.git/blob - application/hub/main/template/answer/announcement/class_XmlAnnouncementAnswerTemplateEngine.php
More fixes: private->protected changed, generic init of stacker
[hub.git] / application / hub / main / template / answer / announcement / class_XmlAnnouncementAnswerTemplateEngine.php
1 <?php
2 /**
3  * An ??? template engine class for XML templates
4  *
5  * @author              Roland Haeder <webmaster@ship-simu.org>
6  * @version             0.0.0
7  * @copyright   Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2012 Core Developer Team
8  * @license             GNU GPL 3.0 or any newer version
9  * @link                http://www.ship-simu.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 BaseXmlTemplateEngine implements CompileableTemplate, Registerable {
26         /**
27          * Some XML nodes must be available for later data extraction
28          */
29         const ANNOUNCEMENT_DATA_SESSION_ID    = 'my-session-id';
30         const ANNOUNCEMENT_DATA_NODE_STATUS   = 'my-status';
31         const ANNOUNCEMENT_DATA_EXTERNAL_IP   = 'my-external-ip';
32         const ANNOUNCEMENT_DATA_INTERNAL_IP   = 'my-internal-ip';
33         const ANNOUNCEMENT_DATA_TCP_PORT      = 'my-tcp-port';
34         const ANNOUNCEMENT_DATA_UDP_PORT      = 'my-udp-port';
35         const ANNOUNCEMENT_DATA_ANSWER_STATUS = 'answer-status';
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 sub-nodes array
47                 $this->subNodes = array(
48                         // These nodes don't contain any data
49                         'my-data',
50                         'your-data',
51                         // Data from *this* node
52                         self::ANNOUNCEMENT_DATA_EXTERNAL_IP,
53                         self::ANNOUNCEMENT_DATA_INTERNAL_IP,
54                         self::ANNOUNCEMENT_DATA_TCP_PORT,
55                         self::ANNOUNCEMENT_DATA_UDP_PORT,
56                         self::ANNOUNCEMENT_DATA_NODE_STATUS,
57                         self::ANNOUNCEMENT_DATA_SESSION_ID,
58                         // Data from other node
59                         'your-external-ip',
60                         'your-internal-ip',
61                         'your-session-id',
62                         // Answer status (code)
63                         self::ANNOUNCEMENT_DATA_ANSWER_STATUS
64                 );
65         }
66
67         /**
68          * Creates an instance of the class TemplateEngine and prepares it for usage
69          *
70          * @return      $templateInstance               An instance of TemplateEngine
71          * @throws      BasePathIsEmptyException                If the provided $templateBasePath is empty
72          * @throws      InvalidBasePathStringException  If $templateBasePath is no string
73          * @throws      BasePathIsNoDirectoryException  If $templateBasePath is no
74          *                                                                                      directory or not found
75          * @throws      BasePathReadProtectedException  If $templateBasePath is
76          *                                                                                      read-protected
77          */
78         public static final function createXmlAnnouncementAnswerTemplateEngine () {
79                 // Get a new instance
80                 $templateInstance = new XmlAnnouncementAnswerTemplateEngine();
81
82                 // Init instance
83                 $templateInstance->initXmlTemplateEngine('node', 'announcement_answer');
84
85                 // Return the prepared instance
86                 return $templateInstance;
87         }
88
89         /**
90          * Load a specified announcement-answer template into the engine
91          *
92          * @param       $template       The announcement-answer template we shall load which is
93          *                                              located in 'announcement_answer' by default
94          * @return      void
95          */
96         public function loadAnnouncementAnswerTemplate ($template = 'announcement_answer') {
97                 // Set template type
98                 $this->setTemplateType($this->getConfigInstance()->getConfigEntry('node_announcement_answer_template_type'));
99
100                 // Load the special template
101                 $this->loadTemplate($template);
102         }
103
104         /**
105          * Currently not used
106          *
107          * @param       $resource               XML parser resource (currently ignored)
108          * @param       $characters             Characters to handle
109          * @return      void
110          * @todo        Find something useful with this!
111          */
112         public function characterHandler ($resource, $characters) {
113                 // Trim all spaces away
114                 $characters = trim($characters);
115
116                 // Is this string empty?
117                 if (empty($characters)) {
118                         // Then skip it silently
119                         return false;
120                 } // END - if
121
122                 /*
123                  * Assign the found characters to variable and use the last entry from
124                  * stack as the name.
125                  */
126                 parent::assignVariable($this->getStackerInstance()->getNamed('announcement_answer'), $characters);
127         }
128
129         /**
130          * Read announcement-answer variables by calling readVariable() with 'general' as
131          * variable stack.
132          *
133          * @param       $key    Key to read from
134          * @return      $value  Value from variable
135          */
136         public function readAnnouncementAnswerData ($key) {
137                 // Read the variable
138                 $value = parent::readVariable($key, 'general');
139
140                 // Return value
141                 return $value;
142         }
143
144         /**
145          * Getter for cache file (FQFN)
146          *
147          * @return      $fqfn   Full-qualified file name of the menu cache
148          */
149         public function getAnnouncementAnswerCacheFqfn () {
150                 $this->partialStub('Please implement this method.');
151         }
152
153         /**
154          * Starts the announcement-answer
155          *
156          * @return      void
157          */
158         protected function startAnnouncementAnswer () {
159                 // Push the node name on the stacker
160                 $this->getStackerInstance()->pushNamed('announcement_answer', 'announcement-answer');
161         }
162
163         /**
164          * Starts the my-data
165          *
166          * @return      void
167          */
168         protected function startMyData () {
169                 // Push the node name on the stacker
170                 $this->getStackerInstance()->pushNamed('announcement_answer', 'my-data');
171         }
172
173         /**
174          * Starts the my-external-ip
175          *
176          * @return      void
177          */
178         protected function startMyExternalIp () {
179                 // Push the node name on the stacker
180                 $this->getStackerInstance()->pushNamed('announcement_answer', self::ANNOUNCEMENT_DATA_EXTERNAL_IP);
181         }
182
183         /**
184          * Starts the my-internal-ip
185          *
186          * @return      void
187          */
188         protected function startMyInternalIp () {
189                 // Push the node name on the stacker
190                 $this->getStackerInstance()->pushNamed('announcement_answer', self::ANNOUNCEMENT_DATA_INTERNAL_IP);
191         }
192
193         /**
194          * Starts the my-tcp-port
195          *
196          * @return      void
197          */
198         protected function startMyTcpPort () {
199                 // Push the node name on the stacker
200                 $this->getStackerInstance()->pushNamed('announcement_answer', self::ANNOUNCEMENT_DATA_TCP_PORT);
201         }
202
203         /**
204          * Starts the my-udp-port
205          *
206          * @return      void
207          */
208         protected function startMyUdpPort () {
209                 // Push the node name on the stacker
210                 $this->getStackerInstance()->pushNamed('announcement_answer', self::ANNOUNCEMENT_DATA_UDP_PORT);
211         }
212
213         /**
214          * Starts the my-session-id
215          *
216          * @return      void
217          */
218         protected function startMySessionId () {
219                 // Push the node name on the stacker
220                 $this->getStackerInstance()->pushNamed('announcement_answer', self::ANNOUNCEMENT_DATA_SESSION_ID);
221         }
222
223         /**
224          * Starts the my-status
225          *
226          * @return      void
227          */
228         protected function startMyStatus () {
229                 // Push the node name on the stacker
230                 $this->getStackerInstance()->pushNamed('announcement_answer', self::ANNOUNCEMENT_DATA_NODE_STATUS);
231         }
232
233         /**
234          * Finishes the my-status
235          *
236          * @return      void
237          */
238         protected function finishMyStatus () {
239                 // Pop the last entry
240                 $this->getStackerInstance()->popNamed('announcement_answer');
241         }
242
243         /**
244          * Finishes the my-session-id
245          *
246          * @return      void
247          */
248         protected function finishMySessionId () {
249                 // Pop the last entry
250                 $this->getStackerInstance()->popNamed('announcement_answer');
251         }
252
253         /**
254          * Finishes the my-udp-port
255          *
256          * @return      void
257          */
258         protected function finishMyUdpPort () {
259                 // Pop the last entry
260                 $this->getStackerInstance()->popNamed('announcement_answer');
261         }
262
263         /**
264          * Finishes the my-tcp-port
265          *
266          * @return      void
267          */
268         protected function finishMyTcpPort () {
269                 // Pop the last entry
270                 $this->getStackerInstance()->popNamed('announcement_answer');
271         }
272
273         /**
274          * Finishes the my-internal-ip
275          *
276          * @return      void
277          */
278         protected function finishMyInternalIp () {
279                 // Pop the last entry
280                 $this->getStackerInstance()->popNamed('announcement_answer');
281         }
282
283         /**
284          * Finishes the my-external-ip
285          *
286          * @return      void
287          */
288         protected function finishMyExternalIp () {
289                 // Pop the last entry
290                 $this->getStackerInstance()->popNamed('announcement_answer');
291         }
292
293         /**
294          * Finishes the my-data
295          *
296          * @return      void
297          */
298         protected function finishMyData () {
299                 // Pop the last entry
300                 $this->getStackerInstance()->popNamed('announcement_answer');
301         }
302
303         /**
304          * Starts the your-data
305          *
306          * @return      void
307          */
308         protected function startYourData () {
309                 // Push the node name on the stacker
310                 $this->getStackerInstance()->pushNamed('announcement_answer', 'your-data');
311         }
312
313         /**
314          * Starts the your-external-ip
315          *
316          * @return      void
317          */
318         protected function startYourExternalIp () {
319                 // Push the node name on the stacker
320                 $this->getStackerInstance()->pushNamed('announcement_answer', 'your-external-ip');
321         }
322
323         /**
324          * Starts the your-internal-ip
325          *
326          * @return      void
327          */
328         protected function startYourInternalIp () {
329                 // Push the node name on the stacker
330                 $this->getStackerInstance()->pushNamed('announcement_answer', 'your-internal-ip');
331         }
332
333         /**
334          * Starts the your-session-id
335          *
336          * @return      void
337          */
338         protected function startYourSessionId () {
339                 // Push the node name on the stacker
340                 $this->getStackerInstance()->pushNamed('announcement_answer', 'your-session-id');
341         }
342
343         /**
344          * Finishes the your-session-id
345          *
346          * @return      void
347          */
348         protected function finishYourSessionId () {
349                 // Pop the last entry
350                 $this->getStackerInstance()->popNamed('announcement_answer');
351         }
352
353         /**
354          * Finishes the your-internal-ip
355          *
356          * @return      void
357          */
358         protected function finishYourInternalIp () {
359                 // Pop the last entry
360                 $this->getStackerInstance()->popNamed('announcement_answer');
361         }
362
363         /**
364          * Finishes the your-external-ip
365          *
366          * @return      void
367          */
368         protected function finishYourExternalIp () {
369                 // Pop the last entry
370                 $this->getStackerInstance()->popNamed('announcement_answer');
371         }
372
373         /**
374          * Finishes the your-data
375          *
376          * @return      void
377          */
378         protected function finishYourData () {
379                 // Pop the last entry
380                 $this->getStackerInstance()->popNamed('announcement_answer');
381         }
382
383         /**
384          * Starts the answer-status
385          *
386          * @return      void
387          */
388         protected function startAnswerStatus () {
389                 // Push the node name on the stacker
390                 $this->getStackerInstance()->pushNamed('announcement_answer', self::ANNOUNCEMENT_DATA_ANSWER_STATUS);
391         }
392
393         /**
394          * Finishes the answer-status
395          *
396          * @return      void
397          */
398         protected function finishAnswerStatus () {
399                 // Pop the last entry
400                 $this->getStackerInstance()->popNamed('announcement_answer');
401         }
402
403         /**
404          * Finishes the announcement-answer
405          *
406          * @return      void
407          */
408         protected function finishAnnouncementAnswer () {
409                 // Pop the last entry
410                 $this->getStackerInstance()->popNamed('announcement_answer');
411         }
412 }
413
414 // [EOF]
415 ?>