]> git.mxchange.org Git - hub.git/blob - application/hub/main/template/objects/class_XmlObjectRegistryTemplateEngine.php
More fixes: private->protected changed, generic init of stacker
[hub.git] / application / hub / main / template / objects / class_XmlObjectRegistryTemplateEngine.php
1 <?php
2 /**
3  * An ObjectRegistry 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 XmlObjectRegistryTemplateEngine extends BaseXmlTemplateEngine implements CompileableTemplate, Registerable {
26         // Constants
27         const OBJECT_TYPE_DATA_NAME                 = 'object-name';
28         const OBJECT_TYPE_DATA_RECIPIENT_LIMITATION = 'object-recipient-limitation';
29         const OBJECT_TYPE_DATA_MAX_SPREAD           = 'object-max-spread';
30         const OBJECT_TYPE_DATA_PROTOCOL             = 'object-protocol';
31         const OBJECT_TYPE_DATA_RECIPIENT_TYPE       = 'object-recipient-type';
32
33         /**
34          * Instance for the object registry
35          */
36         private $objectRegistryInstance = NULL;
37
38         /**
39          * Protected constructor
40          *
41          * @return      void
42          */
43         protected function __construct () {
44                 // Call parent constructor
45                 parent::__construct(__CLASS__);
46
47                 // Init object type registry instance
48                 $this->objectRegistryInstance = ObjectTypeRegistryFactory::createObjectTypeRegistryInstance();
49
50                 // Init sub nodes
51                 $this->subNodes = array(
52                         'object-list',
53                         'object-list-entry',
54                         self::OBJECT_TYPE_DATA_NAME,
55                         self::OBJECT_TYPE_DATA_RECIPIENT_LIMITATION,
56                         self::OBJECT_TYPE_DATA_MAX_SPREAD,
57                         self::OBJECT_TYPE_DATA_PROTOCOL,
58                         self::OBJECT_TYPE_DATA_RECIPIENT_TYPE
59                 );
60         }
61
62         /**
63          * Creates an instance of the class TemplateEngine and prepares it for usage
64          *
65          * @return      $templateInstance               An instance of TemplateEngine
66          * @throws      BasePathIsEmptyException                If the provided $templateBasePath is empty
67          * @throws      InvalidBasePathStringException  If $templateBasePath is no string
68          * @throws      BasePathIsNoDirectoryException  If $templateBasePath is no
69          *                                                                                      directory or not found
70          * @throws      BasePathReadProtectedException  If $templateBasePath is
71          *                                                                                      read-protected
72          */
73         public static final function createXmlObjectRegistryTemplateEngine () {
74                 // Get a new instance
75                 $templateInstance = new XmlObjectRegistryTemplateEngine();
76
77                 // Init template instance
78                 $templateInstance->initXmlTemplateEngine('node', 'object_registry');
79
80                 // Return the prepared instance
81                 return $templateInstance;
82         }
83
84         /**
85          * Load a specified object_registry template into the engine
86          *
87          * @param       $template       The object_registry template we shall load which is
88          *                                              located in 'object_registry' by default
89          * @return      void
90          */
91         public function loadObjectRegistryTemplate ($template = 'object_registry') {
92                 // Set template type
93                 $this->setTemplateType($this->getConfigInstance()->getConfigEntry('node_object_registry_template_type'));
94
95                 // Load the special template
96                 $this->loadTemplate($template);
97         }
98
99         /**
100          * Currently not used
101          *
102          * @param       $resource               XML parser resource (currently ignored)
103          * @param       $characters             Characters to handle
104          * @return      void
105          * @todo        Find something useful with this!
106          */
107         public function characterHandler ($resource, $characters) {
108                 // Trim all spaces away
109                 $characters = trim($characters);
110
111                 // Is this string empty?
112                 if (empty($characters)) {
113                         // Then skip it silently
114                         return false;
115                 } // END - if
116
117                 // Get current XML node name as an array index
118                 $nodeName = $this->getStackerInstance()->getNamed('object_registry');
119
120                 // Is the node name self::OBJECT_TYPE_DATA_NAME?
121                 if ($nodeName == self::OBJECT_TYPE_DATA_NAME) {
122                         // Output debug message
123                         self::createDebugInstance(__CLASS__)->debugOutput('TAGS: Adding object type ' . $characters . ' to registry.');
124                 } // END - if
125
126                 // Add it to the registry
127                 $this->objectRegistryInstance->addEntry($nodeName, $characters);
128         }
129
130         /**
131          * Getter for cache file (FQFN)
132          *
133          * @return      $fqfn   Full-qualified file name of the menu cache
134          */
135         public function getObjectRegistryCacheFqfn () {
136                 $this->partialStub('Please implement this method.');
137         }
138
139         /**
140          * Starts the object-registry
141          *
142          * @return      void
143          */
144         protected function startObjectRegistry () {
145                 // Push the node name on the stacker
146                 $this->getStackerInstance()->pushNamed('object_registry', 'object-registry');
147         }
148
149         /**
150          * Starts the object-list
151          *
152          * @param       $objectCount    Count of all objects
153          * @return      void
154          * @todo        Handle $objectCount
155          */
156         protected function startObjectList ($objectCount) {
157                 // Push the node name on the stacker
158                 $this->getStackerInstance()->pushNamed('object_registry', 'object-list');
159         }
160
161         /**
162          * Starts the object-list-entry
163          *
164          * @return      void
165          */
166         protected function startObjectListEntry () {
167                 // Push the node name on the stacker
168                 $this->getStackerInstance()->pushNamed('object_registry', 'object-list');
169         }
170
171         /**
172          * Starts the object-name
173          *
174          * @return      void
175          */
176         protected function startObjectName () {
177                 // Push the node name on the stacker
178                 $this->getStackerInstance()->pushNamed('object_registry', self::OBJECT_TYPE_DATA_NAME);
179         }
180
181         /**
182          * Starts the object-recipient-limitation
183          *
184          * @return      void
185          */
186         protected function startObjectRecipientLimitation () {
187                 // Push the node name on the stacker
188                 $this->getStackerInstance()->pushNamed('object_registry', self::OBJECT_TYPE_DATA_RECIPIENT_LIMITATION);
189         }
190
191         /**
192          * Starts the object-max-spread
193          *
194          * @return      void
195          */
196         protected function startObjectMaxSpread () {
197                 // Push the node name on the stacker
198                 $this->getStackerInstance()->pushNamed('object_registry', self::OBJECT_TYPE_DATA_MAX_SPREAD);
199         }
200
201         /**
202          * Starts the object-protocol
203          *
204          * @return      void
205          */
206         protected function startObjectProtocol () {
207                 // Push the node name on the stacker
208                 $this->getStackerInstance()->pushNamed('object_registry', self::OBJECT_TYPE_DATA_PROTOCOL);
209         }
210
211         /**
212          * Starts the object-recipient-type
213          *
214          * @return      void
215          */
216         protected function startObjectRecipientType () {
217                 // Push the node name on the stacker
218                 $this->getStackerInstance()->pushNamed('object_registry', self::OBJECT_TYPE_DATA_RECIPIENT_TYPE);
219         }
220
221         /**
222          * Finishes the object-recipient-type
223          *
224          * @return      void
225          */
226         protected function finishObjectRecipientType () {
227                 // Pop the last entry
228                 $this->getStackerInstance()->popNamed('object_registry');
229         }
230
231         /**
232          * Finishes the object-protocol
233          *
234          * @return      void
235          */
236         protected function finishObjectProtocol () {
237                 // Pop the last entry
238                 $this->getStackerInstance()->popNamed('object_registry');
239         }
240
241         /**
242          * Finishes the object-max-spread
243          *
244          * @return      void
245          */
246         protected function finishObjectMaxSpread () {
247                 // Pop the last entry
248                 $this->getStackerInstance()->popNamed('object_registry');
249         }
250
251         /**
252          * Finishes the object-recipient-limitation
253          *
254          * @return      void
255          */
256         protected function finishObjectRecipientLimitation () {
257                 // Pop the last entry
258                 $this->getStackerInstance()->popNamed('object_registry');
259         }
260
261         /**
262          * Finishes the object-name
263          *
264          * @return      void
265          */
266         protected function finishObjectName () {
267                 // Pop the last entry
268                 $this->getStackerInstance()->popNamed('object_registry');
269         }
270
271         /**
272          * Finishes the object-list-entry
273          *
274          * @return      void
275          */
276         protected function finishObjectListEntry () {
277                 // Pop the last entry
278                 $this->getStackerInstance()->popNamed('object_registry');
279         }
280
281         /**
282          * Finishes the object-list
283          *
284          * @return      void
285          */
286         protected function finishObjectList () {
287                 // Pop the last entry
288                 $this->getStackerInstance()->popNamed('object_registry');
289         }
290
291         /**
292          * Finishes the object-registry
293          *
294          * @return      void
295          */
296         protected function finishObjectRegistry () {
297                 // Pop the last entry
298                 $this->getStackerInstance()->popNamed('object_registry');
299         }
300 }
301
302 // [EOF]
303 ?>