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 - 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 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_LISTEN_PORT = 'listen-port';
37 * Protected constructor
41 protected function __construct () {
42 // Call parent constructor
43 parent::__construct(__CLASS__);
46 $this->subNodes = array(
49 self::ANNOUNCEMENT_DATA_NODE_STATUS,
50 self::ANNOUNCEMENT_DATA_NODE_MODE,
51 self::ANNOUNCEMENT_DATA_LISTEN_PORT,
52 self::ANNOUNCEMENT_DATA_SESSION_ID,
53 self::ANNOUNCEMENT_DATA_EXTERNAL_IP,
54 self::ANNOUNCEMENT_DATA_INTERNAL_IP,
60 * Creates an instance of the class TemplateEngine and prepares it for usage
62 * @return $templateInstance An instance of TemplateEngine
63 * @throws BasePathIsEmptyException If the provided $templateBasePath is empty
64 * @throws InvalidBasePathStringException If $templateBasePath is no string
65 * @throws BasePathIsNoDirectoryException If $templateBasePath is no
66 * directory or not found
67 * @throws BasePathReadProtectedException If $templateBasePath is
70 public static final function createXmlAnnouncementTemplateEngine () {
72 $templateInstance = new XmlAnnouncementTemplateEngine();
74 // Init template instance
75 $templateInstance->initXmlTemplateEngine('node', 'announcement');
77 // Return the prepared instance
78 return $templateInstance;
84 * @param $resource XML parser resource (currently ignored)
85 * @param $characters Characters to handle
88 public function characterHandler ($resource, $characters) {
89 // Trim all spaces away
90 $characters = trim($characters);
92 // Is this string empty?
93 if (empty($characters)) {
94 // Then skip it silently
99 * Assign the found characters to variable and use the last entry from
102 parent::assignVariable($this->getStackInstance()->getNamed('node_announcement'), $characters);
106 * Getter for cache file (FQFN)
108 * @return $fqfn Full-qualified file name of the menu cache
110 public function getMenuCacheFqfn () {
111 $this->partialStub('Please implement this method.');
115 * Starts the announcement
119 protected function startAnnouncement () {
120 // Push the node name on the stacker
121 $this->getStackInstance()->pushNamed('node_announcement', 'announcement');
125 * Starts the announcement data
129 protected function startAnnouncementData () {
130 // Push the node name on the stacker
131 $this->getStackInstance()->pushNamed('node_announcement', 'announcement-data');
135 * Starts the node status
139 protected function startNodeStatus () {
140 // Push the node name on the stacker
141 $this->getStackInstance()->pushNamed('node_announcement', self::ANNOUNCEMENT_DATA_NODE_STATUS);
145 * Starts the node-mode
149 protected function startNodeMode () {
150 // Push the node name on the stacker
151 $this->getStackInstance()->pushNamed('node_announcement', self::ANNOUNCEMENT_DATA_NODE_MODE);
155 * Starts the listener
159 protected function startListener () {
160 // Push the node name on the stacker
161 $this->getStackInstance()->pushNamed('node_announcement', 'listener');
165 * Starts the TCP/UDP listen port
169 protected function startListenPort () {
170 // Push the node name on the stacker
171 $this->getStackInstance()->pushNamed('node_announcement', self::ANNOUNCEMENT_DATA_LISTEN_PORT);
175 * Starts the session id
179 protected function startSessionId () {
180 // Push the node name on the stacker
181 $this->getStackInstance()->pushNamed('node_announcement', self::ANNOUNCEMENT_DATA_SESSION_ID);
185 * Starts the public ip
189 protected function startExternalIp () {
190 // Push the node name on the stacker
191 $this->getStackInstance()->pushNamed('node_announcement', self::ANNOUNCEMENT_DATA_EXTERNAL_IP);
195 * Starts the private ip
199 protected function startInternalIp () {
200 // Push the node name on the stacker
201 $this->getStackInstance()->pushNamed('node_announcement', self::ANNOUNCEMENT_DATA_INTERNAL_IP);
205 * Starts the object type list
209 protected function startObjectTypeList () {
210 // Push the node name on the stacker
211 $this->getStackInstance()->pushNamed('node_announcement', 'object-type-list');
215 * Starts the object type
219 protected function startObjectType () {
220 // Push the node name on the stacker
221 $this->getStackInstance()->pushNamed('node_announcement', 'object-type');
225 * Finishes the object type
229 protected function finishObjectType () {
230 // Pop the last entry
231 $this->getStackInstance()->popNamed('node_announcement');
235 * Finishes the object type list
239 protected function finishObjectTypeList () {
240 // Pop the last entry
241 $this->getStackInstance()->popNamed('node_announcement');
245 * Finishes the session id
249 protected function finishSessionId () {
250 // Pop the last entry
251 $this->getStackInstance()->popNamed('node_announcement');
255 * Finishes the private ip
259 protected function finishInternalIp () {
260 // Pop the last entry
261 $this->getStackInstance()->popNamed('node_announcement');
265 * Finishes the public ip
269 protected function finishExternalIp () {
270 // Pop the last entry
271 $this->getStackInstance()->popNamed('node_announcement');
275 * Finishes the TCP/UDP listen port
279 protected function finishListenPort () {
280 // Pop the last entry
281 $this->getStackInstance()->popNamed('node_announcement');
285 * Finishes the listener
289 protected function finishListener () {
290 // Pop the last entry
291 $this->getStackInstance()->popNamed('node_announcement');
295 * Finishes the node mode
299 protected function finishNodeMode () {
300 // Pop the last entry
301 $this->getStackInstance()->popNamed('node_announcement');
305 * Finishes the node status
309 protected function finishNodeStatus () {
310 // Pop the last entry
311 $this->getStackInstance()->popNamed('node_announcement');
315 * Finishes the announcement data
319 protected function finishAnnouncementData () {
320 // Pop the last entry
321 $this->getStackInstance()->popNamed('node_announcement');
325 * Finishes the announcement
329 protected function finishAnnouncement () {
330 // Pop the last entry
331 $this->getStackInstance()->popNamed('node_announcement');