]> git.mxchange.org Git - hub.git/blobdiff - application/hub/main/template/class_BaseXmlTemplateEngine.php
Introduced experimental apt-proxy sub project (a connector for apt-proxy usage into...
[hub.git] / application / hub / main / template / class_BaseXmlTemplateEngine.php
index 5d28ceecd4a17588a2c212c4fa6ae2b22d96018b..ba1b9b8b8355e1cabf42693345350eed476a2770 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
         */
@@ -112,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);
 
@@ -120,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);
        }
 
        /**
@@ -174,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
         *
@@ -187,11 +211,8 @@ class BaseXMLTemplateEngine extends BaseTemplateEngine {
                        // Get a temporay template instance
                        $templateInstance = XmlTemplateEngineFactory::createXmlTemplateEngineInstance($this->typePrefix . '__' . $this->xmlTemplateType . '_template_class');
 
-                       // Create method name
-                       $methodName = 'load' . $this->convertToClassName($this->xmlTemplateType) . 'Template';
-
                        // Then load it
-                       call_user_func(array($templateInstance, $methodName), $templateDependency);
+                       $templateInstance->loadXmlTemplate($templateDependency);
 
                        // Parse the XML content
                        $templateInstance->renderXmlContent();