]> git.mxchange.org Git - hub.git/blob - application/hub/main/template/announcement/class_XmlAnnouncementTemplateEngine.php
Forgot this ... :(
[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@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 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_STATUS = 'node-status';
31         const ANNOUNCEMENT_DATA_NODE_MODE   = 'node-mode';
32         const ANNOUNCEMENT_DATA_EXTERNAL_IP = 'external-ip';
33         const ANNOUNCEMENT_DATA_INTERNAL_IP = 'internal-ip';
34         const ANNOUNCEMENT_DATA_TCP_PORT    = 'tcp-port';
35         const ANNOUNCEMENT_DATA_UDP_PORT    = 'udp-port';
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->subNodes = array(
48                         'announcement-data',
49                         'listener',
50                         self::ANNOUNCEMENT_DATA_NODE_STATUS,
51                         self::ANNOUNCEMENT_DATA_NODE_MODE,
52                         self::ANNOUNCEMENT_DATA_TCP_PORT,
53                         self::ANNOUNCEMENT_DATA_UDP_PORT,
54                         self::ANNOUNCEMENT_DATA_SESSION_ID,
55                         self::ANNOUNCEMENT_DATA_EXTERNAL_IP,
56                         self::ANNOUNCEMENT_DATA_INTERNAL_IP,
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          * Load a specified announcement template into the engine
85          *
86          * @param       $template       The announcement template we shall load which is
87          *                                              located in 'announcement' by default
88          * @return      void
89          */
90         public function loadAnnouncementTemplate ($template = 'self_announcement') {
91                 // Set template type
92                 $this->setTemplateType($this->getConfigInstance()->getConfigEntry('node_announcement_template_type'));
93
94                 // Load the special template
95                 $this->loadTemplate($template);
96         }
97
98         /**
99          * Currently not used
100          *
101          * @param       $resource               XML parser resource (currently ignored)
102          * @param       $characters             Characters to handle
103          * @return      void
104          */
105         public function characterHandler ($resource, $characters) {
106                 // Trim all spaces away
107                 $characters = trim($characters);
108
109                 // Is this string empty?
110                 if (empty($characters)) {
111                         // Then skip it silently
112                         return false;
113                 } // END - if
114
115                 /*
116                  * Assign the found characters to variable and use the last entry from
117                  * stack as the name.
118                  */
119                 parent::assignVariable($this->getStackerInstance()->getNamed('announcement'), $characters);
120         }
121
122         /**
123          * Read announcement variables by calling readVariable() with 'general' as
124          * variable stack.
125          *
126          * @param       $key    Key to read from
127          * @return      $value  Value from variable
128          */
129         public function readAnnouncementData ($key) {
130                 // Read the variable
131                 $value = parent::readVariable($key, 'general');
132
133                 // Return value
134                 return $value;
135         }
136
137         /**
138          * Getter for cache file (FQFN)
139          *
140          * @return      $fqfn   Full-qualified file name of the menu cache
141          */
142         public function getMenuCacheFqfn () {
143                 $this->partialStub('Please implement this method.');
144         }
145
146         /**
147          * Starts the announcement
148          *
149          * @return      void
150          */
151         private function startAnnouncement () {
152                 // Push the node name on the stacker
153                 $this->getStackerInstance()->pushNamed('announcement', 'announcement');
154         }
155
156         /**
157          * Starts the announcement data
158          *
159          * @return      void
160          */
161         private function startAnnouncementData () {
162                 // Push the node name on the stacker
163                 $this->getStackerInstance()->pushNamed('announcement', 'announcement-data');
164         }
165
166         /**
167          * Starts the node status
168          *
169          * @return      void
170          */
171         private function startNodeStatus () {
172                 // Push the node name on the stacker
173                 $this->getStackerInstance()->pushNamed('announcement', self::ANNOUNCEMENT_DATA_NODE_STATUS);
174         }
175
176         /**
177          * Starts the node-mode
178          *
179          * @return      void
180          */
181         private function startNodeMode () {
182                 // Push the node name on the stacker
183                 $this->getStackerInstance()->pushNamed('announcement', self::ANNOUNCEMENT_DATA_NODE_MODE);
184         }
185
186         /**
187          * Starts the listener
188          *
189          * @return      void
190          */
191         private function startListener () {
192                 // Push the node name on the stacker
193                 $this->getStackerInstance()->pushNamed('announcement', 'listener');
194         }
195
196         /**
197          * Starts the TCP port
198          *
199          * @return      void
200          */
201         private function startTcpPort () {
202                 // Push the node name on the stacker
203                 $this->getStackerInstance()->pushNamed('announcement', self::ANNOUNCEMENT_DATA_TCP_PORT);
204         }
205
206         /**
207          * Starts the UDP port
208          *
209          * @return      void
210          */
211         private function startUdpPort () {
212                 // Push the node name on the stacker
213                 $this->getStackerInstance()->pushNamed('announcement', self::ANNOUNCEMENT_DATA_UDP_PORT);
214         }
215
216         /**
217          * Starts the session id
218          *
219          * @return      void
220          */
221         private function startSessionId () {
222                 // Push the node name on the stacker
223                 $this->getStackerInstance()->pushNamed('announcement', self::ANNOUNCEMENT_DATA_SESSION_ID);
224         }
225
226         /**
227          * Starts the public ip
228          *
229          * @return      void
230          */
231         private function startExternalIp () {
232                 // Push the node name on the stacker
233                 $this->getStackerInstance()->pushNamed('announcement', self::ANNOUNCEMENT_DATA_EXTERNAL_IP);
234         }
235
236         /**
237          * Starts the private ip
238          *
239          * @return      void
240          */
241         private function startInternalIp () {
242                 // Push the node name on the stacker
243                 $this->getStackerInstance()->pushNamed('announcement', self::ANNOUNCEMENT_DATA_INTERNAL_IP);
244         }
245
246         /**
247          * Starts the object type list
248          *
249          * @return      void
250          */
251         private function startObjectTypeList () {
252                 // Push the node name on the stacker
253                 $this->getStackerInstance()->pushNamed('announcement', 'object-type-list');
254         }
255
256         /**
257          * Starts the object type
258          *
259          * @return      void
260          */
261         private function startObjectType () {
262                 // Push the node name on the stacker
263                 $this->getStackerInstance()->pushNamed('announcement', 'object-type');
264         }
265
266         /**
267          * Finishes the object type
268          *
269          * @return      void
270          */
271         private function finishObjectType () {
272                 // Pop the last entry
273                 $this->getStackerInstance()->popNamed('announcement');
274         }
275
276         /**
277          * Finishes the object type list
278          *
279          * @return      void
280          */
281         private function finishObjectTypeList () {
282                 // Pop the last entry
283                 $this->getStackerInstance()->popNamed('announcement');
284         }
285
286         /**
287          * Finishes the session id
288          *
289          * @return      void
290          */
291         private function finishSessionId () {
292                 // Pop the last entry
293                 $this->getStackerInstance()->popNamed('announcement');
294         }
295
296         /**
297          * Finishes the private ip
298          *
299          * @return      void
300          */
301         private function finishInternalIp () {
302                 // Pop the last entry
303                 $this->getStackerInstance()->popNamed('announcement');
304         }
305
306         /**
307          * Finishes the public ip
308          *
309          * @return      void
310          */
311         private function finishExternalIp () {
312                 // Pop the last entry
313                 $this->getStackerInstance()->popNamed('announcement');
314         }
315
316         /**
317          * Finishes the UDP port
318          *
319          * @return      void
320          */
321         private function finishUdpPort () {
322                 // Pop the last entry
323                 $this->getStackerInstance()->popNamed('announcement');
324         }
325
326         /**
327          * Finishes the TCP port
328          *
329          * @return      void
330          */
331         private function finishTcpPort () {
332                 // Pop the last entry
333                 $this->getStackerInstance()->popNamed('announcement');
334         }
335
336         /**
337          * Finishes the listener
338          *
339          * @return      void
340          */
341         private function finishListener () {
342                 // Pop the last entry
343                 $this->getStackerInstance()->popNamed('announcement');
344         }
345
346         /**
347          * Finishes the node mode
348          *
349          * @return      void
350          */
351         private function finishNodeMode () {
352                 // Pop the last entry
353                 $this->getStackerInstance()->popNamed('announcement');
354         }
355
356         /**
357          * Finishes the node status
358          *
359          * @return      void
360          */
361         private function finishNodeStatus () {
362                 // Pop the last entry
363                 $this->getStackerInstance()->popNamed('announcement');
364         }
365
366         /**
367          * Finishes the announcement data
368          *
369          * @return      void
370          */
371         private function finishAnnouncementData () {
372                 // Pop the last entry
373                 $this->getStackerInstance()->popNamed('announcement');
374         }
375
376         /**
377          * Finishes the announcement
378          *
379          * @return      void
380          */
381         private function finishAnnouncement () {
382                 // Pop the last entry
383                 $this->getStackerInstance()->popNamed('announcement');
384         }
385 }
386
387 // [EOF]
388 ?>