1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package com.xpn.xwiki

File XWikiContext.java

 

Coverage histogram

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

Code metrics

80
196
88
1
1,022
619
132
0.67
2.23
88
1.5

Classes

Class Line # Actions
XWikiContext 71 196 0% 132 78
0.7857142778.6%
 

Contributing tests

This file is covered by 471 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: a8bb4f7318670118ece81e791f3321522e2fc3e9 $
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    public static final String KEY_LEGACY_VELOCITYCONTEXT = "vcontext";
101   
102    /** Logging helper object. */
103    protected static final Logger LOGGER = LoggerFactory.getLogger(XWikiContext.class);
104   
105    private static final String WIKI_KEY = "wiki";
106   
107    private static final String ORIGINAL_WIKI_KEY = "originalWiki";
108   
109    private static final String USER_KEY = "user";
110   
111    private static final String USERREFERENCE_KEY = "userreference";
112   
113    /**
114    * Used to resolve a string into a proper Document Reference using the current document's reference to fill the
115    * blanks, except for the page name for which the default page name is used instead and for the wiki name for which
116    * the current wiki is used instead of the current document reference's wiki.
117    */
118    private DocumentReferenceResolver<String> currentMixedDocumentReferenceResolver;
119   
120    /**
121    * Used to convert a proper Document Reference to a string but without the wiki name.
122    */
123    private EntityReferenceSerializer<String> localEntityReferenceSerializer;
124   
125    /**
126    * Used to convert a Document Reference to string (compact form without the wiki part if it matches the current
127    * wiki).
128    */
129    private EntityReferenceSerializer<String> compactWikiEntityReferenceSerializer;
130   
131    /** The Execution so that we can check if permissions were dropped there. */
132    private Execution execution;
133   
134    private boolean finished = false;
135   
136    private XWiki wiki;
137   
138    private XWikiEngineContext engine_context;
139   
140    private XWikiRequest request;
141   
142    private XWikiResponse response;
143   
144    private XWikiForm form;
145   
146    private String action;
147   
148    private String orig_wikiId;
149   
150    private WikiReference wikiReference;
151   
152    private DocumentReference userReference;
153   
154    private Locale locale;
155   
156    private static final String LANGUAGE_KEY = "language";
157   
158    private Locale interfaceLocale;
159   
160    private int mode;
161   
162    private URL url;
163   
164    private XWikiURLFactory URLFactory;
165   
166    private int cacheDuration = 0;
167   
168    private int classCacheSize = 20;
169   
170    // Used to avoid recursive loading of documents if there are recursives usage of classes
171    // FIXME: why synchronized since a context is supposed to be tied to a thread ?
172    @SuppressWarnings("unchecked")
173    private Map<DocumentReference, BaseClass> classCache = Collections.synchronizedMap(new LRUMap(this.classCacheSize));
174   
175    // FIXME: why synchronized since a context is supposed to be tied to a thread ?
176    private List<String> displayedFields = Collections.synchronizedList(new ArrayList<String>());
177   
 
178  12078 toggle public XWikiContext()
179    {
180    }
181   
 
182  1655 toggle private DocumentReferenceResolver<String> getCurrentMixedDocumentReferenceResolver()
183    {
184  1657 if (this.currentMixedDocumentReferenceResolver == null) {
185  1037 this.currentMixedDocumentReferenceResolver =
186    Utils.getComponent(DocumentReferenceResolver.TYPE_STRING, "currentmixed");
187    }
188   
189  1676 return this.currentMixedDocumentReferenceResolver;
190    }
191   
 
192  2 toggle private EntityReferenceSerializer<String> getLocalEntityReferenceSerializer()
193    {
194  2 if (this.localEntityReferenceSerializer == null) {
195  1 this.localEntityReferenceSerializer = Utils.getComponent(EntityReferenceSerializer.TYPE_STRING, "local");
196    }
197   
198  2 return this.localEntityReferenceSerializer;
199    }
200   
 
201  111078 toggle private EntityReferenceSerializer<String> getCompactWikiEntityReferenceSerializer()
202    {
203  111087 if (this.compactWikiEntityReferenceSerializer == null) {
204  10004 this.compactWikiEntityReferenceSerializer =
205    Utils.getComponent(EntityReferenceSerializer.TYPE_STRING, "compactwiki");
206    }
207   
208  111109 return this.compactWikiEntityReferenceSerializer;
209    }
210   
 
211  9619 toggle private Execution getExecution()
212    {
213  9617 if (this.execution == null) {
214  6940 this.execution = Utils.getComponent(Execution.class);
215    }
216   
217  9619 return this.execution;
218    }
219   
 
220  2 toggle private ExecutionContext getExecutionContext()
221    {
222  2 if (getExecution() != null) {
223  2 return getExecution().getContext();
224    }
225   
226  0 return null;
227    }
228   
 
229  2317007 toggle public XWiki getWiki()
230    {
231  2317006 return this.wiki;
232    }
233   
 
234  1083 toggle public Util getUtil()
235    {
236  1083 Util util = (Util) this.get("util");
237  1083 if (util == null) {
238  144 util = new Util();
239  144 this.put("util", util);
240    }
241   
242  1083 return util;
243    }
244   
 
245  12107 toggle public void setWiki(XWiki wiki)
246    {
247  12107 this.wiki = wiki;
248    }
249   
 
250  12588 toggle public XWikiEngineContext getEngineContext()
251    {
252  12607 return this.engine_context;
253    }
254   
 
255  11470 toggle public void setEngineContext(XWikiEngineContext engine_context)
256    {
257  11472 this.engine_context = engine_context;
258    }
259   
 
260  480239 toggle public XWikiRequest getRequest()
261    {
262  480256 return this.request;
263    }
264   
 
265  18619 toggle public void setRequest(XWikiRequest request)
266    {
267  18645 this.request = request;
268    }
269   
 
270  106733 toggle public String getAction()
271    {
272  106722 return this.action;
273    }
274   
 
275  11412 toggle public void setAction(String action)
276    {
277  11441 this.action = action;
278    }
279   
 
280  267003 toggle public XWikiResponse getResponse()
281    {
282  267004 return this.response;
283    }
284   
 
285  18869 toggle public void setResponse(XWikiResponse response)
286    {
287  18887 this.response = response;
288    }
289   
290    /**
291    * @deprecated since 6.1M1, use {@link #getWikiId()} instead
292    */
 
293  0 toggle @Deprecated
294    public String getDatabase()
295    {
296  0 return getWikiId();
297    }
298   
299    /**
300    * @return the id of the current wiki, or null if none is set
301    * @since 6.1M1
302    */
 
303  5432033 toggle public String getWikiId()
304    {
305  5432023 return this.wikiReference != null ? this.wikiReference.getName() : null;
306    }
307   
308    /**
309    * @return the reference of the current wiki or null if none is set
310    * @since 7.2M1
311    */
 
312  6928062 toggle public WikiReference getWikiReference()
313    {
314  6928039 return this.wikiReference;
315    }
316   
317    /**
318    * @param wikiId the current wiki id
319    * @deprecated since 6.1M1, use {@link #setWikiId(String)} instead
320    */
 
321  0 toggle @Deprecated
322    public void setDatabase(String wikiId)
323    {
324  0 setWikiId(wikiId);
325    }
326   
327    /**
328    * @param wikiId the current wiki id
329    * @since 6.1M1
330    */
 
331  1396451 toggle public void setWikiId(String wikiId)
332    {
333  1396443 setWikiReference(wikiId != null ? new WikiReference(wikiId) : null);
334    }
335   
336    /**
337    * @param wikiReference the current wiki reference
338    * @since 7.2M1
339    */
 
340  1396515 toggle public void setWikiReference(WikiReference wikiReference)
341    {
342  1396515 this.wikiReference = wikiReference;
343   
344  1396514 if (this.wikiReference == null) {
345  16 super.remove(WIKI_KEY);
346    } else {
347  1396497 super.put(WIKI_KEY, this.wikiReference.getName());
348   
349  1396519 if (this.orig_wikiId == null) {
350  12042 this.orig_wikiId = this.wikiReference.getName();
351  12028 super.put(ORIGINAL_WIKI_KEY, this.wikiReference.getName());
352    }
353    }
354    }
355   
 
356  11896354 toggle @Override
357    public synchronized Object get(Object key)
358    {
359  11896363 Object value;
360   
361  11896334 if (WIKI_KEY.equals(key)) {
362  295404 value = getWikiId();
363  11600962 } else if (KEY_LEGACY_VELOCITYCONTEXT.equals(key)) {
364  2 ExecutionContext executionContext = getExecutionContext();
365  2 if (executionContext != null) {
366  2 value = executionContext.getProperty(VelocityExecutionContextInitializer.VELOCITY_CONTEXT_ID);
367    } else {
368  0 value = null;
369    }
370    } else {
371  11601028 value = super.get(key);
372    }
373   
374  11896361 return value;
375    }
376   
377    /**
378    * {@inheritDoc}
379    * <p>
380    * Make sure to keep wiki field and map synchronized.
381    * </p>
382    *
383    * @see java.util.Hashtable#put(java.lang.Object, java.lang.Object)
384    */
 
385  950179 toggle @Override
386    public synchronized Object put(Object key, Object value)
387    {
388  950177 Object previous;
389   
390  950194 if (WIKI_KEY.equals(key)) {
391  32326 previous = get(WIKI_KEY);
392  32329 setWikiId((String) value);
393  917870 } else if (KEY_LEGACY_VELOCITYCONTEXT.equals(key)) {
394  0 ExecutionContext executionContext = getExecutionContext();
395  0 if (executionContext != null) {
396  0 previous = executionContext.getProperty(VelocityExecutionContextInitializer.VELOCITY_CONTEXT_ID);
397  0 executionContext.setProperty(VelocityExecutionContextInitializer.VELOCITY_CONTEXT_ID, value);
398    } else {
399  0 previous = null;
400    }
401    } else {
402  917905 if (value != null) {
403  898205 previous = super.put(key, value);
404    } else {
405  19707 previous = super.remove(key);
406    }
407    }
408   
409  950167 return previous;
410    }
411   
412    /**
413    * {@inheritDoc}
414    * <p>
415    * Make sure to keep wiki field and map synchronized.
416    * </p>
417    *
418    * @see java.util.Hashtable#remove(java.lang.Object)
419    */
 
420  270495 toggle @Override
421    public synchronized Object remove(Object key)
422    {
423  270490 Object previous;
424   
425  270476 if (WIKI_KEY.equals(key)) {
426  0 previous = get(WIKI_KEY);
427  0 setWikiId(null);
428  270464 } else if (KEY_LEGACY_VELOCITYCONTEXT.equals(key)) {
429  0 ExecutionContext executionContext = getExecutionContext();
430  0 if (executionContext != null) {
431  0 previous = executionContext.getProperty(VelocityExecutionContextInitializer.VELOCITY_CONTEXT_ID);
432  0 executionContext.removeProperty(VelocityExecutionContextInitializer.VELOCITY_CONTEXT_ID);
433    } else {
434  0 previous = null;
435    }
436    } else {
437  270485 previous = super.remove(key);
438    }
439   
440  270471 return previous;
441    }
442   
443    /**
444    * Get the "original" wiki id. This will be the wiki id for the wiki which the user requested. If the wiki is
445    * switched to load some piece of data, this will remember what it should be switched back to.
446    *
447    * @return the wiki id originally requested by the user.
448    * @deprecated since 6.1M1, use {@link #getOriginalWikiId()} instead
449    */
 
450  0 toggle @Deprecated
451    public String getOriginalDatabase()
452    {
453  0 return getOriginalWikiId();
454    }
455   
456    /**
457    * Get the "original" wiki id. This will be the wiki id for the wiki which the user requested. If the wiki is
458    * switched to load some piece of data, this will remember what it should be switched back to.
459    *
460    * @return the wiki id originally requested by the user.
461    * @since 6.1M1
462    */
 
463  139923 toggle public String getOriginalWikiId()
464    {
465  139920 return this.orig_wikiId;
466    }
467   
468    /**
469    * @deprecated since 6.1M1, use {@link #setOriginalWikiId(String)} instead
470    */
 
471  0 toggle @Deprecated
472    public void setOriginalDatabase(String wikiId)
473    {
474  0 setOriginalWikiId(wikiId);
475    }
476   
477    /**
478    * Set the "original" wiki id. This will be the wiki id for the wiki which the user requested. If the wiki is
479    * switched to load some piece of data, this will remember what it should be switched back to.
480    *
481    * @param wikiId the wiki id originally requested by the user
482    * @since 6.1M1
483    */
 
484  165 toggle public void setOriginalWikiId(String wikiId)
485    {
486  165 this.orig_wikiId = wikiId;
487  165 if (wikiId == null) {
488  0 remove(ORIGINAL_WIKI_KEY);
489    } else {
490  165 put(ORIGINAL_WIKI_KEY, wikiId);
491    }
492    }
493   
494    /**
495    * @return true it's main wiki's context, false otherwise.
496    */
 
497  7510 toggle public boolean isMainWiki()
498    {
499  7510 return isMainWiki(getWikiId());
500    }
501   
502    /**
503    * @param wikiName the name of the wiki.
504    * @return true it's main wiki's context, false otherwise.
505    */
 
506  72863 toggle public boolean isMainWiki(String wikiName)
507    {
508  72855 return StringUtils.equalsIgnoreCase(wikiName, getMainXWiki());
509    }
510   
 
511  9873513 toggle public XWikiDocument getDoc()
512    {
513  9873518 return (XWikiDocument) get("doc");
514    }
515   
 
516  328347 toggle public void setDoc(XWikiDocument doc)
517    {
518  328359 if (doc == null) {
519  2141 remove("doc");
520    } else {
521  326198 put("doc", doc);
522    }
523    }
524   
 
525  2999364 toggle public DocumentReference getUserReference()
526    {
527  2999361 return this.userReference;
528    }
529   
 
530  15212 toggle public void setUserReference(DocumentReference userReference)
531    {
532  15213 if (userReference == null) {
533  3108 this.userReference = null;
534  3108 remove(USER_KEY);
535  3108 remove(USERREFERENCE_KEY);
536    } else {
537  12104 this.userReference = new DocumentReference(userReference);
538  12112 boolean ismain = isMainWiki(this.userReference.getWikiReference().getName());
539  12100 put(USER_KEY, new XWikiUser(getUser(), ismain));
540  12117 put(USERREFERENCE_KEY, this.userReference);
541   
542    // Log this since it's probably a mistake so that we find who is doing bad things
543  12116 if (this.userReference.getName().equals(XWikiRightService.GUEST_USER)) {
544  0 LOGGER.warn("A reference to XWikiGuest user has been set instead of null. This is probably a mistake.",
545    new Exception("See stack trace"));
546    }
547    }
548   
549    }
550   
 
551  2086 toggle private void setUserInternal(String user, boolean main)
552    {
553  2101 if (user == null) {
554  240 setUserReference(null);
555  1867 } else if (user.endsWith(XWikiRightService.GUEST_USER_FULLNAME) || user.equals(XWikiRightService.GUEST_USER)) {
556  204 setUserReference(null);
557    // retro-compatibilty hack: some code does not give the same meaning to null XWikiUser and XWikiUser
558    // containing guest user
559  204 put(USER_KEY, new XWikiUser(user, main));
560    } else {
561  1642 setUserReference(resolveUserReference(user));
562    }
563    }
564   
565    /**
566    * Make sure to use "XWiki" as default space when it's not provided in user name.
567    */
 
568  1632 toggle private DocumentReference resolveUserReference(String user)
569    {
570  1638 return getCurrentMixedDocumentReferenceResolver().resolve(user,
571  1675 new SpaceReference("XWiki", new WikiReference(getWikiId() == null ? "xwiki" : getWikiId())));
572    }
573   
574    /**
575    * @deprecated since 3.1M1 use {@link #setUserReference(DocumentReference)} instead
576    */
 
577  2107 toggle @Deprecated
578    public void setUser(String user)
579    {
580  2112 setUserInternal(user, false);
581    }
582   
583    /**
584    * @deprecated since 3.1M1 use {@link #getUserReference()} instead
585    */
 
586  117115 toggle @Deprecated
587    public String getUser()
588    {
589  117127 if (this.userReference != null) {
590  111090 if (getWikiId() == null) {
591  0 return getLocalEntityReferenceSerializer().serialize(this.userReference);
592    } else {
593  111087 return getCompactWikiEntityReferenceSerializer().serialize(this.userReference,
594    new WikiReference(getWikiId()));
595    }
596    } else {
597  6040 return XWikiRightService.GUEST_USER_FULLNAME;
598    }
599    }
600   
601    /**
602    * @deprecated since 3.1M1 use {@link #getUserReference()} instead
603    */
 
604  4 toggle @Deprecated
605    public String getLocalUser()
606    {
607  4 if (this.userReference != null) {
608  2 return getLocalEntityReferenceSerializer().serialize(this.userReference);
609    } else {
610  2 return XWikiRightService.GUEST_USER_FULLNAME;
611    }
612    }
613   
614    /**
615    * @deprecated since 3.1M1 use {@link #getUserReference()} instead
616    */
 
617  1716 toggle @Deprecated
618    public XWikiUser getXWikiUser()
619    {
620  1716 if (this.userReference != null) {
621  871 boolean ismain = isMainWiki(this.userReference.getWikiReference().getName());
622  871 return new XWikiUser(getUser(), ismain);
623    }
624   
625  845 return (XWikiUser) get(USER_KEY);
626    }
627   
628    /**
629    * @deprecated since 4.3M1 use {@link #getLocale()} instead
630    */
 
631  170523 toggle @Deprecated
632    public String getLanguage()
633    {
634  170504 return this.locale != null ? this.locale.toString() : null;
635    }
636   
637    /**
638    * @deprecated since 4.3M1 use {@link #setLocale(Locale)} instead
639    */
 
640  13845 toggle @Deprecated
641    public void setLanguage(String language)
642    {
643  13841 setLocale(LocaleUtils.toLocale(Util.normalizeLanguage(language)));
644   
645    }
646   
647    /**
648    * @return the current locale
649    * @since 4.3M1
650    */
 
651  134619 toggle public Locale getLocale()
652    {
653  134605 return this.locale;
654    }
655   
656    /**
657    * @param locale the current locale
658    * @since 4.3M1
659    */
 
660  25578 toggle public void setLocale(Locale locale)
661    {
662  25575 this.locale = locale;
663   
664  25570 if (locale == null) {
665  474 remove(LANGUAGE_KEY);
666    } else {
667  25098 put(LANGUAGE_KEY, locale.toString());
668    }
669    }
670   
671    /**
672    * @deprecated since 6.0M1, use {@link #getInterfaceLocale()} instead
673    */
 
674  0 toggle @Deprecated
675    public String getInterfaceLanguage()
676    {
677  0 return this.interfaceLocale != null ? this.interfaceLocale.toString() : null;
678    }
679   
680    /**
681    * @return the {@link Locale} to use to display the user interface
682    * @since 6.0M1
683    */
 
684  0 toggle public Locale getInterfaceLocale()
685    {
686  0 return this.interfaceLocale;
687    }
688   
689    /**
690    * @deprecated since 6.0M1, use {@link #setInterfaceLocale(Locale)} instead
691    */
 
692  0 toggle @Deprecated
693    public void setInterfaceLanguage(String interfaceLanguage)
694    {
695  0 setInterfaceLocale(LocaleUtils.toLocale(Util.normalizeLanguage(interfaceLanguage)));
696    }
697   
698    /**
699    * @param interfaceLocale the {@link Locale} to use to display the content
700    * @since 6.0M1
701    */
 
702  0 toggle public void setInterfaceLocale(Locale interfaceLocale)
703    {
704  0 this.interfaceLocale = interfaceLocale;
705    }
706   
 
707  47238 toggle public int getMode()
708    {
709  47269 return this.mode;
710    }
711   
 
712  13204 toggle public void setMode(int mode)
713    {
714  13229 this.mode = mode;
715    }
716   
 
717  53144 toggle public URL getURL()
718    {
719  53151 return this.url;
720    }
721   
 
722  11547 toggle public void setURL(URL url)
723    {
724  11547 this.url = url;
725    }
726   
 
727  238566 toggle public XWikiURLFactory getURLFactory()
728    {
729  238568 return this.URLFactory;
730    }
731   
 
732  11701 toggle public void setURLFactory(XWikiURLFactory URLFactory)
733    {
734  11701 this.URLFactory = URLFactory;
735    }
736   
 
737  1328 toggle public XWikiForm getForm()
738    {
739  1328 return this.form;
740    }
741   
 
742  9595 toggle public void setForm(XWikiForm form)
743    {
744  9621 this.form = form;
745    }
746   
 
747  6892 toggle public boolean isFinished()
748    {
749  6891 return this.finished;
750    }
751   
 
752  1 toggle public void setFinished(boolean finished)
753    {
754  1 this.finished = finished;
755    }
756   
757    /**
758    * @deprecated never made any sense since the context wiki can change any time
759    */
 
760  0 toggle @Deprecated
761    public void setWikiOwner(String wikiOwner)
762    {
763    // Cannot do anything
764    }
765   
766    /**
767    * @deprecated use {@link XWiki#getWikiOwner(String, XWikiContext)} instead
768    */
 
769  0 toggle @Deprecated
770    public String getWikiOwner()
771    {
772  0 try {
773  0 return getWiki().getWikiOwner(getWikiId(), this);
774    } catch (XWikiException e) {
775  0 LOGGER.error("Failed to get owner for wiki [{}]", getWikiId(), e);
776    }
777   
778  0 return null;
779    }
780   
 
781  0 toggle public XWikiDocument getWikiServer()
782    {
783  0 String currentWiki = getWikiId();
784  0 try {
785  0 setWikiId(getMainXWiki());
786   
787  0 return getWiki().getDocument(XWiki.getServerWikiPage(currentWiki), this);
788    } catch (XWikiException e) {
789  0 LOGGER.error("Failed to get wiki descriptor for wiki [{}]", currentWiki, e);
790    } finally {
791  0 setWikiId(currentWiki);
792    }
793   
794  0 return null;
795    }
796   
 
797  0 toggle public int getCacheDuration()
798    {
799  0 return this.cacheDuration;
800    }
801   
 
802  474 toggle public void setCacheDuration(int cacheDuration)
803    {
804  474 this.cacheDuration = cacheDuration;
805    }
806   
 
807  226820 toggle public String getMainXWiki()
808    {
809  226820 return (String) get("mainxwiki");
810    }
811   
 
812  11995 toggle public void setMainXWiki(String str)
813    {
814  12007 put("mainxwiki", str);
815    }
816   
817    // Used to avoid recursive loading of documents if there are recursives usage of classes
 
818  7417 toggle public void addBaseClass(BaseClass bclass)
819    {
820  7419 this.classCache.put(bclass.getDocumentReference(), bclass);
821    }
822   
823    /**
824    * @since 2.2M2
825    */
826    // Used to avoid recursive loading of documents if there are recursives usage of classes
 
827  45891 toggle public BaseClass getBaseClass(DocumentReference classReference)
828    {
829  45887 return this.classCache.get(classReference);
830    }
831   
832    /**
833    * @param classReference the reference of the class
834    * @since 9.0RC1
835    */
 
836  0 toggle public void removeBaseClass(DocumentReference classReference)
837    {
838  0 this.classCache.remove(classReference);
839    }
840   
841    /**
842    * Empty the class cache.
843    */
 
844  474 toggle public void flushClassCache()
845    {
846  474 this.classCache.clear();
847    }
848   
 
849  0 toggle public void setLinksAction(String action)
850    {
851  0 put("links_action", action);
852    }
853   
 
854  0 toggle public void unsetLinksAction()
855    {
856  0 remove("links_action");
857    }
858   
 
859  54947 toggle public String getLinksAction()
860    {
861  54947 return (String) get("links_action");
862    }
863   
 
864  0 toggle public void setLinksQueryString(String value)
865    {
866  0 put("links_qs", value);
867    }
868   
 
869  0 toggle public void unsetLinksQueryString()
870    {
871  0 remove("links_qs");
872    }
873   
 
874  93233 toggle public String getLinksQueryString()
875    {
876  93232 return (String) get("links_qs");
877    }
878   
879    /**
880    * @deprecated since 4.3M2 use {@link org.xwiki.localization.ContextualLocalizationManager} component instead
881    */
 
882  1978 toggle @Deprecated
883    public XWikiMessageTool getMessageTool()
884    {
885  1978 XWikiMessageTool msg = ((XWikiMessageTool) get("msg"));
886  1978 if (msg == null) {
887  33 getWiki().prepareResources(this);
888  33 msg = ((XWikiMessageTool) get("msg"));
889    }
890   
891  1978 return msg;
892    }
893   
 
894  2 toggle public XWikiValidationStatus getValidationStatus()
895    {
896  2 return (XWikiValidationStatus) get("validation_status");
897    }
898   
 
899  1 toggle public void setValidationStatus(XWikiValidationStatus status)
900    {
901  1 put("validation_status", status);
902    }
903   
 
904  956 toggle public void addDisplayedField(String fieldname)
905    {
906  956 this.displayedFields.add(fieldname);
907    }
908   
 
909  0 toggle public List<String> getDisplayedFields()
910    {
911  0 return this.displayedFields;
912    }
913   
914    /**
915    * Returns the list of TextArea fields that use the WYSIWYG editor. This list is automatically built when displaying
916    * TextArea properties.
917    *
918    * @deprecated since 8.2RC1 when we started using the Edit Module to load the configured WYSIWYG editor
919    * @return a string containing a comma-separated list of TextArea field names for which the WYSIWYG editor should be
920    * enabled
921    */
 
922  0 toggle @Deprecated
923    public String getEditorWysiwyg()
924    {
925  0 return (String) get("editor_wysiwyg");
926    }
927   
928    /**
929    * Drop permissions for the remainder of the request cycle.
930    * <p>
931    * After this is called:
932    * <ul>
933    * <li>1. {@link com.xpn.xwiki.api.Api#hasProgrammingRights()} will always return false.</li>
934    * <li>2. {@link com.xpn.xwiki.api.XWiki#getDocumentAsAuthor(org.xwiki.model.reference.DocumentReference)},
935    * {@link com.xpn.xwiki.api.XWiki#getDocumentAsAuthor(String)}, {@link com.xpn.xwiki.api.Document#saveAsAuthor()},
936    * {@link com.xpn.xwiki.api.Document#saveAsAuthor(String)},
937    * {@link com.xpn.xwiki.api.Document#saveAsAuthor(String, boolean)}, and
938    * {@link com.xpn.xwiki.api.Document#deleteAsAuthor()} will perform all of their actions as if the document's
939    * content author was the guest user (XWiki.XWikiGuest).</li>
940    * </ul>
941    * <p>
942    * In effect, no code requiring "programming right" will run, and if the document content author (see:
943    * {@link com.xpn.xwiki.api.Document#getContentAuthor()}) is a user who has "programming right", there will be no
944    * way for code following this call to save another document as this user, blessing it too with programming right.
945    * <p>
946    * Once dropped, permissions cannot be regained for the duration of the request.
947    * <p>
948    * If you are interested in a more flexable sandboxing method which sandboxed code only for the remainder of the
949    * rendering cycle, consider using {@link com.xpn.xwiki.api.Document#dropPermissions()}.
950    *
951    * @since 3.0M3
952    */
 
953  425 toggle public void dropPermissions()
954    {
955  425 this.put(XWikiConstant.DROPPED_PERMISSIONS, Boolean.TRUE);
956    }
957   
958    /**
959    * @return true if {@link XWikiContext#dropPermissions()} has been called on this context, or if the
960    * {@link XWikiConstant#DROPPED_PERMISSIONS} key has been set in the
961    * {@link org.xwiki.context.ExecutionContext} for this thread. This is done by calling
962    * {Document#dropPermissions()}
963    */
 
964  9594 toggle public boolean hasDroppedPermissions()
965    {
966  9594 if (this.get(XWikiConstant.DROPPED_PERMISSIONS) != null) {
967  3 return true;
968    }
969   
970  9591 final Object dropped = getExecution().getContext().getProperty(XWikiConstant.DROPPED_PERMISSIONS);
971   
972  9590 if (dropped == null || !(dropped instanceof Integer)) {
973  9567 return false;
974    }
975   
976  24 return ((Integer) dropped) == System.identityHashCode(getExecution().getContext());
977    }
978   
979    // Object
980   
 
981  7383 toggle @Override
982    public synchronized XWikiContext clone()
983    {
984  7383 XWikiContext context = (XWikiContext) super.clone();
985   
986    // Make sure to have unique instances of the various caches
987  7383 context.displayedFields = Collections.synchronizedList(new ArrayList<String>(this.displayedFields));
988  7383 context.classCache = Collections.synchronizedMap(new LRUMap<DocumentReference, BaseClass>(this.classCacheSize));
989   
990  7383 return context;
991    }
992   
993    /**
994    * There are several places where the XWiki context needs to be declared in the execution, so we add a common method
995    * here.
996    *
997    * @param executionContext The execution context.
998    */
 
999  4816 toggle public void declareInExecutionContext(ExecutionContext executionContext)
1000    {
1001  4819 if (!executionContext.hasProperty(XWikiContext.EXECUTIONCONTEXT_KEY)) {
1002  4815 executionContext.newProperty(XWikiContext.EXECUTIONCONTEXT_KEY).initial(this).inherited().declare();
1003    } else {
1004  1 executionContext.setProperty(XWikiContext.EXECUTIONCONTEXT_KEY, this);
1005    }
1006    }
1007   
1008    /**
1009    * @return the reference of the user being used to check script and programming right (i.e. the author of the
1010    * current script)
1011    * @since 8.3M2
1012    */
 
1013  870 toggle public DocumentReference getAuthorReference()
1014    {
1015  870 XWikiDocument sdoc = (XWikiDocument) get("sdoc");
1016  870 if (sdoc == null) {
1017  598 sdoc = getDoc();
1018    }
1019   
1020  870 return sdoc != null ? sdoc.getContentAuthorReference() : getUserReference();
1021    }
1022    }