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 * Getter for cache file (FQFN)
125 * @return $fqfn Full-qualified file name of the menu cache
127 public function getMenuCacheFqfn () {
128 $this->partialStub('Please implement this method.');
132 * Starts the announcement
136 protected function startAnnouncement () {
137 // Push the node name on the stacker
138 $this->getStackerInstance()->pushNamed('announcement', 'announcement');
142 * Starts the announcement data
146 protected function startAnnouncementData () {
147 // Push the node name on the stacker
148 $this->getStackerInstance()->pushNamed('announcement', 'announcement-data');
152 * Starts the node status
156 protected function startNodeStatus () {
157 // Push the node name on the stacker
158 $this->getStackerInstance()->pushNamed('announcement', self::ANNOUNCEMENT_DATA_NODE_STATUS);
162 * Starts the node-mode
166 protected function startNodeMode () {
167 // Push the node name on the stacker
168 $this->getStackerInstance()->pushNamed('announcement', self::ANNOUNCEMENT_DATA_NODE_MODE);
172 * Starts the listener
176 protected function startListener () {
177 // Push the node name on the stacker
178 $this->getStackerInstance()->pushNamed('announcement', 'listener');
182 * Starts the TCP port
186 protected function startTcpPort () {
187 // Push the node name on the stacker
188 $this->getStackerInstance()->pushNamed('announcement', self::ANNOUNCEMENT_DATA_TCP_PORT);
192 * Starts the UDP port
196 protected function startUdpPort () {
197 // Push the node name on the stacker
198 $this->getStackerInstance()->pushNamed('announcement', self::ANNOUNCEMENT_DATA_UDP_PORT);
202 * Starts the session id
206 protected function startSessionId () {
207 // Push the node name on the stacker
208 $this->getStackerInstance()->pushNamed('announcement', self::ANNOUNCEMENT_DATA_SESSION_ID);
212 * Starts the public ip
216 protected function startExternalIp () {
217 // Push the node name on the stacker
218 $this->getStackerInstance()->pushNamed('announcement', self::ANNOUNCEMENT_DATA_EXTERNAL_IP);
222 * Starts the private ip
226 protected function startInternalIp () {
227 // Push the node name on the stacker
228 $this->getStackerInstance()->pushNamed('announcement', self::ANNOUNCEMENT_DATA_INTERNAL_IP);
232 * Starts the object type list
236 protected function startObjectTypeList () {
237 // Push the node name on the stacker
238 $this->getStackerInstance()->pushNamed('announcement', 'object-type-list');
242 * Starts the object type
246 protected function startObjectType () {
247 // Push the node name on the stacker
248 $this->getStackerInstance()->pushNamed('announcement', 'object-type');
252 * Finishes the object type
256 protected function finishObjectType () {
257 // Pop the last entry
258 $this->getStackerInstance()->popNamed('announcement');
262 * Finishes the object type list
266 protected function finishObjectTypeList () {
267 // Pop the last entry
268 $this->getStackerInstance()->popNamed('announcement');
272 * Finishes the session id
276 protected function finishSessionId () {
277 // Pop the last entry
278 $this->getStackerInstance()->popNamed('announcement');
282 * Finishes the private ip
286 protected function finishInternalIp () {
287 // Pop the last entry
288 $this->getStackerInstance()->popNamed('announcement');
292 * Finishes the public ip
296 protected function finishExternalIp () {
297 // Pop the last entry
298 $this->getStackerInstance()->popNamed('announcement');
302 * Finishes the UDP port
306 protected function finishUdpPort () {
307 // Pop the last entry
308 $this->getStackerInstance()->popNamed('announcement');
312 * Finishes the TCP port
316 protected function finishTcpPort () {
317 // Pop the last entry
318 $this->getStackerInstance()->popNamed('announcement');
322 * Finishes the listener
326 protected function finishListener () {
327 // Pop the last entry
328 $this->getStackerInstance()->popNamed('announcement');
332 * Finishes the node mode
336 protected function finishNodeMode () {
337 // Pop the last entry
338 $this->getStackerInstance()->popNamed('announcement');
342 * Finishes the node status
346 protected function finishNodeStatus () {
347 // Pop the last entry
348 $this->getStackerInstance()->popNamed('announcement');
352 * Finishes the announcement data
356 protected function finishAnnouncementData () {
357 // Pop the last entry
358 $this->getStackerInstance()->popNamed('announcement');
362 * Finishes the announcement
366 protected function finishAnnouncement () {
367 // Pop the last entry
368 $this->getStackerInstance()->popNamed('announcement');