1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package org.xwiki.rendering.transformation

File TransformationContext.java

 

Coverage histogram

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

Code metrics

0
20
14
1
190
76
15
0.75
1.43
14
1.07

Classes

Class Line # Actions
TransformationContext 31 20 0% 15 1
0.970588297.1%
 

Contributing tests

This file is covered by 512 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.XDOM;
23    import org.xwiki.rendering.syntax.Syntax;
24   
25    /**
26    * The context of the transformation process. Contains information such as the current XWiki DOM for the parsed content.
27    *
28    * @version $Id: 344d9a5cee21cbd7677bc002149f90197cae0394 $
29    * @since 2.4M1
30    */
 
31    public class TransformationContext implements Cloneable
32    {
33    /**
34    * The complete {@link XDOM} of the content currently being transformed.
35    */
36    private XDOM xdom;
37   
38    /**
39    * The current syntax.
40    */
41    private Syntax syntax;
42   
43    /**
44    * @see #getId(). Note that the id is optional.
45    */
46    private String id;
47   
48    /**
49    * In restricted mode, only transformations that are deemed safe for execution by untrusted users will be performed.
50    */
51    private boolean restricted;
52   
53    /**
54    * @see #getTargetSyntax()
55    */
56    private Syntax targetSyntax;
57   
58    /**
59    * Default constructor that doesn't set the XDOM or the Syntax. This is because setting the XDOM and the Syntax is
60    * optional and only required by some Macros to behave as expected.
61    */
 
62  97 toggle public TransformationContext()
63    {
64  97 this(null, null);
65    }
66   
67    /**
68    * Some macros require the XDOM and the Syntax to be set.
69    *
70    * @param xdom see {@link #setXDOM(org.xwiki.rendering.block.XDOM)}
71    * @param syntax see {@link #setSyntax(org.xwiki.rendering.syntax.Syntax)}
72    */
 
73  8908 toggle public TransformationContext(XDOM xdom, Syntax syntax)
74    {
75  8908 this(xdom, syntax, false);
76    }
77   
78    /**
79    * Some macros require the XDOM and the Syntax to be set.
80    *
81    * @param xdom see {@link #setXDOM(org.xwiki.rendering.block.XDOM)}
82    * @param syntax see {@link #setSyntax(org.xwiki.rendering.syntax.Syntax)}
83    * @param restricted disables potentially harmful transformations.
84    */
 
85  283197 toggle public TransformationContext(XDOM xdom, Syntax syntax, boolean restricted)
86    {
87  283194 setXDOM(xdom);
88  283244 setSyntax(syntax);
89  283307 setRestricted(restricted);
90    }
91   
92    /**
93    * @return an id representing the transformation being evaluated. It's a free form name that Transformations can
94    * use, for example if they need to perform some caching based on a key. For example the Velocity Macro is
95    * using this id to pass it to the underlying Velocity Engine so that it caches macros using this key.
96    * @since 2.4M2
97    */
 
98  654677 toggle public String getId()
99    {
100  654705 return this.id;
101    }
102   
103    /**
104    * @param id the id
105    * @since 2.4M2
106    * @see #getId()
107    */
 
108  283100 toggle public void setId(String id)
109    {
110  283048 this.id = id;
111    }
112   
113    /**
114    * @param xdom the complete {@link XDOM} of the content currently being transformed.
115    */
 
116  283262 toggle public void setXDOM(XDOM xdom)
117    {
118  283278 this.xdom = xdom;
119    }
120   
121    /**
122    * @return the complete {@link XDOM} of the content currently being transformed.
123    */
 
124  400116 toggle public XDOM getXDOM()
125    {
126  400310 return this.xdom;
127    }
128   
129    /**
130    * @param syntax the current syntax.
131    */
 
132  283327 toggle public void setSyntax(Syntax syntax)
133    {
134  283371 this.syntax = syntax;
135    }
136   
137    /**
138    * @return the current syntax.
139    */
 
140  1405258 toggle public Syntax getSyntax()
141    {
142  1405215 return this.syntax;
143    }
144   
145    /**
146    * @return indicator of whether the transformation context is restricted or not.
147    */
 
148  859729 toggle public boolean isRestricted()
149    {
150  859683 return this.restricted;
151    }
152   
153    /**
154    * @param restricted set indicator of whether the transformation context is restricted or not.
155    */
 
156  283264 toggle public void setRestricted(boolean restricted)
157    {
158  283311 this.restricted = restricted;
159    }
160   
161    /**
162    * @return the syntax of the renderer
163    */
 
164  404520 toggle public Syntax getTargetSyntax()
165    {
166  404580 return this.targetSyntax;
167    }
168   
169    /**
170    * @param targetSyntax the syntax of the renderer
171    */
 
172  255734 toggle public void setTargetSyntax(Syntax targetSyntax)
173    {
174  255844 this.targetSyntax = targetSyntax;
175    }
176   
 
177  2 toggle @Override
178    public TransformationContext clone()
179    {
180  2 TransformationContext newContext;
181  2 try {
182  2 newContext = (TransformationContext) super.clone();
183    } catch (CloneNotSupportedException e) {
184    // Should never happen
185  0 throw new RuntimeException("Failed to clone object", e);
186    }
187   
188  2 return newContext;
189    }
190    }