1. Project Clover database Sat Feb 2 2019 06:45:20 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 493 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: cc5af9ebda2ccc51c51c4305fa19b06f5275ed2e $
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 inline;
48   
49    /**
50    * See {@link #getTransformation()}.
51    */
52    private Transformation transformation;
53   
54    /**
55    * Constructor.
56    */
 
57  54 toggle public MacroTransformationContext()
58    {
59  54 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  285115 toggle public MacroTransformationContext(TransformationContext transformationContext)
69    {
70  285189 this.transformationContext = transformationContext;
71    }
72   
73    /**
74    * @return the context of the transformation process.
75    * @since 2.4M1
76    */
 
77  771114 toggle public TransformationContext getTransformationContext()
78    {
79  771150 return this.transformationContext;
80    }
81   
82    /**
83    * @param currentMacroBlock the macro currently being processed.
84    */
 
85  523050 toggle public void setCurrentMacroBlock(MacroBlock currentMacroBlock)
86    {
87  523066 this.currentMacroBlock = currentMacroBlock;
88    }
89   
90    /**
91    * @return the macro currently being processed.
92    */
 
93  1062093 toggle public MacroBlock getCurrentMacroBlock()
94    {
95  1062223 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  16946 toggle public XDOM getXDOM()
110    {
111  16946 return this.transformationContext.getXDOM();
112    }
113   
114    /**
115    * @param inline if true then the macro is called in inline mode
116    */
 
117  522997 toggle public void setInline(boolean inline)
118    {
119  523074 this.inline = inline;
120    }
121   
122    /**
123    * @return true if the macro is called in inline mode (ie inside a paragraph, a list item, etc)
124    */
 
125  299397 toggle public boolean isInline()
126    {
127  299397 return this.inline;
128    }
129   
130    /**
131    * @param transformation the Transformation being used
132    * @see #getTransformation()
133    * @since 2.4M1
134    */
 
135  285222 toggle public void setTransformation(Transformation transformation)
136    {
137  285259 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  2050 toggle public Transformation getTransformation()
147    {
148  2050 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  213446 toggle public Syntax getSyntax()
163    {
164  213441 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  31 toggle public String getId()
173    {
174  31 return this.transformationContext.getId();
175    }
176   
177    /**
178    * @param id see {@link #getId()}
179    */
 
180  9 toggle public void setId(String id)
181    {
182  9 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    }