1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package com.xpn.xwiki.internal

File XWikiContextProvider.java

 

Coverage histogram

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

Code metrics

8
14
2
1
100
49
6
0.43
7
2
3

Classes

Class Line # Actions
XWikiContextProvider 45 14 0% 6 0
1.0100%
 

Contributing tests

This file is covered by 91 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 com.xpn.xwiki.internal;
21   
22    import javax.inject.Inject;
23    import javax.inject.Provider;
24    import javax.inject.Singleton;
25   
26    import org.xwiki.component.annotation.Component;
27    import org.xwiki.container.Container;
28    import org.xwiki.container.servlet.ServletRequest;
29    import org.xwiki.container.servlet.ServletResponse;
30    import org.xwiki.context.Execution;
31    import org.xwiki.context.ExecutionContext;
32   
33    import com.xpn.xwiki.XWikiContext;
34    import com.xpn.xwiki.util.XWikiStubContextProvider;
35   
36    /**
37    * Provide current {@link XWikiContext} or create one from {@link XWikiStubContextProvider} if there is no current one
38    * yet.
39    *
40    * @version $Id: 1fc384e9c4bc12ed1ab79549b7b186792a93bee1 $
41    * @see ReadOnlyXWikiContextProvider
42    */
43    @Component
44    @Singleton
 
45    public class XWikiContextProvider implements Provider<XWikiContext>
46    {
47    /**
48    * Used to create a new {@link XWikiContext}.
49    */
50    @Inject
51    private XWikiStubContextProvider contextProvider;
52   
53    /**
54    * Used to access current {@link XWikiContext}.
55    */
56    @Inject
57    private Execution execution;
58   
59    @Inject
60    private Container container;
61   
 
62  168839338 toggle @Override
63    public XWikiContext get()
64    {
65  168851069 return getXWikiContext();
66    }
67   
68    /**
69    * @return current XWikiContext or new one
70    */
 
71  168843059 toggle private XWikiContext getXWikiContext()
72    {
73  168849859 XWikiContext xcontext;
74   
75  168851600 ExecutionContext econtext = this.execution.getContext();
76   
77  168855430 if (econtext != null) {
78  168114632 xcontext = (XWikiContext) this.execution.getContext().getProperty(XWikiContext.EXECUTIONCONTEXT_KEY);
79   
80  168121548 if (xcontext == null) {
81  70609 xcontext = this.contextProvider.createStubContext();
82   
83    // Set the XWiki context
84  70609 this.execution.getContext().setProperty(XWikiContext.EXECUTIONCONTEXT_KEY, xcontext);
85   
86    // Set the stub request and the response
87  70609 if (this.container.getRequest() == null) {
88  284 this.container.setRequest(new ServletRequest(xcontext.getRequest()));
89    }
90  70609 if (this.container.getResponse() == null) {
91  7357 this.container.setResponse(new ServletResponse(xcontext.getResponse()));
92    }
93    }
94    } else {
95  738859 xcontext = null;
96    }
97   
98  168856096 return xcontext;
99    }
100    }