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_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_IP = 'external-ip';
34 const DHT_BOOTSTRAP_DATA_INTERNAL_IP = 'internal-ip';
35 const DHT_BOOTSTRAP_DATA_LISTEN_PORT = 'listen-port';
38 * Protected constructor
42 protected function __construct () {
43 // Call parent constructor
44 parent::__construct(__CLASS__);
47 $this->subNodes = array(
48 self::DHT_BOOTSTRAP_DATA_BOOTSTRAP_DATA,
50 self::DHT_BOOTSTRAP_DATA_NODE_STATUS,
51 self::DHT_BOOTSTRAP_DATA_NODE_MODE,
52 self::DHT_BOOTSTRAP_DATA_LISTEN_PORT,
53 self::DHT_BOOTSTRAP_DATA_SESSION_ID,
54 self::DHT_BOOTSTRAP_DATA_EXTERNAL_IP,
55 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('node', '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 dht bootstrap
119 protected function startBootstrap () {
120 // Push the node name on the stacker
121 $this->getStackerInstance()->pushNamed('dht_bootstrap', 'dht-bootstrap');
125 * Starts the dht bootstrap data
129 protected function startDhtBootstrapData () {
130 // Push the node name on the stacker
131 $this->getStackerInstance()->pushNamed('dht_bootstrap', self::DHT_BOOTSTRAP_DATA_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 public ip
179 protected function startExternalIp () {
180 // Push the node name on the stacker
181 $this->getStackerInstance()->pushNamed('dht_bootstrap', self::DHT_BOOTSTRAP_DATA_EXTERNAL_IP);
185 * Starts the private ip
189 protected function startInternalIp () {
190 // Push the node name on the stacker
191 $this->getStackerInstance()->pushNamed('dht_bootstrap', self::DHT_BOOTSTRAP_DATA_INTERNAL_IP);
195 * Starts the session id
199 protected function startSessionId () {
200 // Push the node name on the stacker
201 $this->getStackerInstance()->pushNamed('dht_bootstrap', self::DHT_BOOTSTRAP_DATA_SESSION_ID);
205 * Finishes the session id
209 protected function finishSessionId () {
210 // Pop the last entry
211 $this->getStackerInstance()->popNamed('dht_bootstrap');
215 * Finishes the private ip
219 protected function finishInternalIp () {
220 // Pop the last entry
221 $this->getStackerInstance()->popNamed('dht_bootstrap');
225 * Finishes the public ip
229 protected function finishExternalIp () {
230 // Pop the last entry
231 $this->getStackerInstance()->popNamed('dht_bootstrap');
235 * Finishes the TCP/UDP listen port
239 protected function finishListenPort () {
240 // Pop the last entry
241 $this->getStackerInstance()->popNamed('dht_bootstrap');
245 * Finishes the listener
249 protected function finishListener () {
250 // Pop the last entry
251 $this->getStackerInstance()->popNamed('dht_bootstrap');
255 * Finishes the node mode
259 protected function finishNodeMode () {
260 // Pop the last entry
261 $this->getStackerInstance()->popNamed('dht_bootstrap');
265 * Finishes the node status
269 protected function finishNodeStatus () {
270 // Pop the last entry
271 $this->getStackerInstance()->popNamed('dht_bootstrap');
275 * Finishes the dht bootstrap data
279 protected function finishDhtBootstrapData () {
280 // Pop the last entry
281 $this->getStackerInstance()->popNamed('dht_bootstrap');
285 * Finishes the dht bootstrap
289 protected function finishBootstrap () {
290 // Pop the last entry
291 $this->getStackerInstance()->popNamed('dht_bootstrap');