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_SESSION_ID = 'my-session-id';
30 const ANNOUNCEMENT_DATA_PRIVATE_KEY_HASH = 'my-private-key-hash';
31 const ANNOUNCEMENT_DATA_NODE_STATUS = 'my-status';
32 const ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS = 'my-external-address';
33 const ANNOUNCEMENT_DATA_INTERNAL_ADDRESS = 'my-internal-address';
36 * Protected constructor
40 protected function __construct () {
41 // Call parent constructor
42 parent::__construct(__CLASS__);
44 // Init sub-nodes array
45 $this->setSubNodes(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_NODE_STATUS,
53 self::ANNOUNCEMENT_DATA_SESSION_ID,
54 self::ANNOUNCEMENT_DATA_PRIVATE_KEY_HASH,
55 // Data from other node
56 'your-external-address',
57 'your-internal-address',
60 'your-private-key-hash',
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->getStackInstance()->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->getStackInstance()->pushNamed('node_announcement_answer', 'announcement-answer');
137 protected function startMyData () {
138 // Push the node name on the stacker
139 $this->getStackInstance()->pushNamed('node_announcement_answer', 'my-data');
143 * Starts the my-external-address
147 protected function startMyExternalAddress () {
148 // Push the node name on the stacker
149 $this->getStackInstance()->pushNamed('node_announcement_answer', self::ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS);
153 * Starts the my-internal-address
157 protected function startMyInternalAddress () {
158 // Push the node name on the stacker
159 $this->getStackInstance()->pushNamed('node_announcement_answer', self::ANNOUNCEMENT_DATA_INTERNAL_ADDRESS);
163 * Starts the my-session-id
167 protected function startMySessionId () {
168 // Push the node name on the stacker
169 $this->getStackInstance()->pushNamed('node_announcement_answer', self::ANNOUNCEMENT_DATA_SESSION_ID);
173 * Starts the my-private-key-hash
177 protected function startMyPrivateKeyHash () {
178 // Push the node name on the stacker
179 $this->getStackInstance()->pushNamed('node_announcement_answer', self::ANNOUNCEMENT_DATA_PRIVATE_KEY_HASH);
183 * Starts the my-status
187 protected function startMyStatus () {
188 // Push the node name on the stacker
189 $this->getStackInstance()->pushNamed('node_announcement_answer', self::ANNOUNCEMENT_DATA_NODE_STATUS);
193 * Finishes the my-status
197 protected function finishMyStatus () {
198 // Pop the last entry
199 $this->getStackInstance()->popNamed('node_announcement_answer');
203 * Finishes the my-private-key-hash
207 protected function finishMyPrivateKeyhash () {
208 // Pop the last entry
209 $this->getStackInstance()->popNamed('node_announcement_answer');
213 * Finishes the my-session-id
217 protected function finishMySessionId () {
218 // Pop the last entry
219 $this->getStackInstance()->popNamed('node_announcement_answer');
223 * Finishes the my-internal-address
227 protected function finishMyInternalAddress () {
228 // Pop the last entry
229 $this->getStackInstance()->popNamed('node_announcement_answer');
233 * Finishes the my-external-address
237 protected function finishMyExternalAddress () {
238 // Pop the last entry
239 $this->getStackInstance()->popNamed('node_announcement_answer');
243 * Finishes the my-data
247 protected function finishMyData () {
248 // Pop the last entry
249 $this->getStackInstance()->popNamed('node_announcement_answer');
253 * Starts the your-data
257 protected function startYourData () {
258 // Push the node name on the stacker
259 $this->getStackInstance()->pushNamed('node_announcement_answer', 'your-data');
263 * Starts the your-external-address
267 protected function startYourExternalAddress () {
268 // Push the node name on the stacker
269 $this->getStackInstance()->pushNamed('node_announcement_answer', 'your-external-address');
273 * Starts the your-internal-address
277 protected function startYourInternalAddress () {
278 // Push the node name on the stacker
279 $this->getStackInstance()->pushNamed('node_announcement_answer', 'your-internal-address');
283 * Starts the your-session-id
287 protected function startYourSessionId () {
288 // Push the node name on the stacker
289 $this->getStackInstance()->pushNamed('node_announcement_answer', 'your-session-id');
293 * Starts the your-node-id
297 protected function startYourNodeId () {
298 // Push the node name on the stacker
299 $this->getStackInstance()->pushNamed('node_announcement_answer', 'your-node-id');
303 * Starts the your-private-key-hash
307 protected function startYourPrivateKeyHash () {
308 // Push the node name on the stacker
309 $this->getStackInstance()->pushNamed('node_announcement_answer', 'your-private-key-hash');
313 * Finishes the your-private-key-hash
317 protected function finishYourPrivateKeyHash () {
318 // Pop the last entry
319 $this->getStackInstance()->popNamed('node_announcement_answer');
323 * Finishes the your-node-id
327 protected function finishYourNodeId () {
328 // Pop the last entry
329 $this->getStackInstance()->popNamed('node_announcement_answer');
333 * Finishes the your-session-id
337 protected function finishYourSessionId () {
338 // Pop the last entry
339 $this->getStackInstance()->popNamed('node_announcement_answer');
343 * Finishes the your-internal-address
347 protected function finishYourInternalAddress () {
348 // Pop the last entry
349 $this->getStackInstance()->popNamed('node_announcement_answer');
353 * Finishes the your-external-address
357 protected function finishYourExternalAddress () {
358 // Pop the last entry
359 $this->getStackInstance()->popNamed('node_announcement_answer');
363 * Finishes the your-data
367 protected function finishYourData () {
368 // Pop the last entry
369 $this->getStackInstance()->popNamed('node_announcement_answer');
373 * Finishes the announcement-answer
377 protected function finishAnnouncementAnswer () {
378 // Pop the last entry
379 $this->getStackInstance()->popNamed('node_announcement_answer');