3 * An ObjectRegistry template engine class for XML templates
5 * @author Roland Haeder <webmaster@ship-simu.org>
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()
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.
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.
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/>.
25 class XmlObjectRegistryTemplateEngine extends BaseXmlTemplateEngine implements CompileableTemplate, Registerable {
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';
34 * Instance for the object registry
36 private $objectRegistryInstance = NULL;
39 * Protected constructor
43 protected function __construct () {
44 // Call parent constructor
45 parent::__construct(__CLASS__);
47 // Init object type registry instance
48 $this->objectRegistryInstance = ObjectTypeRegistryFactory::createObjectTypeRegistryInstance();
51 $this->subNodes = array(
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
63 * Creates an instance of the class TemplateEngine and prepares it for usage
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
73 public static final function createXmlObjectRegistryTemplateEngine () {
75 $templateInstance = new XmlObjectRegistryTemplateEngine();
77 // Init template instance
78 $templateInstance->initXmlTemplateEngine('node', 'object_registry');
80 // Return the prepared instance
81 return $templateInstance;
87 * @param $resource XML parser resource (currently ignored)
88 * @param $characters Characters to handle
90 * @todo Find something useful with this!
92 public function characterHandler ($resource, $characters) {
93 // Trim all spaces away
94 $characters = trim($characters);
96 // Is this string empty?
97 if (empty($characters)) {
98 // Then skip it silently
102 // Get current XML node name as an array index
103 $nodeName = $this->getStackerInstance()->getNamed('node_object_registry');
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[' . __LINE__ . ']: Adding object type ' . $characters . ' to registry.');
111 // Add it to the registry
112 $this->objectRegistryInstance->addEntry($nodeName, $characters);
116 * Getter for cache file (FQFN)
118 * @return $fqfn Full-qualified file name of the menu cache
120 public function getObjectRegistryCacheFqfn () {
121 $this->partialStub('Please implement this method.');
125 * Starts the object-registry
129 protected function startObjectRegistry () {
130 // Push the node name on the stacker
131 $this->getStackerInstance()->pushNamed('node_object_registry', 'object-registry');
135 * Starts the object-list
137 * @param $objectCount Count of all objects
139 * @todo Handle $objectCount
141 protected function startObjectList ($objectCount) {
142 // Push the node name on the stacker
143 $this->getStackerInstance()->pushNamed('node_object_registry', 'object-list');
147 * Starts the object-list-entry
151 protected function startObjectListEntry () {
152 // Push the node name on the stacker
153 $this->getStackerInstance()->pushNamed('node_object_registry', 'object-list');
157 * Starts the object-name
161 protected function startObjectName () {
162 // Push the node name on the stacker
163 $this->getStackerInstance()->pushNamed('node_object_registry', self::OBJECT_TYPE_DATA_NAME);
167 * Starts the object-recipient-limitation
171 protected function startObjectRecipientLimitation () {
172 // Push the node name on the stacker
173 $this->getStackerInstance()->pushNamed('node_object_registry', self::OBJECT_TYPE_DATA_RECIPIENT_LIMITATION);
177 * Starts the object-max-spread
181 protected function startObjectMaxSpread () {
182 // Push the node name on the stacker
183 $this->getStackerInstance()->pushNamed('node_object_registry', self::OBJECT_TYPE_DATA_MAX_SPREAD);
187 * Starts the object-protocol
191 protected function startObjectProtocol () {
192 // Push the node name on the stacker
193 $this->getStackerInstance()->pushNamed('node_object_registry', self::OBJECT_TYPE_DATA_PROTOCOL);
197 * Starts the object-recipient-type
201 protected function startObjectRecipientType () {
202 // Push the node name on the stacker
203 $this->getStackerInstance()->pushNamed('node_object_registry', self::OBJECT_TYPE_DATA_RECIPIENT_TYPE);
207 * Finishes the object-recipient-type
211 protected function finishObjectRecipientType () {
212 // Pop the last entry
213 $this->getStackerInstance()->popNamed('node_object_registry');
217 * Finishes the object-protocol
221 protected function finishObjectProtocol () {
222 // Pop the last entry
223 $this->getStackerInstance()->popNamed('node_object_registry');
227 * Finishes the object-max-spread
231 protected function finishObjectMaxSpread () {
232 // Pop the last entry
233 $this->getStackerInstance()->popNamed('node_object_registry');
237 * Finishes the object-recipient-limitation
241 protected function finishObjectRecipientLimitation () {
242 // Pop the last entry
243 $this->getStackerInstance()->popNamed('node_object_registry');
247 * Finishes the object-name
251 protected function finishObjectName () {
252 // Pop the last entry
253 $this->getStackerInstance()->popNamed('node_object_registry');
257 * Finishes the object-list-entry
261 protected function finishObjectListEntry () {
262 // Pop the last entry
263 $this->getStackerInstance()->popNamed('node_object_registry');
267 * Finishes the object-list
271 protected function finishObjectList () {
272 // Pop the last entry
273 $this->getStackerInstance()->popNamed('node_object_registry');
277 * Finishes the object-registry
281 protected function finishObjectRegistry () {
282 // Pop the last entry
283 $this->getStackerInstance()->popNamed('node_object_registry');