Clover Coverage Report - XWiki Rendering - Parent POM 4.0-SNAPSHOT (Aggregated)
Coverage timestamp: Mon Mar 12 2012 18:03:13 CET
../../../../img/srcFileCovDistChart10.png 0% of files have more coverage
21   200   17   1.31
0   83   0.81   16
16     1.06  
1    
 
  MacroTransformationContext       Line # 32 21 0% 17 1 97.3% 0.972973
 
  (115)
 
1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package org.xwiki.rendering.transformation;
21   
22    import org.xwiki.rendering.block.MacroBlock;
23    import org.xwiki.rendering.block.XDOM;
24    import org.xwiki.rendering.syntax.Syntax;
25   
26    /**
27    * The context of the macro transformation process. Contains information such as the current XWiki DOM for the parsed
28    * content and the current Macro block being processed by the Macro transformation.
29    *
30    * @version $Id: 7a8d7d0adda1481469c4e4e55fa9ee2e0b5ef3f6 $
31    */
 
32    public class MacroTransformationContext implements Cloneable
33    {
34    /**
35    * The context of the transformation process.
36    */
37    private TransformationContext transformationContext;
38   
39    /**
40    * The macro currently being processed.
41    */
42    private MacroBlock currentMacroBlock;
43   
44    /**
45    * Whether the macro is called in inline mode or not.
46    */
47    private boolean isInline;
48   
49    /**
50    * See {@link #getTransformation()}.
51    */
52    private Transformation transformation;
53   
54    /**
55    * Constructor.
56    */
 
57  2 toggle public MacroTransformationContext()
58    {
59  2 this.transformationContext = new TransformationContext();
60    }
61   
62    /**
63    * Constructor.
64    *
65    * @param transformationContext the context of the transformation process.
66    * @since 2.4M1
67    */
 
68  132 toggle public MacroTransformationContext(TransformationContext transformationContext)
69    {
70  132 this.transformationContext = transformationContext;
71    }
72   
73    /**
74    * @return the context of the transformation process.
75    * @since 2.4M1
76    */
 
77  12 toggle public TransformationContext getTransformationContext()
78    {
79  12 return this.transformationContext;
80    }
81   
82    /**
83    * @param currentMacroBlock the macro currently being processed.
84    */
 
85  1136 toggle public void setCurrentMacroBlock(MacroBlock currentMacroBlock)
86    {
87  1136 this.currentMacroBlock = currentMacroBlock;
88    }
89   
90    /**
91    * @return the macro currently being processed.
92    */
 
93  52 toggle public MacroBlock getCurrentMacroBlock()
94    {
95  52 return this.currentMacroBlock;
96    }
97   
98    /**
99    * @param xdom the complete {@link XDOM} of the page currently being transformed.
100    */
 
101  1 toggle public void setXDOM(XDOM xdom)
102    {
103  1 this.transformationContext.setXDOM(xdom);
104    }
105   
106    /**
107    * @return the complete {@link XDOM} of the page currently being transformed.
108    */
 
109  61 toggle public XDOM getXDOM()
110    {
111  61 return this.transformationContext.getXDOM();
112    }
113   
114    /**
115    * @param isInline if true then the macro is called in inline mode
116    */
 
117  1142 toggle public void setInline(boolean isInline)
118    {
119  1142 this.isInline = isInline;
120    }
121   
122    /**
123    * @return true if the macro is called in inline mode (ie inside a paragraph, a list item, etc)
124    */
 
125  76 toggle public boolean isInline()
126    {
127  76 return this.isInline;
128    }
129   
130    /**
131    * @param transformation the Transformation being used
132    * @see #getTransformation()
133    * @since 2.4M1
134    */
 
135  133 toggle public void setTransformation(Transformation transformation)
136    {
137  133 this.transformation = transformation;
138    }
139   
140    /**
141    * @return the current Transformation instance being executed. Useful for Macros which need to perform other
142    * transformations in turn such as the Include macro which needs to execute the transformation if the
143    * included page should be executed in its own context.
144    * @since 2.4M1
145    */
 
146  12 toggle public Transformation getTransformation()
147    {
148  12 return this.transformation;
149    }
150   
151    /**
152    * @param syntax the current syntax.
153    */
 
154  1 toggle public void setSyntax(Syntax syntax)
155    {
156  1 this.transformationContext.setSyntax(syntax);
157    }
158   
159    /**
160    * @return the current syntax.
161    */
 
162  34 toggle public Syntax getSyntax()
163    {
164  34 return this.transformationContext.getSyntax();
165    }
166   
167    /**
168    * @return an id representing the transformation being evaluated. It's a free form name that Transformations can
169    * use, for example if they need to perform some caching based on a key. For example the Velocity Macro
170    * is using this id to pass it to the underlying Velocity Engine so that it caches macros using this key.
171    */
 
172  1 toggle public String getId()
173    {
174  1 return this.transformationContext.getId();
175    }
176   
177    /**
178    * @param id see {@link #getId()}
179    */
 
180  1 toggle public void setId(String id)
181    {
182  1 this.transformationContext.setId(id);
183    }
184   
 
185  1 toggle @Override
186    public MacroTransformationContext clone()
187    {
188  1 MacroTransformationContext newContext;
189  1 try {
190  1 newContext = (MacroTransformationContext) super.clone();
191    } catch (CloneNotSupportedException e) {
192    // Should never happen
193  0 throw new RuntimeException("Failed to clone object", e);
194    }
195   
196  1 newContext.transformationContext = getTransformationContext().clone();
197   
198  1 return newContext;
199    }
200    }