3 * An Announcement 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 XmlAnnouncementTemplateEngine extends BaseXmlTemplateEngine implements CompileableTemplate, Registerable {
27 * Some XML nodes must be available for later data extraction
29 const ANNOUNCEMENT_DATA_SESSION_ID = 'session-id';
30 const ANNOUNCEMENT_DATA_NODE_ID = 'node-id';
31 const ANNOUNCEMENT_DATA_PRIVATE_KEY_HASH = 'private-key-hash';
32 const ANNOUNCEMENT_DATA_NODE_STATUS = 'node-status';
33 const ANNOUNCEMENT_DATA_NODE_MODE = 'node-mode';
34 const ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS = 'external-address';
35 const ANNOUNCEMENT_DATA_INTERNAL_ADDRESS = 'internal-address';
38 * Protected constructor
42 protected function __construct () {
43 // Call parent constructor
44 parent::__construct(__CLASS__);
47 $this->setSubNodes(array(
50 self::ANNOUNCEMENT_DATA_NODE_STATUS,
51 self::ANNOUNCEMENT_DATA_NODE_MODE,
52 self::ANNOUNCEMENT_DATA_NODE_ID,
53 self::ANNOUNCEMENT_DATA_SESSION_ID,
54 self::ANNOUNCEMENT_DATA_PRIVATE_KEY_HASH,
55 self::ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS,
56 self::ANNOUNCEMENT_DATA_INTERNAL_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 createXmlAnnouncementTemplateEngine () {
74 $templateInstance = new XmlAnnouncementTemplateEngine();
76 // Init template instance
77 $templateInstance->initXmlTemplateEngine('node', 'announcement');
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('node_announcement'), $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.');
117 * Starts the announcement
121 protected function startAnnouncement () {
122 // Push the node name on the stacker
123 $this->getStackInstance()->pushNamed('node_announcement', 'announcement');
127 * Starts the announcement data
131 protected function startAnnouncementData () {
132 // Push the node name on the stacker
133 $this->getStackInstance()->pushNamed('node_announcement', 'announcement-data');
137 * Starts the node status
141 protected function startNodeStatus () {
142 // Push the node name on the stacker
143 $this->getStackInstance()->pushNamed('node_announcement', self::ANNOUNCEMENT_DATA_NODE_STATUS);
147 * Starts the node-mode
151 protected function startNodeMode () {
152 // Push the node name on the stacker
153 $this->getStackInstance()->pushNamed('node_announcement', self::ANNOUNCEMENT_DATA_NODE_MODE);
157 * Starts the listener
161 protected function startListener () {
162 // Push the node name on the stacker
163 $this->getStackInstance()->pushNamed('node_announcement', 'listener');
167 * Starts the session id
171 protected function startSessionId () {
172 // Push the node name on the stacker
173 $this->getStackInstance()->pushNamed('node_announcement', self::ANNOUNCEMENT_DATA_SESSION_ID);
181 protected function startNodeId () {
182 // Push the node name on the stacker
183 $this->getStackInstance()->pushNamed('node_announcement', self::ANNOUNCEMENT_DATA_NODE_ID);
187 * Starts the private key hash
191 protected function startPrivateKeyHash () {
192 // Push the node name on the stacker
193 $this->getStackInstance()->pushNamed('node_announcement', self::ANNOUNCEMENT_DATA_PRIVATE_KEY_HASH);
197 * Starts the public ip
201 protected function startExternalAddress () {
202 // Push the node name on the stacker
203 $this->getStackInstance()->pushNamed('node_announcement', self::ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS);
207 * Starts the private ip
211 protected function startInternalAddress () {
212 // Push the node name on the stacker
213 $this->getStackInstance()->pushNamed('node_announcement', self::ANNOUNCEMENT_DATA_INTERNAL_ADDRESS);
217 * Starts the object type list
221 protected function startObjectTypeList () {
222 // Push the node name on the stacker
223 $this->getStackInstance()->pushNamed('node_announcement', 'object-type-list');
227 * Starts the object type
231 protected function startObjectType () {
232 // Push the node name on the stacker
233 $this->getStackInstance()->pushNamed('node_announcement', 'object-type');
237 * Finishes the object type
241 protected function finishObjectType () {
242 // Pop the last entry
243 $this->getStackInstance()->popNamed('node_announcement');
247 * Finishes the object type list
251 protected function finishObjectTypeList () {
252 // Pop the last entry
253 $this->getStackInstance()->popNamed('node_announcement');
257 * Finishes the private key hash
261 protected function finishPrivateKeyHash () {
262 // Pop the last entry
263 $this->getStackInstance()->popNamed('node_announcement');
267 * Finishes the node id
271 protected function finishNodeId () {
272 // Pop the last entry
273 $this->getStackInstance()->popNamed('node_announcement');
277 * Finishes the session id
281 protected function finishSessionId () {
282 // Pop the last entry
283 $this->getStackInstance()->popNamed('node_announcement');
287 * Finishes the private ip
291 protected function finishInternalAddress () {
292 // Pop the last entry
293 $this->getStackInstance()->popNamed('node_announcement');
297 * Finishes the public ip
301 protected function finishExternalAddress () {
302 // Pop the last entry
303 $this->getStackInstance()->popNamed('node_announcement');
307 * Finishes the listener
311 protected function finishListener () {
312 // Pop the last entry
313 $this->getStackInstance()->popNamed('node_announcement');
317 * Finishes the node mode
321 protected function finishNodeMode () {
322 // Pop the last entry
323 $this->getStackInstance()->popNamed('node_announcement');
327 * Finishes the node status
331 protected function finishNodeStatus () {
332 // Pop the last entry
333 $this->getStackInstance()->popNamed('node_announcement');
337 * Finishes the announcement data
341 protected function finishAnnouncementData () {
342 // Pop the last entry
343 $this->getStackInstance()->popNamed('node_announcement');
347 * Finishes the announcement
351 protected function finishAnnouncement () {
352 // Pop the last entry
353 $this->getStackInstance()->popNamed('node_announcement');