1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package com.xpn.xwiki.render; |
21 |
|
|
22 |
|
import java.util.Map; |
23 |
|
import java.util.Set; |
24 |
|
|
25 |
|
import javax.script.Bindings; |
26 |
|
import javax.script.ScriptContext; |
27 |
|
|
28 |
|
import org.apache.velocity.VelocityContext; |
29 |
|
import org.apache.velocity.runtime.directive.Scope; |
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
@version |
35 |
|
@since |
36 |
|
|
|
|
| 89.2% |
Uncovered Elements: 4 (37) |
Complexity: 12 |
Complexity Density: 0.57 |
|
37 |
|
public class ScriptVelocityContext extends VelocityContext |
38 |
|
{ |
39 |
|
private final Set<String> reservedBindings; |
40 |
|
|
41 |
|
private ScriptContext scriptContext; |
42 |
|
|
43 |
|
|
44 |
|
@param |
45 |
|
@param |
46 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
47 |
11403 |
public ScriptVelocityContext(VelocityContext parent, Set<String> reservedBindings)... |
48 |
|
{ |
49 |
11416 |
super(parent); |
50 |
|
|
51 |
11396 |
this.reservedBindings = reservedBindings; |
52 |
|
} |
53 |
|
|
54 |
|
|
55 |
|
@return |
56 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
57 |
0 |
public ScriptContext getScriptContext()... |
58 |
|
{ |
59 |
0 |
return this.scriptContext; |
60 |
|
} |
61 |
|
|
62 |
|
|
63 |
|
@param |
64 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
65 |
109360 |
public void setScriptContext(ScriptContext scriptContext)... |
66 |
|
{ |
67 |
109349 |
this.scriptContext = scriptContext; |
68 |
|
|
69 |
109342 |
copyScriptContext(ScriptContext.GLOBAL_SCOPE); |
70 |
109341 |
copyScriptContext(ScriptContext.ENGINE_SCOPE); |
71 |
|
} |
72 |
|
|
|
|
| 84.6% |
Uncovered Elements: 2 (13) |
Complexity: 4 |
Complexity Density: 0.57 |
|
73 |
218646 |
private void copyScriptContext(int scope)... |
74 |
|
{ |
75 |
218674 |
Bindings bindings = this.scriptContext.getBindings(scope); |
76 |
218688 |
if (bindings != null) { |
77 |
109360 |
for (Map.Entry<String, Object> entry : bindings.entrySet()) { |
78 |
7272728 |
if (!this.reservedBindings.contains(entry.getKey())) { |
79 |
7272729 |
Object currentValue = get(entry.getKey()); |
80 |
|
|
81 |
7272474 |
if (!(currentValue instanceof Scope)) { |
82 |
7272532 |
put(entry.getKey(), entry.getValue()); |
83 |
|
} |
84 |
|
} |
85 |
|
} |
86 |
|
} |
87 |
|
} |
88 |
|
|
89 |
|
|
90 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
91 |
9783625 |
@Override... |
92 |
|
public Object internalPut(String key, Object value) |
93 |
|
{ |
94 |
9783655 |
try { |
95 |
9783669 |
return super.internalPut(key, value); |
96 |
|
} finally { |
97 |
9785981 |
if (!this.reservedBindings.contains(key)) { |
98 |
8969615 |
this.scriptContext.setAttribute(key, value, ScriptContext.ENGINE_SCOPE); |
99 |
|
} |
100 |
|
} |
101 |
|
} |
102 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 3 |
Complexity Density: 0.75 |
|
103 |
247986 |
@Override... |
104 |
|
public Object internalRemove(Object key) |
105 |
|
{ |
106 |
247989 |
try { |
107 |
247983 |
return super.internalRemove(key); |
108 |
|
} finally { |
109 |
247987 |
if (key instanceof String && !this.reservedBindings.contains(key)) { |
110 |
191556 |
this.scriptContext.removeAttribute((String) key, ScriptContext.ENGINE_SCOPE); |
111 |
|
} |
112 |
|
} |
113 |
|
} |
114 |
|
} |