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_ADDRESS = 'external-address';
34 const PUBLISH_DATA_PRIVATE_KEY_HASH = 'private-key-hash';
35 const PUBLISH_DATA_ACCEPTED_OBJECT_TYPES = 'accepted-object-types';
38 * Protected constructor
42 protected function __construct () {
43 // Call parent constructor
44 parent::__construct(__CLASS__);
47 $this->setSubNodes(array(
50 self::PUBLISH_DATA_NODE_STATUS,
51 self::PUBLISH_DATA_NODE_MODE,
52 self::PUBLISH_DATA_PRIVATE_KEY_HASH,
53 self::PUBLISH_DATA_ACCEPTED_OBJECT_TYPES,
54 self::PUBLISH_DATA_NODE_ID,
55 self::PUBLISH_DATA_SESSION_ID,
56 self::PUBLISH_DATA_EXTERNAL_ADDRESS,
62 * Creates an instance of the class TemplateEngine and prepares it for usage
64 * @return $templateInstance An instance of TemplateEngine
65 * @throws BasePathIsEmptyException If the provided $templateBasePath is empty
66 * @throws InvalidBasePathStringException If $templateBasePath is no string
67 * @throws BasePathIsNoDirectoryException If $templateBasePath is no
68 * directory or not found
69 * @throws BasePathReadProtectedException If $templateBasePath is
72 public static final function createXmlDhtPublishEntryTemplateEngine () {
74 $templateInstance = new XmlDhtPublishEntryTemplateEngine();
76 // Init template instance
77 $templateInstance->initXmlTemplateEngine('node', 'dht_publish');
79 // Return the prepared instance
80 return $templateInstance;
86 * @param $resource XML parser resource (currently ignored)
87 * @param $characters Characters to handle
90 public function characterHandler ($resource, $characters) {
91 // Trim all spaces away
92 $characters = trim($characters);
94 // Is this string empty?
95 if (empty($characters)) {
96 // Then skip it silently
101 * Assign the found characters to variable and use the last entry from
104 parent::assignVariable($this->getStackInstance()->getNamed('dht_publish'), $characters);
108 * Getter for cache file (FQFN)
110 * @return $fqfn Full-qualified file name of the menu cache
112 public function getMenuCacheFqfn () {
113 $this->partialStub('Please implement this method.');
121 protected function startPublish () {
122 // Push the node name on the stacker
123 $this->getStackInstance()->pushNamed('dht_publish', 'publish');
127 * Starts the publish data
131 protected function startPublishData () {
132 // Push the node name on the stacker
133 $this->getStackInstance()->pushNamed('dht_publish', 'publish-data');
137 * Starts the node status
141 protected function startNodeStatus () {
142 // Push the node name on the stacker
143 $this->getStackInstance()->pushNamed('dht_publish', self::PUBLISH_DATA_NODE_STATUS);
147 * Starts the node-mode
151 protected function startNodeMode () {
152 // Push the node name on the stacker
153 $this->getStackInstance()->pushNamed('dht_publish', self::PUBLISH_DATA_NODE_MODE);
157 * Starts the listener
161 protected function startListener () {
162 // Push the node name on the stacker
163 $this->getStackInstance()->pushNamed('dht_publish', 'listener');
167 * Starts accepted object types
171 protected function startAcceptedObjectTypes () {
172 // Push the node name on the stacker
173 $this->getStackInstance()->pushNamed('dht_publish', self::PUBLISH_DATA_ACCEPTED_OBJECT_TYPES);
177 * Starts hash from private key
181 protected function startPrivateKeyHash () {
182 // Push the node name on the stacker
183 $this->getStackInstance()->pushNamed('dht_publish', self::PUBLISH_DATA_PRIVATE_KEY_HASH);
191 protected function startNodeId () {
192 // Push the node name on the stacker
193 $this->getStackInstance()->pushNamed('dht_publish', self::PUBLISH_DATA_NODE_ID);
197 * Starts the session id
201 protected function startSessionId () {
202 // Push the node name on the stacker
203 $this->getStackInstance()->pushNamed('dht_publish', self::PUBLISH_DATA_SESSION_ID);
207 * Starts the public ip
211 protected function startExternalAddress () {
212 // Push the node name on the stacker
213 $this->getStackInstance()->pushNamed('dht_publish', self::PUBLISH_DATA_EXTERNAL_ADDRESS);
217 * Starts the object type list
221 protected function startObjectTypeList () {
222 // Push the node name on the stacker
223 $this->getStackInstance()->pushNamed('dht_publish', 'object-type-list');
227 * Starts the object type
231 protected function startObjectType () {
232 // Push the node name on the stacker
233 $this->getStackInstance()->pushNamed('dht_publish', 'object-type');
237 * Finishes the object type
241 protected function finishObjectType () {
242 // Pop the last entry
243 $this->getStackInstance()->popNamed('dht_publish');
247 * Finishes the object type list
251 protected function finishObjectTypeList () {
252 // Pop the last entry
253 $this->getStackInstance()->popNamed('dht_publish');
257 * Finishes the session id
261 protected function finishSessionId () {
262 // Pop the last entry
263 $this->getStackInstance()->popNamed('dht_publish');
267 * Finishes the node id
271 protected function finishNodeId () {
272 // Pop the last entry
273 $this->getStackInstance()->popNamed('dht_publish');
277 * Finishes the public ip
281 protected function finishExternalAddress () {
282 // Pop the last entry
283 $this->getStackInstance()->popNamed('dht_publish');
287 * Finishes hash from private key
291 protected function finishPrivateKeyHash () {
292 // Pop the last entry
293 $this->getStackInstance()->popNamed('dht_publish');
297 * Finishes accepted object types
301 protected function finishAcceptedObjectTypes () {
302 // Pop the last entry
303 $this->getStackInstance()->popNamed('dht_publish');
307 * Finishes the listener
311 protected function finishListener () {
312 // Pop the last entry
313 $this->getStackInstance()->popNamed('dht_publish');
317 * Finishes the node mode
321 protected function finishNodeMode () {
322 // Pop the last entry
323 $this->getStackInstance()->popNamed('dht_publish');
327 * Finishes the node status
331 protected function finishNodeStatus () {
332 // Pop the last entry
333 $this->getStackInstance()->popNamed('dht_publish');
337 * Finishes the publish data
341 protected function finishPublishData () {
342 // Pop the last entry
343 $this->getStackInstance()->popNamed('dht_publish');
347 * Finishes the publish
351 protected function finishPublish () {
352 // Pop the last entry
353 $this->getStackInstance()->popNamed('dht_publish');