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