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 BaseXmlAnswerTemplateEngine 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
61 // Answer status (generic field)
67 * Creates an instance of the class TemplateEngine and prepares it for usage
69 * @return $templateInstance An instance of TemplateEngine
70 * @throws BasePathIsEmptyException If the provided $templateBasePath is empty
71 * @throws InvalidBasePathStringException If $templateBasePath is no string
72 * @throws BasePathIsNoDirectoryException If $templateBasePath is no
73 * directory or not found
74 * @throws BasePathReadProtectedException If $templateBasePath is
77 public static final function createXmlAnnouncementAnswerTemplateEngine () {
79 $templateInstance = new XmlAnnouncementAnswerTemplateEngine();
82 $templateInstance->initXmlTemplateEngine('node', 'announcement_answer');
84 // Return the prepared instance
85 return $templateInstance;
91 * @param $resource XML parser resource (currently ignored)
92 * @param $characters Characters to handle
94 * @todo Find something useful with this!
96 public function characterHandler ($resource, $characters) {
97 // Trim all spaces away
98 $characters = trim($characters);
100 // Is this string empty?
101 if (empty($characters)) {
102 // Then skip it silently
107 * Assign the found characters to variable and use the last entry from
110 parent::assignVariable($this->getStackerInstance()->getNamed('node_announcement_answer'), $characters);
114 * Getter for cache file (FQFN)
116 * @return $fqfn Full-qualified file name of the menu cache
118 public function getAnnouncementAnswerCacheFqfn () {
119 $this->partialStub('Please implement this method.');
123 * Starts the announcement-answer
127 protected function startAnnouncementAnswer () {
128 // Push the node name on the stacker
129 $this->getStackerInstance()->pushNamed('node_announcement_answer', 'announcement-answer');
137 protected function startMyData () {
138 // Push the node name on the stacker
139 $this->getStackerInstance()->pushNamed('node_announcement_answer', 'my-data');
143 * Starts the my-external-ip
147 protected function startMyExternalIp () {
148 // Push the node name on the stacker
149 $this->getStackerInstance()->pushNamed('node_announcement_answer', self::ANNOUNCEMENT_DATA_EXTERNAL_IP);
153 * Starts the my-internal-ip
157 protected function startMyInternalIp () {
158 // Push the node name on the stacker
159 $this->getStackerInstance()->pushNamed('node_announcement_answer', self::ANNOUNCEMENT_DATA_INTERNAL_IP);
163 * Starts the my-tcp-port
167 protected function startMyTcpPort () {
168 // Push the node name on the stacker
169 $this->getStackerInstance()->pushNamed('node_announcement_answer', self::ANNOUNCEMENT_DATA_TCP_PORT);
173 * Starts the my-udp-port
177 protected function startMyUdpPort () {
178 // Push the node name on the stacker
179 $this->getStackerInstance()->pushNamed('node_announcement_answer', self::ANNOUNCEMENT_DATA_UDP_PORT);
183 * Starts the my-session-id
187 protected function startMySessionId () {
188 // Push the node name on the stacker
189 $this->getStackerInstance()->pushNamed('node_announcement_answer', self::ANNOUNCEMENT_DATA_SESSION_ID);
193 * Starts the my-status
197 protected function startMyStatus () {
198 // Push the node name on the stacker
199 $this->getStackerInstance()->pushNamed('node_announcement_answer', self::ANNOUNCEMENT_DATA_NODE_STATUS);
203 * Finishes the my-status
207 protected function finishMyStatus () {
208 // Pop the last entry
209 $this->getStackerInstance()->popNamed('node_announcement_answer');
213 * Finishes the my-session-id
217 protected function finishMySessionId () {
218 // Pop the last entry
219 $this->getStackerInstance()->popNamed('node_announcement_answer');
223 * Finishes the my-udp-port
227 protected function finishMyUdpPort () {
228 // Pop the last entry
229 $this->getStackerInstance()->popNamed('node_announcement_answer');
233 * Finishes the my-tcp-port
237 protected function finishMyTcpPort () {
238 // Pop the last entry
239 $this->getStackerInstance()->popNamed('node_announcement_answer');
243 * Finishes the my-internal-ip
247 protected function finishMyInternalIp () {
248 // Pop the last entry
249 $this->getStackerInstance()->popNamed('node_announcement_answer');
253 * Finishes the my-external-ip
257 protected function finishMyExternalIp () {
258 // Pop the last entry
259 $this->getStackerInstance()->popNamed('node_announcement_answer');
263 * Finishes the my-data
267 protected function finishMyData () {
268 // Pop the last entry
269 $this->getStackerInstance()->popNamed('node_announcement_answer');
273 * Starts the your-data
277 protected function startYourData () {
278 // Push the node name on the stacker
279 $this->getStackerInstance()->pushNamed('node_announcement_answer', 'your-data');
283 * Starts the your-external-ip
287 protected function startYourExternalIp () {
288 // Push the node name on the stacker
289 $this->getStackerInstance()->pushNamed('node_announcement_answer', 'your-external-ip');
293 * Starts the your-internal-ip
297 protected function startYourInternalIp () {
298 // Push the node name on the stacker
299 $this->getStackerInstance()->pushNamed('node_announcement_answer', 'your-internal-ip');
303 * Starts the your-session-id
307 protected function startYourSessionId () {
308 // Push the node name on the stacker
309 $this->getStackerInstance()->pushNamed('node_announcement_answer', 'your-session-id');
313 * Finishes the your-session-id
317 protected function finishYourSessionId () {
318 // Pop the last entry
319 $this->getStackerInstance()->popNamed('node_announcement_answer');
323 * Finishes the your-internal-ip
327 protected function finishYourInternalIp () {
328 // Pop the last entry
329 $this->getStackerInstance()->popNamed('node_announcement_answer');
333 * Finishes the your-external-ip
337 protected function finishYourExternalIp () {
338 // Pop the last entry
339 $this->getStackerInstance()->popNamed('node_announcement_answer');
343 * Finishes the your-data
347 protected function finishYourData () {
348 // Pop the last entry
349 $this->getStackerInstance()->popNamed('node_announcement_answer');
353 * Finishes the announcement-answer
357 protected function finishAnnouncementAnswer () {
358 // Pop the last entry
359 $this->getStackerInstance()->popNamed('node_announcement_answer');