]> git.mxchange.org Git - hub.git/blob - application/hub/main/template/answer/announcement/class_XmlAnnouncementAnswerTemplateEngine.php
5245f5a329068f3b69a168b034fbf687e7123af5
[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@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 BaseXmlAnswerTemplateEngine 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
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->subNodes = 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_IP,
52                         self::ANNOUNCEMENT_DATA_INTERNAL_IP,
53                         self::ANNOUNCEMENT_DATA_TCP_PORT,
54                         self::ANNOUNCEMENT_DATA_UDP_PORT,
55                         self::ANNOUNCEMENT_DATA_NODE_STATUS,
56                         self::ANNOUNCEMENT_DATA_SESSION_ID,
57                         // Data from other node
58                         'your-external-ip',
59                         'your-internal-ip',
60                         'your-session-id',
61                         // Answer status (generic field)
62                         self::ANSWER_STATUS,
63                 );
64         }
65
66         /**
67          * Creates an instance of the class TemplateEngine and prepares it for usage
68          *
69          * @return      $templateInstance               An instance of TemplateEngine
70          * @throws      BasePathIsEmptyException                If the provided $templateBasePath is empty
71          * @throws      InvalidBasePathStringException  If $templateBasePath is no string
72          * @throws      BasePathIsNoDirectoryException  If $templateBasePath is no
73          *                                                                                      directory or not found
74          * @throws      BasePathReadProtectedException  If $templateBasePath is
75          *                                                                                      read-protected
76          */
77         public static final function createXmlAnnouncementAnswerTemplateEngine () {
78                 // Get a new instance
79                 $templateInstance = new XmlAnnouncementAnswerTemplateEngine();
80
81                 // Init instance
82                 $templateInstance->initXmlTemplateEngine('node', 'announcement_answer');
83
84                 // Return the prepared instance
85                 return $templateInstance;
86         }
87
88         /**
89          * Currently not used
90          *
91          * @param       $resource               XML parser resource (currently ignored)
92          * @param       $characters             Characters to handle
93          * @return      void
94          * @todo        Find something useful with this!
95          */
96         public function characterHandler ($resource, $characters) {
97                 // Trim all spaces away
98                 $characters = trim($characters);
99
100                 // Is this string empty?
101                 if (empty($characters)) {
102                         // Then skip it silently
103                         return false;
104                 } // END - if
105
106                 /*
107                  * Assign the found characters to variable and use the last entry from
108                  * stack as the name.
109                  */
110                 parent::assignVariable($this->getStackerInstance()->getNamed('node_announcement_answer'), $characters);
111         }
112
113         /**
114          * Getter for cache file (FQFN)
115          *
116          * @return      $fqfn   Full-qualified file name of the menu cache
117          */
118         public function getAnnouncementAnswerCacheFqfn () {
119                 $this->partialStub('Please implement this method.');
120         }
121
122         /**
123          * Starts the announcement-answer
124          *
125          * @return      void
126          */
127         protected function startAnnouncementAnswer () {
128                 // Push the node name on the stacker
129                 $this->getStackerInstance()->pushNamed('node_announcement_answer', 'announcement-answer');
130         }
131
132         /**
133          * Starts the my-data
134          *
135          * @return      void
136          */
137         protected function startMyData () {
138                 // Push the node name on the stacker
139                 $this->getStackerInstance()->pushNamed('node_announcement_answer', 'my-data');
140         }
141
142         /**
143          * Starts the my-external-ip
144          *
145          * @return      void
146          */
147         protected function startMyExternalIp () {
148                 // Push the node name on the stacker
149                 $this->getStackerInstance()->pushNamed('node_announcement_answer', self::ANNOUNCEMENT_DATA_EXTERNAL_IP);
150         }
151
152         /**
153          * Starts the my-internal-ip
154          *
155          * @return      void
156          */
157         protected function startMyInternalIp () {
158                 // Push the node name on the stacker
159                 $this->getStackerInstance()->pushNamed('node_announcement_answer', self::ANNOUNCEMENT_DATA_INTERNAL_IP);
160         }
161
162         /**
163          * Starts the my-tcp-port
164          *
165          * @return      void
166          */
167         protected function startMyTcpPort () {
168                 // Push the node name on the stacker
169                 $this->getStackerInstance()->pushNamed('node_announcement_answer', self::ANNOUNCEMENT_DATA_TCP_PORT);
170         }
171
172         /**
173          * Starts the my-udp-port
174          *
175          * @return      void
176          */
177         protected function startMyUdpPort () {
178                 // Push the node name on the stacker
179                 $this->getStackerInstance()->pushNamed('node_announcement_answer', self::ANNOUNCEMENT_DATA_UDP_PORT);
180         }
181
182         /**
183          * Starts the my-session-id
184          *
185          * @return      void
186          */
187         protected function startMySessionId () {
188                 // Push the node name on the stacker
189                 $this->getStackerInstance()->pushNamed('node_announcement_answer', self::ANNOUNCEMENT_DATA_SESSION_ID);
190         }
191
192         /**
193          * Starts the my-status
194          *
195          * @return      void
196          */
197         protected function startMyStatus () {
198                 // Push the node name on the stacker
199                 $this->getStackerInstance()->pushNamed('node_announcement_answer', self::ANNOUNCEMENT_DATA_NODE_STATUS);
200         }
201
202         /**
203          * Finishes the my-status
204          *
205          * @return      void
206          */
207         protected function finishMyStatus () {
208                 // Pop the last entry
209                 $this->getStackerInstance()->popNamed('node_announcement_answer');
210         }
211
212         /**
213          * Finishes the my-session-id
214          *
215          * @return      void
216          */
217         protected function finishMySessionId () {
218                 // Pop the last entry
219                 $this->getStackerInstance()->popNamed('node_announcement_answer');
220         }
221
222         /**
223          * Finishes the my-udp-port
224          *
225          * @return      void
226          */
227         protected function finishMyUdpPort () {
228                 // Pop the last entry
229                 $this->getStackerInstance()->popNamed('node_announcement_answer');
230         }
231
232         /**
233          * Finishes the my-tcp-port
234          *
235          * @return      void
236          */
237         protected function finishMyTcpPort () {
238                 // Pop the last entry
239                 $this->getStackerInstance()->popNamed('node_announcement_answer');
240         }
241
242         /**
243          * Finishes the my-internal-ip
244          *
245          * @return      void
246          */
247         protected function finishMyInternalIp () {
248                 // Pop the last entry
249                 $this->getStackerInstance()->popNamed('node_announcement_answer');
250         }
251
252         /**
253          * Finishes the my-external-ip
254          *
255          * @return      void
256          */
257         protected function finishMyExternalIp () {
258                 // Pop the last entry
259                 $this->getStackerInstance()->popNamed('node_announcement_answer');
260         }
261
262         /**
263          * Finishes the my-data
264          *
265          * @return      void
266          */
267         protected function finishMyData () {
268                 // Pop the last entry
269                 $this->getStackerInstance()->popNamed('node_announcement_answer');
270         }
271
272         /**
273          * Starts the your-data
274          *
275          * @return      void
276          */
277         protected function startYourData () {
278                 // Push the node name on the stacker
279                 $this->getStackerInstance()->pushNamed('node_announcement_answer', 'your-data');
280         }
281
282         /**
283          * Starts the your-external-ip
284          *
285          * @return      void
286          */
287         protected function startYourExternalIp () {
288                 // Push the node name on the stacker
289                 $this->getStackerInstance()->pushNamed('node_announcement_answer', 'your-external-ip');
290         }
291
292         /**
293          * Starts the your-internal-ip
294          *
295          * @return      void
296          */
297         protected function startYourInternalIp () {
298                 // Push the node name on the stacker
299                 $this->getStackerInstance()->pushNamed('node_announcement_answer', 'your-internal-ip');
300         }
301
302         /**
303          * Starts the your-session-id
304          *
305          * @return      void
306          */
307         protected function startYourSessionId () {
308                 // Push the node name on the stacker
309                 $this->getStackerInstance()->pushNamed('node_announcement_answer', 'your-session-id');
310         }
311
312         /**
313          * Finishes the your-session-id
314          *
315          * @return      void
316          */
317         protected function finishYourSessionId () {
318                 // Pop the last entry
319                 $this->getStackerInstance()->popNamed('node_announcement_answer');
320         }
321
322         /**
323          * Finishes the your-internal-ip
324          *
325          * @return      void
326          */
327         protected function finishYourInternalIp () {
328                 // Pop the last entry
329                 $this->getStackerInstance()->popNamed('node_announcement_answer');
330         }
331
332         /**
333          * Finishes the your-external-ip
334          *
335          * @return      void
336          */
337         protected function finishYourExternalIp () {
338                 // Pop the last entry
339                 $this->getStackerInstance()->popNamed('node_announcement_answer');
340         }
341
342         /**
343          * Finishes the your-data
344          *
345          * @return      void
346          */
347         protected function finishYourData () {
348                 // Pop the last entry
349                 $this->getStackerInstance()->popNamed('node_announcement_answer');
350         }
351
352         /**
353          * Finishes the announcement-answer
354          *
355          * @return      void
356          */
357         protected function finishAnnouncementAnswer () {
358                 // Pop the last entry
359                 $this->getStackerInstance()->popNamed('node_announcement_answer');
360         }
361 }
362
363 // [EOF]
364 ?>