3 * An AnnouncementAnswer 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 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_ADDRESS = 'my-external-address';
32 const ANNOUNCEMENT_DATA_INTERNAL_ADDRESS = 'my-internal-address';
33 const ANNOUNCEMENT_DATA_LISTEN_PORT = 'my-listen-port';
36 * Protected constructor
40 protected function __construct () {
41 // Call parent constructor
42 parent::__construct(__CLASS__);
44 // Init sub-nodes array
45 $this->subNodes = array(
46 // These nodes don't contain any data
49 // Data from *this* node
50 self::ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS,
51 self::ANNOUNCEMENT_DATA_INTERNAL_ADDRESS,
52 self::ANNOUNCEMENT_DATA_LISTEN_PORT,
53 self::ANNOUNCEMENT_DATA_NODE_STATUS,
54 self::ANNOUNCEMENT_DATA_SESSION_ID,
55 // Data from other node
56 'your-external-address',
57 'your-internal-address',
59 // Answer status (generic field)
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->getStackInstance()->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->getStackInstance()->pushNamed('node_announcement_answer', 'announcement-answer');
135 protected function startMyData () {
136 // Push the node name on the stacker
137 $this->getStackInstance()->pushNamed('node_announcement_answer', 'my-data');
141 * Starts the my-external-address
145 protected function startMyExternalAddress () {
146 // Push the node name on the stacker
147 $this->getStackInstance()->pushNamed('node_announcement_answer', self::ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS);
151 * Starts the my-internal-address
155 protected function startMyInternalAddress () {
156 // Push the node name on the stacker
157 $this->getStackInstance()->pushNamed('node_announcement_answer', self::ANNOUNCEMENT_DATA_INTERNAL_ADDRESS);
161 * Starts the my-tcp-port
165 protected function startMyListenPort () {
166 // Push the node name on the stacker
167 $this->getStackInstance()->pushNamed('node_announcement_answer', self::ANNOUNCEMENT_DATA_LISTEN_PORT);
171 * Starts the my-session-id
175 protected function startMySessionId () {
176 // Push the node name on the stacker
177 $this->getStackInstance()->pushNamed('node_announcement_answer', self::ANNOUNCEMENT_DATA_SESSION_ID);
181 * Starts the my-status
185 protected function startMyStatus () {
186 // Push the node name on the stacker
187 $this->getStackInstance()->pushNamed('node_announcement_answer', self::ANNOUNCEMENT_DATA_NODE_STATUS);
191 * Finishes the my-status
195 protected function finishMyStatus () {
196 // Pop the last entry
197 $this->getStackInstance()->popNamed('node_announcement_answer');
201 * Finishes the my-session-id
205 protected function finishMySessionId () {
206 // Pop the last entry
207 $this->getStackInstance()->popNamed('node_announcement_answer');
211 * Finishes the my-tcp-port
215 protected function finishMyListenPort () {
216 // Pop the last entry
217 $this->getStackInstance()->popNamed('node_announcement_answer');
221 * Finishes the my-internal-address
225 protected function finishMyInternalAddress () {
226 // Pop the last entry
227 $this->getStackInstance()->popNamed('node_announcement_answer');
231 * Finishes the my-external-address
235 protected function finishMyExternalAddress () {
236 // Pop the last entry
237 $this->getStackInstance()->popNamed('node_announcement_answer');
241 * Finishes the my-data
245 protected function finishMyData () {
246 // Pop the last entry
247 $this->getStackInstance()->popNamed('node_announcement_answer');
251 * Starts the your-data
255 protected function startYourData () {
256 // Push the node name on the stacker
257 $this->getStackInstance()->pushNamed('node_announcement_answer', 'your-data');
261 * Starts the your-external-address
265 protected function startYourExternalAddress () {
266 // Push the node name on the stacker
267 $this->getStackInstance()->pushNamed('node_announcement_answer', 'your-external-address');
271 * Starts the your-internal-address
275 protected function startYourInternalAddress () {
276 // Push the node name on the stacker
277 $this->getStackInstance()->pushNamed('node_announcement_answer', 'your-internal-address');
281 * Starts the your-session-id
285 protected function startYourSessionId () {
286 // Push the node name on the stacker
287 $this->getStackInstance()->pushNamed('node_announcement_answer', 'your-session-id');
291 * Finishes the your-session-id
295 protected function finishYourSessionId () {
296 // Pop the last entry
297 $this->getStackInstance()->popNamed('node_announcement_answer');
301 * Finishes the your-internal-address
305 protected function finishYourInternalAddress () {
306 // Pop the last entry
307 $this->getStackInstance()->popNamed('node_announcement_answer');
311 * Finishes the your-external-address
315 protected function finishYourExternalAddress () {
316 // Pop the last entry
317 $this->getStackInstance()->popNamed('node_announcement_answer');
321 * Finishes the your-data
325 protected function finishYourData () {
326 // Pop the last entry
327 $this->getStackInstance()->popNamed('node_announcement_answer');
331 * Finishes the announcement-answer
335 protected function finishAnnouncementAnswer () {
336 // Pop the last entry
337 $this->getStackInstance()->popNamed('node_announcement_answer');