1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.velocity.internal

File VelocityExecutionContextInitializer.java

 

Coverage histogram

../../../../img/srcFileCovDistChart9.png
38% of files have more coverage

Code metrics

2
5
1
1
75
36
3
0.6
5
1
3

Classes

Class Line # Actions
VelocityExecutionContextInitializer 45 5 0% 3 1
0.87587.5%
 

Contributing tests

This file is covered by 50 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.velocity.internal;
21   
22    import javax.inject.Inject;
23    import javax.inject.Named;
24    import javax.inject.Singleton;
25   
26    import org.apache.velocity.VelocityContext;
27    import org.xwiki.component.annotation.Component;
28    import org.xwiki.context.ExecutionContext;
29    import org.xwiki.context.ExecutionContextException;
30    import org.xwiki.context.ExecutionContextInitializer;
31    import org.xwiki.velocity.VelocityContextFactory;
32    import org.xwiki.velocity.XWikiVelocityException;
33   
34    /**
35    * Allow registering the Velocity Context in the Execution Context object since it's shared during the whole execution
36    * of the current request.
37    *
38    * @see org.xwiki.context.ExecutionContextInitializer
39    * @since 1.5M1
40    * @version $Id: a522b3a58851b2bc83b6ab858ab5c274f0086309 $
41    */
42    @Component
43    @Named("velocity")
44    @Singleton
 
45    public class VelocityExecutionContextInitializer implements ExecutionContextInitializer
46    {
47    /**
48    * The id under which the Velocity Context is stored in the Execution Context.
49    */
50    public static final String VELOCITY_CONTEXT_ID = "velocityContext";
51   
52    /**
53    * The Velocity context factory component used for creating the Velocity Context (injected automatically by the
54    * Component subsystem).
55    */
56    @Inject
57    private VelocityContextFactory velocityContextFactory;
58   
 
59  36208 toggle @Override
60    public void initialize(ExecutionContext executionContext) throws ExecutionContextException
61    {
62  36206 try {
63  36182 if (!executionContext.hasProperty(VELOCITY_CONTEXT_ID)) {
64  19065 VelocityContext context = this.velocityContextFactory.createContext();
65  19074 executionContext.newProperty(VELOCITY_CONTEXT_ID)
66    .cloneValue()
67    .inherited()
68    .initial(context)
69    .declare();
70    }
71    } catch (XWikiVelocityException e) {
72  0 throw new ExecutionContextException("Failed to initialize Velocity Context", e);
73    }
74    }
75    }