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

File XWiki.java

 

Coverage histogram

../../../../img/srcFileCovDistChart4.png
78% of files have more coverage

Code metrics

110
393
181
1
2,900
1,141
272
0.69
2.17
181
1.5

Classes

Class Line # Actions
XWiki 60 393 0% 272 406
0.4064327540.6%
 

Contributing tests

This file is covered by 27 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.api;
21   
22    import java.io.IOException;
23    import java.lang.reflect.Type;
24    import java.util.ArrayList;
25    import java.util.Collections;
26    import java.util.Date;
27    import java.util.List;
28    import java.util.Locale;
29   
30    import org.apache.commons.lang3.StringUtils;
31    import org.apache.commons.lang3.math.NumberUtils;
32    import org.slf4j.Logger;
33    import org.slf4j.LoggerFactory;
34    import org.xwiki.component.manager.ComponentLookupException;
35    import org.xwiki.job.Job;
36    import org.xwiki.job.event.status.JobStatus;
37    import org.xwiki.job.event.status.JobStatus.State;
38    import org.xwiki.model.reference.DocumentReference;
39    import org.xwiki.model.reference.DocumentReferenceResolver;
40    import org.xwiki.model.reference.EntityReference;
41    import org.xwiki.model.reference.EntityReferenceSerializer;
42    import org.xwiki.model.reference.SpaceReference;
43    import org.xwiki.model.reference.WikiReference;
44    import org.xwiki.rendering.renderer.PrintRendererFactory;
45    import org.xwiki.rendering.syntax.Syntax;
46   
47    import com.xpn.xwiki.XWikiContext;
48    import com.xpn.xwiki.XWikiException;
49    import com.xpn.xwiki.doc.XWikiDeletedDocument;
50    import com.xpn.xwiki.doc.XWikiDocument;
51    import com.xpn.xwiki.internal.XWikiInitializerJob;
52    import com.xpn.xwiki.internal.XWikiInitializerJobStatus;
53    import com.xpn.xwiki.objects.meta.MetaClass;
54    import com.xpn.xwiki.user.api.XWikiUser;
55    import com.xpn.xwiki.util.Programming;
56    import com.xpn.xwiki.web.Utils;
57    import com.xpn.xwiki.web.XWikiEngineContext;
58    import com.xpn.xwiki.web.XWikiURLFactory;
59   
 
60    public class XWiki extends Api
61    {
62    /** Logging helper object. */
63    protected static final Logger LOGGER = LoggerFactory.getLogger(XWiki.class);
64   
65    /** The internal object wrapped by this API. */
66    private com.xpn.xwiki.XWiki xwiki;
67   
68    /**
69    * @see #getStatsService()
70    */
71    private StatsService statsService;
72   
73    /**
74    * @see #getCriteriaService()
75    */
76    private CriteriaService criteriaService;
77   
78    /**
79    * @see com.xpn.xwiki.internal.model.reference.CurrentMixedStringDocumentReferenceResolver
80    */
81    private DocumentReferenceResolver<String> currentMixedDocumentReferenceResolver;
82   
83    /**
84    * @see org.xwiki.model.internal.reference.DefaultStringDocumentReferenceResolver
85    */
86    private DocumentReferenceResolver<String> defaultDocumentReferenceResolver;
87   
88    /**
89    * The object used to serialize entity references into strings. We need it because we have script APIs that work
90    * with entity references but have to call older, often internal, methods that still use string references.
91    */
92    private EntityReferenceSerializer<String> defaultStringEntityReferenceSerializer;
93   
94    private DocumentReferenceResolver<EntityReference> currentgetdocumentResolver;
95   
96    /**
97    * XWiki API Constructor
98    *
99    * @param xwiki XWiki Main Object to wrap
100    * @param context XWikiContext to wrap
101    */
 
102  17722 toggle public XWiki(com.xpn.xwiki.XWiki xwiki, XWikiContext context)
103    {
104  17729 super(context);
105   
106  17715 this.xwiki = xwiki;
107  17710 this.statsService = new StatsService(context);
108  17719 this.criteriaService = new CriteriaService(context);
109    }
110   
 
111  38768 toggle private DocumentReferenceResolver<String> getCurrentMixedDocumentReferenceResolver()
112    {
113  38766 if (this.currentMixedDocumentReferenceResolver == null) {
114  8408 this.currentMixedDocumentReferenceResolver =
115    Utils.getComponent(DocumentReferenceResolver.TYPE_STRING, "currentmixed");
116    }
117   
118  38767 return this.currentMixedDocumentReferenceResolver;
119    }
120   
 
121  988 toggle private DocumentReferenceResolver<EntityReference> getCurrentgetdocumentResolver()
122    {
123  988 if (this.currentgetdocumentResolver == null) {
124  810 this.currentgetdocumentResolver =
125    Utils.getComponent(DocumentReferenceResolver.TYPE_REFERENCE, "currentgetdocument");
126    }
127   
128  988 return this.currentgetdocumentResolver;
129    }
130   
 
131  0 toggle private DocumentReferenceResolver<String> getDefaultDocumentReferenceResolver()
132    {
133  0 if (this.defaultDocumentReferenceResolver == null) {
134  0 this.defaultDocumentReferenceResolver = Utils.getComponent(DocumentReferenceResolver.TYPE_STRING);
135    }
136   
137  0 return this.defaultDocumentReferenceResolver;
138    }
139   
 
140  6 toggle private EntityReferenceSerializer<String> getDefaultStringEntityReferenceSerializer()
141    {
142  6 if (this.defaultStringEntityReferenceSerializer == null) {
143  3 this.defaultStringEntityReferenceSerializer = Utils.getComponent(EntityReferenceSerializer.TYPE_STRING);
144    }
145   
146  6 return this.defaultStringEntityReferenceSerializer;
147    }
148   
149    /**
150    * Privileged API allowing to access the underlying main XWiki Object
151    *
152    * @return Privileged Main XWiki Object
153    */
 
154  0 toggle @Programming
155    public com.xpn.xwiki.XWiki getXWiki()
156    {
157  0 if (hasProgrammingRights()) {
158  0 return this.xwiki;
159    }
160   
161  0 return null;
162    }
163   
164    /**
165    * @return the status of the job initializing {@link com.xpn.xwiki.XWiki} instance
166    * @since 6.1M1
167    */
 
168  0 toggle public XWikiInitializerJobStatus getJobStatus()
169    {
170  0 XWikiInitializerJob job = Utils.getComponent((Type) Job.class, XWikiInitializerJob.JOBTYPE);
171   
172  0 return job != null ? job.getStatus() : null;
173    }
174   
175    /**
176    * @return the status of the job initializing the instance or the current wiki
177    * @since 8.4RC1
178    */
 
179  0 toggle public JobStatus getCurrentInitializerJobStatus()
180    {
181    // Get XWiki intiializer job
182  0 XWikiInitializerJobStatus xwikiStatus = getJobStatus();
183   
184  0 if (xwikiStatus == null) {
185  0 return null;
186    }
187   
188    // The XWiki initialization is not done yet
189  0 if (xwikiStatus.getState() != State.FINISHED) {
190  0 return xwikiStatus;
191    }
192   
193    // Get current wiki initializer job
194  0 Job wikiJob = this.xwiki.getWikiInitializerJob(this.context.getWikiId());
195   
196  0 return wikiJob != null ? wikiJob.getStatus() : null;
197    }
198   
199    /**
200    * @return XWiki's version in the format <code>(version).(SVN build number)</code>, or "Unknown version" if it
201    * failed to be retrieved
202    */
 
203  1063 toggle public String getVersion()
204    {
205  1063 return this.xwiki.getVersion();
206    }
207   
208    /**
209    * API Allowing to access the current request URL being requested.
210    *
211    * @return the URL
212    * @throws XWikiException failed to create the URL
213    */
 
214  1 toggle public String getRequestURL() throws XWikiException
215    {
216  1 return getXWikiContext().getURLFactory().getRequestURL(getXWikiContext()).toString();
217    }
218   
219    /**
220    * API Allowing to access the current request URL being requested as a relative URL.
221    *
222    * @return the URL
223    * @throws XWikiException failed to create the URL
224    * @since 4.0M1
225    */
 
226  8605 toggle public String getRelativeRequestURL() throws XWikiException
227    {
228  8605 XWikiURLFactory urlFactory = getXWikiContext().getURLFactory();
229   
230  8603 return urlFactory.getURL(urlFactory.getRequestURL(getXWikiContext()), getXWikiContext());
231    }
232   
233    /**
234    * Loads an Document from the database. Rights are checked before sending back the document.
235    *
236    * @param fullName the full name of the XWiki document to be loaded
237    * @return a Document object (if the document couldn't be found a new one is created in memory - but not saved, you
238    * can check whether it's a new document or not by using {@link com.xpn.xwiki.api.Document#isNew()}
239    * @throws XWikiException
240    */
 
241  38286 toggle public Document getDocument(String fullName) throws XWikiException
242    {
243  38286 DocumentReference reference;
244   
245    // We ignore the passed full name if it's null to be backward compatible with previous behaviors.
246  38286 if (fullName != null) {
247    // Note: We use the CurrentMixed Resolver since we want to use the default page name if the page isn't
248    // specified in the passed string, rather than use the current document's page name.
249  38284 reference = getCurrentMixedDocumentReferenceResolver().resolve(fullName);
250    } else {
251  0 reference = getDefaultDocumentReferenceResolver().resolve("");
252    }
253   
254  38287 return getDocument(reference);
255    }
256   
257    /**
258    * Loads a Document from the database. Rights are checked before sending back the document.
259    *
260    * @param reference the reference of the XWiki document to be loaded
261    * @return a Document object (if the document couldn't be found a new one is created in memory - but not saved, you
262    * can check whether it's a new document or not by using {@link com.xpn.xwiki.api.Document#isNew()}
263    * @throws XWikiException
264    * @since 2.3M1
265    */
 
266  47414 toggle public Document getDocument(DocumentReference reference) throws XWikiException
267    {
268  47415 try {
269  47414 XWikiDocument doc = this.xwiki.getDocument(reference, getXWikiContext());
270  47416 if (this.xwiki.getRightService().hasAccessLevel("view", getXWikiContext().getUser(),
271    doc.getPrefixedFullName(), getXWikiContext()) == false) {
272  5 return null;
273    }
274   
275  47409 Document newdoc = doc.newDocument(getXWikiContext());
276  47411 return newdoc;
277    } catch (Exception ex) {
278  0 LOGGER.warn("Failed to access document " + reference + ": " + ex.getMessage());
279  0 return new Document(new XWikiDocument(reference), getXWikiContext());
280    }
281    }
282   
283    /**
284    * Loads a Document from the store. Rights are checked before sending back the document.
285    * <p>
286    * The passed reference can be anything. If if a document child, the document reference will be extracted from it.
287    * If it's a document parent it will be completed with the necessary default references (for example if it's a space
288    * reference it will load the space home page).
289    *
290    * @param reference the reference close to the XWiki document to be loaded
291    * @return a Document object (if the document couldn't be found a new one is created in memory - but not saved, you
292    * can check whether it's a new document or not by using {@link com.xpn.xwiki.api.Document#isNew()}
293    * @throws XWikiException
294    * @since 7.1M2
295    */
 
296  988 toggle public Document getDocument(EntityReference reference) throws XWikiException
297    {
298  988 return getDocument(getCurrentgetdocumentResolver().resolve(reference));
299    }
300   
301    /**
302    * Loads an Document from the database. Rights are checked on the author (contentAuthor) of the document containing
303    * the currently executing script before sending back the loaded document.
304    *
305    * @param fullName the full name of the XWiki document to be loaded
306    * @return a Document object (if the document couldn't be found a new one is created in memory - but not saved, you
307    * can check whether it's a new document or not by using {@link com.xpn.xwiki.api.Document#isNew()}
308    * @throws XWikiException
309    * @since 2.3M2
310    */
 
311  7 toggle public Document getDocumentAsAuthor(String fullName) throws XWikiException
312    {
313  7 DocumentReference reference;
314   
315    // We ignore the passed full name if it's null to match behavior of getDocument
316  7 if (fullName != null) {
317    // Note: We use the CurrentMixed Resolver since we want to use the default page name if the page isn't
318    // specified in the passed string, rather than use the current document's page name.
319  7 reference = getCurrentMixedDocumentReferenceResolver().resolve(fullName);
320    } else {
321  0 reference = getDefaultDocumentReferenceResolver().resolve("");
322    }
323   
324  7 return getDocumentAsAuthor(reference);
325    }
326   
327    /**
328    * Loads an Document from the database. Rights are checked on the author (contentAuthor) of the document containing
329    * the currently executing script before sending back the loaded document.
330    *
331    * @param reference the reference of the XWiki document to be loaded
332    * @return a Document object (if the document couldn't be found a new one is created in memory - but not saved, you
333    * can check whether it's a new document or not by using {@link com.xpn.xwiki.api.Document#isNew()}
334    * @throws XWikiException
335    * @since 2.3M2
336    */
 
337  7 toggle public Document getDocumentAsAuthor(DocumentReference reference) throws XWikiException
338    {
339  7 String author = this.getEffectiveScriptAuthorName();
340  7 XWikiDocument doc = this.xwiki.getDocument(reference, getXWikiContext());
341  7 if (this.xwiki.getRightService().hasAccessLevel("view", author, doc.getFullName(),
342    getXWikiContext()) == false) {
343  0 return null;
344    }
345   
346  7 Document newdoc = doc.newDocument(getXWikiContext());
347  7 return newdoc;
348    }
349   
350    /**
351    * @param fullname the {@link XWikiDocument#getFullName() name} of the document to search for.
352    * @param locale an optional {@link XWikiDocument#getLocale() locale} to filter results.
353    * @return A list with all the deleted versions of a document in the recycle bin.
354    * @throws XWikiException if any error
355    */
 
356  304 toggle public List<DeletedDocument> getDeletedDocuments(String fullname, String locale) throws XWikiException
357    {
358  304 XWikiDeletedDocument[] dds = this.xwiki.getDeletedDocuments(fullname, locale, this.context);
359  302 if (dds == null || dds.length == 0) {
360  287 return Collections.emptyList();
361    }
362  15 List<DeletedDocument> result = new ArrayList<DeletedDocument>(dds.length);
363  15 for (XWikiDeletedDocument dd : dds) {
364  17 result.add(new DeletedDocument(dd, this.context));
365    }
366  15 return result;
367    }
368   
369    /**
370    * @return specified documents in recycle bin
371    * @param fullname - {@link XWikiDocument#getFullName()}
372    * @param locale - {@link XWikiDocument#getLocale()}
373    * @throws XWikiException if any error
374    */
 
375  0 toggle public DeletedDocument getDeletedDocument(String fullname, String locale, String index) throws XWikiException
376    {
377  0 if (!NumberUtils.isDigits(index)) {
378  0 return null;
379    }
380  0 XWikiDeletedDocument dd =
381    this.xwiki.getDeletedDocument(fullname, locale, Integer.parseInt(index), this.context);
382  0 if (dd == null) {
383  0 return null;
384    }
385   
386  0 return new DeletedDocument(dd, this.context);
387    }
388   
389    /**
390    * Retrieve all the deleted attachments that belonged to a certain document. Note that this does not distinguish
391    * between different incarnations of a document name, and it does not require that the document still exists, it
392    * returns all the attachments that at the time of their deletion had a document with the specified name as their
393    * owner.
394    *
395    * @param docName the {@link XWikiDocument#getFullName() name} of the owner document
396    * @return A list with all the deleted attachments which belonged to the specified document. If no such attachments
397    * are found in the trash, an empty list is returned.
398    */
 
399  0 toggle public List<DeletedAttachment> getDeletedAttachments(String docName)
400    {
401  0 try {
402  0 List<com.xpn.xwiki.doc.DeletedAttachment> attachments =
403    this.xwiki.getDeletedAttachments(docName, this.context);
404  0 if (attachments == null || attachments.isEmpty()) {
405  0 attachments = Collections.emptyList();
406    }
407  0 List<DeletedAttachment> result = new ArrayList<DeletedAttachment>(attachments.size());
408  0 for (com.xpn.xwiki.doc.DeletedAttachment attachment : attachments) {
409  0 result.add(new DeletedAttachment(attachment, this.context));
410    }
411  0 return result;
412    } catch (Exception ex) {
413  0 LOGGER.warn("Failed to retrieve deleted attachments", ex);
414    }
415  0 return Collections.emptyList();
416    }
417   
418    /**
419    * Retrieve all the deleted attachments that belonged to a certain document and had the specified name. Multiple
420    * versions can be returned since the same file can be uploaded and deleted several times, creating different
421    * instances in the trash. Note that this does not distinguish between different incarnations of a document name,
422    * and it does not require that the document still exists, it returns all the attachments that at the time of their
423    * deletion had a document with the specified name as their owner.
424    *
425    * @param docName the {@link DeletedAttachment#getDocName() name of the document} the attachment belonged to
426    * @param filename the {@link DeletedAttachment#getFilename() name} of the attachment to search for
427    * @return A list with all the deleted attachments which belonged to the specified document and had the specified
428    * filename. If no such attachments are found in the trash, an empty list is returned.
429    */
 
430  0 toggle public List<DeletedAttachment> getDeletedAttachments(String docName, String filename)
431    {
432  0 try {
433  0 List<com.xpn.xwiki.doc.DeletedAttachment> attachments =
434    this.xwiki.getDeletedAttachments(docName, filename, this.context);
435  0 if (attachments == null) {
436  0 attachments = Collections.emptyList();
437    }
438  0 List<DeletedAttachment> result = new ArrayList<DeletedAttachment>(attachments.size());
439  0 for (com.xpn.xwiki.doc.DeletedAttachment attachment : attachments) {
440  0 result.add(new DeletedAttachment(attachment, this.context));
441    }
442  0 return result;
443    } catch (Exception ex) {
444  0 LOGGER.warn("Failed to retrieve deleted attachments", ex);
445    }
446  0 return Collections.emptyList();
447    }
448   
449    /**
450    * Retrieve a specific attachment from the trash.
451    *
452    * @param id the unique identifier of the entry in the trash
453    * @return specified attachment from the trash, {@code null} if not found
454    */
 
455  0 toggle public DeletedAttachment getDeletedAttachment(String id)
456    {
457  0 try {
458  0 com.xpn.xwiki.doc.DeletedAttachment attachment = this.xwiki.getDeletedAttachment(id, this.context);
459  0 if (attachment != null) {
460  0 return new DeletedAttachment(attachment, this.context);
461    }
462    } catch (Exception ex) {
463  0 LOGGER.warn("Failed to retrieve deleted attachment", ex);
464    }
465  0 return null;
466    }
467   
468    /**
469    * Returns whether a document exists or not
470    *
471    * @param fullname Fullname of the XWiki document to be loaded
472    * @return true if the document exists, false if not
473    * @throws XWikiException
474    */
 
475  37317 toggle public boolean exists(String fullname) throws XWikiException
476    {
477  37316 return this.xwiki.exists(fullname, getXWikiContext());
478    }
479   
480    /**
481    * Returns whether a document exists or not
482    *
483    * @param reference the reference of the document to check for its existence
484    * @return true if the document exists, false if not
485    * @since 2.3M2
486    */
 
487  1435 toggle public boolean exists(DocumentReference reference) throws XWikiException
488    {
489  1435 return this.xwiki.exists(reference, getXWikiContext());
490    }
491   
492    /**
493    * Verify the rights the current user has on a document. If the document requires rights and the user is not
494    * authenticated he will be redirected to the login page.
495    *
496    * @param docname fullname of the document
497    * @param right right to check ("view", "edit", "admin", "delete")
498    * @return true if it exists
499    */
 
500  13 toggle public boolean checkAccess(String docname, String right)
501    {
502  13 try {
503  13 DocumentReference docReference = getCurrentMixedDocumentReferenceResolver().resolve(docname);
504  13 XWikiDocument doc = getXWikiContext().getWiki().getDocument(docReference, this.context);
505  13 return getXWikiContext().getWiki().checkAccess(right, doc, getXWikiContext());
506    } catch (XWikiException e) {
507  0 return false;
508    }
509    }
510   
511    /**
512    * Loads an Document from the database. Rights are checked before sending back the document.
513    *
514    * @param space Space to use in case no space is defined in the provided <code>fullname</code>
515    * @param fullname the full name or relative name of the document to load
516    * @return a Document object (if the document couldn't be found a new one is created in memory - but not saved, you
517    * can check whether it's a new document or not by using {@link com.xpn.xwiki.api.Document#isNew()}
518    * @throws XWikiException
519    */
 
520  0 toggle public Document getDocument(String space, String fullname) throws XWikiException
521    {
522  0 XWikiDocument doc = this.xwiki.getDocument(space, fullname, getXWikiContext());
523  0 if (this.xwiki.getRightService().hasAccessLevel("view", getXWikiContext().getUser(), doc.getFullName(),
524    getXWikiContext()) == false) {
525  0 return null;
526    }
527   
528  0 return doc.newDocument(getXWikiContext());
529    }
530   
531    /**
532    * Load a specific revision of a document
533    *
534    * @param doc Document for which to load a specific revision
535    * @param rev Revision number
536    * @return Specific revision of a document
537    * @throws XWikiException
538    */
 
539  3 toggle public Document getDocument(Document doc, String rev) throws XWikiException
540    {
541  3 if ((doc == null) || (doc.getDoc() == null)) {
542  0 return null;
543    }
544   
545  3 if (this.xwiki.getRightService().hasAccessLevel("view", getXWikiContext().getUser(), doc.getFullName(),
546    getXWikiContext()) == false) {
547    // Finally we return null, otherwise showing search result is a real pain
548  0 return null;
549    }
550   
551  3 try {
552  3 XWikiDocument revdoc = this.xwiki.getDocument(doc.getDoc(), rev, getXWikiContext());
553  3 return revdoc.newDocument(getXWikiContext());
554    } catch (Exception e) {
555    // Can't read versioned document
556  0 LOGGER.error("Failed to read versioned document", e);
557   
558  0 return null;
559    }
560    }
561   
562    /**
563    * Output content in the edit content textarea
564    *
565    * @param content content to output
566    * @return the textarea text content
567    */
 
568  0 toggle public String getTextArea(String content)
569    {
570  0 return com.xpn.xwiki.XWiki.getTextArea(content, getXWikiContext());
571    }
572   
573    /**
574    * Get the list of available classes in the wiki
575    *
576    * @return list of classes names
577    * @throws XWikiException
578    */
 
579  28 toggle public List<String> getClassList() throws XWikiException
580    {
581  28 return this.xwiki.getClassList(getXWikiContext());
582    }
583   
584    /**
585    * Get the global MetaClass object
586    *
587    * @return MetaClass object
588    */
 
589  184 toggle public MetaClass getMetaclass()
590    {
591  184 return this.xwiki.getMetaclass();
592    }
593   
594    /**
595    * API allowing to search for document names matching a query. Examples:
596    * <ul>
597    * <li>Query: <code>where doc.space='Main' order by doc.creationDate desc</code>. Result: All the documents in space
598    * 'Main' ordered by the creation date from the most recent</li>
599    * <li>Query: <code>where doc.name like '%sport%' order by doc.name asc</code>. Result: All the documents containing
600    * 'sport' in their name ordered by document name</li>
601    * <li>Query: <code>where doc.content like '%sport%' order by doc.author</code> Result: All the documents containing
602    * 'sport' in their content ordered by the author</li>
603    * <li>Query: <code>where doc.creator = 'XWiki.LudovicDubost' order by doc.creationDate
604    * desc</code>. Result: All the documents with creator LudovicDubost ordered by the creation date from the
605    * most recent</li>
606    * <li>Query: <code>where doc.author = 'XWiki.LudovicDubost' order by doc.date desc</code>. Result: All the
607    * documents with last author LudovicDubost ordered by the last modification date from the most recent.</li>
608    * <li>Query: <code>,BaseObject as obj where doc.fullName=obj.name and
609    * obj.className='XWiki.XWikiComments' order by doc.date desc</code>. Result: All the documents with at least
610    * one comment ordered by the last modification date from the most recent</li>
611    * <li>Query: <code>,BaseObject as obj, StringProperty as prop where
612    * doc.fullName=obj.name and obj.className='XWiki.XWikiComments' and obj.id=prop.id.id
613    * and prop.id.name='author' and prop.value='XWiki.LudovicDubost' order by doc.date
614    * desc</code>. Result: All the documents with at least one comment from LudovicDubost ordered by the last
615    * modification date from the most recent</li>
616    * </ul>
617    *
618    * @param wheresql Query to be run (either starting with ", BaseObject as obj where.." or by "where ..."
619    * @return List of document names matching (Main.Page1, Main.Page2)
620    * @throws XWikiException
621    * @deprecated use query service instead
622    */
 
623  0 toggle @Deprecated
624    public List<String> searchDocuments(String wheresql) throws XWikiException
625    {
626  0 return this.xwiki.getStore().searchDocumentsNames(wheresql, getXWikiContext());
627    }
628   
629    /**
630    * API allowing to search for document names matching a query return only a limited number of elements and skipping
631    * the first rows. The query part is the same as searchDocuments
632    *
633    * @param wheresql query to use similar to searchDocuments(wheresql)
634    * @param nb return only 'nb' rows
635    * @param start skip the first 'start' rows
636    * @return List of document names matching
637    * @throws XWikiException
638    * @see List searchDocuments(String where sql)
639    * @deprecated use query service instead
640    */
 
641  0 toggle @Deprecated
642    public List<String> searchDocuments(String wheresql, int nb, int start) throws XWikiException
643    {
644  0 return this.xwiki.getStore().searchDocumentsNames(wheresql, nb, start, getXWikiContext());
645    }
646   
647    /**
648    * Privileged API allowing to search for document names matching a query return only a limited number of elements
649    * and skipping the first rows. The return values contain the list of columns specified in addition to the document
650    * space and name The query part is the same as searchDocuments
651    *
652    * @param wheresql query to use similar to searchDocuments(wheresql)
653    * @param nb return only 'nb' rows
654    * @param start skip the first 'start' rows
655    * @param selectColumns List of columns to add to the result
656    * @return List of Object[] with the column values of the matching rows
657    * @throws XWikiException
658    * @deprecated use query service instead
659    */
 
660  0 toggle @Deprecated
661    public List<String> searchDocuments(String wheresql, int nb, int start, String selectColumns) throws XWikiException
662    {
663  0 if (hasProgrammingRights()) {
664  0 return this.xwiki.getStore().searchDocumentsNames(wheresql, nb, start, selectColumns, getXWikiContext());
665    }
666   
667  0 return Collections.emptyList();
668    }
669   
670    /**
671    * API allowing to search for documents allowing to have mutliple entries per locale
672    *
673    * @param wheresql query to use similar to searchDocuments(wheresql)
674    * @param distinctbylocale true to return multiple rows per locale
675    * @return List of Document object matching
676    * @throws XWikiException
677    */
 
678  0 toggle public List<Document> searchDocuments(String wheresql, boolean distinctbylocale) throws XWikiException
679    {
680  0 return convert(this.xwiki.getStore().searchDocuments(wheresql, distinctbylocale, getXWikiContext()));
681    }
682   
683    /**
684    * API allowing to search for documents allowing to have multiple entries per locale
685    *
686    * @param wheresql query to use similar to searchDocuments(wheresql)
687    * @param distinctbylocale true to return multiple rows per locale
688    * @return List of Document object matching
689    * @param nb return only 'nb' rows
690    * @param start skip the first 'start' rows
691    * @throws XWikiException
692    */
 
693  0 toggle public List<Document> searchDocuments(String wheresql, boolean distinctbylocale, int nb, int start)
694    throws XWikiException
695    {
696  0 return convert(this.xwiki.getStore().searchDocuments(wheresql, distinctbylocale, nb, start, getXWikiContext()));
697    }
698   
699    /**
700    * Search documents by passing HQL where clause values as parameters. This allows generating a Named HQL query which
701    * will automatically encode the passed values (like escaping single quotes). This API is recommended to be used
702    * over the other similar methods where the values are passed inside the where clause and for which you'll need to
703    * do the encoding/escaping yourself before calling them.
704    * <p>
705    * Example
706    * </p>
707    *
708    * <pre>
709    * &lt;code&gt;
710    * #set($orphans = $xwiki.searchDocuments(&quot; where doc.fullName &lt;&gt; ? and (doc.parent = ? or &quot;
711    * + &quot;(doc.parent = ? and doc.space = ?))&quot;,
712    * [&quot;${doc.fullName}as&quot;, ${doc.fullName}, ${doc.name}, ${doc.space}]))
713    * &lt;/code&gt;
714    * </pre>
715    *
716    * @param parameterizedWhereClause the HQL where clause. For example
717    * {@code where doc.fullName <> ? and (doc.parent = ? or (doc.parent = ? and doc.space = ?))}
718    * @param maxResults the number of rows to return. If 0 then all rows are returned
719    * @param startOffset the number of rows to skip. If 0 don't skip any row
720    * @param parameterValues the where clause values that replace the question marks (?)
721    * @return a list of document names
722    * @throws XWikiException in case of error while performing the query
723    * @deprecated use query service instead
724    */
 
725  0 toggle @Deprecated
726    public List<String> searchDocuments(String parameterizedWhereClause, int maxResults, int startOffset,
727    List<?> parameterValues) throws XWikiException
728    {
729  0 return this.xwiki.getStore().searchDocumentsNames(parameterizedWhereClause, maxResults, startOffset,
730    parameterValues, getXWikiContext());
731    }
732   
733    /**
734    * Same as {@link #searchDocuments(String, int, int, java.util.List)} but returns all rows.
735    *
736    * @see #searchDocuments(String, int, int, java.util.List)
737    * @deprecated use query service instead
738    */
 
739  0 toggle @Deprecated
740    public List<String> searchDocuments(String parameterizedWhereClause, List<?> parameterValues) throws XWikiException
741    {
742  0 return this.xwiki.getStore().searchDocumentsNames(parameterizedWhereClause, parameterValues, getXWikiContext());
743    }
744   
745    /**
746    * Search documents in the provided wiki by passing HQL where clause values as parameters. See
747    * {@link #searchDocuments(String, int, int, java.util.List)} for more details.
748    *
749    * @param wikiName the name of the wiki where to search.
750    * @param parameterizedWhereClause the HQL where clause. For example
751    * {@code where doc.fullName <> ? and (doc.parent = ? or (doc.parent = ? and doc.space = ?))}
752    * @param maxResults the number of rows to return. If 0 then all rows are returned
753    * @param startOffset the number of rows to skip. If 0 don't skip any row
754    * @param parameterValues the where clause values that replace the question marks (?)
755    * @return a list of document full names (Space.Name).
756    * @see #searchDocuments(String, int, int, java.util.List)
757    * @throws XWikiException in case of error while performing the query
758    * @deprecated use query service instead
759    */
 
760  0 toggle @Deprecated
761    public List<String> searchDocumentsNames(String wikiName, String parameterizedWhereClause, int maxResults,
762    int startOffset, List<?> parameterValues) throws XWikiException
763    {
764  0 String database = this.context.getWikiId();
765   
766  0 try {
767  0 this.context.setWikiId(wikiName);
768   
769  0 return searchDocuments(parameterizedWhereClause, maxResults, startOffset, parameterValues);
770    } finally {
771  0 this.context.setWikiId(database);
772    }
773    }
774   
775    /**
776    * Search spaces by passing HQL where clause values as parameters. See
777    * {@link #searchDocuments(String, int, int, List)} for more about parameterized hql clauses.
778    *
779    * @param parametrizedSqlClause the HQL where clause. For example
780    * {@code where doc.fullName <> ? and (doc.parent = ? or (doc.parent = ? and doc.space = ?))}
781    * @param nb the number of rows to return. If 0 then all rows are returned
782    * @param start the number of rows to skip. If 0 don't skip any row
783    * @param parameterValues the where clause values that replace the question marks (?)
784    * @return a list of spaces names.
785    * @throws XWikiException in case of error while performing the query
786    */
 
787  0 toggle public List<String> searchSpacesNames(String parametrizedSqlClause, int nb, int start, List<?> parameterValues)
788    throws XWikiException
789    {
790  0 return this.xwiki.getStore().search("select distinct doc.space from XWikiDocument doc " + parametrizedSqlClause,
791    nb, start, parameterValues, this.context);
792    }
793   
794    /**
795    * Search attachments by passing HQL where clause values as parameters. See
796    * {@link #searchDocuments(String, int, int, List)} for more about parameterized hql clauses. You can specify
797    * properties of attach (the attachment) or doc (the document it is attached to)
798    *
799    * @param parametrizedSqlClause The HQL where clause. For example
800    * {@code where doc.fullName <> ? and (attach.author = ? or (attach.filename = ? and doc.space = ?))}
801    * @param nb The number of rows to return. If 0 then all rows are returned
802    * @param start The number of rows to skip at the beginning.
803    * @param parameterValues A {@link java.util.List} of the where clause values that replace the question marks (?)
804    * @return A List of {@link Attachment} objects.
805    * @throws XWikiException in case of error while performing the query
806    * @since 5.0M2
807    */
 
808  2 toggle public List<Attachment> searchAttachments(String parametrizedSqlClause, int nb, int start, List<?> parameterValues)
809    throws XWikiException
810    {
811  2 return convertAttachments(
812    this.xwiki.searchAttachments(parametrizedSqlClause, true, nb, start, parameterValues, this.context));
813    }
814   
815    /**
816    * Count attachments returned by a given parameterized query
817    *
818    * @param parametrizedSqlClause Everything which would follow the "WHERE" in HQL see:
819    * {@link #searchDocuments(String, int, int, List)}
820    * @param parameterValues A {@link java.util.List} of the where clause values that replace the question marks (?)
821    * @return int number of attachments found.
822    * @throws XWikiException
823    * @see #searchAttachments(String, int, int, List)
824    * @since 5.0M2
825    */
 
826  2 toggle public int countAttachments(String parametrizedSqlClause, List<?> parameterValues) throws XWikiException
827    {
828  2 return this.xwiki.countAttachments(parametrizedSqlClause, parameterValues, this.context);
829    }
830   
831    /**
832    * Function to wrap a list of XWikiDocument into Document objects
833    *
834    * @param docs list of XWikiDocument
835    * @return list of Document objects
836    */
 
837  6 toggle public List<Document> wrapDocs(List<?> docs)
838    {
839  6 List<Document> result = new ArrayList<Document>();
840  6 if (docs != null) {
841  6 for (java.lang.Object obj : docs) {
842  8 try {
843  8 if (obj instanceof XWikiDocument) {
844  4 XWikiDocument doc = (XWikiDocument) obj;
845  4 Document wrappedDoc = doc.newDocument(getXWikiContext());
846  4 result.add(wrappedDoc);
847  4 } else if (obj instanceof Document) {
848  2 result.add((Document) obj);
849  2 } else if (obj instanceof String) {
850  2 Document doc = getDocument(obj.toString());
851  2 if (doc != null) {
852  2 result.add(doc);
853    }
854    }
855    } catch (XWikiException ex) {
856    }
857    }
858    }
859   
860  6 return result;
861    }
862   
863    /**
864    * API allowing to parse a text content to evaluate velocity scripts
865    *
866    * @param content
867    * @return evaluated content if the content contains velocity scripts
868    * @deprecated Since 7.2M1. Use specific rendering/parsing options for the content type you want to parse/render.
869    */
 
870  0 toggle @Deprecated
871    public String parseContent(String content)
872    {
873  0 return this.xwiki.parseContent(content, getXWikiContext());
874    }
875   
876    /**
877    * API to parse a velocity template provided by the current Skin The template is first looked in the skin active for
878    * the user, the space or the wiki. If the template does not exist in that skin, the template is looked up in the
879    * "parent skin" of the skin
880    *
881    * @param template Template name ("view", "edit", "comment")
882    * @return Evaluated content from the template
883    */
 
884  71458 toggle public String parseTemplate(String template)
885    {
886  71455 return this.xwiki.parseTemplate(template, getXWikiContext());
887    }
888   
889    /**
890    * API to render a velocity template provided by the current Skin The template is first looked in the skin active
891    * for the user, the space or the wiki. If the template does not exist in that skin, the template is looked up in
892    * the "parent skin" of the skin
893    *
894    * @param template Template name ("view", "edit", "comment")
895    * @return Evaluated content from the template
896    */
 
897  0 toggle public String renderTemplate(String template)
898    {
899  0 return this.xwiki.renderTemplate(template, getXWikiContext());
900    }
901   
902    /**
903    * Designed to include dynamic content, such as Servlets or JSPs, inside Velocity templates; works by creating a
904    * RequestDispatcher, buffering the output, then returning it as a string.
905    *
906    * @param url URL of the servlet
907    * @return text result of the servlet
908    */
 
909  0 toggle public String invokeServletAndReturnAsString(String url)
910    {
911  0 return this.xwiki.invokeServletAndReturnAsString(url, getXWikiContext());
912    }
913   
914    /**
915    * Return the URL of the static file provided by the current skin The file is first looked in the skin active for
916    * the user, the space or the wiki. If the file does not exist in that skin, the file is looked up in the "parent
917    * skin" of the skin. The file can be a CSS file, an image file, a javascript file, etc.
918    *
919    * @param filename Filename to be looked up in the skin (logo.gif, style.css)
920    * @return URL to access this file
921    */
 
922  14424 toggle public String getSkinFile(String filename)
923    {
924  14423 return this.xwiki.getSkinFile(filename, getXWikiContext());
925    }
926   
927    /**
928    * Return the URL of the static file provided by the current skin The file is first looked in the skin active for
929    * the user, the space or the wiki. If the file does not exist in that skin, the file is looked up in the "parent
930    * skin" of the skin. The file can be a CSS file, an image file, a javascript file, etc.
931    *
932    * @param filename Filename to be looked up in the skin (logo.gif, style.css)
933    * @param forceSkinAction true to make sure that static files are retrieved through the skin action, to allow
934    * parsing of velocity on CSS files
935    * @return URL to access this file
936    */
 
937  7248 toggle public String getSkinFile(String filename, boolean forceSkinAction)
938    {
939  7248 return this.xwiki.getSkinFile(filename, forceSkinAction, getXWikiContext());
940    }
941   
942    /**
943    * API to retrieve the current skin for this request and user The skin is first derived from the request "skin"
944    * parameter If this parameter does not exist, the user preference "skin" is looked up If this parameter does not
945    * exist or is empty, the space preference "skin" is looked up If this parameter does not exist or is empty, the
946    * XWiki preference "skin" is looked up If this parameter does not exist or is empty, the xwiki.cfg parameter
947    * xwiki.defaultskin is looked up If this parameter does not exist or is empty, the xwiki.cfg parameter
948    * xwiki.defaultbaseskin is looked up If this parameter does not exist or is empty, the skin is "colibri"
949    *
950    * @return The current skin for this request and user
951    */
 
952  9003 toggle public String getSkin()
953    {
954  9002 return this.xwiki.getSkin(getXWikiContext());
955    }
956   
957    /**
958    * API to retrieve the current skin for this request and user. Each skin has a skin it is based on. If not the base
959    * skin is the xwiki.cfg parameter "xwiki.defaultbaseskin". If this parameter does not exist or is empty, the base
960    * skin is "colibri".
961    *
962    * @return The current baseskin for this request and user
963    */
 
964  0 toggle public String getBaseSkin()
965    {
966  0 return this.xwiki.getBaseSkin(getXWikiContext());
967    }
968   
969    /**
970    * API to access the copyright for this space. The copyright is read in the space preferences. If it does not exist
971    * or is empty it is read from the XWiki preferences.
972    *
973    * @return the text for the copyright
974    */
 
975  6827 toggle public String getSpaceCopyright()
976    {
977  6827 return this.xwiki.getSpaceCopyright(getXWikiContext());
978    }
979   
980    /**
981    * API to access an XWiki Preference There can be one preference object per locale This function will find the right
982    * preference object associated to the current active locale
983    *
984    * @param preference Preference name
985    * @return The preference for this wiki and the current locale
986    */
 
987  2240 toggle public String getXWikiPreference(String preference)
988    {
989  2234 return this.xwiki.getXWikiPreference(preference, getXWikiContext());
990    }
991   
992    /**
993    * API to access an XWiki Preference There can be one preference object per locale This function will find the right
994    * preference object associated to the current active locale
995    *
996    * @param preference Preference name
997    * @param defaultValue default value to return if the preference does not exist or is empty
998    * @return The preference for this wiki and the current locale
999    */
 
1000  0 toggle public String getXWikiPreference(String preference, String defaultValue)
1001    {
1002  0 return this.xwiki.getXWikiPreference(preference, defaultValue, getXWikiContext());
1003    }
1004   
1005    /**
1006    * API to access an Space Preference There can be one preference object per locale This function will find the right
1007    * preference object associated to the current active locale If no preference is found it will look in the XWiki
1008    * Preferences
1009    *
1010    * @param preference Preference name
1011    * @return The preference for this wiki and the current locale
1012    */
 
1013  44821 toggle public String getSpacePreference(String preference)
1014    {
1015  44821 return this.xwiki.getSpacePreference(preference, getXWikiContext());
1016    }
1017   
1018    /**
1019    * API to access an Space Preference There can be one preference object per locale This function will find the right
1020    * preference object associated to the current active locale If no preference is found it will look in the XWiki
1021    * Preferences
1022    *
1023    * @param preference Preference name
1024    * @param defaultValue default value to return if the preference does not exist or is empty
1025    * @return The preference for this wiki and the current locale
1026    */
 
1027  0 toggle public String getSpacePreference(String preference, String defaultValue)
1028    {
1029  0 return this.xwiki.getSpacePreference(preference, defaultValue, getXWikiContext());
1030    }
1031   
1032    /**
1033    * API to access a Skin Preference The skin object is the current user's skin
1034    *
1035    * @param preference Preference name
1036    * @return The preference for the current skin
1037    */
 
1038  0 toggle public String getSkinPreference(String preference)
1039    {
1040  0 return this.xwiki.getSkinPreference(preference, getXWikiContext());
1041    }
1042   
1043    /**
1044    * API to access a Skin Preference The skin object is the current user's skin
1045    *
1046    * @param preference Preference name
1047    * @param defaultValue default value to return if the preference does not exist or is empty
1048    * @return The preference for the current skin
1049    */
 
1050  1063 toggle public String getSkinPreference(String preference, String defaultValue)
1051    {
1052  1062 return this.xwiki.getSkinPreference(preference, defaultValue, getXWikiContext());
1053    }
1054   
1055    /**
1056    * Get the reference of the space and fallback on parent space or wiki in case nothing is found.
1057    * <p>
1058    * If the property is not set on any level then empty String is returned.
1059    *
1060    * @param preference Preference name
1061    * @param space The space for which this preference is requested
1062    * @return The preference for this wiki and the current locale
1063    */
 
1064  0 toggle public String getSpacePreferenceFor(String preference, String space)
1065    {
1066  0 return getSpacePreferenceFor(preference, space, "");
1067    }
1068   
1069    /**
1070    * Get the reference of the space and fallback on parent space or wiki in case nothing is found.
1071    * <p>
1072    * If the property is not set on any level then <code>defaultValue</code> is returned.
1073    *
1074    * @param preference Preference name
1075    * @param space The space for which this preference is requested
1076    * @param defaultValue default value to return if the preference does not exist or is empty
1077    * @return The preference for this wiki and the current locale in long format
1078    */
 
1079  0 toggle public String getSpacePreferenceFor(String preference, String space, String defaultValue)
1080    {
1081  0 return this.xwiki.getSpacePreference(preference, space, defaultValue, getXWikiContext());
1082    }
1083   
1084    /**
1085    * Get the reference of the space and fallback on parent space or wiki in case nothing is found.
1086    * <p>
1087    * If the property is not set on any level then empty String is returned.
1088    *
1089    * @param preference the name of the preference key
1090    * @param spaceReference the reference of the space
1091    * @return the value of the preference or empty String if it could not be found
1092    * @since 7.4M1
1093    */
 
1094  0 toggle public String getSpacePreferenceFor(String preference, SpaceReference spaceReference)
1095    {
1096  0 return this.xwiki.getSpacePreference(preference, spaceReference, getXWikiContext());
1097    }
1098   
1099    /**
1100    * Get the reference of the space and fallback on parent space or wiki in case nothing is found.
1101    * <p>
1102    * If the property is not set on any level then <code>defaultValue</code> is returned.
1103    *
1104    * @param preference the name of the preference key
1105    * @param spaceReference the reference of the space
1106    * @param defaultValue the value to return if the preference can't be found
1107    * @return the value of the preference or <code>defaultValue</code> if it could not be found
1108    * @since 7.4M1
1109    */
 
1110  0 toggle public String getSpacePreferenceFor(String preference, SpaceReference spaceReference, String defaultValue)
1111    {
1112  0 return this.xwiki.getSpacePreference(preference, spaceReference, defaultValue, getXWikiContext());
1113    }
1114   
1115    /**
1116    * API to access an XWiki Preference as a long number There can be one preference object per locale This function
1117    * will find the right preference object associated to the current active locale
1118    *
1119    * @param preference Preference name
1120    * @param defaultValue default value to return if the preference does not exist or is empty
1121    * @return The preference for this wiki and the current locale in long format
1122    */
 
1123  0 toggle public long getXWikiPreferenceAsLong(String preference, long defaultValue)
1124    {
1125  0 return this.xwiki.getXWikiPreferenceAsLong(preference, defaultValue, getXWikiContext());
1126    }
1127   
1128    /**
1129    * API to access an XWiki Preference as a long number There can be one preference object per locale This function
1130    * will find the right preference object associated to the current active locale
1131    *
1132    * @param preference Preference name
1133    * @return The preference for this wiki and the current locale in long format
1134    */
 
1135  0 toggle public long getXWikiPreferenceAsLong(String preference)
1136    {
1137  0 return this.xwiki.getXWikiPreferenceAsLong(preference, getXWikiContext());
1138    }
1139   
1140    /**
1141    * API to access a Space Preference as a long number There can be one preference object per locale This function
1142    * will find the right preference object associated to the current active locale If no preference is found it will
1143    * look for the XWiki Preference
1144    *
1145    * @param preference Preference name
1146    * @param defaultValue default value to return if the prefenrece does not exist or is empty
1147    * @return The preference for this wiki and the current locale in long format
1148    */
 
1149  0 toggle public long getSpacePreferenceAsLong(String preference, long defaultValue)
1150    {
1151  0 return this.xwiki.getSpacePreferenceAsLong(preference, defaultValue, getXWikiContext());
1152    }
1153   
1154    /**
1155    * API to access a Space Preference as a long number There can be one preference object per locale This function
1156    * will find the right preference object associated to the current active locale If no preference is found it will
1157    * look for the XWiki Preference
1158    *
1159    * @param preference Preference name
1160    * @return The preference for this wiki and the current locale in long format
1161    */
 
1162  0 toggle public long getSpacePreferenceAsLong(String preference)
1163    {
1164  0 return this.xwiki.getSpacePreferenceAsLong(preference, getXWikiContext());
1165    }
1166   
1167    /**
1168    * API to access an XWiki Preference as an int number There can be one preference object per locale This function
1169    * will find the right preference object associated to the current active locale
1170    *
1171    * @param preference Preference name
1172    * @param defaultValue default value to return if the prefenrece does not exist or is empty
1173    * @return The preference for this wiki and the current locale in int format
1174    */
 
1175  118 toggle public int getXWikiPreferenceAsInt(String preference, int defaultValue)
1176    {
1177  118 return this.xwiki.getXWikiPreferenceAsInt(preference, defaultValue, getXWikiContext());
1178    }
1179   
1180    /**
1181    * API to access an XWiki Preference as a int number There can be one preference object per locale This function
1182    * will find the right preference object associated to the current active locale
1183    *
1184    * @param preference Preference name
1185    * @return The preference for this wiki and the current locale in int format
1186    */
 
1187  0 toggle public int getXWikiPreferenceAsInt(String preference)
1188    {
1189  0 return this.xwiki.getXWikiPreferenceAsInt(preference, getXWikiContext());
1190    }
1191   
1192    /**
1193    * API to access a space Preference as a int number There can be one preference object per locale This function will
1194    * find the right preference object associated to the current active locale If no preference is found it will look
1195    * for the XWiki Preference
1196    *
1197    * @param preference Preference name
1198    * @param defaultValue default value to return if the prefenrece does not exist or is empty
1199    * @return The preference for this wiki and the current locale in int format
1200    */
 
1201  572 toggle public int getSpacePreferenceAsInt(String preference, int defaultValue)
1202    {
1203  572 return this.xwiki.getSpacePreferenceAsInt(preference, defaultValue, getXWikiContext());
1204    }
1205   
1206    /**
1207    * API to access a Space Preference as a int number There can be one preference object per locale This function will
1208    * find the right preference object associated to the current active locale If no preference is found it will look
1209    * for the XWiki Preference
1210    *
1211    * @param preference Preference name
1212    * @return The preference for this wiki and the current locale in int format
1213    */
 
1214  0 toggle public int getSpacePreferenceAsInt(String preference)
1215    {
1216  0 return this.xwiki.getSpacePreferenceAsInt(preference, getXWikiContext());
1217    }
1218   
1219    /**
1220    * API to access a User Preference This function will look in the User profile for the preference If no preference
1221    * is found it will look in the Space Preferences If no preference is found it will look in the XWiki Preferences
1222    *
1223    * @param preference Preference name
1224    * @return The preference for this wiki and the current locale
1225    */
 
1226  4797 toggle public String getUserPreference(String preference)
1227    {
1228  4796 return this.xwiki.getUserPreference(preference, getXWikiContext());
1229    }
1230   
1231    /**
1232    * API to access a User Preference from cookie This function will look in the session cookie for the preference
1233    *
1234    * @param preference Preference name
1235    * @return The preference for this wiki and the current locale
1236    */
 
1237  0 toggle public String getUserPreferenceFromCookie(String preference)
1238    {
1239  0 return this.xwiki.getUserPreferenceFromCookie(preference, getXWikiContext());
1240    }
1241   
1242    /**
1243    * Same as {@link #getLocalePreference()} but as a String.
1244    *
1245    * @return the locale to use
1246    * @deprecated since 8.0M1, use {@link #getLocalePreference()} instead
1247    */
 
1248  0 toggle @Deprecated
1249    public String getLanguagePreference()
1250    {
1251  0 return this.xwiki.getLanguagePreference(getXWikiContext());
1252    }
1253   
1254    /**
1255    * First try to find the current locale in use from the XWiki context. If none is used and if the wiki is not
1256    * multilingual use the default locale defined in the XWiki preferences. If the wiki is multilingual try to get the
1257    * locale passed in the request. If none was passed try to get it from a cookie. If no locale cookie exists then use
1258    * the user default locale and barring that use the browser's "Accept-Language" header sent in HTTP request. If none
1259    * is defined use the default locale.
1260    *
1261    * @return the locale to use
1262    * @since 8.0M1
1263    */
 
1264  0 toggle public Locale getLocalePreference()
1265    {
1266  0 return this.xwiki.getLocalePreference(getXWikiContext());
1267    }
1268   
1269    /**
1270    * Same as {@link #getInterfaceLocalePreference()} but as a String.
1271    *
1272    * @return the document locale preference for the request
1273    * @deprecated since 8.0M1, use {@link #getInterfaceLocalePreference()} instead
1274    */
 
1275  0 toggle @Deprecated
1276    public String getInterfaceLanguagePreference()
1277    {
1278  0 return this.xwiki.getInterfaceLanguagePreference(getXWikiContext());
1279    }
1280   
1281    /**
1282    * API to access the interface locale preference for the request Order of evaluation is: locale of the wiki in
1283    * mono-lingual mode locale request parameter locale in context locale user preference locale in cookie locale
1284    * accepted by the navigator
1285    *
1286    * @return the document locale preference for the request
1287    */
 
1288  0 toggle public Locale getInterfaceLocalePreference()
1289    {
1290  0 return this.xwiki.getInterfaceLocalePreference(getXWikiContext());
1291    }
1292   
1293    /**
1294    * @return the list of all wiki names, including the main wiki, corresponding to the available wiki descriptors.
1295    * Example: the descriptor for the wiki <i>wikiname</i> is a document in the main wiki, named
1296    * <i>XWiki.XWikiServerWikiname</i>, containing an XWiki.XWikiServerClass object.
1297    * @see com.xpn.xwiki.XWiki#getVirtualWikisDatabaseNames(XWikiContext)
1298    */
 
1299  49 toggle public List<String> getWikiNames()
1300    {
1301  49 List<String> result = new ArrayList<String>();
1302   
1303  49 try {
1304  49 result = this.xwiki.getVirtualWikisDatabaseNames(getXWikiContext());
1305    } catch (Exception e) {
1306  0 LOGGER.error("Failed to get the list of all wiki names", e);
1307    }
1308   
1309  49 return result;
1310    }
1311   
1312    /**
1313    * Convenience method to ask if the current XWiki instance contains subwikis (in addition to the main wiki)
1314    *
1315    * @return true if at least 1 subwiki exists; false otherwise
1316    * @see #getWikiNames()
1317    */
 
1318  49 toggle public boolean hasSubWikis()
1319    {
1320  49 return getWikiNames().size() > 1;
1321    }
1322   
1323    /**
1324    * API to check is wiki is multi-lingual
1325    *
1326    * @return true for multi-lingual/false for mono-lingual
1327    */
 
1328  9226 toggle public boolean isMultiLingual()
1329    {
1330  9226 return this.xwiki.isMultiLingual(getXWikiContext());
1331    }
1332   
1333    /**
1334    * Privileged API to flush the cache of the Wiki installation This flushed the cache of all wikis, all plugins, all
1335    * renderers
1336    */
 
1337  0 toggle public void flushCache()
1338    {
1339  0 if (hasProgrammingRights()) {
1340  0 this.xwiki.flushCache(getXWikiContext());
1341    }
1342    }
1343   
1344    /**
1345    * Privileged API to create a new user from the request This API is used by RegisterNewUser wiki page
1346    *
1347    * @return the integer status code
1348    * <ul>
1349    * <li>1: ok</li>
1350    * <li>-2: passwords are different or password is empty</li>
1351    * <li>-3: user already exists</li>
1352    * <li>-4: invalid username provided</li>
1353    * <li>-8: user already exists</li>
1354    * </ul>
1355    * @throws XWikiException
1356    */
 
1357  0 toggle public int createUser() throws XWikiException
1358    {
1359  0 return createUser(false, "edit");
1360    }
1361   
1362    /**
1363    * Privileged API to create a new user from the request This API is used by RegisterNewUser wiki page This version
1364    * sends a validation email to the user Configuration of validation email is in the XWiki Preferences
1365    *
1366    * @param withValidation true to send the validationemail
1367    * @return the integer status code
1368    * <ul>
1369    * <li>1: ok</li>
1370    * <li>-2: passwords are different or password is empty</li>
1371    * <li>-3: user already exists</li>
1372    * <li>-4: invalid username provided</li>
1373    * <li>-8: user already exists</li>
1374    * </ul>
1375    * @throws XWikiException
1376    */
 
1377  0 toggle public int createUser(boolean withValidation) throws XWikiException
1378    {
1379  0 return createUser(withValidation, "edit");
1380    }
1381   
1382    /**
1383    * Privileged API to create a new user from the request.
1384    * <p>
1385    * This API is used by the RegisterNewUser wiki page.
1386    * <p>
1387    * This version sends a validation email to the user. Configuration of validation email is in the XWiki Preferences.
1388    *
1389    * @param withValidation true to send the validation email
1390    * @param userRights Rights to set for the user for it's own page(defaults to "edit")
1391    * @return the integer status code
1392    * <ul>
1393    * <li>1: ok</li>
1394    * <li>-2: passwords are different or password is empty</li>
1395    * <li>-3: user already exists</li>
1396    * <li>-4: invalid username provided</li>
1397    * <li>-8: user already exists</li>
1398    * </ul>
1399    * @throws XWikiException
1400    */
 
1401  0 toggle public int createUser(boolean withValidation, String userRights) throws XWikiException
1402    {
1403  0 boolean registerRight;
1404  0 try {
1405    // So, what's the register right for? This says that if the creator of the page
1406    // (Admin) has programming rights, anybody can register. Is this OK?
1407  0 if (hasProgrammingRights()) {
1408  0 registerRight = true;
1409    } else {
1410  0 registerRight = this.xwiki.getRightService().hasAccessLevel("register", getXWikiContext().getUser(),
1411    "XWiki.XWikiPreferences", getXWikiContext());
1412    }
1413   
1414  0 if (registerRight) {
1415  0 return this.xwiki.createUser(withValidation, userRights, getXWikiContext());
1416    }
1417   
1418  0 return -1;
1419    } catch (Exception e) {
1420  0 LOGGER.error("Failed to create user", e);
1421   
1422  0 return -10;
1423    }
1424   
1425    }
1426   
1427    /**
1428    * Privileged API to validate the return code given by a user in response to an email validation email The
1429    * validation information are taken from the request object
1430    *
1431    * @param withConfirmEmail true to send a account confirmation email/false to not send it
1432    * @return Success of Failure code (0 for success, -1 for missing programming rights, &gt; 0 for other errors
1433    * @throws XWikiException
1434    */
 
1435  0 toggle public int validateUser(boolean withConfirmEmail) throws XWikiException
1436    {
1437  0 return this.xwiki.validateUser(withConfirmEmail, getXWikiContext());
1438    }
1439   
1440    /**
1441    * Privileged API to add a user to the XWiki.XWikiAllGroup
1442    *
1443    * @param fullwikiname user name to add
1444    * @throws XWikiException
1445    */
 
1446  0 toggle public void addToAllGroup(String fullwikiname) throws XWikiException
1447    {
1448  0 if (hasProgrammingRights()) {
1449  0 this.xwiki.setUserDefaultGroup(fullwikiname, getXWikiContext());
1450    }
1451    }
1452   
1453    /**
1454    * Privileged API to send a confirmation email to a user
1455    *
1456    * @param xwikiname user to send the email to
1457    * @param password password to put in the mail
1458    * @param email email to send to
1459    * @param add_message Additional message to send to the user
1460    * @param contentfield Preference field to use as a mail template
1461    * @throws XWikiException if the mail was not send successfully
1462    */
 
1463  0 toggle public void sendConfirmationMail(String xwikiname, String password, String email, String add_message,
1464    String contentfield) throws XWikiException
1465    {
1466  0 if (hasProgrammingRights()) {
1467  0 this.xwiki.sendConfirmationEmail(xwikiname, password, email, add_message, contentfield, getXWikiContext());
1468    }
1469    }
1470   
1471    /**
1472    * Privileged API to send a confirmation email to a user
1473    *
1474    * @param xwikiname user to send the email to
1475    * @param password password to put in the mail
1476    * @param email email to send to
1477    * @param contentfield Preference field to use as a mail template
1478    * @throws XWikiException if the mail was not send successfully
1479    */
 
1480  0 toggle public void sendConfirmationMail(String xwikiname, String password, String email, String contentfield)
1481    throws XWikiException
1482    {
1483  0 if (hasProgrammingRights()) {
1484  0 this.xwiki.sendConfirmationEmail(xwikiname, password, email, "", contentfield, getXWikiContext());
1485    }
1486    }
1487   
1488    /**
1489    * API to copy a document to another document in the same wiki
1490    *
1491    * @param docname source document
1492    * @param targetdocname target document
1493    * @return true if the copy was sucessfull
1494    * @throws XWikiException if the document was not copied properly
1495    */
 
1496  3 toggle public boolean copyDocument(String docname, String targetdocname) throws XWikiException
1497    {
1498  3 return this.copyDocument(docname, targetdocname, null, null, null, false, false);
1499    }
1500