Added missing methods and removed methods that have already protected access level.
[core.git] / inc / classes / main / decorator / template / class_XmlRewriterTemplateDecorator.php
1 <?php
2 /**
3  * A decorator for XML template engines which rewrites the XML for compacting
4  * it.
5  *
6  * @author              Roland Haeder <webmaster@shipsimu.org>
7  * @version             0.0.0
8  * @copyright   Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Core Developer Team
9  * @license             GNU GPL 3.0 or any newer version
10  * @link                http://www.shipsimu.org
11  *
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.
16  *
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.
21  *
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/>.
24  */
25 class XmlRewriterTemplateDecorator extends BaseDecorator implements CompileableTemplate {
26         /**
27          * Protected constructor
28          *
29          * @return      void
30          */
31         protected function __construct () {
32                 // Call parent constructor
33                 parent::__construct(__CLASS__);
34         }
35
36         /**
37          * Creates an instance of the class TemplateEngine and prepares it for usage
38          *
39          * @param       $innerTemplateInstance  A CompileableTemplate instance
40          * @return      $templateInstance       An instance of TemplateEngine
41          */
42         public static final function createXmlRewriterTemplateDecorator (CompileableTemplate $innerTemplateInstance) {
43                 // Get a new instance
44                 $templateInstance = new XmlRewriterTemplateDecorator();
45
46                 // Set the inner template engine
47                 $templateInstance->setTemplateInstance($innerTemplateInstance);
48
49                 // Return the prepared instance
50                 return $templateInstance;
51         }
52
53         /**
54          * Settter for variable group
55          *
56          * @param       $groupName      Name of variable group
57          * @param       $add            Whether add this group
58          * @return      void
59          */
60         public function setVariableGroup ($groupName, $add = TRUE) {
61                 // Call the inner class' method
62                 $this->getTemplateInstance()->setVariableGroup($groupName, $add);
63         }
64
65         /**
66          * Adds a variable to current group
67          *
68          * @param       $var    Variable to set
69          * @param       $value  Value to store in variable
70          * @return      void
71          */
72         public function addGroupVariable ($var, $value) {
73                 // Call the inner class' method
74                 $this->getTemplateInstance()->addGroupVariable($var, $value);
75         }
76
77         /**
78          * Getter for base path
79          *
80          * @return      $templateBasePath       The relative base path for all templates
81          */
82         public final function getTemplateBasePath () {
83                 // Call the inner class' method
84                 return $this->getTemplateInstance()->getTemplateBasePath();
85         }
86
87         /**
88          * Getter for generic base path
89          *
90          * @return      $templateBasePath       The relative base path for all templates
91          */
92         public final function getGenericBasePath () {
93                 // Call the inner class' method
94                 return $this->getTemplateInstance()->getGenericBasePath();
95         }
96
97         /**
98          * Getter for template extension
99          *
100          * @return      $templateExtension      The file extension for all uncompiled templates
101          */
102         public final function getRawTemplateExtension () {
103                 // Call the inner class' method
104                 return $this->getTemplateInstance()->getRawTemplateExtension();
105         }
106
107         /**
108          * Getter for given variable group
109          *
110          * @param       $variableGroup  Variable group to check
111          * @return      $varStack               Found variable group
112          */
113         public function getVarStack ($variableGroup) {
114                 // Call the inner class' method
115                 return $this->getTemplateInstance()->getVarStack($variableGroup);
116         }
117
118         /**
119          * Getter for code-template extension
120          *
121          * @return      $codeExtension  The file extension for all code templates
122          */
123         public final function getCodeTemplateExtension () {
124                 // Call the inner class' method
125                 return $this->getTemplateInstance()->getCodeTemplateExtension();
126         }
127
128         /**
129          * Getter for template type
130          *
131          * @return      $templateType   The current template's type
132          */
133         public final function getTemplateType () {
134                 // Call the inner class' method
135                 return $this->getTemplateInstance()->getTemplateType();
136         }
137
138         /**
139          * Assign (add) a given variable with a value
140          *
141          * @param       $var    The variable we are looking for
142          * @param       $value  The value we want to store in the variable
143          * @return      void
144          * @throws      EmptyVariableException  If the variable name is left empty
145          */
146         public function assignVariable ($var, $value) {
147                 // Call the inner class' method
148                 $this->getTemplateInstance()->assignVariable($var, $value);
149         }
150
151         /**
152          * Removes a given variable
153          *
154          * @param       $variableName   The variable we are looking for
155          * @param       $variableGroup  Name of variable group (default: 'general')
156          * @return      void
157          */
158         public function removeVariable ($variableName, $variableGroup = 'general') {
159                 // Call the inner class' method
160                 $this->getTemplateInstance()->removeVariable($variableName, $variableGroup);
161         }
162
163         /**
164          * Load a specified HTML template into the engine
165          *
166          * @param       $template       The web template we shall load which is located in
167          *                                              'html' by default
168          * @return      void
169          */
170         public function loadHtmlTemplate ($template) {
171                 // Call the inner class' method
172                 $this->getTemplateInstance()->loadHtmlTemplate($template);
173         }
174
175         /**
176          * Assign a given congfiguration variable with a value
177          *
178          * @param       $variableName   The configuration variable we want to assign
179          * @return      void
180          */
181         public function assignConfigVariable ($variableName) {
182                 // Call the inner class' method
183                 $this->getTemplateInstance()->assignConfigVariable($variableName);
184         }
185
186         /**
187          * Load a specified code template into the engine
188          *
189          * @param       $template       The code template we shall load which is
190          *                                              located in 'code' by default
191          * @return      void
192          */
193         public function loadCodeTemplate ($template) {
194                 // Call the inner class' method
195                 $this->getTemplateInstance()->loadCodeTemplate($template);
196         }
197
198         /**
199          * Load a specified email template into the engine for later compilation
200          * with other code/web/email templates.
201          *
202          * @param       $template       The email template we shall load which is
203          *                                              located in "html" by default
204          * @return      void
205          */
206         public function loadEmailTemplate ($template) {
207                 // Call the inner class' method
208                 $this->getTemplateInstance()->loadEmailTemplate($template);
209         }
210
211         /**
212          * Compiles configuration place-holders in all variables. This 'walks'
213          * through the variable stack 'general'. It interprets all values from that
214          * variables as configuration entries after compiling them.
215          *
216          * @return      void
217          */
218         public function compileConfigInVariables () {
219                 // Call the inner class' method
220                 $this->getTemplateInstance()->compileConfigInVariables();
221         }
222
223         /**
224          * Compile all variables by inserting their respective values
225          *
226          * @return      void
227          */
228         public function compileVariables () {
229                 // Call the inner class' method
230                 $this->getTemplateInstance()->compileVariables();
231         }
232
233         /**
234          * Compile all required templates into the current loaded one
235          *
236          * @return      void
237          */
238         public function compileTemplate () {
239                 // Call the inner class' method
240                 $this->getTemplateInstance()->compileTemplate();
241         }
242
243         /**
244          * Assigns the last loaded raw template content with a given variable
245          *
246          * @param       $templateName   Name of the template we want to assign
247          * @param       $variableName   Name of the variable we want to assign
248          * @return      void
249          */
250         public function assignTemplateWithVariable ($templateName, $variableName) {
251                 // Call the inner class' method
252                 $this->getTemplateInstance()->assignTemplateWithVariable($templateName, $variableName);
253         }
254
255         /**
256          * Transfers the content of this template engine to a given response instance
257          *
258          * @param       $responseInstance       An instance of a response class
259          * @return      void
260          */
261         public function transferToResponse (Responseable $responseInstance) {
262                 // Call the inner class' method
263                 $this->getTemplateInstance()->transportToResponse($responseInstance);
264         }
265
266         /**
267          * Assigns all the application data with template variables
268          *
269          * @param       $applicationInstance    A manageable application instance
270          * @return      void
271          */
272         public function assignApplicationData (ManageableApplication $applicationInstance) {
273                 // Call the inner class' method
274                 $this->getTemplateInstance()->assignApplicationData($applicationInstance);
275         }
276
277         /**
278          * "Compiles" a variable by replacing {?var?} with it's content
279          *
280          * @param       $rawCode                        Raw code to compile
281          * @param       $setMatchAsCode         Sets $match if readVariable() returns empty result
282          * @return      $rawCode                        Compile code with inserted variable value
283          */
284         public function compileRawCode ($rawCode, $setMatchAsCode = FALSE) {
285                 return $this->getTemplateInstance()->compileRawCode($rawCode, $setMatchAsCode);
286         }
287
288         /**
289          * Getter for variable group array
290          *
291          * @return      $variableGroups         All variable groups
292          */
293         public final function getVariableGroups () {
294                 // Call the inner class' method
295                 return $this->getTemplateInstance()->getVariableGroups();
296         }
297
298         /**
299          * Getter for raw template data
300          *
301          * @return      $rawTemplateData        The raw data from the template
302          */
303         public function getRawTemplateData () {
304                 // Call the inner class' method
305                 return $this->getTemplateInstance()->getRawTemplateData();
306         }
307
308         /**
309          * Renames a variable in code and in stack
310          *
311          * @param       $oldName        Old name of variable
312          * @param       $newName        New name of variable
313          * @return      void
314          */
315         public function renameVariable ($oldName, $newName) {
316                 // Call the inner class' method
317                 $this->getTemplateInstance()->renameVariable($oldName, $newName);
318         }
319
320         /**
321          * Renders the given XML content
322          *
323          * @param       $content        Valid XML content or if not set the current loaded raw content
324          * @return      void
325          * @throws      XmlParserException      If an XML error was found
326          */
327         public function renderXmlContent ($content = NULL) {
328                 // Call the inner class' method
329                 $this->getTemplateInstance()->renderXmlContent($content);
330         }
331
332         /**
333          * Enables or disables language support
334          *
335          * @param       $languageSupport        New language support setting
336          * @return      void
337          */
338         public function enableLanguageSupport ($languageSupport = TRUE) {
339                 // Call the inner class' method
340                 $this->getTemplateInstance()->enableLanguageSupport($languageSupport);
341         }
342
343         /**
344          * Checks whether language support is enabled
345          *
346          * @return      $languageSupport        Whether language support is enabled or disabled
347          */
348         public function isLanguageSupportEnabled () {
349                 // Call the inner class' method
350                 return $this->getTemplateInstance()->isLanguageSupportEnabled();
351         }
352
353         /**
354          * Enables or disables XML compacting
355          *
356          * @param       $xmlCompacting  New XML compacting setting
357          * @return      void
358          */
359         public function enableXmlCompacting ($xmlCompacting = TRUE) {
360                 // Call the inner class' method
361                 $this->getTemplateInstance()->enableXmlCompacting($xmlCompacting);
362         }
363
364         /**
365          * Checks whether XML compacting is enabled
366          *
367          * @return      $xmlCompacting  Whether XML compacting is enabled or disabled
368          */
369         public function isXmlCompactingEnabled () {
370                 // Call the inner class' method
371                 return $this->getTemplateInstance()->isXmlCompactingEnabled();
372         }
373
374         /**
375          * Handles the start element of an XML resource
376          *
377          * @param       $resource               XML parser resource (currently ignored)
378          * @param       $element                The element we shall handle
379          * @param       $attributes             All attributes
380          * @return      void
381          * @throws      InvalidXmlNodeException         If an unknown/invalid XML node name was found
382          */
383         public function startElement ($resource, $element, array $attributes) {
384                 // Call the inner class' method
385                 $this->getTemplateInstance()->startElement($resource, $element, $attributes);
386         }
387
388         /**
389          * Ends the main or sub node by sending out the gathered data
390          *
391          * @param       $resource       An XML resource pointer (currently ignored)
392          * @param       $nodeName       Name of the node we want to finish
393          * @return      void
394          * @throws      XmlNodeMismatchException        If current main node mismatches the closing one
395          */
396         public function finishElement ($resource, $nodeName) {
397                 // Call the inner class' method
398                 $this->getTemplateInstance()->finishElement($resource, $nodeName);
399         }
400
401         /**
402          * Currently not used
403          *
404          * @param       $resource               XML parser resource (currently ignored)
405          * @param       $characters             Characters to handle
406          * @return      void
407          * @todo        Find something useful with this!
408          */
409         public function characterHandler ($resource, $characters) {
410                 // Call the inner class' method but trim the characters before
411                 $this->getTemplateInstance()->characterHandler($resource, trim($characters));
412         }
413
414         /**
415          * Removes all comments, tabs and new-line charcters to compact the content
416          *
417          * @param       $uncompactedContent             The uncompacted content
418          * @return      $compactedContent               The compacted content
419          */
420         public function compactContent ($uncompactedContent) {
421                 // Compact it ...
422                 $compactedContent = $this->getTemplateInstance()->compactContent($uncompactedContent);
423
424                 // ... and return it
425                 return $compactedContent;
426         }
427
428         /**
429          * Assigns a lot variables into the stack of currently loaded template.
430          * This method should only be used in very rare circumstances, e.g. when
431          * you have to copy a whole set of variables into the template engine.
432          * Before you use this method, please make sure you have considered all
433          * other possiblities.
434          *
435          * @param       $variables      An array with variables to be assigned
436          * @return      void
437          */
438         public function assignMultipleVariables (array $variables) {
439                 // Call the inner class' method but trim the characters before
440                 $this->getTemplateInstance()->assignMultipleVariables($variables);
441         }
442 }
443
444 // [EOF]
445 ?>