1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.rendering.internal.transformation; |
21 |
|
|
22 |
|
import javax.inject.Inject; |
23 |
|
import javax.inject.Provider; |
24 |
|
import javax.inject.Singleton; |
25 |
|
|
26 |
|
import org.slf4j.Logger; |
27 |
|
import org.xwiki.component.annotation.Component; |
28 |
|
import org.xwiki.component.manager.ComponentLookupException; |
29 |
|
import org.xwiki.component.manager.ComponentManager; |
30 |
|
import org.xwiki.rendering.block.XDOM; |
31 |
|
import org.xwiki.rendering.syntax.Syntax; |
32 |
|
import org.xwiki.rendering.transformation.Transformation; |
33 |
|
import org.xwiki.skin.SkinManager; |
34 |
|
import org.xwiki.velocity.VelocityManager; |
35 |
|
|
36 |
|
|
37 |
|
@link |
38 |
|
|
39 |
|
@version |
40 |
|
@since |
41 |
|
|
42 |
|
@Component |
43 |
|
@Singleton |
|
|
| 97.8% |
Uncovered Elements: 1 (45) |
Complexity: 15 |
Complexity Density: 0.56 |
|
44 |
|
public class XWikiRenderingContext extends DefaultRenderingContext |
45 |
|
{ |
46 |
|
@Inject |
47 |
|
private ComponentManager componentManager; |
48 |
|
|
49 |
|
@Inject |
50 |
|
private Provider<SkinManager> skinManagerProvider; |
51 |
|
|
52 |
|
@Inject |
53 |
|
private Logger logger; |
54 |
|
|
55 |
|
private VelocityManager velocityManager; |
56 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 3 |
Complexity Density: 0.6 |
|
57 |
98885 |
private VelocityManager getVelocityManager()... |
58 |
|
{ |
59 |
98890 |
if (this.velocityManager == null) { |
60 |
94 |
try { |
61 |
94 |
this.velocityManager = this.componentManager.getInstance(VelocityManager.class); |
62 |
|
} catch (ComponentLookupException e) { |
63 |
27 |
this.logger.debug("Failed to initialize VelocityManager, velocity cache won't be cleaned", e); |
64 |
|
} |
65 |
|
} |
66 |
|
|
67 |
98881 |
return this.velocityManager; |
68 |
|
} |
69 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
70 |
24976 |
@Override... |
71 |
|
public void push(Transformation transformation, XDOM xdom, Syntax syntax, String id, boolean restricted, |
72 |
|
Syntax targetSyntax) |
73 |
|
{ |
74 |
24976 |
super.push(transformation, xdom, syntax, id, restricted, targetSyntax); |
75 |
|
|
76 |
24969 |
String namespace = id; |
77 |
24967 |
if (namespace != null) { |
78 |
24733 |
openNamespace(namespace); |
79 |
|
} |
80 |
|
} |
81 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
82 |
24977 |
@Override... |
83 |
|
public void pop() |
84 |
|
{ |
85 |
24976 |
String namespace = peek().getTransformationId(); |
86 |
24974 |
if (namespace != null) { |
87 |
24727 |
closeNamespace(namespace); |
88 |
|
} |
89 |
|
|
90 |
24978 |
super.pop(); |
91 |
|
} |
92 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 3 |
Complexity Density: 0.6 |
|
93 |
24720 |
private void openNamespace(String namespace)... |
94 |
|
{ |
95 |
24729 |
if (getVelocityManager() != null) { |
96 |
24707 |
try { |
97 |
|
|
98 |
24712 |
getVelocityManager().getVelocityEngine().startedUsingMacroNamespace(namespace); |
99 |
24722 |
logger.debug("Started using velocity macro namespace [{}].", namespace); |
100 |
|
} catch (Exception e) { |
101 |
|
|
102 |
|
|
103 |
2 |
logger.warn("Failed to notify Velocity Macro cache for opening the [{}] namespace. Reason = [{}]", |
104 |
|
namespace, e.getMessage()); |
105 |
|
} |
106 |
|
} |
107 |
|
} |
108 |
|
|
|
|
| 85.7% |
Uncovered Elements: 1 (7) |
Complexity: 3 |
Complexity Density: 0.6 |
|
109 |
24724 |
private void closeNamespace(String namespace)... |
110 |
|
{ |
111 |
24723 |
if (getVelocityManager() != null) { |
112 |
24719 |
try { |
113 |
24718 |
getVelocityManager().getVelocityEngine().stoppedUsingMacroNamespace(namespace); |
114 |
24722 |
logger.debug("Stopped using velocity macro namespace [{}].", namespace); |
115 |
|
} catch (Exception e) { |
116 |
|
|
117 |
|
|
118 |
0 |
logger.warn("Failed to notify Velocity Macro cache for closing the [{}] namespace. Reason = [{}]", |
119 |
|
namespace, e.getMessage()); |
120 |
|
} |
121 |
|
} |
122 |
|
} |
123 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
124 |
26769 |
@Override... |
125 |
|
public Syntax getTargetSyntax() |
126 |
|
{ |
127 |
26769 |
Syntax targetSyntax = super.getTargetSyntax(); |
128 |
|
|
129 |
26763 |
if (targetSyntax == null) { |
130 |
|
|
131 |
11168 |
targetSyntax = skinManagerProvider.get().getCurrentSkin(true).getOutputSyntax(); |
132 |
|
} |
133 |
|
|
134 |
26766 |
return targetSyntax; |
135 |
|
} |
136 |
|
} |