1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.rendering.transformation

File MacroTransformationContext.java

 

Coverage histogram

../../../../img/srcFileCovDistChart10.png
0% of files have more coverage

Code metrics

0
21
16
1
200
83
17
0.81
1.31
16
1.06

Classes

Class Line # Actions
MacroTransformationContext 32 21 0% 17 1
0.97297397.3%
 

Contributing tests

This file is covered by 456 tests. .

Source view

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: 9bff3bed7f8f04c36eeb15fa0b9d42908f4cebe6 $
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  51 toggle public MacroTransformationContext()
58    {
59  51 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  9348 toggle public MacroTransformationContext(TransformationContext transformationContext)
69    {
70  9348 this.transformationContext = transformationContext;
71    }
72   
73    /**
74    * @return the context of the transformation process.
75    * @since 2.4M1
76    */
 
77  25965 toggle public TransformationContext getTransformationContext()
78    {
79  25966 return this.transformationContext;
80    }
81   
82    /**
83    * @param currentMacroBlock the macro currently being processed.
84    */
 
85  17473 toggle public void setCurrentMacroBlock(MacroBlock currentMacroBlock)
86    {
87  17473 this.currentMacroBlock = currentMacroBlock;
88    }
89   
90    /**
91    * @return the macro currently being processed.
92    */
 
93  36972 toggle public MacroBlock getCurrentMacroBlock()
94    {
95  36972 return this.currentMacroBlock;
96    }
97   
98    /**
99    * @param xdom the complete {@link XDOM} of the page currently being transformed.
100    */
 
101  5 toggle public void setXDOM(XDOM xdom)
102    {
103  5 this.transformationContext.setXDOM(xdom);
104    }
105   
106    /**
107    * @return the complete {@link XDOM} of the page currently being transformed.
108    */
 
109  238 toggle public XDOM getXDOM()
110    {
111  238 return this.transformationContext.getXDOM();
112    }
113   
114    /**
115    * @param isInline if true then the macro is called in inline mode
116    */
 
117  17442 toggle public void setInline(boolean isInline)
118    {
119  17441 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  13461 toggle public boolean isInline()
126    {
127  13462 return this.isInline;
128    }
129   
130    /**
131    * @param transformation the Transformation being used
132    * @see #getTransformation()
133    * @since 2.4M1
134    */
 
135  9354 toggle public void setTransformation(Transformation transformation)
136    {
137  9354 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  194 toggle public Transformation getTransformation()
147    {
148  194 return this.transformation;
149    }
150   
151    /**
152    * @param syntax the current syntax.
153    */
 
154  27 toggle public void setSyntax(Syntax syntax)
155    {
156  27 this.transformationContext.setSyntax(syntax);
157    }
158   
159    /**
160    * @return the current syntax.
161    */
 
162  7891 toggle public Syntax getSyntax()
163    {
164  7890 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  169 toggle public String getId()
173    {
174  169 return this.transformationContext.getId();
175    }
176   
177    /**
178    * @param id see {@link #getId()}
179    */
 
180  8 toggle public void setId(String id)
181    {
182  8 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    }