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 - 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()
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_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';
36 * Protected constructor
40 protected function __construct () {
41 // Call parent constructor
42 parent::__construct(__CLASS__);
44 // Init sub-nodes array
45 $this->setSubNodes(array(
46 // These nodes don't contain any 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',
58 // Answer status (generic field)
61 self::DHT_BOOTSTRAP_DATA_NODE_LIST,
66 * Creates an instance of the class TemplateEngine and prepares it for usage
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
76 public static final function createXmlDhtBootstrapAnswerTemplateEngine () {
78 $templateInstance = new XmlDhtBootstrapAnswerTemplateEngine();
81 $templateInstance->initXmlTemplateEngine('node', 'dht_bootstrap_answer');
83 // Return the prepared instance
84 return $templateInstance;
90 * @param $resource XML parser resource (currently ignored)
91 * @param $characters Characters to handle
93 * @todo Find something useful with this!
95 public function characterHandler ($resource, $characters) {
96 // Trim all spaces away
97 $characters = trim($characters);
99 // Is this string empty?
100 if (empty($characters)) {
101 // Then skip it silently
106 * Assign the found characters to variable and use the last entry from
109 parent::assignVariable($this->getStackInstance()->getNamed('node_dht_bootstrap_answer'), $characters);
113 * Getter for cache file (FQFN)
115 * @return $fqfn Full-qualified file name of the menu cache
117 public function getDhtBootstrapAnswerCacheFqfn () {
118 $this->partialStub('Please implement this method.');
122 * Starts the dht_bootstrap-answer
126 protected function startDhtBootstrapAnswer () {
127 // Push the node name on the stacker
128 $this->getStackInstance()->pushNamed('node_dht_bootstrap_answer', 'dht_bootstrap-answer');
136 protected function startMyData () {
137 // Push the node name on the stacker
138 $this->getStackInstance()->pushNamed('node_dht_bootstrap_answer', 'my-data');
142 * Starts the my-external-address
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);
152 * Starts the my-internal-address
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);
162 * Starts the my-session-id
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);
172 * Starts the my-status
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);
182 * Starts the dht-nodes-list
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);
192 * Finishes the dht-nodes-list
196 protected function finishDhtNodesList () {
197 // Pop the last entry
198 $this->getStackInstance()->popNamed('node_dht_bootstrap_answer');
202 * Finishes the my-status
206 protected function finishMyStatus () {
207 // Pop the last entry
208 $this->getStackInstance()->popNamed('node_dht_bootstrap_answer');
212 * Finishes the my-session-id
216 protected function finishMySessionId () {
217 // Pop the last entry
218 $this->getStackInstance()->popNamed('node_dht_bootstrap_answer');
222 * Finishes the my-internal-address
226 protected function finishMyInternalAddress () {
227 // Pop the last entry
228 $this->getStackInstance()->popNamed('node_dht_bootstrap_answer');
232 * Finishes the my-external-address
236 protected function finishMyExternalAddress () {
237 // Pop the last entry
238 $this->getStackInstance()->popNamed('node_dht_bootstrap_answer');
242 * Finishes the my-data
246 protected function finishMyData () {
247 // Pop the last entry
248 $this->getStackInstance()->popNamed('node_dht_bootstrap_answer');
252 * Starts the your-data
256 protected function startYourData () {
257 // Push the node name on the stacker
258 $this->getStackInstance()->pushNamed('node_dht_bootstrap_answer', 'your-data');
262 * Starts the your-external-address
266 protected function startYourExternalAddress () {
267 // Push the node name on the stacker
268 $this->getStackInstance()->pushNamed('node_dht_bootstrap_answer', 'your-external-address');
272 * Starts the your-internal-address
276 protected function startYourInternalAddress () {
277 // Push the node name on the stacker
278 $this->getStackInstance()->pushNamed('node_dht_bootstrap_answer', 'your-internal-address');
282 * Starts the your-session-id
286 protected function startYourSessionId () {
287 // Push the node name on the stacker
288 $this->getStackInstance()->pushNamed('node_dht_bootstrap_answer', 'your-session-id');
292 * Finishes the your-session-id
296 protected function finishYourSessionId () {
297 // Pop the last entry
298 $this->getStackInstance()->popNamed('node_dht_bootstrap_answer');
302 * Finishes the your-internal-address
306 protected function finishYourInternalAddress () {
307 // Pop the last entry
308 $this->getStackInstance()->popNamed('node_dht_bootstrap_answer');
312 * Finishes the your-external-address
316 protected function finishYourExternalAddress () {
317 // Pop the last entry
318 $this->getStackInstance()->popNamed('node_dht_bootstrap_answer');
322 * Finishes the your-data
326 protected function finishYourData () {
327 // Pop the last entry
328 $this->getStackInstance()->popNamed('node_dht_bootstrap_answer');
332 * Finishes the dht_bootstrap-answer
336 protected function finishDhtBootstrapAnswer () {
337 // Pop the last entry
338 $this->getStackInstance()->popNamed('node_dht_bootstrap_answer');