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 - 2015 Hub 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_NODE_ID = 'my-node-id';
30 const ANNOUNCEMENT_DATA_SESSION_ID = 'my-session-id';
31 const ANNOUNCEMENT_DATA_PRIVATE_KEY_HASH = 'my-private-key-hash';
32 const ANNOUNCEMENT_DATA_NODE_STATUS = 'my-status';
33 const ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS = 'my-external-address';
34 const ANNOUNCEMENT_DATA_INTERNAL_ADDRESS = 'my-internal-address';
37 * Protected constructor
41 protected function __construct () {
42 // Call parent constructor
43 parent::__construct(__CLASS__);
45 // Init sub-nodes array
46 $this->setSubNodes(array(
47 // These nodes don't contain any data
50 // Data from *this* node
51 self::ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS,
52 self::ANNOUNCEMENT_DATA_INTERNAL_ADDRESS,
53 self::ANNOUNCEMENT_DATA_NODE_STATUS,
54 self::ANNOUNCEMENT_DATA_NODE_ID,
55 self::ANNOUNCEMENT_DATA_SESSION_ID,
56 self::ANNOUNCEMENT_DATA_PRIVATE_KEY_HASH,
57 // Data from other node
58 'your-external-address',
59 'your-internal-address',
62 'your-private-key-hash',
63 // Answer status (generic field)
69 * Creates an instance of the class TemplateEngine and prepares it for usage
71 * @return $templateInstance An instance of TemplateEngine
72 * @throws BasePathIsEmptyException If the provided $templateBasePath is empty
73 * @throws InvalidBasePathStringException If $templateBasePath is no string
74 * @throws BasePathIsNoDirectoryException If $templateBasePath is no
75 * directory or not found
76 * @throws BasePathReadProtectedException If $templateBasePath is
79 public static final function createXmlAnnouncementAnswerTemplateEngine () {
81 $templateInstance = new XmlAnnouncementAnswerTemplateEngine();
84 $templateInstance->initXmlTemplateEngine('node', 'announcement_answer');
86 // Return the prepared instance
87 return $templateInstance;
93 * @param $resource XML parser resource (currently ignored)
94 * @param $characters Characters to handle
96 * @todo Find something useful with this!
98 public function characterHandler ($resource, $characters) {
99 // Trim all spaces away
100 $characters = trim($characters);
102 // Is this string empty?
103 if (empty($characters)) {
104 // Then skip it silently
109 * Assign the found characters to variable and use the last entry from
112 parent::assignVariable($this->getStackInstance()->getNamed('node_announcement_answer'), $characters);
116 * Getter for cache file (FQFN)
118 * @return $fqfn Full-qualified file name of the menu cache
120 public function getAnnouncementAnswerCacheFqfn () {
121 $this->partialStub('Please implement this method.');
125 * Starts the announcement-answer
129 protected function startAnnouncementAnswer () {
130 // Push the node name on the stacker
131 $this->getStackInstance()->pushNamed('node_announcement_answer', 'announcement-answer');
139 protected function startMyData () {
140 // Push the node name on the stacker
141 $this->getStackInstance()->pushNamed('node_announcement_answer', 'my-data');
145 * Starts the my-external-address
149 protected function startMyExternalAddress () {
150 // Push the node name on the stacker
151 $this->getStackInstance()->pushNamed('node_announcement_answer', self::ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS);
155 * Starts the my-internal-address
159 protected function startMyInternalAddress () {
160 // Push the node name on the stacker
161 $this->getStackInstance()->pushNamed('node_announcement_answer', self::ANNOUNCEMENT_DATA_INTERNAL_ADDRESS);
165 * Starts the my-node-id
169 protected function startMyNodeId () {
170 // Push the node name on the stacker
171 $this->getStackInstance()->pushNamed('node_announcement_answer', self::ANNOUNCEMENT_DATA_NODE_ID);
175 * Starts the my-session-id
179 protected function startMySessionId () {
180 // Push the node name on the stacker
181 $this->getStackInstance()->pushNamed('node_announcement_answer', self::ANNOUNCEMENT_DATA_SESSION_ID);
185 * Starts the my-private-key-hash
189 protected function startMyPrivateKeyHash () {
190 // Push the node name on the stacker
191 $this->getStackInstance()->pushNamed('node_announcement_answer', self::ANNOUNCEMENT_DATA_PRIVATE_KEY_HASH);
195 * Starts the my-status
199 protected function startMyStatus () {
200 // Push the node name on the stacker
201 $this->getStackInstance()->pushNamed('node_announcement_answer', self::ANNOUNCEMENT_DATA_NODE_STATUS);
205 * Finishes the my-status
209 protected function finishMyStatus () {
210 // Pop the last entry
211 $this->getStackInstance()->popNamed('node_announcement_answer');
215 * Finishes the my-private-key-hash
219 protected function finishMyPrivateKeyhash () {
220 // Pop the last entry
221 $this->getStackInstance()->popNamed('node_announcement_answer');
225 * Finishes the my-session-id
229 protected function finishMySessionId () {
230 // Pop the last entry
231 $this->getStackInstance()->popNamed('node_announcement_answer');
235 * Finishes the my-node-id
239 protected function finishMyNodeId () {
240 // Pop the last entry
241 $this->getStackInstance()->popNamed('node_announcement_answer');
245 * Finishes the my-internal-address
249 protected function finishMyInternalAddress () {
250 // Pop the last entry
251 $this->getStackInstance()->popNamed('node_announcement_answer');
255 * Finishes the my-external-address
259 protected function finishMyExternalAddress () {
260 // Pop the last entry
261 $this->getStackInstance()->popNamed('node_announcement_answer');
265 * Finishes the my-data
269 protected function finishMyData () {
270 // Pop the last entry
271 $this->getStackInstance()->popNamed('node_announcement_answer');
275 * Starts the your-data
279 protected function startYourData () {
280 // Push the node name on the stacker
281 $this->getStackInstance()->pushNamed('node_announcement_answer', 'your-data');
285 * Starts the your-external-address
289 protected function startYourExternalAddress () {
290 // Push the node name on the stacker
291 $this->getStackInstance()->pushNamed('node_announcement_answer', 'your-external-address');
295 * Starts the your-internal-address
299 protected function startYourInternalAddress () {
300 // Push the node name on the stacker
301 $this->getStackInstance()->pushNamed('node_announcement_answer', 'your-internal-address');
305 * Starts the your-session-id
309 protected function startYourSessionId () {
310 // Push the node name on the stacker
311 $this->getStackInstance()->pushNamed('node_announcement_answer', 'your-session-id');
315 * Starts the your-node-id
319 protected function startYourNodeId () {
320 // Push the node name on the stacker
321 $this->getStackInstance()->pushNamed('node_announcement_answer', 'your-node-id');
325 * Starts the your-private-key-hash
329 protected function startYourPrivateKeyHash () {
330 // Push the node name on the stacker
331 $this->getStackInstance()->pushNamed('node_announcement_answer', 'your-private-key-hash');
335 * Finishes the your-private-key-hash
339 protected function finishYourPrivateKeyHash () {
340 // Pop the last entry
341 $this->getStackInstance()->popNamed('node_announcement_answer');
345 * Finishes the your-node-id
349 protected function finishYourNodeId () {
350 // Pop the last entry
351 $this->getStackInstance()->popNamed('node_announcement_answer');
355 * Finishes the your-session-id
359 protected function finishYourSessionId () {
360 // Pop the last entry
361 $this->getStackInstance()->popNamed('node_announcement_answer');
365 * Finishes the your-internal-address
369 protected function finishYourInternalAddress () {
370 // Pop the last entry
371 $this->getStackInstance()->popNamed('node_announcement_answer');
375 * Finishes the your-external-address
379 protected function finishYourExternalAddress () {
380 // Pop the last entry
381 $this->getStackInstance()->popNamed('node_announcement_answer');
385 * Finishes the your-data
389 protected function finishYourData () {
390 // Pop the last entry
391 $this->getStackInstance()->popNamed('node_announcement_answer');
395 * Finishes the announcement-answer
399 protected function finishAnnouncementAnswer () {
400 // Pop the last entry
401 $this->getStackInstance()->popNamed('node_announcement_answer');