]> git.mxchange.org Git - hub.git/blob - application/hub/main/template/publish/class_XmlDhtPublishEntryTemplateEngine.php
Added unfinished support for XML-based publishing of DHT entries.
[hub.git] / application / hub / main / template / publish / class_XmlDhtPublishEntryTemplateEngine.php
1 <?php
2 /**
3  * An PublishEntry 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 - 2012 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 XmlDhtPublishEntryTemplateEngine extends BaseXmlTemplateEngine implements CompileableTemplate, Registerable {
26         /**
27          * Some XML nodes must be available for later data extraction
28          */
29         const PUBLISH_DATA_NODE_ID               = 'node-id';
30         const PUBLISH_DATA_SESSION_ID            = 'session-id';
31         const PUBLISH_DATA_NODE_STATUS           = 'node-status';
32         const PUBLISH_DATA_NODE_MODE             = 'node-mode';
33         const PUBLISH_DATA_EXTERNAL_IP           = 'external-ip';
34         const PUBLISH_DATA_LISTEN_PORT           = 'listen-port';
35         const PUBLISH_DATA_PRIVATE_KEY_HASH      = 'private-key-hash';
36         const PUBLISH_DATA_ACCEPTED_OBJECT_TYPES = 'accepted-object-types';
37
38         /**
39          * Protected constructor
40          *
41          * @return      void
42          */
43         protected function __construct () {
44                 // Call parent constructor
45                 parent::__construct(__CLASS__);
46
47                 // Init array
48                 $this->subNodes = array(
49                         'publish-data',
50                         'listener',
51                         self::PUBLISH_DATA_NODE_STATUS,
52                         self::PUBLISH_DATA_NODE_MODE,
53                         self::PUBLISH_DATA_LISTEN_PORT,
54                         self::PUBLISH_DATA_PRIVATE_KEY_HASH,
55                         self::PUBLISH_DATA_ACCEPTED_OBJECT_TYPES,
56                         self::PUBLISH_DATA_NODE_ID,
57                         self::PUBLISH_DATA_SESSION_ID,
58                         self::PUBLISH_DATA_EXTERNAL_IP,
59                         'object-type-list',
60                 );
61         }
62
63         /**
64          * Creates an instance of the class TemplateEngine and prepares it for usage
65          *
66          * @return      $templateInstance               An instance of TemplateEngine
67          * @throws      BasePathIsEmptyException                If the provided $templateBasePath is empty
68          * @throws      InvalidBasePathStringException  If $templateBasePath is no string
69          * @throws      BasePathIsNoDirectoryException  If $templateBasePath is no
70          *                                                                                      directory or not found
71          * @throws      BasePathReadProtectedException  If $templateBasePath is
72          *                                                                                      read-protected
73          */
74         public static final function createXmlDhtPublishEntryTemplateEngine () {
75                 // Get a new instance
76                 $templateInstance = new XmlDhtPublishEntryTemplateEngine();
77
78                 // Init template instance
79                 $templateInstance->initXmlTemplateEngine('dht', 'publish');
80
81                 // Return the prepared instance
82                 return $templateInstance;
83         }
84
85         /**
86          * Currently not used
87          *
88          * @param       $resource               XML parser resource (currently ignored)
89          * @param       $characters             Characters to handle
90          * @return      void
91          */
92         public function characterHandler ($resource, $characters) {
93                 // Trim all spaces away
94                 $characters = trim($characters);
95
96                 // Is this string empty?
97                 if (empty($characters)) {
98                         // Then skip it silently
99                         return;
100                 } // END - if
101
102                 /*
103                  * Assign the found characters to variable and use the last entry from
104                  * stack as the name.
105                  */
106                 parent::assignVariable($this->getStackerInstance()->getNamed('dht_publish'), $characters);
107         }
108
109         /**
110          * Getter for cache file (FQFN)
111          *
112          * @return      $fqfn   Full-qualified file name of the menu cache
113          */
114         public function getMenuCacheFqfn () {
115                 $this->partialStub('Please implement this method.');
116         }
117
118         /**
119          * Starts the publish
120          *
121          * @return      void
122          */
123         protected function startPublish () {
124                 // Push the node name on the stacker
125                 $this->getStackerInstance()->pushNamed('dht_publish', 'publish');
126         }
127
128         /**
129          * Starts the publish data
130          *
131          * @return      void
132          */
133         protected function startPublishData () {
134                 // Push the node name on the stacker
135                 $this->getStackerInstance()->pushNamed('dht_publish', 'publish-data');
136         }
137
138         /**
139          * Starts the node status
140          *
141          * @return      void
142          */
143         protected function startNodeStatus () {
144                 // Push the node name on the stacker
145                 $this->getStackerInstance()->pushNamed('dht_publish', self::PUBLISH_DATA_NODE_STATUS);
146         }
147
148         /**
149          * Starts the node-mode
150          *
151          * @return      void
152          */
153         protected function startNodeMode () {
154                 // Push the node name on the stacker
155                 $this->getStackerInstance()->pushNamed('dht_publish', self::PUBLISH_DATA_NODE_MODE);
156         }
157
158         /**
159          * Starts the listener
160          *
161          * @return      void
162          */
163         protected function startListener () {
164                 // Push the node name on the stacker
165                 $this->getStackerInstance()->pushNamed('dht_publish', 'listener');
166         }
167
168         /**
169          * Starts the TCP/UDP listen port
170          *
171          * @return      void
172          */
173         protected function startListenPort () {
174                 // Push the node name on the stacker
175                 $this->getStackerInstance()->pushNamed('dht_publish', self::PUBLISH_DATA_LISTEN_PORT);
176         }
177
178         /**
179          * Starts accepted object types
180          *
181          * @return      void
182          */
183         protected function startAcceptedObjectTypes () {
184                 // Push the node name on the stacker
185                 $this->getStackerInstance()->pushNamed('dht_publish', self::PUBLISH_DATA_ACCEPTED_OBJECT_TYPES);
186         }
187
188         /**
189          * Starts hash from private key
190          *
191          * @return      void
192          */
193         protected function startPrivateKeyHash () {
194                 // Push the node name on the stacker
195                 $this->getStackerInstance()->pushNamed('dht_publish', self::PUBLISH_DATA_PRIVATE_KEY_HASH);
196         }
197
198         /**
199          * Starts the node id
200          *
201          * @return      void
202          */
203         protected function startNodeId () {
204                 // Push the node name on the stacker
205                 $this->getStackerInstance()->pushNamed('dht_publish', self::PUBLISH_DATA_NODE_ID);
206         }
207
208         /**
209          * Starts the session id
210          *
211          * @return      void
212          */
213         protected function startSessionId () {
214                 // Push the node name on the stacker
215                 $this->getStackerInstance()->pushNamed('dht_publish', self::PUBLISH_DATA_SESSION_ID);
216         }
217
218         /**
219          * Starts the public ip
220          *
221          * @return      void
222          */
223         protected function startExternalIp () {
224                 // Push the node name on the stacker
225                 $this->getStackerInstance()->pushNamed('dht_publish', self::PUBLISH_DATA_EXTERNAL_IP);
226         }
227
228         /**
229          * Starts the object type list
230          *
231          * @return      void
232          */
233         protected function startObjectTypeList () {
234                 // Push the node name on the stacker
235                 $this->getStackerInstance()->pushNamed('dht_publish', 'object-type-list');
236         }
237
238         /**
239          * Starts the object type
240          *
241          * @return      void
242          */
243         protected function startObjectType () {
244                 // Push the node name on the stacker
245                 $this->getStackerInstance()->pushNamed('dht_publish', 'object-type');
246         }
247
248         /**
249          * Finishes the object type
250          *
251          * @return      void
252          */
253         protected function finishObjectType () {
254                 // Pop the last entry
255                 $this->getStackerInstance()->popNamed('dht_publish');
256         }
257
258         /**
259          * Finishes the object type list
260          *
261          * @return      void
262          */
263         protected function finishObjectTypeList () {
264                 // Pop the last entry
265                 $this->getStackerInstance()->popNamed('dht_publish');
266         }
267
268         /**
269          * Finishes the session id
270          *
271          * @return      void
272          */
273         protected function finishSessionId () {
274                 // Pop the last entry
275                 $this->getStackerInstance()->popNamed('dht_publish');
276         }
277
278         /**
279          * Finishes the node id
280          *
281          * @return      void
282          */
283         protected function finishNodeId () {
284                 // Pop the last entry
285                 $this->getStackerInstance()->popNamed('dht_publish');
286         }
287
288         /**
289          * Finishes the public ip
290          *
291          * @return      void
292          */
293         protected function finishExternalIp () {
294                 // Pop the last entry
295                 $this->getStackerInstance()->popNamed('dht_publish');
296         }
297
298         /**
299          * Finishes the TCP/UDP listen port
300          *
301          * @return      void
302          */
303         protected function finishListenPort () {
304                 // Pop the last entry
305                 $this->getStackerInstance()->popNamed('dht_publish');
306         }
307
308         /**
309          * Finishes hash from private key
310          *
311          * @return      void
312          */
313         protected function finishPrivateKeyHash () {
314                 // Pop the last entry
315                 $this->getStackerInstance()->popNamed('dht_publish');
316         }
317
318         /**
319          * Finishes accepted object types
320          *
321          * @return      void
322          */
323         protected function finishAcceptedObjectTypes () {
324                 // Pop the last entry
325                 $this->getStackerInstance()->popNamed('dht_publish');
326         }
327
328         /**
329          * Finishes the listener
330          *
331          * @return      void
332          */
333         protected function finishListener () {
334                 // Pop the last entry
335                 $this->getStackerInstance()->popNamed('dht_publish');
336         }
337
338         /**
339          * Finishes the node mode
340          *
341          * @return      void
342          */
343         protected function finishNodeMode () {
344                 // Pop the last entry
345                 $this->getStackerInstance()->popNamed('dht_publish');
346         }
347
348         /**
349          * Finishes the node status
350          *
351          * @return      void
352          */
353         protected function finishNodeStatus () {
354                 // Pop the last entry
355                 $this->getStackerInstance()->popNamed('dht_publish');
356         }
357
358         /**
359          * Finishes the publish data
360          *
361          * @return      void
362          */
363         protected function finishPublishData () {
364                 // Pop the last entry
365                 $this->getStackerInstance()->popNamed('dht_publish');
366         }
367
368         /**
369          * Finishes the publish
370          *
371          * @return      void
372          */
373         protected function finishPublish () {
374                 // Pop the last entry
375                 $this->getStackerInstance()->popNamed('dht_publish');
376         }
377 }
378
379 // [EOF]
380 ?>