3 namespace Org\Shipsimu\Hub\Template\Engine\Xml\Answer\Announcement;
5 // Import application-specific stuff
6 use Org\Shipsimu\Hub\Template\Engine\Xml\Network\Answer\BaseXmlAnswerTemplateEngine;
8 // Import framework stuff
9 use Org\Mxchange\CoreFramework\Registry\Registerable;
10 use Org\Mxchange\CoreFramework\Template\Xml\CompileableXmlTemplate;
13 * An AnnouncementAnswer template engine class for XML templates
15 * @author Roland Haeder <webmaster@shipsimu.org>
17 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2020 Hub Developer Team
18 * @license GNU GPL 3.0 or any newer version
19 * @link http://www.shipsimu.org
20 * @todo This template engine does not make use of setTemplateType()
22 * This program is free software: you can redistribute it and/or modify
23 * it under the terms of the GNU General Public License as published by
24 * the Free Software Foundation, either version 3 of the License, or
25 * (at your option) any later version.
27 * This program is distributed in the hope that it will be useful,
28 * but WITHOUT ANY WARRANTY; without even the implied warranty of
29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30 * GNU General Public License for more details.
32 * You should have received a copy of the GNU General Public License
33 * along with this program. If not, see <http://www.gnu.org/licenses/>.
35 class XmlAnnouncementAnswerTemplateEngine extends BaseXmlAnswerTemplateEngine implements CompileableXmlTemplate, Registerable {
37 * Some XML nodes must be available for later data extraction
39 const ANNOUNCEMENT_DATA_NODE_ID = 'my-node-id';
40 const ANNOUNCEMENT_DATA_SESSION_ID = 'my-session-id';
41 const ANNOUNCEMENT_DATA_PRIVATE_KEY_HASH = 'my-private-key-hash';
42 const ANNOUNCEMENT_DATA_NODE_STATUS = 'my-status';
43 const ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS = 'my-external-address';
44 const ANNOUNCEMENT_DATA_INTERNAL_ADDRESS = 'my-internal-address';
47 * Protected constructor
51 protected function __construct () {
52 // Call parent constructor
53 parent::__construct(__CLASS__);
55 // Init sub-nodes array
56 $this->setSubNodes(array(
57 // These nodes don't contain any data
60 // Data from *this* node
61 self::ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS,
62 self::ANNOUNCEMENT_DATA_INTERNAL_ADDRESS,
63 self::ANNOUNCEMENT_DATA_NODE_STATUS,
64 self::ANNOUNCEMENT_DATA_NODE_ID,
65 self::ANNOUNCEMENT_DATA_SESSION_ID,
66 self::ANNOUNCEMENT_DATA_PRIVATE_KEY_HASH,
67 // Data from other node
68 'your-external-address',
69 'your-internal-address',
72 'your-private-key-hash',
73 // Answer status (generic field)
79 * Creates an instance of the class TemplateEngine and prepares it for usage
81 * @return $templateInstance An instance of TemplateEngine
82 * @throws BasePathIsEmptyException If the provided $templateBasePath is empty
83 * @throws InvalidBasePathStringException If $templateBasePath is no string
84 * @throws BasePathIsNoDirectoryException If $templateBasePath is no
85 * directory or not found
86 * @throws BasePathReadProtectedException If $templateBasePath is
89 public static final function createXmlAnnouncementAnswerTemplateEngine () {
91 $templateInstance = new XmlAnnouncementAnswerTemplateEngine();
94 $templateInstance->initXmlTemplateEngine('node', 'announcement_answer');
96 // Return the prepared instance
97 return $templateInstance;
103 * @param $resource XML parser resource (currently ignored)
104 * @param $characters Characters to handle
106 * @todo Find something useful with this!
108 public function characterHandler ($resource, string $characters) {
109 // Trim all spaces away
110 $characters = trim($characters);
112 // Is this string empty?
113 if (empty($characters)) {
114 // Then skip it silently
119 * Assign the found characters to variable and use the last entry from
122 parent::assignVariable($this->getStackInstance()->getNamed('node_announcement_answer'), $characters);
126 * Getter for cache file (FQFN)
128 * @return $fqfn Full-qualified file name of the menu cache
130 public function getAnnouncementAnswerCacheFqfn () {
131 $this->partialStub('Please implement this method.');
135 * Starts the announcement-answer
139 protected function startAnnouncementAnswer () {
140 // Push the node name on the stacker
141 $this->getStackInstance()->pushNamed('node_announcement_answer', 'announcement-answer');
149 protected function startMyData () {
150 // Push the node name on the stacker
151 $this->getStackInstance()->pushNamed('node_announcement_answer', 'my-data');
155 * Starts the my-external-address
159 protected function startMyExternalAddress () {
160 // Push the node name on the stacker
161 $this->getStackInstance()->pushNamed('node_announcement_answer', self::ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS);
165 * Starts the my-internal-address
169 protected function startMyInternalAddress () {
170 // Push the node name on the stacker
171 $this->getStackInstance()->pushNamed('node_announcement_answer', self::ANNOUNCEMENT_DATA_INTERNAL_ADDRESS);
175 * Starts the my-node-id
179 protected function startMyNodeId () {
180 // Push the node name on the stacker
181 $this->getStackInstance()->pushNamed('node_announcement_answer', self::ANNOUNCEMENT_DATA_NODE_ID);
185 * Starts the my-session-id
189 protected function startMySessionId () {
190 // Push the node name on the stacker
191 $this->getStackInstance()->pushNamed('node_announcement_answer', self::ANNOUNCEMENT_DATA_SESSION_ID);
195 * Starts the my-private-key-hash
199 protected function startMyPrivateKeyHash () {
200 // Push the node name on the stacker
201 $this->getStackInstance()->pushNamed('node_announcement_answer', self::ANNOUNCEMENT_DATA_PRIVATE_KEY_HASH);
205 * Starts the my-status
209 protected function startMyStatus () {
210 // Push the node name on the stacker
211 $this->getStackInstance()->pushNamed('node_announcement_answer', self::ANNOUNCEMENT_DATA_NODE_STATUS);
215 * Finishes the my-status
219 protected function finishMyStatus () {
220 // Pop the last entry
221 $this->getStackInstance()->popNamed('node_announcement_answer');
225 * Finishes the my-private-key-hash
229 protected function finishMyPrivateKeyhash () {
230 // Pop the last entry
231 $this->getStackInstance()->popNamed('node_announcement_answer');
235 * Finishes the my-session-id
239 protected function finishMySessionId () {
240 // Pop the last entry
241 $this->getStackInstance()->popNamed('node_announcement_answer');
245 * Finishes the my-node-id
249 protected function finishMyNodeId () {
250 // Pop the last entry
251 $this->getStackInstance()->popNamed('node_announcement_answer');
255 * Finishes the my-internal-address
259 protected function finishMyInternalAddress () {
260 // Pop the last entry
261 $this->getStackInstance()->popNamed('node_announcement_answer');
265 * Finishes the my-external-address
269 protected function finishMyExternalAddress () {
270 // Pop the last entry
271 $this->getStackInstance()->popNamed('node_announcement_answer');
275 * Finishes the my-data
279 protected function finishMyData () {
280 // Pop the last entry
281 $this->getStackInstance()->popNamed('node_announcement_answer');
285 * Starts the your-data
289 protected function startYourData () {
290 // Push the node name on the stacker
291 $this->getStackInstance()->pushNamed('node_announcement_answer', 'your-data');
295 * Starts the your-external-address
299 protected function startYourExternalAddress () {
300 // Push the node name on the stacker
301 $this->getStackInstance()->pushNamed('node_announcement_answer', 'your-external-address');
305 * Starts the your-internal-address
309 protected function startYourInternalAddress () {
310 // Push the node name on the stacker
311 $this->getStackInstance()->pushNamed('node_announcement_answer', 'your-internal-address');
315 * Starts the your-session-id
319 protected function startYourSessionId () {
320 // Push the node name on the stacker
321 $this->getStackInstance()->pushNamed('node_announcement_answer', 'your-session-id');
325 * Starts the your-node-id
329 protected function startYourNodeId () {
330 // Push the node name on the stacker
331 $this->getStackInstance()->pushNamed('node_announcement_answer', 'your-node-id');
335 * Starts the your-private-key-hash
339 protected function startYourPrivateKeyHash () {
340 // Push the node name on the stacker
341 $this->getStackInstance()->pushNamed('node_announcement_answer', 'your-private-key-hash');
345 * Finishes the your-private-key-hash
349 protected function finishYourPrivateKeyHash () {
350 // Pop the last entry
351 $this->getStackInstance()->popNamed('node_announcement_answer');
355 * Finishes the your-node-id
359 protected function finishYourNodeId () {
360 // Pop the last entry
361 $this->getStackInstance()->popNamed('node_announcement_answer');
365 * Finishes the your-session-id
369 protected function finishYourSessionId () {
370 // Pop the last entry
371 $this->getStackInstance()->popNamed('node_announcement_answer');
375 * Finishes the your-internal-address
379 protected function finishYourInternalAddress () {
380 // Pop the last entry
381 $this->getStackInstance()->popNamed('node_announcement_answer');
385 * Finishes the your-external-address
389 protected function finishYourExternalAddress () {
390 // Pop the last entry
391 $this->getStackInstance()->popNamed('node_announcement_answer');
395 * Finishes the your-data
399 protected function finishYourData () {
400 // Pop the last entry
401 $this->getStackInstance()->popNamed('node_announcement_answer');
405 * Finishes the announcement-answer
409 protected function finishAnnouncementAnswer () {
410 // Pop the last entry
411 $this->getStackInstance()->popNamed('node_announcement_answer');