]> git.mxchange.org Git - hub.git/blobdiff - application/hub/main/template/class_BaseXmlTemplateEngine.php
Added template class for entries in a request-node-list
[hub.git] / application / hub / main / template / class_BaseXmlTemplateEngine.php
index 0027674180fb47eb4aee169b44b501944b6d9487..d46c5a1b36988c6ffaff249a5566a8ff3fdc0cd4 100644 (file)
@@ -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
         */
@@ -78,6 +78,9 @@ class BaseXMLTemplateEngine extends BaseTemplateEngine {
         *                                                                                      read-protected
         */
        protected function initXmlTemplateEngine ($typePrefix, $xmlTemplateType) {
+               // Get template instance
+               $applicationInstance = Registry::getRegistry()->getInstance('app');
+
                // Determine base path
                $templateBasePath = $this->getConfigInstance()->getConfigEntry('application_base_path') . $applicationInstance->getRequestInstance()->getRequestElement('app') . '/';
 
@@ -101,7 +104,7 @@ class BaseXMLTemplateEngine extends BaseTemplateEngine {
 
                // Set template extensions
                $this->setRawTemplateExtension($this->getConfigInstance()->getConfigEntry('raw_template_extension'));
-               $this->setCodeTemplateExtension($this->getConfigInstance()->getConfigEntry($typePrefix . '__message_template_extension'));
+               $this->setCodeTemplateExtension($this->getConfigInstance()->getConfigEntry($typePrefix . '_message_template_extension'));
 
                // Absolute output path for compiled templates
                $this->setCompileOutputPath($this->getConfigInstance()->getConfigEntry('base_path') . $this->getConfigInstance()->getConfigEntry('compile_output_path'));
@@ -109,6 +112,9 @@ class BaseXMLTemplateEngine extends BaseTemplateEngine {
                // Init a variable stacker
                $stackerInstance = ObjectFactory::createObjectByConfiguredName($typePrefix . '_' . $xmlTemplateType . '_stacker_class');
 
+               // Init stacker
+               $stackerInstance->initStacker($typePrefix . '_' . $xmlTemplateType);
+
                // Set it
                $this->setStackerInstance($stackerInstance);
 
@@ -117,21 +123,27 @@ class BaseXMLTemplateEngine extends BaseTemplateEngine {
                $this->typePrefix      = $typePrefix;
 
                // Set it in main nodes
-               array_push($this->mainNodes, $xmlTemplateType);
+               array_push($this->mainNodes, str_replace('_', '-', $xmlTemplateType));
        }
 
        /**
         * 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);
        }
 
        /**
@@ -171,6 +183,21 @@ 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');
+
+               // Return value
+               return $value;
+       }
+
        /**
         * Handles the template dependency for given node
         *
@@ -179,16 +206,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();