3 * An Announcement template engine class for XML templates
5 * @author Roland Haeder <webmaster@ship-simu.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.ship-simu.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_STATUS = 'node-status';
31 const ANNOUNCEMENT_DATA_NODE_MODE = 'node-mode';
32 const ANNOUNCEMENT_DATA_EXTERNAL_IP = 'external-ip';
33 const ANNOUNCEMENT_DATA_INTERNAL_IP = 'internal-ip';
34 const ANNOUNCEMENT_DATA_TCP_PORT = 'tcp-port';
35 const ANNOUNCEMENT_DATA_UDP_PORT = 'udp-port';
38 * Protected constructor
42 protected function __construct () {
43 // Call parent constructor
44 parent::__construct(__CLASS__);
47 $this->subNodes = array(
50 self::ANNOUNCEMENT_DATA_NODE_STATUS,
51 self::ANNOUNCEMENT_DATA_NODE_MODE,
52 self::ANNOUNCEMENT_DATA_TCP_PORT,
53 self::ANNOUNCEMENT_DATA_UDP_PORT,
54 self::ANNOUNCEMENT_DATA_SESSION_ID,
55 self::ANNOUNCEMENT_DATA_EXTERNAL_IP,
56 self::ANNOUNCEMENT_DATA_INTERNAL_IP,
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;
84 * Load a specified announcement template into the engine
86 * @param $template The announcement template we shall load which is
87 * located in 'announcement' by default
90 public function loadAnnouncementTemplate ($template = 'self_announcement') {
92 $this->setTemplateType($this->getConfigInstance()->getConfigEntry('node_announcement_template_type'));
94 // Load the special template
95 $this->loadTemplate($template);
101 * @param $resource XML parser resource (currently ignored)
102 * @param $characters Characters to handle
105 public function characterHandler ($resource, $characters) {
106 // Trim all spaces away
107 $characters = trim($characters);
109 // Is this string empty?
110 if (empty($characters)) {
111 // Then skip it silently
116 * Assign the found characters to variable and use the last entry from
119 parent::assignVariable($this->getStackerInstance()->getNamed('announcement'), $characters);
123 * Read announcement variables by calling readVariable() with 'general' as
126 * @param $key Key to read from
127 * @return $value Value from variable
129 public function readAnnouncementData ($key) {
131 $value = parent::readVariable($key, 'general');
138 * Getter for cache file (FQFN)
140 * @return $fqfn Full-qualified file name of the menu cache
142 public function getMenuCacheFqfn () {
143 $this->partialStub('Please implement this method.');
147 * Starts the announcement
151 protected function startAnnouncement () {
152 // Push the node name on the stacker
153 $this->getStackerInstance()->pushNamed('announcement', 'announcement');
157 * Starts the announcement data
161 protected function startAnnouncementData () {
162 // Push the node name on the stacker
163 $this->getStackerInstance()->pushNamed('announcement', 'announcement-data');
167 * Starts the node status
171 protected function startNodeStatus () {
172 // Push the node name on the stacker
173 $this->getStackerInstance()->pushNamed('announcement', self::ANNOUNCEMENT_DATA_NODE_STATUS);
177 * Starts the node-mode
181 protected function startNodeMode () {
182 // Push the node name on the stacker
183 $this->getStackerInstance()->pushNamed('announcement', self::ANNOUNCEMENT_DATA_NODE_MODE);
187 * Starts the listener
191 protected function startListener () {
192 // Push the node name on the stacker
193 $this->getStackerInstance()->pushNamed('announcement', 'listener');
197 * Starts the TCP port
201 protected function startTcpPort () {
202 // Push the node name on the stacker
203 $this->getStackerInstance()->pushNamed('announcement', self::ANNOUNCEMENT_DATA_TCP_PORT);
207 * Starts the UDP port
211 protected function startUdpPort () {
212 // Push the node name on the stacker
213 $this->getStackerInstance()->pushNamed('announcement', self::ANNOUNCEMENT_DATA_UDP_PORT);
217 * Starts the session id
221 protected function startSessionId () {
222 // Push the node name on the stacker
223 $this->getStackerInstance()->pushNamed('announcement', self::ANNOUNCEMENT_DATA_SESSION_ID);
227 * Starts the public ip
231 protected function startExternalIp () {
232 // Push the node name on the stacker
233 $this->getStackerInstance()->pushNamed('announcement', self::ANNOUNCEMENT_DATA_EXTERNAL_IP);
237 * Starts the private ip
241 protected function startInternalIp () {
242 // Push the node name on the stacker
243 $this->getStackerInstance()->pushNamed('announcement', self::ANNOUNCEMENT_DATA_INTERNAL_IP);
247 * Starts the object type list
251 protected function startObjectTypeList () {
252 // Push the node name on the stacker
253 $this->getStackerInstance()->pushNamed('announcement', 'object-type-list');
257 * Starts the object type
261 protected function startObjectType () {
262 // Push the node name on the stacker
263 $this->getStackerInstance()->pushNamed('announcement', 'object-type');
267 * Finishes the object type
271 protected function finishObjectType () {
272 // Pop the last entry
273 $this->getStackerInstance()->popNamed('announcement');
277 * Finishes the object type list
281 protected function finishObjectTypeList () {
282 // Pop the last entry
283 $this->getStackerInstance()->popNamed('announcement');
287 * Finishes the session id
291 protected function finishSessionId () {
292 // Pop the last entry
293 $this->getStackerInstance()->popNamed('announcement');
297 * Finishes the private ip
301 protected function finishInternalIp () {
302 // Pop the last entry
303 $this->getStackerInstance()->popNamed('announcement');
307 * Finishes the public ip
311 protected function finishExternalIp () {
312 // Pop the last entry
313 $this->getStackerInstance()->popNamed('announcement');
317 * Finishes the UDP port
321 protected function finishUdpPort () {
322 // Pop the last entry
323 $this->getStackerInstance()->popNamed('announcement');
327 * Finishes the TCP port
331 protected function finishTcpPort () {
332 // Pop the last entry
333 $this->getStackerInstance()->popNamed('announcement');
337 * Finishes the listener
341 protected function finishListener () {
342 // Pop the last entry
343 $this->getStackerInstance()->popNamed('announcement');
347 * Finishes the node mode
351 protected function finishNodeMode () {
352 // Pop the last entry
353 $this->getStackerInstance()->popNamed('announcement');
357 * Finishes the node status
361 protected function finishNodeStatus () {
362 // Pop the last entry
363 $this->getStackerInstance()->popNamed('announcement');
367 * Finishes the announcement data
371 protected function finishAnnouncementData () {
372 // Pop the last entry
373 $this->getStackerInstance()->popNamed('announcement');
377 * Finishes the announcement
381 protected function finishAnnouncement () {
382 // Pop the last entry
383 $this->getStackerInstance()->popNamed('announcement');