3 * An DhtBootstrapAnswer template engine class for XML templates
5 * @author Roland Haeder <webmaster@shipsimu.org>
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()
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.
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.
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/>.
25 class XmlDhtBootstrapAnswerTemplateEngine extends BaseXmlAnswerTemplateEngine implements CompileableTemplate, Registerable {
27 * Some XML nodes must be available for later data extraction
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';
37 * Protected constructor
41 protected function __construct () {
42 // Call parent constructor
43 parent::__construct(__CLASS__);
45 // Init sub-nodes array
46 $this->setSubNodes(array(
47 // These nodes don't contain any 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',
59 // Answer status (generic field)
62 self::DHT_BOOTSTRAP_DATA_NODE_LIST,
67 * Creates an instance of the class TemplateEngine and prepares it for usage
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
77 public static final function createXmlDhtBootstrapAnswerTemplateEngine () {
79 $templateInstance = new XmlDhtBootstrapAnswerTemplateEngine();
82 $templateInstance->initXmlTemplateEngine('node', 'dht_bootstrap_answer');
84 // Return the prepared instance
85 return $templateInstance;
91 * @param $resource XML parser resource (currently ignored)
92 * @param $characters Characters to handle
94 * @todo Find something useful with this!
96 public function characterHandler ($resource, $characters) {
97 // Trim all spaces away
98 $characters = trim($characters);
100 // Is this string empty?
101 if (empty($characters)) {
102 // Then skip it silently
107 * Assign the found characters to variable and use the last entry from
110 parent::assignVariable($this->getStackInstance()->getNamed('node_dht_bootstrap_answer'), $characters);
114 * Getter for cache file (FQFN)
116 * @return $fqfn Full-qualified file name of the menu cache
118 public function getDhtBootstrapAnswerCacheFqfn () {
119 $this->partialStub('Please implement this method.');
123 * Starts the dht_bootstrap-answer
127 protected function startDhtBootstrapAnswer () {
128 // Push the node name on the stacker
129 $this->getStackInstance()->pushNamed('node_dht_bootstrap_answer', 'dht_bootstrap-answer');
137 protected function startMyData () {
138 // Push the node name on the stacker
139 $this->getStackInstance()->pushNamed('node_dht_bootstrap_answer', 'my-data');
143 * Starts the my-external-address
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);
153 * Starts the my-internal-address
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);
163 * Starts the my-session-id
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);
173 * Starts the my-private-key-hash
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);
183 * Starts the my-status
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);
193 * Starts the dht-nodes-list
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);
203 * Finishes the dht-nodes-list
207 protected function finishDhtNodesList () {
208 // Pop the last entry
209 $this->getStackInstance()->popNamed('node_dht_bootstrap_answer');
213 * Finishes the my-status
217 protected function finishMyStatus () {
218 // Pop the last entry
219 $this->getStackInstance()->popNamed('node_dht_bootstrap_answer');
223 * Finishes the my-private-key-hash
227 protected function finishMyPrivateKeyHash () {
228 // Pop the last entry
229 $this->getStackInstance()->popNamed('node_dht_bootstrap_answer');
233 * Finishes the my-session-id
237 protected function finishMySessionId () {
238 // Pop the last entry
239 $this->getStackInstance()->popNamed('node_dht_bootstrap_answer');
243 * Finishes the my-internal-address
247 protected function finishMyInternalAddress () {
248 // Pop the last entry
249 $this->getStackInstance()->popNamed('node_dht_bootstrap_answer');
253 * Finishes the my-external-address
257 protected function finishMyExternalAddress () {
258 // Pop the last entry
259 $this->getStackInstance()->popNamed('node_dht_bootstrap_answer');
263 * Finishes the my-data
267 protected function finishMyData () {
268 // Pop the last entry
269 $this->getStackInstance()->popNamed('node_dht_bootstrap_answer');
273 * Starts the your-data
277 protected function startYourData () {
278 // Push the node name on the stacker
279 $this->getStackInstance()->pushNamed('node_dht_bootstrap_answer', 'your-data');
283 * Starts the your-external-address
287 protected function startYourExternalAddress () {
288 // Push the node name on the stacker
289 $this->getStackInstance()->pushNamed('node_dht_bootstrap_answer', 'your-external-address');
293 * Starts the your-internal-address
297 protected function startYourInternalAddress () {
298 // Push the node name on the stacker
299 $this->getStackInstance()->pushNamed('node_dht_bootstrap_answer', 'your-internal-address');
303 * Starts the your-session-id
307 protected function startYourSessionId () {
308 // Push the node name on the stacker
309 $this->getStackInstance()->pushNamed('node_dht_bootstrap_answer', 'your-session-id');
313 * Starts the your-private-key-hash
317 protected function startYourPrivateKeyHash () {
318 // Push the node name on the stacker
319 $this->getStackInstance()->pushNamed('node_dht_bootstrap_answer', 'your-private-key-hash');
323 * Finishes the your-private-key-hash
327 protected function finishYourPrivateKeyHash () {
328 // Pop the last entry
329 $this->getStackInstance()->popNamed('node_dht_bootstrap_answer');
333 * Finishes the your-session-id
337 protected function finishYourSessionId () {
338 // Pop the last entry
339 $this->getStackInstance()->popNamed('node_dht_bootstrap_answer');
343 * Finishes the your-internal-address
347 protected function finishYourInternalAddress () {
348 // Pop the last entry
349 $this->getStackInstance()->popNamed('node_dht_bootstrap_answer');
353 * Finishes the your-external-address
357 protected function finishYourExternalAddress () {
358 // Pop the last entry
359 $this->getStackInstance()->popNamed('node_dht_bootstrap_answer');
363 * Finishes the your-data
367 protected function finishYourData () {
368 // Pop the last entry
369 $this->getStackInstance()->popNamed('node_dht_bootstrap_answer');
373 * Finishes the dht_bootstrap-answer
377 protected function finishDhtBootstrapAnswer () {
378 // Pop the last entry
379 $this->getStackInstance()->popNamed('node_dht_bootstrap_answer');