]> git.mxchange.org Git - hub.git/blob - application/hub/main/template/requests/class_XmlRequestNodeListTemplateEngine.php
Missed to implement this :( It is really warm here ... around 30-35 degrees Celsius :(
[hub.git] / application / hub / main / template / requests / class_XmlRequestNodeListTemplateEngine.php
1 <?php
2 /**
3  * An ??? 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 - 2012 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 XmlRequestNodeListTemplateEngine extends BaseTemplateEngine implements CompileableTemplate, Registerable {
26         /**
27          * Main nodes in the XML tree
28          */
29         private $mainNodes = array(
30                 'node-request-node-list'
31         );
32
33         /**
34          * Sub nodes in the XML tree
35          */
36         private $subNodes = array(
37                 'accepted-object-types'
38         );
39
40         /**
41          * Current main node
42          */
43         private $curr = array();
44
45         /**
46          * Protected constructor
47          *
48          * @return      void
49          */
50         protected function __construct () {
51                 // Call parent constructor
52                 parent::__construct(__CLASS__);
53         }
54
55         /**
56          * Creates an instance of the class TemplateEngine and prepares it for usage
57          *
58          * @return      $templateInstance               An instance of TemplateEngine
59          * @throws      BasePathIsEmptyException                If the provided $templateBasePath is empty
60          * @throws      InvalidBasePathStringException  If $templateBasePath is no string
61          * @throws      BasePathIsNoDirectoryException  If $templateBasePath is no
62          *                                                                                      directory or not found
63          * @throws      BasePathReadProtectedException  If $templateBasePath is
64          *                                                                                      read-protected
65          */
66         public static final function createXmlRequestNodeListTemplateEngine () {
67                 // Get a new instance
68                 $templateInstance = new XmlRequestNodeListTemplateEngine();
69
70                 // Get application instance from registry
71                 $applicationInstance = Registry::getRegistry()->getInstance('app');
72
73                 // Determine base path
74                 $templateBasePath = $templateInstance->getConfigInstance()->getConfigEntry('application_base_path') . $applicationInstance->getRequestInstance()->getRequestElement('app') . '/';
75
76                 // Is the base path valid?
77                 if (empty($templateBasePath)) {
78                         // Base path is empty
79                         throw new BasePathIsEmptyException($templateInstance, self::EXCEPTION_UNEXPECTED_EMPTY_STRING);
80                 } elseif (!is_string($templateBasePath)) {
81                         // Is not a string
82                         throw new InvalidBasePathStringException(array($templateInstance, $templateBasePath), self::EXCEPTION_INVALID_STRING);
83                 } elseif (!is_dir($templateBasePath)) {
84                         // Is not a path
85                         throw new BasePathIsNoDirectoryException(array($templateInstance, $templateBasePath), self::EXCEPTION_INVALID_PATH_NAME);
86                 } elseif (!is_readable($templateBasePath)) {
87                         // Is not readable
88                         throw new BasePathReadProtectedException(array($templateInstance, $templateBasePath), self::EXCEPTION_READ_PROTECED_PATH);
89                 }
90
91                 // Set the base path
92                 $templateInstance->setTemplateBasePath($templateBasePath);
93
94                 // Set template extensions
95                 $templateInstance->setRawTemplateExtension($templateInstance->getConfigInstance()->getConfigEntry('raw_template_extension'));
96                 $templateInstance->setCodeTemplateExtension($templateInstance->getConfigInstance()->getConfigEntry('node_message_template_extension'));
97
98                 // Absolute output path for compiled templates
99                 $templateInstance->setCompileOutputPath($templateInstance->getConfigInstance()->getConfigEntry('base_path') . $templateInstance->getConfigInstance()->getConfigEntry('compile_output_path'));
100
101                 // Init a variable stacker
102                 $stackerInstance = ObjectFactory::createObjectByConfiguredName('node_request_node_list_stacker_class');
103
104                 // Set it
105                 $templateInstance->setStackerInstance($stackerInstance);
106
107                 // Return the prepared instance
108                 return $templateInstance;
109         }
110
111         /**
112          * Load a specified request_node_list template into the engine
113          *
114          * @param       $template       The request_node_list template we shall load which is
115          *                                              located in 'node_request_node_list' by default
116          * @return      void
117          */
118         public function loadRequestNodeListTemplate ($template = 'node_request_node_list') {
119                 // Set template type
120                 $this->setTemplateType($this->getConfigInstance()->getConfigEntry('node_request_node_list_template_type'));
121
122                 // Load the special template
123                 $this->loadTemplate($template);
124         }
125
126         /**
127          * Getter for current main node
128          *
129          * @return      $currMainNode   Current main node
130          */
131         public final function getCurrMainNode () {
132                 return $this->curr['main_node'];
133         }
134
135         /**
136          * Setter for current main node
137          *
138          * @param       $element                Element name to set as current main node
139          * @return      $currMainNode   Current main node
140          */
141         private final function setCurrMainNode ($element) {
142                 $this->curr['main_node'] = (string) $element;
143         }
144
145         /**
146          * Getter for main node array
147          *
148          * @return      $mainNodes      Array with valid main node names
149          */
150         public final function getMainNodes () {
151                 return $this->mainNodes;
152         }
153
154         /**
155          * Getter for sub node array
156          *
157          * @return      $subNodes       Array with valid sub node names
158          */
159         public final function getSubNodes () {
160                 return $this->subNodes;
161         }
162
163         /**
164          * Handles the start element of an XML resource
165          *
166          * @param       $resource               XML parser resource (currently ignored)
167          * @param       $element                The element we shall handle
168          * @param       $attributes             All attributes
169          * @return      void
170          * @throws      InvalidXmlNodeException         If an unknown/invalid XML node name was found
171          */
172         public function startElement ($resource, $element, array $attributes) {
173                 // Initial method name which will never be called...
174                 $methodName = 'initNodeRequestNodeList';
175
176                 // Make the element name lower-case
177                 $element = strtolower($element);
178
179                 // Is the element a main node?
180                 //* DEBUG: */ echo "START: &gt;".$element."&lt;<br />\n";
181                 if (in_array($element, $this->getMainNodes())) {
182                         // Okay, main node found!
183                         $methodName = 'start' . $this->convertToClassName($element);
184
185                         // Set it
186                         $this->setCurrMainNode($element);
187                 } elseif (in_array($element, $this->getSubNodes())) {
188                         // Sub node found
189                         $methodName = 'start' . $this->convertToClassName($element);
190                 } else {
191                         // Invalid node name found
192                         throw new InvalidXmlNodeException(array($this, $element, $attributes), XmlParser::EXCEPTION_XML_NODE_UNKNOWN);
193                 }
194
195                 // Call method
196                 call_user_func_array(array($this, $methodName), $attributes);
197         }
198
199         /**
200          * Ends the main or sub node by sending out the gathered data
201          *
202          * @param       $resource       An XML resource pointer (currently ignored)
203          * @param       $nodeName       Name of the node we want to finish
204          * @return      void
205          * @throws      XmlNodeMismatchException        If current main node mismatches the closing one
206          */
207         public function endElement ($resource, $nodeName) {
208                 // Make all lower-case
209                 $nodeName = strtolower($nodeName);
210
211                 // Does this match with current main node?
212                 //* DEBUG: */ echo "END: &gt;".$nodeName."&lt;<br />\n";
213                 if (($nodeName != $this->getCurrMainNode()) && (in_array($nodeName, $this->getMainNodes()))) {
214                         // Did not match!
215                         throw new XmlNodeMismatchException (array($this, $nodeName, $this->getCurrMainNode()), XmlParser::EXCEPTION_XML_NODE_MISMATCH);
216                 } // END - if
217
218                 // Construct method name
219                 $methodName = 'finish' . $this->convertToClassName($nodeName);
220
221                 // Call the corresponding method
222                 //* DEBUG: */ echo "call: ".$methodName."<br />\n";
223                 call_user_func_array(array($this, $methodName), array());
224         }
225
226         /**
227          * Currently not used
228          *
229          * @param       $resource               XML parser resource (currently ignored)
230          * @param       $characters             Characters to handle
231          * @return      void
232          * @todo        Find something useful with this!
233          */
234         public function characterHandler ($resource, $characters) {
235                 // Trim all spaces away
236                 $characters = trim($characters);
237
238                 // Is this string empty?
239                 if (empty($characters)) {
240                         // Then skip it silently
241                         return false;
242                 } // END - if
243
244                 // Assign data with matching variable here
245                 parent::assignVariable($this->getStackerInstance()->getNamed('node_request_node_list'), $characters);
246         }
247
248         /**
249          * Getter for cache file (FQFN)
250          *
251          * @return      $fqfn   Full-qualified file name of the menu cache
252          */
253         public function getNodeRequestNodeListCacheFqfn () {
254                 $this->partialStub('Please implement this method.');
255         }
256
257         /**
258          * Starts the node-request-node-list
259          *
260          * @return      void
261          */
262         private function startNodeRequestNodeList () {
263                 // Push the node name on the stacker
264                 $this->getStackerInstance()->pushNamed('node_request_node_list', 'node-request-node-list');
265         }
266
267         /**
268          * Starts the accepted-object-types
269          *
270          * @return      void
271          */
272         private function startAcceptedObjectTypes () {
273                 // Push the node name on the stacker
274                 $this->getStackerInstance()->pushNamed('node_request_node_list', 'accepted-object-types');
275         }
276
277         /**
278          * Finishes the accepted-object-types
279          *
280          * @return      void
281          */
282         private function finishAcceptedObjectTypes () {
283                 // Pop the last entry
284                 $this->getStackerInstance()->popNamed('node_request_node_list');
285         }
286
287         /**
288          * Finishes the node-request-node-list
289          *
290          * @return      void
291          */
292         private function finishNodeRequestNodeList () {
293                 // Pop the last entry
294                 $this->getStackerInstance()->popNamed('node_request_node_list');
295         }
296 }
297
298 // [EOF]
299 ?>