3 * An Bootstrap template engine class for XML templates
5 * @author Roland Haeder <webmaster@shipsimu.org>
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()
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 XmlDhtBootstrapTemplateEngine extends BaseXmlTemplateEngine implements CompileableTemplate, Registerable {
27 * Some XML nodes must be available for later data extraction
29 const DHT_BOOTSTRAP_DATA_SESSION_ID = 'session-id';
30 const DHT_BOOTSTRAP_DATA_NODE_STATUS = 'node-status';
31 const DHT_BOOTSTRAP_DATA_NODE_MODE = 'node-mode';
32 const DHT_BOOTSTRAP_DATA_EXTERNAL_IP = 'external-ip';
33 const DHT_BOOTSTRAP_DATA_INTERNAL_IP = 'internal-ip';
34 const DHT_BOOTSTRAP_DATA_LISTEN_PORT = 'listen-port';
37 * Protected constructor
41 protected function __construct () {
42 // Call parent constructor
43 parent::__construct(__CLASS__);
46 $this->subNodes = array(
49 self::DHT_BOOTSTRAP_DATA_NODE_STATUS,
50 self::DHT_BOOTSTRAP_DATA_NODE_MODE,
51 self::DHT_BOOTSTRAP_DATA_LISTEN_PORT,
52 self::DHT_BOOTSTRAP_DATA_SESSION_ID,
53 self::DHT_BOOTSTRAP_DATA_EXTERNAL_IP,
54 self::DHT_BOOTSTRAP_DATA_INTERNAL_IP,
60 * Creates an instance of the class TemplateEngine and prepares it for usage
62 * @return $templateInstance An instance of TemplateEngine
63 * @throws BasePathIsEmptyException If the provided $templateBasePath is empty
64 * @throws InvalidBasePathStringException If $templateBasePath is no string
65 * @throws BasePathIsNoDirectoryException If $templateBasePath is no
66 * directory or not found
67 * @throws BasePathReadProtectedException If $templateBasePath is
70 public static final function createXmlDhtBootstrapTemplateEngine () {
72 $templateInstance = new XmlDhtBootstrapTemplateEngine();
74 // Init template instance
75 $templateInstance->initXmlTemplateEngine('dht', 'bootstrap');
77 // Return the prepared instance
78 return $templateInstance;
84 * @param $resource XML parser resource (currently ignored)
85 * @param $characters Characters to handle
88 public function characterHandler ($resource, $characters) {
89 // Trim all spaces away
90 $characters = trim($characters);
92 // Is this string empty?
93 if (empty($characters)) {
94 // Then skip it silently
99 * Assign the found characters to variable and use the last entry from
102 parent::assignVariable($this->getStackerInstance()->getNamed('dht_bootstrap'), $characters);
106 * Getter for cache file (FQFN)
108 * @return $fqfn Full-qualified file name of the menu cache
110 public function getMenuCacheFqfn () {
111 $this->partialStub('Please implement this method.');
115 * Starts the bootstrap
119 protected function startBootstrap () {
120 // Push the node name on the stacker
121 $this->getStackerInstance()->pushNamed('dht_bootstrap', 'bootstrap');
125 * Starts the bootstrap data
129 protected function startBootstrapData () {
130 // Push the node name on the stacker
131 $this->getStackerInstance()->pushNamed('dht_bootstrap', 'bootstrap-data');
135 * Starts the node status
139 protected function startNodeStatus () {
140 // Push the node name on the stacker
141 $this->getStackerInstance()->pushNamed('dht_bootstrap', self::DHT_BOOTSTRAP_DATA_NODE_STATUS);
145 * Starts the node-mode
149 protected function startNodeMode () {
150 // Push the node name on the stacker
151 $this->getStackerInstance()->pushNamed('dht_bootstrap', self::DHT_BOOTSTRAP_DATA_NODE_MODE);
155 * Starts the listener
159 protected function startListener () {
160 // Push the node name on the stacker
161 $this->getStackerInstance()->pushNamed('dht_bootstrap', 'listener');
165 * Starts the TCP/UDP listen port
169 protected function startListenPort () {
170 // Push the node name on the stacker
171 $this->getStackerInstance()->pushNamed('dht_bootstrap', self::DHT_BOOTSTRAP_DATA_LISTEN_PORT);
175 * Starts the session id
179 protected function startSessionId () {
180 // Push the node name on the stacker
181 $this->getStackerInstance()->pushNamed('dht_bootstrap', self::DHT_BOOTSTRAP_DATA_SESSION_ID);
185 * Starts the public ip
189 protected function startExternalIp () {
190 // Push the node name on the stacker
191 $this->getStackerInstance()->pushNamed('dht_bootstrap', self::DHT_BOOTSTRAP_DATA_EXTERNAL_IP);
195 * Starts the private ip
199 protected function startInternalIp () {
200 // Push the node name on the stacker
201 $this->getStackerInstance()->pushNamed('dht_bootstrap', self::DHT_BOOTSTRAP_DATA_INTERNAL_IP);
205 * Starts the object type list
209 protected function startObjectTypeList () {
210 // Push the node name on the stacker
211 $this->getStackerInstance()->pushNamed('dht_bootstrap', 'object-type-list');
215 * Starts the object type
219 protected function startObjectType () {
220 // Push the node name on the stacker
221 $this->getStackerInstance()->pushNamed('dht_bootstrap', 'object-type');
225 * Finishes the object type
229 protected function finishObjectType () {
230 // Pop the last entry
231 $this->getStackerInstance()->popNamed('dht_bootstrap');
235 * Finishes the object type list
239 protected function finishObjectTypeList () {
240 // Pop the last entry
241 $this->getStackerInstance()->popNamed('dht_bootstrap');
245 * Finishes the session id
249 protected function finishSessionId () {
250 // Pop the last entry
251 $this->getStackerInstance()->popNamed('dht_bootstrap');
255 * Finishes the private ip
259 protected function finishInternalIp () {
260 // Pop the last entry
261 $this->getStackerInstance()->popNamed('dht_bootstrap');
265 * Finishes the public ip
269 protected function finishExternalIp () {
270 // Pop the last entry
271 $this->getStackerInstance()->popNamed('dht_bootstrap');
275 * Finishes the TCP/UDP listen port
279 protected function finishListenPort () {
280 // Pop the last entry
281 $this->getStackerInstance()->popNamed('dht_bootstrap');
285 * Finishes the listener
289 protected function finishListener () {
290 // Pop the last entry
291 $this->getStackerInstance()->popNamed('dht_bootstrap');
295 * Finishes the node mode
299 protected function finishNodeMode () {
300 // Pop the last entry
301 $this->getStackerInstance()->popNamed('dht_bootstrap');
305 * Finishes the node status
309 protected function finishNodeStatus () {
310 // Pop the last entry
311 $this->getStackerInstance()->popNamed('dht_bootstrap');
315 * Finishes the bootstrap data
319 protected function finishBootstrapData () {
320 // Pop the last entry
321 $this->getStackerInstance()->popNamed('dht_bootstrap');
325 * Finishes the bootstrap
329 protected function finishBootstrap () {
330 // Pop the last entry
331 $this->getStackerInstance()->popNamed('dht_bootstrap');