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 - 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 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_IP = 'my-external-ip';
32 const DHT_BOOTSTRAP_DATA_INTERNAL_IP = 'my-internal-ip';
33 const DHT_BOOTSTRAP_DATA_LISTEN_PORT = 'my-listen-port';
34 const DHT_BOOTSTRAP_DATA_NODE_LIST = 'dht-node-list';
37 * Protected constructor
41 protected function __construct () {
42 // Call parent constructor
43 parent::__construct(__CLASS__);
45 // Init sub-nodes array
46 $this->subNodes = array(
47 // These nodes don't contain any data
50 // Data from *this* node
51 self::DHT_BOOTSTRAP_DATA_EXTERNAL_IP,
52 self::DHT_BOOTSTRAP_DATA_INTERNAL_IP,
53 self::DHT_BOOTSTRAP_DATA_LISTEN_PORT,
54 self::DHT_BOOTSTRAP_DATA_NODE_STATUS,
55 self::DHT_BOOTSTRAP_DATA_SESSION_ID,
56 // Data from other node
60 // Answer status (generic field)
63 self::DHT_BOOTSTRAP_DATA_NODE_LIST,
68 * Creates an instance of the class TemplateEngine and prepares it for usage
70 * @return $templateInstance An instance of TemplateEngine
71 * @throws BasePathIsEmptyException If the provided $templateBasePath is empty
72 * @throws InvalidBasePathStringException If $templateBasePath is no string
73 * @throws BasePathIsNoDirectoryException If $templateBasePath is no
74 * directory or not found
75 * @throws BasePathReadProtectedException If $templateBasePath is
78 public static final function createXmlDhtBootstrapAnswerTemplateEngine () {
80 $templateInstance = new XmlDhtBootstrapAnswerTemplateEngine();
83 $templateInstance->initXmlTemplateEngine('node', 'dht_bootstrap_answer');
85 // Return the prepared instance
86 return $templateInstance;
92 * @param $resource XML parser resource (currently ignored)
93 * @param $characters Characters to handle
95 * @todo Find something useful with this!
97 public function characterHandler ($resource, $characters) {
98 // Trim all spaces away
99 $characters = trim($characters);
101 // Is this string empty?
102 if (empty($characters)) {
103 // Then skip it silently
108 * Assign the found characters to variable and use the last entry from
111 parent::assignVariable($this->getStackerInstance()->getNamed('node_dht_bootstrap_answer'), $characters);
115 * Getter for cache file (FQFN)
117 * @return $fqfn Full-qualified file name of the menu cache
119 public function getDhtBootstrapAnswerCacheFqfn () {
120 $this->partialStub('Please implement this method.');
124 * Starts the dht_bootstrap-answer
128 protected function startDhtBootstrapAnswer () {
129 // Push the node name on the stacker
130 $this->getStackerInstance()->pushNamed('node_dht_bootstrap_answer', 'dht_bootstrap-answer');
138 protected function startMyData () {
139 // Push the node name on the stacker
140 $this->getStackerInstance()->pushNamed('node_dht_bootstrap_answer', 'my-data');
144 * Starts the my-external-ip
148 protected function startMyExternalIp () {
149 // Push the node name on the stacker
150 $this->getStackerInstance()->pushNamed('node_dht_bootstrap_answer', self::DHT_BOOTSTRAP_DATA_EXTERNAL_IP);
154 * Starts the my-internal-ip
158 protected function startMyInternalIp () {
159 // Push the node name on the stacker
160 $this->getStackerInstance()->pushNamed('node_dht_bootstrap_answer', self::DHT_BOOTSTRAP_DATA_INTERNAL_IP);
164 * Starts the my-tcp-port
168 protected function startMyListenPort () {
169 // Push the node name on the stacker
170 $this->getStackerInstance()->pushNamed('node_dht_bootstrap_answer', self::DHT_BOOTSTRAP_DATA_LISTEN_PORT);
174 * Starts the my-session-id
178 protected function startMySessionId () {
179 // Push the node name on the stacker
180 $this->getStackerInstance()->pushNamed('node_dht_bootstrap_answer', self::DHT_BOOTSTRAP_DATA_SESSION_ID);
184 * Starts the my-status
188 protected function startMyStatus () {
189 // Push the node name on the stacker
190 $this->getStackerInstance()->pushNamed('node_dht_bootstrap_answer', self::DHT_BOOTSTRAP_DATA_NODE_STATUS);
194 * Starts the dht-node-list
198 protected function startDhtNodeList () {
199 // Push the node name on the stacker
200 $this->getStackerInstance()->pushNamed('node_dht_bootstrap_answer', self::DHT_BOOTSTRAP_DATA_NODE_LIST);
204 * Finishes the dht-node-list
208 protected function finishDhtNodeList () {
209 // Pop the last entry
210 $this->getStackerInstance()->popNamed('node_dht_bootstrap_answer');
214 * Finishes the my-status
218 protected function finishMyStatus () {
219 // Pop the last entry
220 $this->getStackerInstance()->popNamed('node_dht_bootstrap_answer');
224 * Finishes the my-session-id
228 protected function finishMySessionId () {
229 // Pop the last entry
230 $this->getStackerInstance()->popNamed('node_dht_bootstrap_answer');
234 * Finishes the my-tcp-port
238 protected function finishMyListenPort () {
239 // Pop the last entry
240 $this->getStackerInstance()->popNamed('node_dht_bootstrap_answer');
244 * Finishes the my-internal-ip
248 protected function finishMyInternalIp () {
249 // Pop the last entry
250 $this->getStackerInstance()->popNamed('node_dht_bootstrap_answer');
254 * Finishes the my-external-ip
258 protected function finishMyExternalIp () {
259 // Pop the last entry
260 $this->getStackerInstance()->popNamed('node_dht_bootstrap_answer');
264 * Finishes the my-data
268 protected function finishMyData () {
269 // Pop the last entry
270 $this->getStackerInstance()->popNamed('node_dht_bootstrap_answer');
274 * Starts the your-data
278 protected function startYourData () {
279 // Push the node name on the stacker
280 $this->getStackerInstance()->pushNamed('node_dht_bootstrap_answer', 'your-data');
284 * Starts the your-external-ip
288 protected function startYourExternalIp () {
289 // Push the node name on the stacker
290 $this->getStackerInstance()->pushNamed('node_dht_bootstrap_answer', 'your-external-ip');
294 * Starts the your-internal-ip
298 protected function startYourInternalIp () {
299 // Push the node name on the stacker
300 $this->getStackerInstance()->pushNamed('node_dht_bootstrap_answer', 'your-internal-ip');
304 * Starts the your-session-id
308 protected function startYourSessionId () {
309 // Push the node name on the stacker
310 $this->getStackerInstance()->pushNamed('node_dht_bootstrap_answer', 'your-session-id');
314 * Finishes the your-session-id
318 protected function finishYourSessionId () {
319 // Pop the last entry
320 $this->getStackerInstance()->popNamed('node_dht_bootstrap_answer');
324 * Finishes the your-internal-ip
328 protected function finishYourInternalIp () {
329 // Pop the last entry
330 $this->getStackerInstance()->popNamed('node_dht_bootstrap_answer');
334 * Finishes the your-external-ip
338 protected function finishYourExternalIp () {
339 // Pop the last entry
340 $this->getStackerInstance()->popNamed('node_dht_bootstrap_answer');
344 * Finishes the your-data
348 protected function finishYourData () {
349 // Pop the last entry
350 $this->getStackerInstance()->popNamed('node_dht_bootstrap_answer');
354 * Finishes the dht_bootstrap-answer
358 protected function finishDhtBootstrapAnswer () {
359 // Pop the last entry
360 $this->getStackerInstance()->popNamed('node_dht_bootstrap_answer');