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

File XWikiContext.java

 

Coverage histogram

../../../img/srcFileCovDistChart8.png
56% of files have more coverage

Code metrics

80
196
88
1
1,023
620
131
0.67
2.23
88
1.49

Classes

Class Line # Actions
XWikiContext 71 196 0% 131 74
0.796703379.7%
 

Contributing tests

This file is covered by 511 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;
21   
22    import java.lang.reflect.ParameterizedType;
23    import java.net.URL;
24    import java.util.ArrayList;
25    import java.util.Collections;
26    import java.util.Hashtable;
27    import java.util.List;
28    import java.util.Locale;
29    import java.util.Map;
30   
31    import javax.inject.Provider;
32   
33    import org.apache.commons.collections4.map.LRUMap;
34    import org.apache.commons.lang3.StringUtils;
35    import org.slf4j.Logger;
36    import org.slf4j.LoggerFactory;
37    import org.xwiki.component.util.DefaultParameterizedType;
38    import org.xwiki.context.Execution;
39    import org.xwiki.context.ExecutionContext;
40    import org.xwiki.localization.LocaleUtils;
41    import org.xwiki.model.reference.DocumentReference;
42    import org.xwiki.model.reference.DocumentReferenceResolver;
43    import org.xwiki.model.reference.EntityReferenceSerializer;
44    import org.xwiki.model.reference.SpaceReference;
45    import org.xwiki.model.reference.WikiReference;
46    import org.xwiki.velocity.VelocityManager;
47    import org.xwiki.velocity.internal.VelocityExecutionContextInitializer;
48   
49    import com.xpn.xwiki.doc.XWikiDocument;
50    import com.xpn.xwiki.objects.classes.BaseClass;
51    import com.xpn.xwiki.user.api.XWikiRightService;
52    import com.xpn.xwiki.user.api.XWikiUser;
53    import com.xpn.xwiki.util.Util;
54    import com.xpn.xwiki.validation.XWikiValidationStatus;
55    import com.xpn.xwiki.web.Utils;
56    import com.xpn.xwiki.web.XWikiEngineContext;
57    import com.xpn.xwiki.web.XWikiForm;
58    import com.xpn.xwiki.web.XWikiMessageTool;
59    import com.xpn.xwiki.web.XWikiRequest;
60    import com.xpn.xwiki.web.XWikiResponse;
61    import com.xpn.xwiki.web.XWikiURLFactory;
62   
63    /**
64    * Represents the execution environment for all the wiki pages. An instance of the <code>Context</code> class is
65    * available as a predefined variable for scripting inside any wiki page. You can access it using <code>$xcontext</code>
66    * in Velocity scripts or simply <code>xcontext</code> in Groovy ones. The <code>Context</code> class provides a means
67    * of getting contextual information about the current request or configuring XWiki on the fly.
68    *
69    * @version $Id: 6a6220bc8ba4b5f1292402923afd575a41b6c125 $
70    */
 
71    public class XWikiContext extends Hashtable<Object, Object>
72    {
73    /**
74    * Type instance for {@code Provider<XWikiContext>}.
75    *
76    * @since 5.0M1
77    */
78    public static final ParameterizedType TYPE_PROVIDER =
79    new DefaultParameterizedType(null, Provider.class, XWikiContext.class);
80   
81    public static final int MODE_SERVLET = 0;
82   
83    public static final int MODE_PORTLET = 1;
84   
85    public static final int MODE_XMLRPC = 2;
86   
87    public static final int MODE_ATOM = 3;
88   
89    public static final int MODE_PDF = 4;
90   
91    public static final int MODE_GWT = 5;
92   
93    public static final int MODE_GWT_DEBUG = 6;
94   
95    public static final String EXECUTIONCONTEXT_KEY = "xwikicontext";
96   
97    /**
98    * @deprecated use {@link VelocityManager#getVelocityContext()} instead
99    */
100    @Deprecated
101    public static final String KEY_LEGACY_VELOCITYCONTEXT = "vcontext";
102   
103    /** Logging helper object. */
104    protected static final Logger LOGGER = LoggerFactory.getLogger(XWikiContext.class);
105   
106    private static final String WIKI_KEY = "wiki";
107   
108    private static final String ORIGINAL_WIKI_KEY = "originalWiki";
109   
110    private static final String USER_KEY = "user";
111   
112    private static final String USERREFERENCE_KEY = "userreference";
113   
114    /**
115    * Used to resolve a string into a proper Document Reference using the current document's reference to fill the
116    * blanks, except for the page name for which the default page name is used instead and for the wiki name for which
117    * the current wiki is used instead of the current document reference's wiki.
118    */
119    private DocumentReferenceResolver<String> currentMixedDocumentReferenceResolver;
120   
121    /**
122    * Used to convert a proper Document Reference to a string but without the wiki name.
123    */
124    private EntityReferenceSerializer<String> localEntityReferenceSerializer;
125   
126    /**
127    * Used to convert a Document Reference to string (compact form without the wiki part if it matches the current
128    * wiki).
129    */
130    private EntityReferenceSerializer<String> compactWikiEntityReferenceSerializer;
131   
132    /** The Execution so that we can check if permissions were dropped there. */
133    private Execution execution;
134   
135    private boolean finished = false;
136   
137    private XWiki wiki;
138   
139    private XWikiEngineContext engine_context;
140   
141    private XWikiRequest request;
142   
143    private XWikiResponse response;
144   
145    private XWikiForm form;
146   
147    private String action;
148   
149    private String orig_wikiId;
150   
151    private WikiReference wikiReference;
152   
153    private DocumentReference userReference;
154   
155    private Locale locale;
156   
157    private static final String LANGUAGE_KEY = "language";
158   
159    private Locale interfaceLocale;
160   
161    private int mode;
162   
163    private URL url;
164   
165    private XWikiURLFactory URLFactory;
166   
167    private int cacheDuration = 0;
168   
169    private int classCacheSize = 20;
170   
171    // Used to avoid recursive loading of documents if there are recursives usage of classes
172    // FIXME: why synchronized since a context is supposed to be tied to a thread ?
173    @SuppressWarnings("unchecked")
174    private Map<DocumentReference, BaseClass> classCache = Collections.synchronizedMap(new LRUMap(this.classCacheSize));
175   
176    // FIXME: why synchronized since a context is supposed to be tied to a thread ?
177    private List<String> displayedFields = Collections.synchronizedList(new ArrayList<String>());
178   
 
179  43727 toggle public XWikiContext()
180    {
181    }
182   
 
183  10455 toggle private DocumentReferenceResolver<String> getCurrentMixedDocumentReferenceResolver()
184    {
185  10459 if (this.currentMixedDocumentReferenceResolver == null) {
186  1179 this.currentMixedDocumentReferenceResolver =
187    Utils.getComponent(DocumentReferenceResolver.TYPE_STRING, "currentmixed");
188    }
189   
190  10464 return this.currentMixedDocumentReferenceResolver;
191    }
192   
 
193  2 toggle private EntityReferenceSerializer<String> getLocalEntityReferenceSerializer()
194    {
195  2 if (this.localEntityReferenceSerializer == null) {
196  1 this.localEntityReferenceSerializer = Utils.getComponent(EntityReferenceSerializer.TYPE_STRING, "local");
197    }
198   
199  2 return this.localEntityReferenceSerializer;
200    }
201   
 
202  724189 toggle private EntityReferenceSerializer<String> getCompactWikiEntityReferenceSerializer()
203    {
204  724434 if (this.compactWikiEntityReferenceSerializer == null) {
205  44723 this.compactWikiEntityReferenceSerializer =
206    Utils.getComponent(EntityReferenceSerializer.TYPE_STRING, "compactwiki");
207    }
208   
209  724463 return this.compactWikiEntityReferenceSerializer;
210    }
211   
 
212  210867 toggle private Execution getExecution()
213    {
214  210866 if (this.execution == null) {
215  27786 this.execution = Utils.getComponent(Execution.class);
216    }
217   
218  210867 return this.execution;
219    }
220   
 
221  2 toggle private ExecutionContext getExecutionContext()
222    {
223  2 if (getExecution() != null) {