Clover Coverage Report - XWiki Commons - Parent POM 4.0-SNAPSHOT (Aggregated)
Coverage timestamp: Mon Mar 12 2012 17:13:48 CET
../../../../img/srcFileCovDistChart0.png 69% of files have more coverage
4   72   1   4
0   29   0.25   1
1     1  
1    
 
  DefaultScriptContextManager       Line # 40 4 0% 1 5 0% 0.0
 
No Tests
 
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.script.internal;
21   
22    import java.util.List;
23   
24    import javax.inject.Inject;
25    import javax.inject.Singleton;
26    import javax.script.ScriptContext;
27   
28    import org.xwiki.component.annotation.Component;
29    import org.xwiki.context.Execution;
30    import org.xwiki.script.ScriptContextInitializer;
31    import org.xwiki.script.ScriptContextManager;
32   
33    /**
34    * Default implementation of {@link ScriptContextManager}.
35    *
36    * @version $Id: 9f47e62a86b1d80d7fe5955c0b926dff7a000523 $
37    */
38    @Component
39    @Singleton
 
40    public class DefaultScriptContextManager implements ScriptContextManager
41    {
42    /**
43    * Used to get and insert script context in current execution context.
44    */
45    @Inject
46    private Execution execution;
47   
48    /**
49    * The {@link ScriptContextInitializer} list used to initialize {@link ScriptContext}.
50    */
51    @Inject
52    private List<ScriptContextInitializer> scriptContextInitializerList;
53   
 
54  0 toggle @Override
55    public ScriptContext getScriptContext()
56    {
57    // The Script Context is set in ScriptExecutionContextInitializer, when the XWiki Execution Context is
58    // initialized so we are guaranteed it is defined when this method is called.
59  0 ScriptContext context =
60    (ScriptContext) this.execution.getContext()
61    .getProperty(ScriptExecutionContextInitializer.SCRIPT_CONTEXT_ID);
62   
63    // We re-initialize the Script Context with all Script Context Initializers. We do this in order to ensure
64    // that the Script Context always contain correct values even if user scripts or XWiki code have modified them.
65    // For example the current document in the Script Context could have changed and thus needs to be set back.
66  0 for (ScriptContextInitializer scriptContextInitializer : this.scriptContextInitializerList) {
67  0 scriptContextInitializer.initialize(context);
68    }
69   
70  0 return context;
71    }
72    }