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_ADDRESS = 'external-address';
33 const ANNOUNCEMENT_DATA_INTERNAL_ADDRESS = 'internal-address';
36 * Protected constructor
40 protected function __construct () {
41 // Call parent constructor
42 parent::__construct(__CLASS__);
45 $this->setSubNodes(array(
48 self::ANNOUNCEMENT_DATA_NODE_STATUS,
49 self::ANNOUNCEMENT_DATA_NODE_MODE,
50 self::ANNOUNCEMENT_DATA_SESSION_ID,
51 self::ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS,
52 self::ANNOUNCEMENT_DATA_INTERNAL_ADDRESS,
58 * Creates an instance of the class TemplateEngine and prepares it for usage
60 * @return $templateInstance An instance of TemplateEngine
61 * @throws BasePathIsEmptyException If the provided $templateBasePath is empty
62 * @throws InvalidBasePathStringException If $templateBasePath is no string
63 * @throws BasePathIsNoDirectoryException If $templateBasePath is no
64 * directory or not found
65 * @throws BasePathReadProtectedException If $templateBasePath is
68 public static final function createXmlAnnouncementTemplateEngine () {
70 $templateInstance = new XmlAnnouncementTemplateEngine();
72 // Init template instance
73 $templateInstance->initXmlTemplateEngine('node', 'announcement');
75 // Return the prepared instance
76 return $templateInstance;
82 * @param $resource XML parser resource (currently ignored)
83 * @param $characters Characters to handle
86 public function characterHandler ($resource, $characters) {
87 // Trim all spaces away
88 $characters = trim($characters);
90 // Is this string empty?
91 if (empty($characters)) {
92 // Then skip it silently
97 * Assign the found characters to variable and use the last entry from
100 parent::assignVariable($this->getStackInstance()->getNamed('node_announcement'), $characters);
104 * Getter for cache file (FQFN)
106 * @return $fqfn Full-qualified file name of the menu cache
108 public function getMenuCacheFqfn () {
109 $this->partialStub('Please implement this method.');
113 * Starts the announcement
117 protected function startAnnouncement () {
118 // Push the node name on the stacker
119 $this->getStackInstance()->pushNamed('node_announcement', 'announcement');
123 * Starts the announcement data
127 protected function startAnnouncementData () {
128 // Push the node name on the stacker
129 $this->getStackInstance()->pushNamed('node_announcement', 'announcement-data');
133 * Starts the node status
137 protected function startNodeStatus () {
138 // Push the node name on the stacker
139 $this->getStackInstance()->pushNamed('node_announcement', self::ANNOUNCEMENT_DATA_NODE_STATUS);
143 * Starts the node-mode
147 protected function startNodeMode () {
148 // Push the node name on the stacker
149 $this->getStackInstance()->pushNamed('node_announcement', self::ANNOUNCEMENT_DATA_NODE_MODE);
153 * Starts the listener
157 protected function startListener () {
158 // Push the node name on the stacker
159 $this->getStackInstance()->pushNamed('node_announcement', 'listener');
163 * Starts the session id
167 protected function startSessionId () {
168 // Push the node name on the stacker
169 $this->getStackInstance()->pushNamed('node_announcement', self::ANNOUNCEMENT_DATA_SESSION_ID);
173 * Starts the public ip
177 protected function startExternalAddress () {
178 // Push the node name on the stacker
179 $this->getStackInstance()->pushNamed('node_announcement', self::ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS);
183 * Starts the private ip
187 protected function startInternalAddress () {
188 // Push the node name on the stacker
189 $this->getStackInstance()->pushNamed('node_announcement', self::ANNOUNCEMENT_DATA_INTERNAL_ADDRESS);
193 * Starts the object type list
197 protected function startObjectTypeList () {
198 // Push the node name on the stacker
199 $this->getStackInstance()->pushNamed('node_announcement', 'object-type-list');
203 * Starts the object type
207 protected function startObjectType () {
208 // Push the node name on the stacker
209 $this->getStackInstance()->pushNamed('node_announcement', 'object-type');
213 * Finishes the object type
217 protected function finishObjectType () {
218 // Pop the last entry
219 $this->getStackInstance()->popNamed('node_announcement');
223 * Finishes the object type list
227 protected function finishObjectTypeList () {
228 // Pop the last entry
229 $this->getStackInstance()->popNamed('node_announcement');
233 * Finishes the session id
237 protected function finishSessionId () {
238 // Pop the last entry
239 $this->getStackInstance()->popNamed('node_announcement');
243 * Finishes the private ip
247 protected function finishInternalAddress () {
248 // Pop the last entry
249 $this->getStackInstance()->popNamed('node_announcement');
253 * Finishes the public ip
257 protected function finishExternalAddress () {
258 // Pop the last entry
259 $this->getStackInstance()->popNamed('node_announcement');
263 * Finishes the listener
267 protected function finishListener () {
268 // Pop the last entry
269 $this->getStackInstance()->popNamed('node_announcement');
273 * Finishes the node mode
277 protected function finishNodeMode () {
278 // Pop the last entry
279 $this->getStackInstance()->popNamed('node_announcement');
283 * Finishes the node status
287 protected function finishNodeStatus () {
288 // Pop the last entry
289 $this->getStackInstance()->popNamed('node_announcement');
293 * Finishes the announcement data
297 protected function finishAnnouncementData () {
298 // Pop the last entry
299 $this->getStackInstance()->popNamed('node_announcement');
303 * Finishes the announcement
307 protected function finishAnnouncement () {
308 // Pop the last entry
309 $this->getStackInstance()->popNamed('node_announcement');