3 * An AnnouncementAnswer 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 XmlAnnouncementAnswerTemplateEngine extends BaseXmlTemplateEngine implements CompileableTemplate, Registerable {
27 * Some XML nodes must be available for later data extraction
29 const ANNOUNCEMENT_DATA_SESSION_ID = 'my-session-id';
30 const ANNOUNCEMENT_DATA_NODE_STATUS = 'my-status';
31 const ANNOUNCEMENT_DATA_EXTERNAL_IP = 'my-external-ip';
32 const ANNOUNCEMENT_DATA_INTERNAL_IP = 'my-internal-ip';
33 const ANNOUNCEMENT_DATA_TCP_PORT = 'my-tcp-port';
34 const ANNOUNCEMENT_DATA_UDP_PORT = 'my-udp-port';
37 * Protected constructor
41 protected function __construct () {
42 // Call parent constructor
43 parent::__construct(__CLASS__);
45 // Init sub-nodes array
46 $this->subNodes = array(
47 // These nodes don't contain any data
50 // Data from *this* node
51 self::ANNOUNCEMENT_DATA_EXTERNAL_IP,
52 self::ANNOUNCEMENT_DATA_INTERNAL_IP,
53 self::ANNOUNCEMENT_DATA_TCP_PORT,
54 self::ANNOUNCEMENT_DATA_UDP_PORT,
55 self::ANNOUNCEMENT_DATA_NODE_STATUS,
56 self::ANNOUNCEMENT_DATA_SESSION_ID,
57 // Data from other node
65 * Creates an instance of the class TemplateEngine and prepares it for usage
67 * @return $templateInstance An instance of TemplateEngine
68 * @throws BasePathIsEmptyException If the provided $templateBasePath is empty
69 * @throws InvalidBasePathStringException If $templateBasePath is no string
70 * @throws BasePathIsNoDirectoryException If $templateBasePath is no
71 * directory or not found
72 * @throws BasePathReadProtectedException If $templateBasePath is
75 public static final function createXmlAnnouncementAnswerTemplateEngine () {
77 $templateInstance = new XmlAnnouncementAnswerTemplateEngine();
80 $templateInstance->initXmlTemplateEngine('node', 'announcement_answer');
82 // Return the prepared instance
83 return $templateInstance;
89 * @param $resource XML parser resource (currently ignored)
90 * @param $characters Characters to handle
92 * @todo Find something useful with this!
94 public function characterHandler ($resource, $characters) {
95 // Trim all spaces away
96 $characters = trim($characters);
98 // Is this string empty?
99 if (empty($characters)) {
100 // Then skip it silently
105 * Assign the found characters to variable and use the last entry from
108 parent::assignVariable($this->getStackerInstance()->getNamed('node_announcement_answer'), $characters);
112 * Getter for cache file (FQFN)
114 * @return $fqfn Full-qualified file name of the menu cache
116 public function getAnnouncementAnswerCacheFqfn () {
117 $this->partialStub('Please implement this method.');
121 * Starts the announcement-answer
125 protected function startAnnouncementAnswer () {
126 // Push the node name on the stacker
127 $this->getStackerInstance()->pushNamed('node_announcement_answer', 'announcement-answer');
135 protected function startMyData () {
136 // Push the node name on the stacker
137 $this->getStackerInstance()->pushNamed('node_announcement_answer', 'my-data');
141 * Starts the my-external-ip
145 protected function startMyExternalIp () {
146 // Push the node name on the stacker
147 $this->getStackerInstance()->pushNamed('node_announcement_answer', self::ANNOUNCEMENT_DATA_EXTERNAL_IP);
151 * Starts the my-internal-ip
155 protected function startMyInternalIp () {
156 // Push the node name on the stacker
157 $this->getStackerInstance()->pushNamed('node_announcement_answer', self::ANNOUNCEMENT_DATA_INTERNAL_IP);
161 * Starts the my-tcp-port
165 protected function startMyTcpPort () {
166 // Push the node name on the stacker
167 $this->getStackerInstance()->pushNamed('node_announcement_answer', self::ANNOUNCEMENT_DATA_TCP_PORT);
171 * Starts the my-udp-port
175 protected function startMyUdpPort () {
176 // Push the node name on the stacker
177 $this->getStackerInstance()->pushNamed('node_announcement_answer', self::ANNOUNCEMENT_DATA_UDP_PORT);
181 * Starts the my-session-id
185 protected function startMySessionId () {
186 // Push the node name on the stacker
187 $this->getStackerInstance()->pushNamed('node_announcement_answer', self::ANNOUNCEMENT_DATA_SESSION_ID);
191 * Starts the my-status
195 protected function startMyStatus () {
196 // Push the node name on the stacker
197 $this->getStackerInstance()->pushNamed('node_announcement_answer', self::ANNOUNCEMENT_DATA_NODE_STATUS);
201 * Finishes the my-status
205 protected function finishMyStatus () {
206 // Pop the last entry
207 $this->getStackerInstance()->popNamed('node_announcement_answer');
211 * Finishes the my-session-id
215 protected function finishMySessionId () {
216 // Pop the last entry
217 $this->getStackerInstance()->popNamed('node_announcement_answer');
221 * Finishes the my-udp-port
225 protected function finishMyUdpPort () {
226 // Pop the last entry
227 $this->getStackerInstance()->popNamed('node_announcement_answer');
231 * Finishes the my-tcp-port
235 protected function finishMyTcpPort () {
236 // Pop the last entry
237 $this->getStackerInstance()->popNamed('node_announcement_answer');
241 * Finishes the my-internal-ip
245 protected function finishMyInternalIp () {
246 // Pop the last entry
247 $this->getStackerInstance()->popNamed('node_announcement_answer');
251 * Finishes the my-external-ip
255 protected function finishMyExternalIp () {
256 // Pop the last entry
257 $this->getStackerInstance()->popNamed('node_announcement_answer');
261 * Finishes the my-data
265 protected function finishMyData () {
266 // Pop the last entry
267 $this->getStackerInstance()->popNamed('node_announcement_answer');
271 * Starts the your-data
275 protected function startYourData () {
276 // Push the node name on the stacker
277 $this->getStackerInstance()->pushNamed('node_announcement_answer', 'your-data');
281 * Starts the your-external-ip
285 protected function startYourExternalIp () {
286 // Push the node name on the stacker
287 $this->getStackerInstance()->pushNamed('node_announcement_answer', 'your-external-ip');
291 * Starts the your-internal-ip
295 protected function startYourInternalIp () {
296 // Push the node name on the stacker
297 $this->getStackerInstance()->pushNamed('node_announcement_answer', 'your-internal-ip');
301 * Starts the your-session-id
305 protected function startYourSessionId () {
306 // Push the node name on the stacker
307 $this->getStackerInstance()->pushNamed('node_announcement_answer', 'your-session-id');
311 * Finishes the your-session-id
315 protected function finishYourSessionId () {
316 // Pop the last entry
317 $this->getStackerInstance()->popNamed('node_announcement_answer');
321 * Finishes the your-internal-ip
325 protected function finishYourInternalIp () {
326 // Pop the last entry
327 $this->getStackerInstance()->popNamed('node_announcement_answer');
331 * Finishes the your-external-ip
335 protected function finishYourExternalIp () {
336 // Pop the last entry
337 $this->getStackerInstance()->popNamed('node_announcement_answer');
341 * Finishes the your-data
345 protected function finishYourData () {
346 // Pop the last entry
347 $this->getStackerInstance()->popNamed('node_announcement_answer');
351 * Finishes the announcement-answer
355 protected function finishAnnouncementAnswer () {
356 // Pop the last entry
357 $this->getStackerInstance()->popNamed('node_announcement_answer');