]> git.mxchange.org Git - hub.git/blob - application/hub/main/template/answer/dht/class_XmlDhtBootstrapAnswerTemplateEngine.php
Continued with refacturing:
[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_ADDRESS = 'my-external-address';
32         const DHT_BOOTSTRAP_DATA_INTERNAL_ADDRESS = 'my-internal-address';
33         const DHT_BOOTSTRAP_DATA_NODE_LIST        = 'dht-nodes-list';
34
35         /**
36          * Protected constructor
37          *
38          * @return      void
39          */
40         protected function __construct () {
41                 // Call parent constructor
42                 parent::__construct(__CLASS__);
43
44                 // Init sub-nodes array
45                 $this->subNodes = array(
46                         // These nodes don't contain any data
47                         'my-data',
48                         'your-data',
49                         // Data from *this* node
50                         self::DHT_BOOTSTRAP_DATA_EXTERNAL_ADDRESS,
51                         self::DHT_BOOTSTRAP_DATA_INTERNAL_ADDRESS,
52                         self::DHT_BOOTSTRAP_DATA_NODE_STATUS,
53                         self::DHT_BOOTSTRAP_DATA_SESSION_ID,
54                         // Data from other node
55                         'your-external-address',
56                         'your-internal-address',
57                         'your-session-id',
58                         // Answer status (generic field)
59                         self::ANSWER_STATUS,
60                         // DHT node list
61                         self::DHT_BOOTSTRAP_DATA_NODE_LIST,
62                 );
63         }
64
65         /**
66          * Creates an instance of the class TemplateEngine and prepares it for usage
67          *
68          * @return      $templateInstance               An instance of TemplateEngine
69          * @throws      BasePathIsEmptyException                If the provided $templateBasePath is empty
70          * @throws      InvalidBasePathStringException  If $templateBasePath is no string
71          * @throws      BasePathIsNoDirectoryException  If $templateBasePath is no
72          *                                                                                      directory or not found
73          * @throws      BasePathReadProtectedException  If $templateBasePath is
74          *                                                                                      read-protected
75          */
76         public static final function createXmlDhtBootstrapAnswerTemplateEngine () {
77                 // Get a new instance
78                 $templateInstance = new XmlDhtBootstrapAnswerTemplateEngine();
79
80                 // Init instance
81                 $templateInstance->initXmlTemplateEngine('node', 'dht_bootstrap_answer');
82
83                 // Return the prepared instance
84                 return $templateInstance;
85         }
86
87         /**
88          * Currently not used
89          *
90          * @param       $resource               XML parser resource (currently ignored)
91          * @param       $characters             Characters to handle
92          * @return      void
93          * @todo        Find something useful with this!
94          */
95         public function characterHandler ($resource, $characters) {
96                 // Trim all spaces away
97                 $characters = trim($characters);
98
99                 // Is this string empty?
100                 if (empty($characters)) {
101                         // Then skip it silently
102                         return;
103                 } // END - if
104
105                 /*
106                  * Assign the found characters to variable and use the last entry from
107                  * stack as the name.
108                  */
109                 parent::assignVariable($this->getStackInstance()->getNamed('node_dht_bootstrap_answer'), $characters);
110         }
111
112         /**
113          * Getter for cache file (FQFN)
114          *
115          * @return      $fqfn   Full-qualified file name of the menu cache
116          */
117         public function getDhtBootstrapAnswerCacheFqfn () {
118                 $this->partialStub('Please implement this method.');
119         }
120
121         /**
122          * Starts the dht_bootstrap-answer
123          *
124          * @return      void
125          */
126         protected function startDhtBootstrapAnswer () {
127                 // Push the node name on the stacker
128                 $this->getStackInstance()->pushNamed('node_dht_bootstrap_answer', 'dht_bootstrap-answer');
129         }
130
131         /**
132          * Starts the my-data
133          *
134          * @return      void
135          */
136         protected function startMyData () {
137                 // Push the node name on the stacker
138                 $this->getStackInstance()->pushNamed('node_dht_bootstrap_answer', 'my-data');
139         }
140
141         /**
142          * Starts the my-external-address
143          *
144          * @return      void
145          */
146         protected function startMyExternalAddress () {
147                 // Push the node name on the stacker
148                 $this->getStackInstance()->pushNamed('node_dht_bootstrap_answer', self::DHT_BOOTSTRAP_DATA_EXTERNAL_ADDRESS);
149         }
150
151         /**
152          * Starts the my-internal-address
153          *
154          * @return      void
155          */
156         protected function startMyInternalAddress () {
157                 // Push the node name on the stacker
158                 $this->getStackInstance()->pushNamed('node_dht_bootstrap_answer', self::DHT_BOOTSTRAP_DATA_INTERNAL_ADDRESS);
159         }
160
161         /**
162          * Starts the my-session-id
163          *
164          * @return      void
165          */
166         protected function startMySessionId () {
167                 // Push the node name on the stacker
168                 $this->getStackInstance()->pushNamed('node_dht_bootstrap_answer', self::DHT_BOOTSTRAP_DATA_SESSION_ID);
169         }
170
171         /**
172          * Starts the my-status
173          *
174          * @return      void
175          */
176         protected function startMyStatus () {
177                 // Push the node name on the stacker
178                 $this->getStackInstance()->pushNamed('node_dht_bootstrap_answer', self::DHT_BOOTSTRAP_DATA_NODE_STATUS);
179         }
180
181         /**
182          * Starts the dht-nodes-list
183          *
184          * @return      void
185          */
186         protected function startDhtNodesList () {
187                 // Push the node name on the stacker
188                 $this->getStackInstance()->pushNamed('node_dht_bootstrap_answer', self::DHT_BOOTSTRAP_DATA_NODE_LIST);
189         }
190
191         /**
192          * Finishes the dht-nodes-list
193          *
194          * @return      void
195          */
196         protected function finishDhtNodesList () {
197                 // Pop the last entry
198                 $this->getStackInstance()->popNamed('node_dht_bootstrap_answer');
199         }
200
201         /**
202          * Finishes the my-status
203          *
204          * @return      void
205          */
206         protected function finishMyStatus () {
207                 // Pop the last entry
208                 $this->getStackInstance()->popNamed('node_dht_bootstrap_answer');
209         }
210
211         /**
212          * Finishes the my-session-id
213          *
214          * @return      void
215          */
216         protected function finishMySessionId () {
217                 // Pop the last entry
218                 $this->getStackInstance()->popNamed('node_dht_bootstrap_answer');
219         }
220
221         /**
222          * Finishes the my-internal-address
223          *
224          * @return      void
225          */
226         protected function finishMyInternalAddress () {
227                 // Pop the last entry
228                 $this->getStackInstance()->popNamed('node_dht_bootstrap_answer');
229         }
230
231         /**
232          * Finishes the my-external-address
233          *
234          * @return      void
235          */
236         protected function finishMyExternalAddress () {
237                 // Pop the last entry
238                 $this->getStackInstance()->popNamed('node_dht_bootstrap_answer');
239         }
240
241         /**
242          * Finishes the my-data
243          *
244          * @return      void
245          */
246         protected function finishMyData () {
247                 // Pop the last entry
248                 $this->getStackInstance()->popNamed('node_dht_bootstrap_answer');
249         }
250
251         /**
252          * Starts the your-data
253          *
254          * @return      void
255          */
256         protected function startYourData () {
257                 // Push the node name on the stacker
258                 $this->getStackInstance()->pushNamed('node_dht_bootstrap_answer', 'your-data');
259         }
260
261         /**
262          * Starts the your-external-address
263          *
264          * @return      void
265          */
266         protected function startYourExternalAddress () {
267                 // Push the node name on the stacker
268                 $this->getStackInstance()->pushNamed('node_dht_bootstrap_answer', 'your-external-address');
269         }
270
271         /**
272          * Starts the your-internal-address
273          *
274          * @return      void
275          */
276         protected function startYourInternalAddress () {
277                 // Push the node name on the stacker
278                 $this->getStackInstance()->pushNamed('node_dht_bootstrap_answer', 'your-internal-address');
279         }
280
281         /**
282          * Starts the your-session-id
283          *
284          * @return      void
285          */
286         protected function startYourSessionId () {
287                 // Push the node name on the stacker
288                 $this->getStackInstance()->pushNamed('node_dht_bootstrap_answer', 'your-session-id');
289         }
290
291         /**
292          * Finishes the your-session-id
293          *
294          * @return      void
295          */
296         protected function finishYourSessionId () {
297                 // Pop the last entry
298                 $this->getStackInstance()->popNamed('node_dht_bootstrap_answer');
299         }
300
301         /**
302          * Finishes the your-internal-address
303          *
304          * @return      void
305          */
306         protected function finishYourInternalAddress () {
307                 // Pop the last entry
308                 $this->getStackInstance()->popNamed('node_dht_bootstrap_answer');
309         }
310
311         /**
312          * Finishes the your-external-address
313          *
314          * @return      void
315          */
316         protected function finishYourExternalAddress () {
317                 // Pop the last entry
318                 $this->getStackInstance()->popNamed('node_dht_bootstrap_answer');
319         }
320
321         /**
322          * Finishes the your-data
323          *
324          * @return      void
325          */
326         protected function finishYourData () {
327                 // Pop the last entry
328                 $this->getStackInstance()->popNamed('node_dht_bootstrap_answer');
329         }
330
331         /**
332          * Finishes the dht_bootstrap-answer
333          *
334          * @return      void
335          */
336         protected function finishDhtBootstrapAnswer () {
337                 // Pop the last entry
338                 $this->getStackInstance()->popNamed('node_dht_bootstrap_answer');
339         }
340 }
341
342 // [EOF]
343 ?>