]> git.mxchange.org Git - hub.git/blob - application/hub/main/template/producer/test_units/class_XmlCruncherTestUnitTemplateEngine.php
968220f63fc34d6039b91c8166c07c3c049cd38d
[hub.git] / application / hub / main / template / producer / test_units / class_XmlCruncherTestUnitTemplateEngine.php
1 <?php
2 /**
3  * An TestUnit template engine class for XML templates
4  *
5  * @author              Roland Haeder <webmaster@ship-simu.org>
6  * @version             0.0.0
7  * @copyright   Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2011 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()
11  *
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.
16  *
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.
21  *
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/>.
24  */
25 class XmlCruncherTestUnitTemplateEngine extends BaseTemplateEngine implements CompileableTemplate, Registerable {
26         /**
27          * Main nodes in the XML tree
28          */
29         private $mainNodes = array(
30                 'cruncher-test-unit'
31         );
32
33         /**
34          * Sub nodes in the XML tree
35          */
36         private $subNodes = array(
37                 'meta-data',
38                 'global-project-identifier',
39                 'test-unit-created',
40                 'cipher',
41                 'cipher-function',
42                 'cipher-name',
43                 'unprocessed-data',
44                 'encrypted-message',
45                 'cruncher-key-list',
46                 'cruncher-key',
47                 'key-id',
48                 'key-value'
49         );
50
51         /**
52          * Current main node
53          */
54         private $curr = array();
55
56         /**
57          * Protected constructor
58          *
59          * @return      void
60          */
61         protected function __construct () {
62                 // Call parent constructor
63                 parent::__construct(__CLASS__);
64         }
65
66         /**
67          * Creates an instance of the class TemplateEngine and prepares it for usage
68          *
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
75          *                                                                                      read-protected
76          */
77         public static final function createXmlCruncherTestUnitTemplateEngine () {
78                 // Get a new instance
79                 $templateInstance = new XmlCruncherTestUnitTemplateEngine();
80
81                 // Get application instance from registry
82                 $applicationInstance = Registry::getRegistry()->getInstance('app');
83
84                 // Determine base path
85                 $templateBasePath = $templateInstance->getConfigInstance()->getConfigEntry('application_base_path') . $applicationInstance->getRequestInstance()->getRequestElement('app') . '/';
86
87                 // Is the base path valid?
88                 if (empty($templateBasePath)) {
89                         // Base path is empty
90                         throw new BasePathIsEmptyException($templateInstance, self::EXCEPTION_UNEXPECTED_EMPTY_STRING);
91                 } elseif (!is_string($templateBasePath)) {
92                         // Is not a string
93                         throw new InvalidBasePathStringException(array($templateInstance, $templateBasePath), self::EXCEPTION_INVALID_STRING);
94                 } elseif (!is_dir($templateBasePath)) {
95                         // Is not a path
96                         throw new BasePathIsNoDirectoryException(array($templateInstance, $templateBasePath), self::EXCEPTION_INVALID_PATH_NAME);
97                 } elseif (!is_readable($templateBasePath)) {
98                         // Is not readable
99                         throw new BasePathReadProtectedException(array($templateInstance, $templateBasePath), self::EXCEPTION_READ_PROTECED_PATH);
100                 }
101
102                 // Set the base path
103                 $templateInstance->setTemplateBasePath($templateBasePath);
104
105                 // Set template extensions
106                 $templateInstance->setRawTemplateExtension($templateInstance->getConfigInstance()->getConfigEntry('raw_template_extension'));
107                 $templateInstance->setCodeTemplateExtension($templateInstance->getConfigInstance()->getConfigEntry('cruncher_test_unit_template_extension'));
108
109                 // Absolute output path for compiled templates
110                 $templateInstance->setCompileOutputPath($templateInstance->getConfigInstance()->getConfigEntry('base_path') . $templateInstance->getConfigInstance()->getConfigEntry('compile_output_path'));
111
112                 // Init a variable stacker
113                 $stackerInstance = ObjectFactory::createObjectByConfiguredName('cruncher_test_unit_stacker_class');
114
115                 // Set it
116                 $templateInstance->setStackerInstance($stackerInstance);
117
118                 // Return the prepared instance
119                 return $templateInstance;
120         }
121
122         /**
123          * Load a specified cruncher_test_unit template into the engine
124          *
125          * @param       $template       The cruncher_test_unit template we shall load which is
126          *                                              located in 'cruncher_test_unit' by default
127          * @return      void
128          */
129         public function loadCruncherTestUnitTemplate ($template) {
130                 // Set template type
131                 $this->setTemplateType($this->getConfigInstance()->getConfigEntry('cruncher_test_unit_template_type'));
132
133                 // Load the special template
134                 $this->loadTemplate($template);
135         }
136
137         /**
138          * Getter for current main node
139          *
140          * @return      $currMainNode   Current main node
141          */
142         public final function getCurrMainNode () {
143                 return $this->curr['main_node'];
144         }
145
146         /**
147          * Setter for current main node
148          *
149          * @param       $element                Element name to set as current main node
150          * @return      $currMainNode   Current main node
151          */
152         private final function setCurrMainNode ($element) {
153                 $this->curr['main_node'] = (string) $element;
154         }
155
156         /**
157          * Getter for main node array
158          *
159          * @return      $mainNodes      Array with valid main node names
160          */
161         public final function getMainNodes () {
162                 return $this->mainNodes;
163         }
164
165         /**
166          * Getter for sub node array
167          *
168          * @return      $subNodes       Array with valid sub node names
169          */
170         public final function getSubNodes () {
171                 return $this->subNodes;
172         }
173
174         /**
175          * Handles the start element of an XML resource
176          *
177          * @param       $resource               XML parser resource (currently ignored)
178          * @param       $element                The element we shall handle
179          * @param       $attributes             All attributes
180          * @return      void
181          * @throws      InvalidXmlNodeException         If an unknown/invalid XML node name was found
182          */
183         public function startElement ($resource, $element, array $attributes) {
184                 // Initial method name which will never be called...
185                 $methodName = 'initTestUnit';
186
187                 // Make the element name lower-case
188                 $element = strtolower($element);
189
190                 // Is the element a main node?
191                 //* DEBUG: */ echo "START: &gt;".$element."&lt;<br />\n";
192                 if (in_array($element, $this->getMainNodes())) {
193                         // Okay, main node found!
194                         $methodName = 'start' . $this->convertToClassName($element);
195
196                         // Set it
197                         $this->setCurrMainNode($element);
198                 } elseif (in_array($element, $this->getSubNodes())) {
199                         // Sub node found
200                         $methodName = 'start' . $this->convertToClassName($element);
201                 } else {
202                         // Invalid node name found
203                         throw new InvalidXmlNodeException(array($this, $element, $attributes), XmlParser::EXCEPTION_XML_NODE_UNKNOWN);
204                 }
205
206                 // Call method
207                 call_user_func_array(array($this, $methodName), $attributes);
208         }
209
210         /**
211          * Ends the main or sub node by sending out the gathered data
212          *
213          * @param       $resource       An XML resource pointer (currently ignored)
214          * @param       $nodeName       Name of the node we want to finish
215          * @return      void
216          * @throws      XmlNodeMismatchException        If current main node mismatches the closing one
217          */
218         public function endElement ($resource, $nodeName) {
219                 // Make all lower-case
220                 $nodeName = strtolower($nodeName);
221
222                 // Does this match with current main node?
223                 //* DEBUG: */ echo "END: &gt;".$nodeName."&lt;<br />\n";
224                 if (($nodeName != $this->getCurrMainNode()) && (in_array($nodeName, $this->getMainNodes()))) {
225                         // Did not match!
226                         throw new XmlNodeMismatchException (array($this, $nodeName, $this->getCurrMainNode()), XmlParser::EXCEPTION_XML_NODE_MISMATCH);
227                 } // END - if
228
229                 // Construct method name
230                 $methodName = 'finish' . $this->convertToClassName($nodeName);
231
232                 // Call the corresponding method
233                 //* DEBUG: */ echo "call: ".$methodName."<br />\n";
234                 call_user_func_array(array($this, $methodName), array());
235         }
236
237         /**
238          * Currently not used
239          *
240          * @param       $resource               XML parser resource (currently ignored)
241          * @param       $characters             Characters to handle
242          * @return      void
243          */
244         public function characterHandler ($resource, $characters) {
245                 // Trim all spaces away
246                 $characters = trim($characters);
247
248                 // Is this string empty?
249                 if (empty($characters)) {
250                         // Then skip it silently
251                         return false;
252                 } // END - if
253
254                 // Assign the found characters to variable and use the last entry from
255                 // stack as the name
256                 parent::assignVariable($this->getStackerInstance()->getNamed('cruncher_test_unit'), $characters);
257         }
258
259         /**
260          * Getter for cache file (FQFN)
261          *
262          * @return      $fqfn   Full-qualified file name of the menu cache
263          */
264         public function getCruncherTestUnitCacheFqfn () {
265                 $this->partialStub('Please implement this method.');
266         }
267
268         /**
269          * Starts the test-unit
270          *
271          * @return      void
272          */
273         private function startCruncherTestUnit () {
274                 // Push the node name on the stacker
275                 $this->getStackerInstance()->pushNamed('cruncher_test_unit', 'cruncher-test-unit');
276         }
277
278         /**
279          * Starts the meta-data
280          *
281          * @return      void
282          */
283         private function startMetaData () {
284                 // Push the node name on the stacker
285                 $this->getStackerInstance()->pushNamed('cruncher_test_unit', 'meta-data');
286         }
287
288         /**
289          * Starts the global-project-identifier
290          *
291          * @return      void
292          */
293         private function startGlobalProjectIdentifier () {
294                 // Push the node name on the stacker
295                 $this->getStackerInstance()->pushNamed('cruncher_test_unit', 'global-project-identifier');
296         }
297
298         /**
299          * Finishes the global-project-identifier
300          *
301          * @return      void
302          */
303         private function finishGlobalProjectIdentifier () {
304                 // Pop the last entry
305                 $this->getStackerInstance()->popNamed('cruncher_test_unit');
306         }
307
308         /**
309          * Starts the test-unit-created
310          *
311          * @return      void
312          */
313         private function startTestUnitCreated () {
314                 // Push the node name on the stacker
315                 $this->getStackerInstance()->pushNamed('cruncher_test_unit', 'test-unit-created');
316         }
317
318         /**
319          * Finishes the test-unit-created
320          *
321          * @return      void
322          */
323         private function finishTestUnitCreated () {
324                 // Pop the last entry
325                 $this->getStackerInstance()->popNamed('cruncher_test_unit');
326         }
327
328         /**
329          * Starts the cipher
330          *
331          * @return      void
332          */
333         private function startCipher () {
334                 // Push the node name on the stacker
335                 $this->getStackerInstance()->pushNamed('cruncher_test_unit', 'cipher');
336         }
337
338         /**
339          * Starts the cipher-function
340          *
341          * @return      void
342          */
343         private function startCipherFunction () {
344                 // Push the node name on the stacker
345                 $this->getStackerInstance()->pushNamed('cruncher_test_unit', 'cipher-function');
346         }
347
348         /**
349          * Finishes the cipher-function
350          *
351          * @return      void
352          */
353         private function finishCipherFunction () {
354                 // Pop the last entry
355                 $this->getStackerInstance()->popNamed('cruncher_test_unit');
356         }
357
358         /**
359          * Starts the cipher-name
360          *
361          * @return      void
362          */
363         private function startCipherName () {
364                 // Push the node name on the stacker
365                 $this->getStackerInstance()->pushNamed('cruncher_test_unit', 'cipher-name');
366         }
367
368         /**
369          * Finishes the cipher-name
370          *
371          * @return      void
372          */
373         private function finishCipherName () {
374                 // Pop the last entry
375                 $this->getStackerInstance()->popNamed('cruncher_test_unit');
376         }
377
378         /**
379          * Finishes the cipher
380          *
381          * @return      void
382          */
383         private function finishCipher () {
384                 // Pop the last entry
385                 $this->getStackerInstance()->popNamed('cruncher_test_unit');
386         }
387
388         /**
389          * Finishes the meta-data
390          *
391          * @return      void
392          */
393         private function finishMetaData () {
394                 // Pop the last entry
395                 $this->getStackerInstance()->popNamed('cruncher_test_unit');
396         }
397
398         /**
399          * Starts the unprocessed-data
400          *
401          * @return      void
402          */
403         private function startUnprocessedData () {
404                 // Push the node name on the stacker
405                 $this->getStackerInstance()->pushNamed('cruncher_test_unit', 'unprocessed-data');
406         }
407
408         /**
409          * Starts the encrypted-message
410          *
411          * @return      void
412          */
413         private function startEncryptedMessage () {
414                 // Push the node name on the stacker
415                 $this->getStackerInstance()->pushNamed('cruncher_test_unit', 'encrypted-message');
416         }
417
418         /**
419          * Finishes the encrypted-message
420          *
421          * @return      void
422          */
423         private function finishEncryptedMessage () {
424                 // Pop the last entry
425                 $this->getStackerInstance()->popNamed('cruncher_test_unit');
426         }
427
428         /**
429          * Starts the cruncher-key-list
430          *
431          * @param       $keyCount       Count of keys in this test unit
432          * @return      void
433          * @todo        Handle $keyCount
434          */
435         private function startCruncherKeyList ($keyCount) {
436                 // Push the node name on the stacker
437                 $this->getStackerInstance()->pushNamed('cruncher_test_unit', 'cruncher-key-list');
438         }
439
440         /**
441          * Starts the cruncher-key
442          *
443          * @return      void
444          */
445         private function startCruncherKey () {
446                 // Push the node name on the stacker
447                 $this->getStackerInstance()->pushNamed('cruncher_test_unit', 'cruncher-key');
448         }
449
450         /**
451          * Starts the key-id
452          *
453          * @return      void
454          */
455         private function startKeyId () {
456                 // Push the node name on the stacker
457                 $this->getStackerInstance()->pushNamed('cruncher_test_unit', 'key-id');
458         }
459
460         /**
461          * Finishes the key-id
462          *
463          * @return      void
464          */
465         private function finishKeyId () {
466                 // Pop the last entry
467                 $this->getStackerInstance()->popNamed('cruncher_test_unit');
468         }
469
470         /**
471          * Starts the key-value
472          *
473          * @return      void
474          */
475         private function startKeyValue () {
476                 // Push the node name on the stacker
477                 $this->getStackerInstance()->pushNamed('cruncher_test_unit', 'key-value');
478         }
479
480         /**
481          * Finishes the key-value
482          *
483          * @return      void
484          */
485         private function finishKeyValue () {
486                 // Pop the last entry
487                 $this->getStackerInstance()->popNamed('cruncher_test_unit');
488         }
489
490         /**
491          * Finishes the cruncher-key
492          *
493          * @return      void
494          */
495         private function finishCruncherKey () {
496                 // Pop the last entry
497                 $this->getStackerInstance()->popNamed('cruncher_test_unit');
498         }
499
500         /**
501          * Finishes the cruncher-key-list
502          *
503          * @return      void
504          */
505         private function finishCruncherKeyList () {
506                 // Pop the last entry
507                 $this->getStackerInstance()->popNamed('cruncher_test_unit');
508         }
509
510         /**
511          * Finishes the unprocessed-data
512          *
513          * @return      void
514          */
515         private function finishUnprocessedData () {
516                 // Pop the last entry
517                 $this->getStackerInstance()->popNamed('cruncher_test_unit');
518         }
519
520         /**
521          * Finishes the test-unit
522          *
523          * @return      void
524          */
525         private function finishCruncherTestUnit () {
526                 // Pop the last entry
527                 $this->getStackerInstance()->popNamed('cruncher_test_unit');
528         }
529 }
530
531 // [EOF]
532 ?>