]> git.mxchange.org Git - hub.git/blobdiff - application/hub/main/template/class_BaseXmlTemplateEngine.php
Continued:
[hub.git] / application / hub / main / template / class_BaseXmlTemplateEngine.php
index 16ce5159ea4df9726482e7c0b7478545ba230537..8d2c54de53f2a064553848775ff4cd00f84e344d 100644 (file)
@@ -2,11 +2,11 @@
 /**
  * A generic XML template engine class
  *
- * @author             Roland Haeder <webmaster@ship-simu.org>
+ * @author             Roland Haeder <webmaster@shipsimu.org>
  * @version            0.0.0
  * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2012 Core Developer Team
  * @license            GNU GPL 3.0 or any newer version
- * @link               http://www.ship-simu.org
+ * @link               http://www.shipsimu.org
  * @todo               This template engine does not make use of setTemplateType()
  *
  * This program is free software: you can redistribute it and/or modify
@@ -22,7 +22,7 @@
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
-class BaseXMLTemplateEngine extends BaseTemplateEngine {
+class BaseXmlTemplateEngine extends BaseTemplateEngine {
        /**
         * Main nodes in the XML tree
         */
@@ -48,6 +48,11 @@ class BaseXMLTemplateEngine extends BaseTemplateEngine {
         */
        private $typePrefix = 'xml';
 
+       /**
+        * Name of stacker
+        */
+       private $stackerName = '';
+
        /**
         * Content from dependency
         */
@@ -110,13 +115,16 @@ class BaseXMLTemplateEngine extends BaseTemplateEngine {
                $this->setCompileOutputPath($this->getConfigInstance()->getConfigEntry('base_path') . $this->getConfigInstance()->getConfigEntry('compile_output_path'));
 
                // Init a variable stacker
-               $stackerInstance = ObjectFactory::createObjectByConfiguredName($typePrefix . '_' . $xmlTemplateType . '_stacker_class');
+               $stackInstance = ObjectFactory::createObjectByConfiguredName($typePrefix . '_' . $xmlTemplateType . '_stacker_class');
+
+               // Set name
+               $this->stackerName = $typePrefix . '_' . $xmlTemplateType;
 
                // Init stacker
-               $stackerInstance->initStacker($xmlTemplateType);
+               $stackInstance->initStack($this->stackerName);
 
                // Set it
-               $this->setStackerInstance($stackerInstance);
+               $this->setStackInstance($stackInstance);
 
                // Set XML template type and prefix
                $this->xmlTemplateType = $xmlTemplateType;
@@ -129,15 +137,21 @@ class BaseXMLTemplateEngine extends BaseTemplateEngine {
        /**
         * Load a specified XML template into the engine
         *
-        * @param       $template       The XML template we shall load
+        * @param       $templateName   Optional name of template
         * @return      void
         */
-       public function loadXmlTemplate ($template) {
+       public function loadXmlTemplate ($templateName = '') {
+               // Is the template name empty?
+               if (empty($templateName)) {
+                       // Set generic template name
+                       $templateName = $this->typePrefix . '_' . $this->xmlTemplateType . '_template_type';
+               } // END - if
+
                // Set template type
-               $this->setTemplateType($this->getConfigInstance()->getConfigEntry($this->xmlTemplateType . '_template_type'));
+               $this->setTemplateType($this->getConfigInstance()->getConfigEntry($templateName));
 
                // Load the special template
-               $this->loadTemplate($template);
+               $this->loadTemplate($this->xmlTemplateType);
        }
 
        /**
@@ -168,6 +182,15 @@ class BaseXMLTemplateEngine extends BaseTemplateEngine {
                return $this->mainNodes;
        }
 
+       /**
+        * Getter for stacker name
+        *
+        * @return      $stackerName    Name of stacker of this class
+        */
+       protected final function getStackerName () {
+               return $this->stackerName;
+       }
+
        /**
         * Getter for sub node array
         *
@@ -177,6 +200,27 @@ class BaseXMLTemplateEngine extends BaseTemplateEngine {
                return $this->subNodes;
        }
 
+       /**
+        * Read XML variables by calling readVariable() with 'general' as
+        * variable stack.
+        *
+        * @param       $key    Key to read from
+        * @return      $value  Value from variable
+        */
+       public function readXmlData ($key) {
+               // Read the variable
+               $value = parent::readVariable($key, 'general');
+
+               // Is this null?
+               if (is_null($value)) {
+                       // Bah, needs fixing.
+                       $this->debugInstance('key=' . $key . ' returns NULL');
+               } // END - if
+
+               // Return value
+               return $value;
+       }
+
        /**
         * Handles the template dependency for given node
         *
@@ -185,16 +229,16 @@ class BaseXMLTemplateEngine extends BaseTemplateEngine {
         * @return      void
         */
        protected function handleTemplateDependency ($node, $templateDependency) {
+               // Check that node is not empty
+               assert(!empty($node));
+
                // Is the template dependency set?
                if ((!empty($templateDependency)) && (!isset($this->dependencyContent[$node]))) {
                        // Get a temporay template instance
-                       $templateInstance = XmlTemplateEngineFactory::createXmlTemplateEngineInstance($this->typePrefix . '__' . $this->xmlTemplateType . '_template_class');
-
-                       // Create method name
-                       $methodName = 'load' . $this->convertToClassName($this->xmlTemplateType) . 'Template';
+                       $templateInstance = XmlTemplateEngineFactory::createXmlTemplateEngineInstance($this->typePrefix . '_' . $this->convertDashesToUnderscores($node) . '_' . $this->xmlTemplateType . '_template_class');
 
                        // Then load it
-                       call_user_func(array($templateInstance, $methodName), $templateDependency);
+                       $templateInstance->loadXmlTemplate($templateDependency);
 
                        // Parse the XML content
                        $templateInstance->renderXmlContent();
@@ -248,7 +292,7 @@ class BaseXMLTemplateEngine extends BaseTemplateEngine {
         * @return      void
         * @throws      XmlNodeMismatchException        If current main node mismatches the closing one
         */
-       public final function endElement ($resource, $nodeName) {
+       public final function finishElement ($resource, $nodeName) {
                // Make all lower-case
                $nodeName = strtolower($nodeName);