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

File XWikiRenderingContext.java

 

Coverage histogram

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

Code metrics

12
27
6
1
136
88
15
0.56
4.5
6
2.5

Classes

Class Line # Actions
XWikiRenderingContext 44 27 0% 15 0
1.0100%
 

Contributing tests

This file is covered by 10 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.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    * Add some XWiki level stuff to {@link DefaultRenderingContext}.
38    *
39    * @version $Id: f9d621d87cd5cc18424c943889f5b4ebc07b8ae7 $
40    * @since 6.0
41    */
42    @Component
43    @Singleton
 
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   
 
57  1577808 toggle private VelocityManager getVelocityManager()
58    {
59  1578418 if (this.velocityManager == null) {
60  120 try {
61  120 this.velocityManager = this.componentManager.getInstance(VelocityManager.class);
62    } catch (ComponentLookupException e) {
63  38 this.logger.debug("Failed to initialize VelocityManager, velocity cache won't be cleaned", e);
64    }
65    }
66   
67  1578297 return this.velocityManager;
68    }
69   
 
70  439463 toggle @Override
71    public void push(Transformation transformation, XDOM xdom, Syntax syntax, String id, boolean restricted,
72    Syntax targetSyntax)
73    {
74  439918 super.push(transformation, xdom, syntax, id, restricted, targetSyntax);
75   
76  440400 String namespace = id;
77  440329 if (namespace != null) {
78  394737 openNamespace(namespace);
79    }
80    }
81   
 
82  440379 toggle @Override
83    public void pop()
84    {
85  440464 String namespace = peek().getTransformationId();
86  440536 if (namespace != null) {
87  394793 closeNamespace(namespace);
88    }
89   
90  440595 super.pop();
91    }
92   
 
93  394788 toggle private void openNamespace(String namespace)
94    {
95  394620 if (getVelocityManager() != null) {
96  394641 try {
97    // Mark that we're starting to use a different Velocity macro name-space.
98  394680 getVelocityManager().getVelocityEngine().startedUsingMacroNamespace(namespace);
99  394356 logger.debug("Started using velocity macro namespace [{}].", namespace);
100    } catch (Exception e) {
101    // Failed to get the Velocity Engine and thus to clear Velocity Macro cache. Log this as a warning but
102    // continue since it's not absolutely critical.
103  3 logger.warn("Failed to notify Velocity Macro cache for opening the [{}] namespace. Reason = [{}]",
104    namespace, e.getMessage());
105    }
106    }
107    }
108   
 
109  394844 toggle private void closeNamespace(String namespace)
110    {
111  394883 if (getVelocityManager() != null) {
112  394870 try {
113  394851 getVelocityManager().getVelocityEngine().stoppedUsingMacroNamespace(namespace);
114  394899 logger.debug("Stopped using velocity macro namespace [{}].", namespace);
115    } catch (Exception e) {
116    // Failed to get the Velocity Engine and thus to clear Velocity Macro cache. Log this as a warning but
117    // continue since it's not absolutely critical.
118  3 logger.warn("Failed to notify Velocity Macro cache for closing the [{}] namespace. Reason = [{}]",
119    namespace, e.getMessage());
120    }
121    }
122    }
123   
 
124  495331 toggle @Override
125    public Syntax getTargetSyntax()
126    {
127  495512 Syntax targetSyntax = super.getTargetSyntax();
128   
129  495698 if (targetSyntax == null) {
130    // Fallback to the skin syntax
131  120865 targetSyntax = skinManagerProvider.get().getCurrentSkin(true).getOutputSyntax();
132    }
133   
134  494911 return targetSyntax;
135    }
136    }