]> git.mxchange.org Git - hub.git/blob - application/hub/main/template/answer/dht/class_XmlDhtBootstrapAnswerTemplateEngine.php
Updated 'core'.
[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 - 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 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_PRIVATE_KEY_HASH = 'my-private-key-hash';
31         const DHT_BOOTSTRAP_DATA_NODE_STATUS      = 'my-status';
32         const DHT_BOOTSTRAP_DATA_EXTERNAL_ADDRESS = 'my-external-address';
33         const DHT_BOOTSTRAP_DATA_INTERNAL_ADDRESS = 'my-internal-address';
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->setSubNodes(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_ADDRESS,
52                         self::DHT_BOOTSTRAP_DATA_INTERNAL_ADDRESS,
53                         self::DHT_BOOTSTRAP_DATA_NODE_STATUS,
54                         self::DHT_BOOTSTRAP_DATA_SESSION_ID,
55                         // Data from other node
56                         'your-external-address',
57                         'your-internal-address',
58                         'your-session-id',
59                         // Answer status (generic field)
60                         self::ANSWER_STATUS,
61                         // DHT node list
62                         self::DHT_BOOTSTRAP_DATA_NODE_LIST,
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 createXmlDhtBootstrapAnswerTemplateEngine () {
78                 // Get a new instance
79                 $templateInstance = new XmlDhtBootstrapAnswerTemplateEngine();
80
81                 // Init instance
82                 $templateInstance->initXmlTemplateEngine('node', 'dht_bootstrap_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;
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->getStackInstance()->getNamed('node_dht_bootstrap_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 getDhtBootstrapAnswerCacheFqfn () {
119                 $this->partialStub('Please implement this method.');
120         }
121
122         /**
123          * Starts the dht_bootstrap-answer
124          *
125          * @return      void
126          */
127         protected function startDhtBootstrapAnswer () {
128                 // Push the node name on the stacker
129                 $this->getStackInstance()->pushNamed('node_dht_bootstrap_answer', 'dht_bootstrap-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->getStackInstance()->pushNamed('node_dht_bootstrap_answer', 'my-data');
140         }
141
142         /**
143          * Starts the my-external-address
144          *
145          * @return      void
146          */
147         protected function startMyExternalAddress () {
148                 // Push the node name on the stacker
149                 $this->getStackInstance()->pushNamed('node_dht_bootstrap_answer', self::DHT_BOOTSTRAP_DATA_EXTERNAL_ADDRESS);
150         }
151
152         /**
153          * Starts the my-internal-address
154          *
155          * @return      void
156          */
157         protected function startMyInternalAddress () {
158                 // Push the node name on the stacker
159                 $this->getStackInstance()->pushNamed('node_dht_bootstrap_answer', self::DHT_BOOTSTRAP_DATA_INTERNAL_ADDRESS);
160         }
161
162         /**
163          * Starts the my-session-id
164          *
165          * @return      void
166          */
167         protected function startMySessionId () {
168                 // Push the node name on the stacker
169                 $this->getStackInstance()->pushNamed('node_dht_bootstrap_answer', self::DHT_BOOTSTRAP_DATA_SESSION_ID);
170         }
171
172         /**
173          * Starts the my-private-key-hash
174          *
175          * @return      void
176          */
177         protected function startMyPrivateKeyHash () {
178                 // Push the node name on the stacker
179                 $this->getStackInstance()->pushNamed('node_dht_bootstrap_answer', self::DHT_BOOTSTRAP_DATA_PRIVATE_KEY_HASH);
180         }
181
182         /**
183          * Starts the my-status
184          *
185          * @return      void
186          */
187         protected function startMyStatus () {
188                 // Push the node name on the stacker
189                 $this->getStackInstance()->pushNamed('node_dht_bootstrap_answer', self::DHT_BOOTSTRAP_DATA_NODE_STATUS);
190         }
191
192         /**
193          * Starts the dht-nodes-list
194          *
195          * @return      void
196          */
197         protected function startDhtNodesList () {
198                 // Push the node name on the stacker
199                 $this->getStackInstance()->pushNamed('node_dht_bootstrap_answer', self::DHT_BOOTSTRAP_DATA_NODE_LIST);
200         }
201
202         /**
203          * Finishes the dht-nodes-list
204          *
205          * @return      void
206          */
207         protected function finishDhtNodesList () {
208                 // Pop the last entry
209                 $this->getStackInstance()->popNamed('node_dht_bootstrap_answer');
210         }
211
212         /**
213          * Finishes the my-status
214          *
215          * @return      void
216          */
217         protected function finishMyStatus () {
218                 // Pop the last entry
219                 $this->getStackInstance()->popNamed('node_dht_bootstrap_answer');
220         }
221
222         /**
223          * Finishes the my-private-key-hash
224          *
225          * @return      void
226          */
227         protected function finishMyPrivateKeyHash () {
228                 // Pop the last entry
229                 $this->getStackInstance()->popNamed('node_dht_bootstrap_answer');
230         }
231
232         /**
233          * Finishes the my-session-id
234          *
235          * @return      void
236          */
237         protected function finishMySessionId () {
238                 // Pop the last entry
239                 $this->getStackInstance()->popNamed('node_dht_bootstrap_answer');
240         }
241
242         /**
243          * Finishes the my-internal-address
244          *
245          * @return      void
246          */
247         protected function finishMyInternalAddress () {
248                 // Pop the last entry
249                 $this->getStackInstance()->popNamed('node_dht_bootstrap_answer');
250         }
251
252         /**
253          * Finishes the my-external-address
254          *
255          * @return      void
256          */
257         protected function finishMyExternalAddress () {
258                 // Pop the last entry
259                 $this->getStackInstance()->popNamed('node_dht_bootstrap_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->getStackInstance()->popNamed('node_dht_bootstrap_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->getStackInstance()->pushNamed('node_dht_bootstrap_answer', 'your-data');
280         }
281
282         /**
283          * Starts the your-external-address
284          *
285          * @return      void
286          */
287         protected function startYourExternalAddress () {
288                 // Push the node name on the stacker
289                 $this->getStackInstance()->pushNamed('node_dht_bootstrap_answer', 'your-external-address');
290         }
291
292         /**
293          * Starts the your-internal-address
294          *
295          * @return      void
296          */
297         protected function startYourInternalAddress () {
298                 // Push the node name on the stacker
299                 $this->getStackInstance()->pushNamed('node_dht_bootstrap_answer', 'your-internal-address');
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->getStackInstance()->pushNamed('node_dht_bootstrap_answer', 'your-session-id');
310         }
311
312         /**
313          * Starts the your-private-key-hash
314          *
315          * @return      void
316          */
317         protected function startYourPrivateKeyHash () {
318                 // Push the node name on the stacker
319                 $this->getStackInstance()->pushNamed('node_dht_bootstrap_answer', 'your-private-key-hash');
320         }
321
322         /**
323          * Finishes the your-private-key-hash
324          *
325          * @return      void
326          */
327         protected function finishYourPrivateKeyHash () {
328                 // Pop the last entry
329                 $this->getStackInstance()->popNamed('node_dht_bootstrap_answer');
330         }
331
332         /**
333          * Finishes the your-session-id
334          *
335          * @return      void
336          */
337         protected function finishYourSessionId () {
338                 // Pop the last entry
339                 $this->getStackInstance()->popNamed('node_dht_bootstrap_answer');
340         }
341
342         /**
343          * Finishes the your-internal-address
344          *
345          * @return      void
346          */
347         protected function finishYourInternalAddress () {
348                 // Pop the last entry
349                 $this->getStackInstance()->popNamed('node_dht_bootstrap_answer');
350         }
351
352         /**
353          * Finishes the your-external-address
354          *
355          * @return      void
356          */
357         protected function finishYourExternalAddress () {
358                 // Pop the last entry
359                 $this->getStackInstance()->popNamed('node_dht_bootstrap_answer');
360         }
361
362         /**
363          * Finishes the your-data
364          *
365          * @return      void
366          */
367         protected function finishYourData () {
368                 // Pop the last entry
369                 $this->getStackInstance()->popNamed('node_dht_bootstrap_answer');
370         }
371
372         /**
373          * Finishes the dht_bootstrap-answer
374          *
375          * @return      void
376          */
377         protected function finishDhtBootstrapAnswer () {
378                 // Pop the last entry
379                 $this->getStackInstance()->popNamed('node_dht_bootstrap_answer');
380         }
381 }
382
383 // [EOF]
384 ?>