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

File JobRequestContext.java

 

Coverage histogram

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

Code metrics

10
36
20
1
264
129
26
0.72
1.8
20
1.3

Classes

Class Line # Actions
JobRequestContext 41 36 0% 26 5
0.9242424492.4%
 

Contributing tests

No tests hitting this source file were found.

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.job;
21   
22    import java.net.MalformedURLException;
23    import java.net.URL;
24    import java.util.HashMap;
25    import java.util.Map;
26   
27    import org.xwiki.job.AbstractRequest;
28    import org.xwiki.job.Request;
29    import org.xwiki.model.reference.DocumentReference;
30   
31    import com.xpn.xwiki.XWikiContext;
32    import com.xpn.xwiki.doc.XWikiDocument;
33    import com.xpn.xwiki.web.XWikiRequest;
34   
35    /**
36    * Contains various information about the context which asked for a job execution.
37    *
38    * @version $Id: b627ce46c5a9ee3acade832c34c812122404460a $
39    * @since 8.3RC1
40    */
 
41    public class JobRequestContext
42    {
43    /**
44    * The key to user in the {@link Request} properties map.
45    */
46    public static final String KEY = "oldcore.xwikicontext";
47   
48    private boolean wikiIdSet;
49   
50    private String wikiId;
51   
52    private boolean documentSet;
53   
54    private XWikiDocument document;
55   
56    private boolean sDocumentSet;
57   
58    private XWikiDocument sDocument;
59   
60    private boolean userReferenceSet;
61   
62    private DocumentReference userReference;
63   
64    private boolean requestSet;
65   
66    private URL requestURL;
67   
68    private Map<String, String[]> requestParameters;
69   
70    /**
71    * Default constructor.
72    */
 
73  0 toggle public JobRequestContext()
74    {
75    }
76   
77    /**
78    * @param xcontext the XWiki context to extract informations from
79    */
 
80  33 toggle public JobRequestContext(XWikiContext xcontext)
81    {
82  33 if (xcontext != null) {
83  33 setWikiId(xcontext.getWikiId());
84  33 setUserReference(xcontext.getUserReference());
85  33 setDocument(xcontext.getDoc());
86  33 setSDocument((XWikiDocument) xcontext.get(XWikiDocument.CKEY_SDOC));
87   
88  33 XWikiRequest request = xcontext.getRequest();
89  33 if (request != null) {
90  33 if (request.getRequestURL() != null) {
91  33 try {
92  33 setRequestUrl(new URL(request.getRequestURL().toString()));
93    } catch (MalformedURLException e) {
94    // Log something ? I guess I should never happen (it returns a StringBuffer so that it can be
95    // modified).
96    }
97    }
98  33 if (request.getParameterMap() != null) {
99  2 setRequestParameters(request.getParameterMap());
100    }
101    }
102    }
103    }
104   
105    /**
106    * Register part of the {@link XWikiContext} in the job request.
107    *
108    * @param request the job request
109    * @param xcontext the XWiki context
110    * @since 8.4RC1
111    */
 
112  33 toggle public static void set(AbstractRequest request, XWikiContext xcontext)
113    {
114  33 if (xcontext != null) {
115  33 request.setProperty(JobRequestContext.KEY, new JobRequestContext(xcontext));
116    }
117    }
118   
119    /**
120    * @return true if the identifier of the wiki has been set
121    */
 
122  33 toggle public boolean isWikiIdSet()
123    {
124  33 return this.wikiIdSet;
125    }
126   
127    /**
128    * @return the identifier of the wiki
129    */
 
130  33 toggle public String getWikiId()
131    {
132  33 return this.wikiId;
133    }
134   
135    /**
136    * @param wikiId the identifier of the wiki
137    */
 
138  33 toggle public void setWikiId(String wikiId)
139    {
140  33 this.wikiId = wikiId;
141  33 this.wikiIdSet = true;
142    }
143   
144    /**
145    * @return true if the reference of the user has been set
146    */
 
147  33 toggle public boolean isUserReferenceSet()
148    {
149  33 return this.userReferenceSet;
150    }
151   
152    /**
153    * @return the reference of the user
154    */
 
155  33 toggle public DocumentReference getUserReference()
156    {
157  33 return this.userReference;
158    }
159   
160    /**
161    * @param userReference the reference of the user
162    */
 
163  33 toggle public void setUserReference(DocumentReference userReference)
164    {
165  33 this.userReference = userReference;
166  33 this.userReferenceSet = true;
167    }
168   
169    /**
170    * @return true of the current document has been set
171    */
 
172  33 toggle public boolean isDocumentSet()
173    {
174  33 return this.documentSet;
175    }
176   
177    /**
178    * @param document the current document
179    */
 
180  33 toggle public void setDocument(XWikiDocument document)
181    {
182  33 this.document = document;
183  33 this.documentSet = true;
184    }
185   
186    /**
187    * @return the current document
188    */
 
189  33 toggle public XWikiDocument getDocument()
190    {
191  33 return this.document;
192    }
193   
194    /**
195    * @return true if the document holding the current author has been set
196    */
 
197  33 toggle public boolean isSDocumentSet()
198    {
199  33 return this.sDocumentSet;
200    }
201   
202    /**
203    * @param sdocument the document holding the current author
204    */
 
205  33 toggle public void setSDocument(XWikiDocument sdocument)
206    {
207  33 this.sDocument = sdocument;
208  33 this.sDocumentSet = true;
209    }
210   
211    /**
212    * @return the document holding the current author
213    */
 
214  33 toggle public XWikiDocument getSDocument()
215    {
216  33 return this.sDocument;
217    }
218   
219    /**
220    * @return true if the request informations have been set
221    * @since 8.4RC1
222    */
 
223  33 toggle public boolean isRequestSet()
224    {
225  33 return this.requestSet;
226    }
227   
228    /**
229    * @param requestURL the request {@link URL}
230    * @since 8.4RC1
231    */
 
232  2 toggle public void setRequestUrl(URL requestURL)
233    {
234  2 this.requestURL = requestURL;
235  2 this.requestSet = true;
236    }
237   
238    /**
239    * @return the request URL
240    * @since 8.4RC1
241    */
 
242  2 toggle public URL getRequestURL()
243    {
244  2 return this.requestURL;
245    }
246   
247    /**
248    * @param requestParameters the parameters of the request
249    * @since 8.4RC1
250    */
 
251  2 toggle public void setRequestParameters(Map<String, String[]> requestParameters)
252    {
253  2 this.requestParameters = new HashMap<>(requestParameters);
254    }
255   
256    /**
257    * @return the parameters of the request
258    * @since 8.4RC1
259    */
 
260  2 toggle public Map<String, String[]> getRequestParameters()
261    {
262  2 return this.requestParameters;
263    }
264    }