Updated 'core'.
[hub.git] / application / hub / main / template / dht / class_XmlDhtBootstrapTemplateEngine.php
1 <?php
2 /**
3  * An Bootstrap 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 XmlDhtBootstrapTemplateEngine extends BaseXmlTemplateEngine implements CompileableTemplate, Registerable {
26         /**
27          * Some XML nodes must be available for later data extraction
28          */
29         const DHT_BOOTSTRAP_DATA_BOOTSTRAP_DATA   = 'dht-bootstrap-data';
30         const DHT_BOOTSTRAP_DATA_SESSION_ID       = 'session-id';
31         const DHT_BOOTSTRAP_DATA_NODE_STATUS      = 'node-status';
32         const DHT_BOOTSTRAP_DATA_NODE_MODE        = 'node-mode';
33         const DHT_BOOTSTRAP_DATA_EXTERNAL_ADDRESS = 'external-address';
34         const DHT_BOOTSTRAP_DATA_INTERNAL_ADDRESS = 'internal-address';
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 array
46                 $this->setSubNodes(array(
47                         self::DHT_BOOTSTRAP_DATA_BOOTSTRAP_DATA,
48                         'listener',
49                         self::DHT_BOOTSTRAP_DATA_NODE_STATUS,
50                         self::DHT_BOOTSTRAP_DATA_NODE_MODE,
51                         self::DHT_BOOTSTRAP_DATA_SESSION_ID,
52                         self::DHT_BOOTSTRAP_DATA_EXTERNAL_ADDRESS,
53                         self::DHT_BOOTSTRAP_DATA_INTERNAL_ADDRESS
54                 ));
55         }
56
57         /**
58          * Creates an instance of the class TemplateEngine and prepares it for usage
59          *
60          * @return      $templateInstance               An instance of TemplateEngine
61          * @throws      BasePathIsEmptyException                If the provided $templateBasePath is empty
62          * @throws      InvalidBasePathStringException  If $templateBasePath is no string
63          * @throws      BasePathIsNoDirectoryException  If $templateBasePath is no
64          *                                                                                      directory or not found
65          * @throws      BasePathReadProtectedException  If $templateBasePath is
66          *                                                                                      read-protected
67          */
68         public static final function createXmlDhtBootstrapTemplateEngine () {
69                 // Get a new instance
70                 $templateInstance = new XmlDhtBootstrapTemplateEngine();
71
72                 // Init template instance
73                 $templateInstance->initXmlTemplateEngine('node', 'dht_bootstrap');
74
75                 // Return the prepared instance
76                 return $templateInstance;
77         }
78
79         /**
80          * Currently not used
81          *
82          * @param       $resource               XML parser resource (currently ignored)
83          * @param       $characters             Characters to handle
84          * @return      void
85          */
86         public function characterHandler ($resource, $characters) {
87                 // Trim all spaces away
88                 $characters = trim($characters);
89
90                 // Is this string empty?
91                 if (empty($characters)) {
92                         // Then skip it silently
93                         return;
94                 } // END - if
95
96                 /*
97                  * Assign the found characters to variable and use the last entry from
98                  * stack as the name.
99                  */
100                 parent::assignVariable($this->getStackInstance()->getNamed('dht_bootstrap'), $characters);
101         }
102
103         /**
104          * Getter for cache file (FQFN)
105          *
106          * @return      $fqfn   Full-qualified file name of the menu cache
107          */
108         public function getMenuCacheFqfn () {
109                 $this->partialStub('Please implement this method.');
110         }
111
112         /**
113          * Starts the dht bootstrap
114          *
115          * @return      void
116          */
117         protected function startDhtBootstrap () {
118                 // Push the node name on the stacker
119                 $this->getStackInstance()->pushNamed('dht_bootstrap', 'dht-bootstrap');
120         }
121
122         /**
123          * Starts the dht bootstrap data
124          *
125          * @return      void
126          */
127         protected function startDhtBootstrapData () {
128                 // Push the node name on the stacker
129                 $this->getStackInstance()->pushNamed('dht_bootstrap', self::DHT_BOOTSTRAP_DATA_BOOTSTRAP_DATA);
130         }
131
132         /**
133          * Starts the node status
134          *
135          * @return      void
136          */
137         protected function startNodeStatus () {
138                 // Push the node name on the stacker
139                 $this->getStackInstance()->pushNamed('dht_bootstrap', self::DHT_BOOTSTRAP_DATA_NODE_STATUS);
140         }
141
142         /**
143          * Starts the node-mode
144          *
145          * @return      void
146          */
147         protected function startNodeMode () {
148                 // Push the node name on the stacker
149                 $this->getStackInstance()->pushNamed('dht_bootstrap', self::DHT_BOOTSTRAP_DATA_NODE_MODE);
150         }
151
152         /**
153          * Starts the listener
154          *
155          * @return      void
156          */
157         protected function startListener () {
158                 // Push the node name on the stacker
159                 $this->getStackInstance()->pushNamed('dht_bootstrap', 'listener');
160         }
161
162         /**
163          * Starts the public ip
164          *
165          * @return      void
166          */
167         protected function startExternalAddress () {
168                 // Push the node name on the stacker
169                 $this->getStackInstance()->pushNamed('dht_bootstrap', self::DHT_BOOTSTRAP_DATA_EXTERNAL_ADDRESS);
170         }
171
172         /**
173          * Starts the private ip
174          *
175          * @return      void
176          */
177         protected function startInternalAddress () {
178                 // Push the node name on the stacker
179                 $this->getStackInstance()->pushNamed('dht_bootstrap', self::DHT_BOOTSTRAP_DATA_INTERNAL_ADDRESS);
180         }
181
182         /**
183          * Starts the session id
184          *
185          * @return      void
186          */
187         protected function startSessionId () {
188                 // Push the node name on the stacker
189                 $this->getStackInstance()->pushNamed('dht_bootstrap', self::DHT_BOOTSTRAP_DATA_SESSION_ID);
190         }
191
192         /**
193          * Finishes the session id
194          *
195          * @return      void
196          */
197         protected function finishSessionId () {
198                 // Pop the last entry
199                 $this->getStackInstance()->popNamed('dht_bootstrap');
200         }
201
202         /**
203          * Finishes the private ip
204          *
205          * @return      void
206          */
207         protected function finishInternalAddress () {
208                 // Pop the last entry
209                 $this->getStackInstance()->popNamed('dht_bootstrap');
210         }
211
212         /**
213          * Finishes the public ip
214          *
215          * @return      void
216          */
217         protected function finishExternalAddress () {
218                 // Pop the last entry
219                 $this->getStackInstance()->popNamed('dht_bootstrap');
220         }
221
222         /**
223          * Finishes the listener
224          *
225          * @return      void
226          */
227         protected function finishListener () {
228                 // Pop the last entry
229                 $this->getStackInstance()->popNamed('dht_bootstrap');
230         }
231
232         /**
233          * Finishes the node mode
234          *
235          * @return      void
236          */
237         protected function finishNodeMode () {
238                 // Pop the last entry
239                 $this->getStackInstance()->popNamed('dht_bootstrap');
240         }
241
242         /**
243          * Finishes the node status
244          *
245          * @return      void
246          */
247         protected function finishNodeStatus () {
248                 // Pop the last entry
249                 $this->getStackInstance()->popNamed('dht_bootstrap');
250         }
251
252         /**
253          * Finishes the dht bootstrap data
254          *
255          * @return      void
256          */
257         protected function finishDhtBootstrapData () {
258                 // Pop the last entry
259                 $this->getStackInstance()->popNamed('dht_bootstrap');
260         }
261
262         /**
263          * Finishes the dht bootstrap
264          *
265          * @return      void
266          */
267         protected function finishDhtBootstrap () {
268                 // Pop the last entry
269                 $this->getStackInstance()->popNamed('dht_bootstrap');
270         }
271 }
272
273 // [EOF]
274 ?>