3 * An PublishEntry 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 XmlDhtPublishEntryTemplateEngine extends BaseXmlTemplateEngine implements CompileableTemplate, Registerable {
27 * Some XML nodes must be available for later data extraction
29 const PUBLISH_DATA_NODE_ID = 'node-id';
30 const PUBLISH_DATA_SESSION_ID = 'session-id';
31 const PUBLISH_DATA_NODE_STATUS = 'node-status';
32 const PUBLISH_DATA_NODE_MODE = 'node-mode';
33 const PUBLISH_DATA_EXTERNAL_IP = 'external-ip';
34 const PUBLISH_DATA_LISTEN_PORT = 'listen-port';
35 const PUBLISH_DATA_PRIVATE_KEY_HASH = 'private-key-hash';
36 const PUBLISH_DATA_ACCEPTED_OBJECT_TYPES = 'accepted-object-types';
39 * Protected constructor
43 protected function __construct () {
44 // Call parent constructor
45 parent::__construct(__CLASS__);
48 $this->subNodes = array(
51 self::PUBLISH_DATA_NODE_STATUS,
52 self::PUBLISH_DATA_NODE_MODE,
53 self::PUBLISH_DATA_LISTEN_PORT,
54 self::PUBLISH_DATA_PRIVATE_KEY_HASH,
55 self::PUBLISH_DATA_ACCEPTED_OBJECT_TYPES,
56 self::PUBLISH_DATA_NODE_ID,
57 self::PUBLISH_DATA_SESSION_ID,
58 self::PUBLISH_DATA_EXTERNAL_IP,
64 * Creates an instance of the class TemplateEngine and prepares it for usage
66 * @return $templateInstance An instance of TemplateEngine
67 * @throws BasePathIsEmptyException If the provided $templateBasePath is empty
68 * @throws InvalidBasePathStringException If $templateBasePath is no string
69 * @throws BasePathIsNoDirectoryException If $templateBasePath is no
70 * directory or not found
71 * @throws BasePathReadProtectedException If $templateBasePath is
74 public static final function createXmlDhtPublishEntryTemplateEngine () {
76 $templateInstance = new XmlDhtPublishEntryTemplateEngine();
78 // Init template instance
79 $templateInstance->initXmlTemplateEngine('node', 'dht_publish');
81 // Return the prepared instance
82 return $templateInstance;
88 * @param $resource XML parser resource (currently ignored)
89 * @param $characters Characters to handle
92 public function characterHandler ($resource, $characters) {
93 // Trim all spaces away
94 $characters = trim($characters);
96 // Is this string empty?
97 if (empty($characters)) {
98 // Then skip it silently
103 * Assign the found characters to variable and use the last entry from
106 parent::assignVariable($this->getStackInstance()->getNamed('dht_publish'), $characters);
110 * Getter for cache file (FQFN)
112 * @return $fqfn Full-qualified file name of the menu cache
114 public function getMenuCacheFqfn () {
115 $this->partialStub('Please implement this method.');
123 protected function startPublish () {
124 // Push the node name on the stacker
125 $this->getStackInstance()->pushNamed('dht_publish', 'publish');
129 * Starts the publish data
133 protected function startPublishData () {
134 // Push the node name on the stacker
135 $this->getStackInstance()->pushNamed('dht_publish', 'publish-data');
139 * Starts the node status
143 protected function startNodeStatus () {
144 // Push the node name on the stacker
145 $this->getStackInstance()->pushNamed('dht_publish', self::PUBLISH_DATA_NODE_STATUS);
149 * Starts the node-mode
153 protected function startNodeMode () {
154 // Push the node name on the stacker
155 $this->getStackInstance()->pushNamed('dht_publish', self::PUBLISH_DATA_NODE_MODE);
159 * Starts the listener
163 protected function startListener () {
164 // Push the node name on the stacker
165 $this->getStackInstance()->pushNamed('dht_publish', 'listener');
169 * Starts the TCP/UDP listen port
173 protected function startListenPort () {
174 // Push the node name on the stacker
175 $this->getStackInstance()->pushNamed('dht_publish', self::PUBLISH_DATA_LISTEN_PORT);
179 * Starts accepted object types
183 protected function startAcceptedObjectTypes () {
184 // Push the node name on the stacker
185 $this->getStackInstance()->pushNamed('dht_publish', self::PUBLISH_DATA_ACCEPTED_OBJECT_TYPES);
189 * Starts hash from private key
193 protected function startPrivateKeyHash () {
194 // Push the node name on the stacker
195 $this->getStackInstance()->pushNamed('dht_publish', self::PUBLISH_DATA_PRIVATE_KEY_HASH);
203 protected function startNodeId () {
204 // Push the node name on the stacker
205 $this->getStackInstance()->pushNamed('dht_publish', self::PUBLISH_DATA_NODE_ID);
209 * Starts the session id
213 protected function startSessionId () {
214 // Push the node name on the stacker
215 $this->getStackInstance()->pushNamed('dht_publish', self::PUBLISH_DATA_SESSION_ID);
219 * Starts the public ip
223 protected function startExternalIp () {
224 // Push the node name on the stacker
225 $this->getStackInstance()->pushNamed('dht_publish', self::PUBLISH_DATA_EXTERNAL_IP);
229 * Starts the object type list
233 protected function startObjectTypeList () {
234 // Push the node name on the stacker
235 $this->getStackInstance()->pushNamed('dht_publish', 'object-type-list');
239 * Starts the object type
243 protected function startObjectType () {
244 // Push the node name on the stacker
245 $this->getStackInstance()->pushNamed('dht_publish', 'object-type');
249 * Finishes the object type
253 protected function finishObjectType () {
254 // Pop the last entry
255 $this->getStackInstance()->popNamed('dht_publish');
259 * Finishes the object type list
263 protected function finishObjectTypeList () {
264 // Pop the last entry
265 $this->getStackInstance()->popNamed('dht_publish');
269 * Finishes the session id
273 protected function finishSessionId () {
274 // Pop the last entry
275 $this->getStackInstance()->popNamed('dht_publish');
279 * Finishes the node id
283 protected function finishNodeId () {
284 // Pop the last entry
285 $this->getStackInstance()->popNamed('dht_publish');
289 * Finishes the public ip
293 protected function finishExternalIp () {
294 // Pop the last entry
295 $this->getStackInstance()->popNamed('dht_publish');
299 * Finishes the TCP/UDP listen port
303 protected function finishListenPort () {
304 // Pop the last entry
305 $this->getStackInstance()->popNamed('dht_publish');
309 * Finishes hash from private key
313 protected function finishPrivateKeyHash () {
314 // Pop the last entry
315 $this->getStackInstance()->popNamed('dht_publish');
319 * Finishes accepted object types
323 protected function finishAcceptedObjectTypes () {
324 // Pop the last entry
325 $this->getStackInstance()->popNamed('dht_publish');
329 * Finishes the listener
333 protected function finishListener () {
334 // Pop the last entry
335 $this->getStackInstance()->popNamed('dht_publish');
339 * Finishes the node mode
343 protected function finishNodeMode () {
344 // Pop the last entry
345 $this->getStackInstance()->popNamed('dht_publish');
349 * Finishes the node status
353 protected function finishNodeStatus () {
354 // Pop the last entry
355 $this->getStackInstance()->popNamed('dht_publish');
359 * Finishes the publish data
363 protected function finishPublishData () {
364 // Pop the last entry
365 $this->getStackInstance()->popNamed('dht_publish');
369 * Finishes the publish
373 protected function finishPublish () {
374 // Pop the last entry
375 $this->getStackInstance()->popNamed('dht_publish');