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;
85 * Load a specified object_registry template into the engine
87 * @param $template The object_registry template we shall load which is
88 * located in 'object_registry' by default
91 public function loadObjectRegistryTemplate ($template = 'object_registry') {
93 $this->setTemplateType($this->getConfigInstance()->getConfigEntry('node_object_registry_template_type'));
95 // Load the special template
96 $this->loadTemplate($template);
102 * @param $resource XML parser resource (currently ignored)
103 * @param $characters Characters to handle
105 * @todo Find something useful with this!
107 public function characterHandler ($resource, $characters) {
108 // Trim all spaces away
109 $characters = trim($characters);
111 // Is this string empty?
112 if (empty($characters)) {
113 // Then skip it silently
117 // Get current XML node name as an array index
118 $nodeName = $this->getStackerInstance()->getNamed('object_registry');
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.');
126 // Add it to the registry
127 $this->objectRegistryInstance->addEntry($nodeName, $characters);
131 * Getter for cache file (FQFN)
133 * @return $fqfn Full-qualified file name of the menu cache
135 public function getObjectRegistryCacheFqfn () {
136 $this->partialStub('Please implement this method.');
140 * Starts the object-registry
144 private function startObjectRegistry () {
145 // Push the node name on the stacker
146 $this->getStackerInstance()->pushNamed('object_registry', 'object-registry');
150 * Starts the object-list
152 * @param $objectCount Count of all objects
154 * @todo Handle $objectCount
156 private function startObjectList ($objectCount) {
157 // Push the node name on the stacker
158 $this->getStackerInstance()->pushNamed('object_registry', 'object-list');
162 * Starts the object-list-entry
166 private function startObjectListEntry () {
167 // Push the node name on the stacker
168 $this->getStackerInstance()->pushNamed('object_registry', 'object-list');
172 * Starts the object-name
176 private function startObjectName () {
177 // Push the node name on the stacker
178 $this->getStackerInstance()->pushNamed('object_registry', self::OBJECT_TYPE_DATA_NAME);
182 * Starts the object-recipient-limitation
186 private function startObjectRecipientLimitation () {
187 // Push the node name on the stacker
188 $this->getStackerInstance()->pushNamed('object_registry', self::OBJECT_TYPE_DATA_RECIPIENT_LIMITATION);
192 * Starts the object-max-spread
196 private function startObjectMaxSpread () {
197 // Push the node name on the stacker
198 $this->getStackerInstance()->pushNamed('object_registry', self::OBJECT_TYPE_DATA_MAX_SPREAD);
202 * Starts the object-protocol
206 private function startObjectProtocol () {
207 // Push the node name on the stacker
208 $this->getStackerInstance()->pushNamed('object_registry', self::OBJECT_TYPE_DATA_PROTOCOL);
212 * Starts the object-recipient-type
216 private function startObjectRecipientType () {
217 // Push the node name on the stacker
218 $this->getStackerInstance()->pushNamed('object_registry', self::OBJECT_TYPE_DATA_RECIPIENT_TYPE);
222 * Finishes the object-recipient-type
226 private function finishObjectRecipientType () {
227 // Pop the last entry
228 $this->getStackerInstance()->popNamed('object_registry');
232 * Finishes the object-protocol
236 private function finishObjectProtocol () {
237 // Pop the last entry
238 $this->getStackerInstance()->popNamed('object_registry');
242 * Finishes the object-max-spread
246 private function finishObjectMaxSpread () {
247 // Pop the last entry
248 $this->getStackerInstance()->popNamed('object_registry');
252 * Finishes the object-recipient-limitation
256 private function finishObjectRecipientLimitation () {
257 // Pop the last entry
258 $this->getStackerInstance()->popNamed('object_registry');
262 * Finishes the object-name
266 private function finishObjectName () {
267 // Pop the last entry
268 $this->getStackerInstance()->popNamed('object_registry');
272 * Finishes the object-list-entry
276 private function finishObjectListEntry () {
277 // Pop the last entry
278 $this->getStackerInstance()->popNamed('object_registry');
282 * Finishes the object-list
286 private function finishObjectList () {
287 // Pop the last entry
288 $this->getStackerInstance()->popNamed('object_registry');
292 * Finishes the object-registry
296 private function finishObjectRegistry () {
297 // Pop the last entry
298 $this->getStackerInstance()->popNamed('object_registry');