]> git.mxchange.org Git - hub.git/blob
fb687da9f72973f904ba6567db3b2fb4799a0edc
[hub.git] /
1 <?php
2 // Own namespace
3 namespace Org\Shipsimu\Hub\Template\Engine\Xml\Answer\Announcement;
4
5 // Import application-specific stuff
6 use Org\Shipsimu\Hub\Template\Engine\Xml\Network\Answer\BaseXmlAnswerTemplateEngine;
7
8 // Import framework stuff
9 use Org\Mxchange\CoreFramework\Registry\Registerable;
10 use Org\Mxchange\CoreFramework\Template\Xml\CompileableXmlTemplate;
11
12 /**
13  * An AnnouncementAnswer template engine class for XML templates
14  *
15  * @author              Roland Haeder <webmaster@shipsimu.org>
16  * @version             0.0.0
17  * @copyright   Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2020 Hub Developer Team
18  * @license             GNU GPL 3.0 or any newer version
19  * @link                http://www.shipsimu.org
20  * @todo                This template engine does not make use of setTemplateType()
21  *
22  * This program is free software: you can redistribute it and/or modify
23  * it under the terms of the GNU General Public License as published by
24  * the Free Software Foundation, either version 3 of the License, or
25  * (at your option) any later version.
26  *
27  * This program is distributed in the hope that it will be useful,
28  * but WITHOUT ANY WARRANTY; without even the implied warranty of
29  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
30  * GNU General Public License for more details.
31  *
32  * You should have received a copy of the GNU General Public License
33  * along with this program. If not, see <http://www.gnu.org/licenses/>.
34  */
35 class XmlAnnouncementAnswerTemplateEngine extends BaseXmlAnswerTemplateEngine implements CompileableXmlTemplate, Registerable {
36         /**
37          * Some XML nodes must be available for later data extraction
38          */
39         const ANNOUNCEMENT_DATA_NODE_ID          = 'my-node-id';
40         const ANNOUNCEMENT_DATA_SESSION_ID       = 'my-session-id';
41         const ANNOUNCEMENT_DATA_PRIVATE_KEY_HASH = 'my-private-key-hash';
42         const ANNOUNCEMENT_DATA_NODE_STATUS      = 'my-status';
43         const ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS = 'my-external-address';
44         const ANNOUNCEMENT_DATA_INTERNAL_ADDRESS = 'my-internal-address';
45
46         /**
47          * Protected constructor
48          *
49          * @return      void
50          */
51         private function __construct () {
52                 // Call parent constructor
53                 parent::__construct(__CLASS__);
54
55                 // Init sub-nodes array
56                 $this->setSubNodes(array(
57                         // These nodes don't contain any data
58                         'my-data',
59                         'your-data',
60                         // Data from *this* node
61                         self::ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS,
62                         self::ANNOUNCEMENT_DATA_INTERNAL_ADDRESS,
63                         self::ANNOUNCEMENT_DATA_NODE_STATUS,
64                         self::ANNOUNCEMENT_DATA_NODE_ID,
65                         self::ANNOUNCEMENT_DATA_SESSION_ID,
66                         self::ANNOUNCEMENT_DATA_PRIVATE_KEY_HASH,
67                         // Data from other node
68                         'your-external-address',
69                         'your-internal-address',
70                         'your-node-id',
71                         'your-session-id',
72                         'your-private-key-hash',
73                         // Answer status (generic field)
74                         self::ANSWER_STATUS,
75                 ));
76         }
77
78         /**
79          * Creates an instance of the class TemplateEngine and prepares it for usage
80          *
81          * @return      $templateInstance               An instance of TemplateEngine
82          * @throws      BasePathIsEmptyException                If the provided $templateBasePath is empty
83          * @throws      InvalidBasePathStringException  If $templateBasePath is no string
84          * @throws      BasePathIsNoDirectoryException  If $templateBasePath is no
85          *                                                                                      directory or not found
86          * @throws      BasePathReadProtectedException  If $templateBasePath is
87          *                                                                                      read-protected
88          */
89         public static final function createXmlAnnouncementAnswerTemplateEngine () {
90                 // Get a new instance
91                 $templateInstance = new XmlAnnouncementAnswerTemplateEngine();
92
93                 // Init instance
94                 $templateInstance->initXmlTemplateEngine('node', 'announcement_answer');
95
96                 // Return the prepared instance
97                 return $templateInstance;
98         }
99
100         /**
101          * Currently not used
102          *
103          * @param       $resource               XML parser resource (currently ignored)
104          * @param       $characters             Characters to handle
105          * @return      void
106          * @todo        Find something useful with this!
107          */
108         public function characterHandler ($resource, string $characters) {
109                 // Trim all spaces away
110                 $characters = trim($characters);
111
112                 // Is this string empty?
113                 if (empty($characters)) {
114                         // Then skip it silently
115                         return;
116                 }
117
118                 /*
119                  * Assign the found characters to variable and use the last entry from
120                  * stack as the name.
121                  */
122                 parent::assignVariable($this->getStackInstance()->getNamed('node_announcement_answer'), $characters);
123         }
124
125         /**
126          * Getter for cache file (FQFN)
127          *
128          * @return      $fqfn   Full-qualified file name of the menu cache
129          */
130         public function getAnnouncementAnswerCacheFqfn () {
131                 $this->partialStub('Please implement this method.');
132         }
133
134         /**
135          * Starts the announcement-answer
136          *
137          * @return      void
138          */
139         protected function startAnnouncementAnswer () {
140                 // Push the node name on the stacker
141                 $this->getStackInstance()->pushNamed('node_announcement_answer', 'announcement-answer');
142         }
143
144         /**
145          * Starts the my-data
146          *
147          * @return      void
148          */
149         protected function startMyData () {
150                 // Push the node name on the stacker
151                 $this->getStackInstance()->pushNamed('node_announcement_answer', 'my-data');
152         }
153
154         /**
155          * Starts the my-external-address
156          *
157          * @return      void
158          */
159         protected function startMyExternalAddress () {
160                 // Push the node name on the stacker
161                 $this->getStackInstance()->pushNamed('node_announcement_answer', self::ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS);
162         }
163
164         /**
165          * Starts the my-internal-address
166          *
167          * @return      void
168          */
169         protected function startMyInternalAddress () {
170                 // Push the node name on the stacker
171                 $this->getStackInstance()->pushNamed('node_announcement_answer', self::ANNOUNCEMENT_DATA_INTERNAL_ADDRESS);
172         }
173
174         /**
175          * Starts the my-node-id
176          *
177          * @return      void
178          */
179         protected function startMyNodeId () {
180                 // Push the node name on the stacker
181                 $this->getStackInstance()->pushNamed('node_announcement_answer', self::ANNOUNCEMENT_DATA_NODE_ID);
182         }
183
184         /**
185          * Starts the my-session-id
186          *
187          * @return      void
188          */
189         protected function startMySessionId () {
190                 // Push the node name on the stacker
191                 $this->getStackInstance()->pushNamed('node_announcement_answer', self::ANNOUNCEMENT_DATA_SESSION_ID);
192         }
193
194         /**
195          * Starts the my-private-key-hash
196          *
197          * @return      void
198          */
199         protected function startMyPrivateKeyHash () {
200                 // Push the node name on the stacker
201                 $this->getStackInstance()->pushNamed('node_announcement_answer', self::ANNOUNCEMENT_DATA_PRIVATE_KEY_HASH);
202         }
203
204         /**
205          * Starts the my-status
206          *
207          * @return      void
208          */
209         protected function startMyStatus () {
210                 // Push the node name on the stacker
211                 $this->getStackInstance()->pushNamed('node_announcement_answer', self::ANNOUNCEMENT_DATA_NODE_STATUS);
212         }
213
214         /**
215          * Finishes the my-status
216          *
217          * @return      void
218          */
219         protected function finishMyStatus () {
220                 // Pop the last entry
221                 $this->getStackInstance()->popNamed('node_announcement_answer');
222         }
223
224         /**
225          * Finishes the my-private-key-hash
226          *
227          * @return      void
228          */
229         protected function finishMyPrivateKeyhash () {
230                 // Pop the last entry
231                 $this->getStackInstance()->popNamed('node_announcement_answer');
232         }
233
234         /**
235          * Finishes the my-session-id
236          *
237          * @return      void
238          */
239         protected function finishMySessionId () {
240                 // Pop the last entry
241                 $this->getStackInstance()->popNamed('node_announcement_answer');
242         }
243
244         /**
245          * Finishes the my-node-id
246          *
247          * @return      void
248          */
249         protected function finishMyNodeId () {
250                 // Pop the last entry
251                 $this->getStackInstance()->popNamed('node_announcement_answer');
252         }
253
254         /**
255          * Finishes the my-internal-address
256          *
257          * @return      void
258          */
259         protected function finishMyInternalAddress () {
260                 // Pop the last entry
261                 $this->getStackInstance()->popNamed('node_announcement_answer');
262         }
263
264         /**
265          * Finishes the my-external-address
266          *
267          * @return      void
268          */
269         protected function finishMyExternalAddress () {
270                 // Pop the last entry
271                 $this->getStackInstance()->popNamed('node_announcement_answer');
272         }
273
274         /**
275          * Finishes the my-data
276          *
277          * @return      void
278          */
279         protected function finishMyData () {
280                 // Pop the last entry
281                 $this->getStackInstance()->popNamed('node_announcement_answer');
282         }
283
284         /**
285          * Starts the your-data
286          *
287          * @return      void
288          */
289         protected function startYourData () {
290                 // Push the node name on the stacker
291                 $this->getStackInstance()->pushNamed('node_announcement_answer', 'your-data');
292         }
293
294         /**
295          * Starts the your-external-address
296          *
297          * @return      void
298          */
299         protected function startYourExternalAddress () {
300                 // Push the node name on the stacker
301                 $this->getStackInstance()->pushNamed('node_announcement_answer', 'your-external-address');
302         }
303
304         /**
305          * Starts the your-internal-address
306          *
307          * @return      void
308          */
309         protected function startYourInternalAddress () {
310                 // Push the node name on the stacker
311                 $this->getStackInstance()->pushNamed('node_announcement_answer', 'your-internal-address');
312         }
313
314         /**
315          * Starts the your-session-id
316          *
317          * @return      void
318          */
319         protected function startYourSessionId () {
320                 // Push the node name on the stacker
321                 $this->getStackInstance()->pushNamed('node_announcement_answer', 'your-session-id');
322         }
323
324         /**
325          * Starts the your-node-id
326          *
327          * @return      void
328          */
329         protected function startYourNodeId () {
330                 // Push the node name on the stacker
331                 $this->getStackInstance()->pushNamed('node_announcement_answer', 'your-node-id');
332         }
333
334         /**
335          * Starts the your-private-key-hash
336          *
337          * @return      void
338          */
339         protected function startYourPrivateKeyHash () {
340                 // Push the node name on the stacker
341                 $this->getStackInstance()->pushNamed('node_announcement_answer', 'your-private-key-hash');
342         }
343
344         /**
345          * Finishes the your-private-key-hash
346          *
347          * @return      void
348          */
349         protected function finishYourPrivateKeyHash () {
350                 // Pop the last entry
351                 $this->getStackInstance()->popNamed('node_announcement_answer');
352         }
353
354         /**
355          * Finishes the your-node-id
356          *
357          * @return      void
358          */
359         protected function finishYourNodeId () {
360                 // Pop the last entry
361                 $this->getStackInstance()->popNamed('node_announcement_answer');
362         }
363
364         /**
365          * Finishes the your-session-id
366          *
367          * @return      void
368          */
369         protected function finishYourSessionId () {
370                 // Pop the last entry
371                 $this->getStackInstance()->popNamed('node_announcement_answer');
372         }
373
374         /**
375          * Finishes the your-internal-address
376          *
377          * @return      void
378          */
379         protected function finishYourInternalAddress () {
380                 // Pop the last entry
381                 $this->getStackInstance()->popNamed('node_announcement_answer');
382         }
383
384         /**
385          * Finishes the your-external-address
386          *
387          * @return      void
388          */
389         protected function finishYourExternalAddress () {
390                 // Pop the last entry
391                 $this->getStackInstance()->popNamed('node_announcement_answer');
392         }
393
394         /**
395          * Finishes the your-data
396          *
397          * @return      void
398          */
399         protected function finishYourData () {
400                 // Pop the last entry
401                 $this->getStackInstance()->popNamed('node_announcement_answer');
402         }
403
404         /**
405          * Finishes the announcement-answer
406          *
407          * @return      void
408          */
409         protected function finishAnnouncementAnswer () {
410                 // Pop the last entry
411                 $this->getStackInstance()->popNamed('node_announcement_answer');
412         }
413
414 }