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 - 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 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_ADDRESS = 'external-address';
34 const DHT_BOOTSTRAP_DATA_INTERNAL_ADDRESS = 'internal-address';
37 * Protected constructor
41 protected function __construct () {
42 // Call parent constructor
43 parent::__construct(__CLASS__);
46 $this->setSubNodes(array(
47 self::DHT_BOOTSTRAP_DATA_BOOTSTRAP_DATA,
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
58 * Creates an instance of the class TemplateEngine and prepares it for usage
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
68 public static final function createXmlDhtBootstrapTemplateEngine () {
70 $templateInstance = new XmlDhtBootstrapTemplateEngine();
72 // Init template instance
73 $templateInstance->initXmlTemplateEngine('node', 'dht_bootstrap');
75 // Return the prepared instance
76 return $templateInstance;
82 * @param $resource XML parser resource (currently ignored)
83 * @param $characters Characters to handle
86 public function characterHandler ($resource, $characters) {
87 // Trim all spaces away
88 $characters = trim($characters);
90 // Is this string empty?
91 if (empty($characters)) {
92 // Then skip it silently
97 * Assign the found characters to variable and use the last entry from
100 parent::assignVariable($this->getStackInstance()->getNamed('dht_bootstrap'), $characters);
104 * Getter for cache file (FQFN)
106 * @return $fqfn Full-qualified file name of the menu cache
108 public function getMenuCacheFqfn () {
109 $this->partialStub('Please implement this method.');
113 * Starts the dht bootstrap
117 protected function startDhtBootstrap () {
118 // Push the node name on the stacker
119 $this->getStackInstance()->pushNamed('dht_bootstrap', 'dht-bootstrap');
123 * Starts the dht bootstrap data
127 protected function startDhtBootstrapData () {
128 // Push the node name on the stacker
129 $this->getStackInstance()->pushNamed('dht_bootstrap', self::DHT_BOOTSTRAP_DATA_BOOTSTRAP_DATA);
133 * Starts the node status
137 protected function startNodeStatus () {
138 // Push the node name on the stacker
139 $this->getStackInstance()->pushNamed('dht_bootstrap', self::DHT_BOOTSTRAP_DATA_NODE_STATUS);
143 * Starts the node-mode
147 protected function startNodeMode () {
148 // Push the node name on the stacker
149 $this->getStackInstance()->pushNamed('dht_bootstrap', self::DHT_BOOTSTRAP_DATA_NODE_MODE);
153 * Starts the listener
157 protected function startListener () {
158 // Push the node name on the stacker
159 $this->getStackInstance()->pushNamed('dht_bootstrap', 'listener');
163 * Starts the public ip
167 protected function startExternalAddress () {
168 // Push the node name on the stacker
169 $this->getStackInstance()->pushNamed('dht_bootstrap', self::DHT_BOOTSTRAP_DATA_EXTERNAL_ADDRESS);
173 * Starts the private ip
177 protected function startInternalAddress () {
178 // Push the node name on the stacker
179 $this->getStackInstance()->pushNamed('dht_bootstrap', self::DHT_BOOTSTRAP_DATA_INTERNAL_ADDRESS);
183 * Starts the session id
187 protected function startSessionId () {
188 // Push the node name on the stacker
189 $this->getStackInstance()->pushNamed('dht_bootstrap', self::DHT_BOOTSTRAP_DATA_SESSION_ID);
193 * Finishes the session id
197 protected function finishSessionId () {
198 // Pop the last entry
199 $this->getStackInstance()->popNamed('dht_bootstrap');
203 * Finishes the private ip
207 protected function finishInternalAddress () {
208 // Pop the last entry
209 $this->getStackInstance()->popNamed('dht_bootstrap');
213 * Finishes the public ip
217 protected function finishExternalAddress () {
218 // Pop the last entry
219 $this->getStackInstance()->popNamed('dht_bootstrap');
223 * Finishes the listener
227 protected function finishListener () {
228 // Pop the last entry
229 $this->getStackInstance()->popNamed('dht_bootstrap');
233 * Finishes the node mode
237 protected function finishNodeMode () {
238 // Pop the last entry
239 $this->getStackInstance()->popNamed('dht_bootstrap');
243 * Finishes the node status
247 protected function finishNodeStatus () {
248 // Pop the last entry
249 $this->getStackInstance()->popNamed('dht_bootstrap');
253 * Finishes the dht bootstrap data
257 protected function finishDhtBootstrapData () {
258 // Pop the last entry
259 $this->getStackInstance()->popNamed('dht_bootstrap');
263 * Finishes the dht bootstrap
267 protected function finishDhtBootstrap () {
268 // Pop the last entry
269 $this->getStackInstance()->popNamed('dht_bootstrap');