Updated 'core'.
[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@shipsimu.org>
6  * @version             0.0.0
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()
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->setSubNodes(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          * Currently not used
86          *
87          * @param       $resource               XML parser resource (currently ignored)
88          * @param       $characters             Characters to handle
89          * @return      void
90          * @todo        Find something useful with this!
91          */
92         public function characterHandler ($resource, $characters) {
93                 // Trim all spaces away
94                 $characters = trim($characters);
95
96                 // Is this string empty?
97                 if (empty($characters)) {
98                         // Then skip it silently
99                         return;
100                 } // END - if
101
102                 // Get current XML node name as an array index
103                 $nodeName = $this->getStackInstance()->getNamed('node_object_registry');
104
105                 // Is the node name self::OBJECT_TYPE_DATA_NAME?
106                 if ($nodeName == self::OBJECT_TYPE_DATA_NAME) {
107                         // Output debug message
108                         self::createDebugInstance(__CLASS__)->debugOutput('TAGS[' . __METHOD__ . ':' . __LINE__ . ']: Adding object type ' . $characters . ' to registry.');
109                 } // END - if
110
111                 // Add it to the registry
112                 $this->objectRegistryInstance->addEntry($nodeName, $characters);
113         }
114
115         /**
116          * Getter for cache file (FQFN)
117          *
118          * @return      $fqfn   Full-qualified file name of the menu cache
119          */
120         public function getObjectRegistryCacheFqfn () {
121                 $this->partialStub('Please implement this method.');
122         }
123
124         /**
125          * Starts the object-registry
126          *
127          * @return      void
128          */
129         protected function startObjectRegistry () {
130                 // Push the node name on the stacker
131                 $this->getStackInstance()->pushNamed('node_object_registry', 'object-registry');
132         }
133
134         /**
135          * Starts the object-list
136          *
137          * @param       $objectCount    Count of all objects
138          * @return      void
139          * @todo        Handle $objectCount
140          */
141         protected function startObjectList ($objectCount) {
142                 // Push the node name on the stacker
143                 $this->getStackInstance()->pushNamed('node_object_registry', 'object-list');
144         }
145
146         /**
147          * Starts the object-list-entry
148          *
149          * @return      void
150          */
151         protected function startObjectListEntry () {
152                 // Push the node name on the stacker
153                 $this->getStackInstance()->pushNamed('node_object_registry', 'object-list-entry');
154         }
155
156         /**
157          * Starts the object-name
158          *
159          * @return      void
160          */
161         protected function startObjectName () {
162                 // Push the node name on the stacker
163                 $this->getStackInstance()->pushNamed('node_object_registry', self::OBJECT_TYPE_DATA_NAME);
164         }
165
166         /**
167          * Starts the object-recipient-limitation
168          *
169          * @return      void
170          */
171         protected function startObjectRecipientLimitation () {
172                 // Push the node name on the stacker
173                 $this->getStackInstance()->pushNamed('node_object_registry', self::OBJECT_TYPE_DATA_RECIPIENT_LIMITATION);
174         }
175
176         /**
177          * Starts the object-max-spread
178          *
179          * @return      void
180          */
181         protected function startObjectMaxSpread () {
182                 // Push the node name on the stacker
183                 $this->getStackInstance()->pushNamed('node_object_registry', self::OBJECT_TYPE_DATA_MAX_SPREAD);
184         }
185
186         /**
187          * Starts the object-protocol
188          *
189          * @return      void
190          */
191         protected function startObjectProtocol () {
192                 // Push the node name on the stacker
193                 $this->getStackInstance()->pushNamed('node_object_registry', self::OBJECT_TYPE_DATA_PROTOCOL);
194         }
195
196         /**
197          * Starts the object-recipient-type
198          *
199          * @return      void
200          */
201         protected function startObjectRecipientType () {
202                 // Push the node name on the stacker
203                 $this->getStackInstance()->pushNamed('node_object_registry', self::OBJECT_TYPE_DATA_RECIPIENT_TYPE);
204         }
205
206         /**
207          * Finishes the object-recipient-type
208          *
209          * @return      void
210          */
211         protected function finishObjectRecipientType () {
212                 // Pop the last entry
213                 $this->getStackInstance()->popNamed('node_object_registry');
214         }
215
216         /**
217          * Finishes the object-protocol
218          *
219          * @return      void
220          */
221         protected function finishObjectProtocol () {
222                 // Pop the last entry
223                 $this->getStackInstance()->popNamed('node_object_registry');
224         }
225
226         /**
227          * Finishes the object-max-spread
228          *
229          * @return      void
230          */
231         protected function finishObjectMaxSpread () {
232                 // Pop the last entry
233                 $this->getStackInstance()->popNamed('node_object_registry');
234         }
235
236         /**
237          * Finishes the object-recipient-limitation
238          *
239          * @return      void
240          */
241         protected function finishObjectRecipientLimitation () {
242                 // Pop the last entry
243                 $this->getStackInstance()->popNamed('node_object_registry');
244         }
245
246         /**
247          * Finishes the object-name
248          *
249          * @return      void
250          */
251         protected function finishObjectName () {
252                 // Pop the last entry
253                 $this->getStackInstance()->popNamed('node_object_registry');
254         }
255
256         /**
257          * Finishes the object-list-entry
258          *
259          * @return      void
260          */
261         protected function finishObjectListEntry () {
262                 // Pop the last entry
263                 $this->getStackInstance()->popNamed('node_object_registry');
264         }
265
266         /**
267          * Finishes the object-list
268          *
269          * @return      void
270          */
271         protected function finishObjectList () {
272                 // Pop the last entry
273                 $this->getStackInstance()->popNamed('node_object_registry');
274         }
275
276         /**
277          * Finishes the object-registry
278          *
279          * @return      void
280          */
281         protected function finishObjectRegistry () {
282                 // Pop the last entry
283                 $this->getStackInstance()->popNamed('node_object_registry');
284         }
285 }
286
287 // [EOF]
288 ?>