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   
1501    /**
1502    * API to copy a translation of a document to another document in the same wiki
1503    *
1504    * @param docname source document
1505    * @param targetdocname target document
1506    * @param wikilocale locale to copy
1507    * @return true if the copy was sucessfull
1508    * @throws XWikiException if the document was not copied properly
1509    */
 
1510  0 toggle public boolean copyDocument(String docname, String targetdocname, String wikilocale) throws XWikiException
1511    {
1512  0 return this.copyDocument(docname, targetdocname, null, null, wikilocale, false, false);
1513    }
1514   
1515    /**
1516    * API to copy a translation of a document to another document of the same name in another wiki
1517    *
1518    * @param docname source document
1519    * @param sourceWiki source wiki
1520    * @param targetWiki target wiki
1521    * @param wikilocale locale to copy
1522    * @return true if the copy was sucessfull
1523    * @throws XWikiException if the document was not copied properly
1524    */
 
1525  0 toggle public boolean copyDocument(String docname, String sourceWiki, String targetWiki, String wikilocale)
1526    throws XWikiException
1527    {
1528  0 return this.copyDocument(docname, docname, sourceWiki, targetWiki, wikilocale, true, false);
1529    }
1530   
1531    /**
1532    * API to copy a translation of a document to another document of the same name in another wiki additionally
1533    * resetting the version
1534    *
1535    * @param docname source document
1536    * @param sourceWiki source wiki
1537    * @param targetWiki target wiki
1538    * @param wikilocale locale to copy
1539    * @param reset true to reset versions
1540    * @return true if the copy was sucessfull
1541    * @throws XWikiException if the document was not copied properly
1542    */
 
1543  0 toggle public boolean copyDocument(String docname, String targetdocname, String sourceWiki, String targetWiki,
1544    String wikilocale, boolean reset) throws XWikiException
1545    {
1546  0 return this.copyDocument(docname, targetdocname, sourceWiki, targetWiki, wikilocale, reset, false);
1547    }
1548   
1549    /**
1550    * API to copy a translation of a document to another document of the same name in another wiki additionally
1551    * resetting the version and overwriting the previous document
1552    *
1553    * @param docname source document name
1554    * @param targetdocname target document name
1555    * @param sourceWiki source wiki
1556    * @param targetWiki target wiki
1557    * @param wikilocale locale to copy
1558    * @param reset true to reset versions
1559    * @param force true to overwrite the previous document
1560    * @return true if the copy was sucessfull
1561    * @throws XWikiException if the document was not copied properly
1562    */
 
1563  3 toggle public boolean copyDocument(String docname, String targetdocname, String sourceWiki, String targetWiki,
1564    String wikilocale, boolean reset, boolean force) throws XWikiException
1565    {
1566  3 DocumentReference sourceDocumentReference = getCurrentMixedDocumentReferenceResolver().resolve(docname);
1567  3 if (!StringUtils.isEmpty(sourceWiki)) {
1568  0 sourceDocumentReference = sourceDocumentReference.replaceParent(sourceDocumentReference.getWikiReference(),
1569    new WikiReference(sourceWiki));
1570    }
1571   
1572  3 DocumentReference targetDocumentReference = getCurrentMixedDocumentReferenceResolver().resolve(targetdocname);
1573  3 if (!StringUtils.isEmpty(targetWiki)) {
1574  0 targetDocumentReference = targetDocumentReference.replaceParent(targetDocumentReference.getWikiReference(),
1575    new WikiReference(targetWiki));
1576    }
1577   
1578  3 return this.copyDocument(sourceDocumentReference, targetDocumentReference, wikilocale, reset, force);
1579    }
1580   
1581    /**
1582    * API to copy a translation of a document to another document of the same name in another wiki additionally
1583    * resetting the version and overwriting the previous document
1584    *
1585    * @param sourceDocumentReference the reference to the document to copy
1586    * @param targetDocumentReference the reference to the document to create
1587    * @param wikilocale locale to copy
1588    * @param resetHistory {@code true} to reset versions
1589    * @param overwrite {@code true} to overwrite the previous document
1590    * @return {@code true} if the copy was sucessful
1591    * @throws XWikiException if the document was not copied properly
1592    * @since 3.0M3
1593    */
 
1594  3 toggle public boolean copyDocument(DocumentReference sourceDocumentReference, DocumentReference targetDocumentReference,
1595    String wikilocale, boolean resetHistory, boolean overwrite) throws XWikiException
1596    {
1597    // In order to copy the source document the user must have at least the right to view it.
1598  3 if (hasAccessLevel("view", getDefaultStringEntityReferenceSerializer().serialize(sourceDocumentReference))) {
1599  3 String targetDocStringRef = getDefaultStringEntityReferenceSerializer().serialize(targetDocumentReference);
1600    // To create the target document the user must have edit rights. If the target document exists and the user
1601    // wants to overwrite it then he needs delete right.
1602    // Note: We have to check if the target document exists before checking the delete right because delete
1603    // right is denied if not explicitly specified.
1604  3 if (hasAccessLevel("edit", targetDocStringRef)
1605    && (!overwrite || !exists(targetDocumentReference) || hasAccessLevel("delete", targetDocStringRef))) {
1606    // Reset creation data otherwise the required rights for page copy need to be reconsidered.
1607  3 return this.xwiki.copyDocument(sourceDocumentReference, targetDocumentReference, wikilocale,
1608    resetHistory, overwrite, true, getXWikiContext());
1609    }
1610    }
1611   
1612  0 return false;
1613    }
1614   
1615    /**
1616    * Privileged API to copy a space to another wiki, optionally deleting all document of the target space
1617    *
1618    * @param space source Space
1619    * @param sourceWiki source Wiki
1620    * @param targetWiki target Wiki
1621    * @param locale locale to copy
1622    * @param clean true to delete all document of the target space
1623    * @return number of copied documents
1624    * @throws XWikiException if the space was not copied properly
1625    */
 
1626  0 toggle public int copySpaceBetweenWikis(String space, String sourceWiki, String targetWiki, String locale, boolean clean)
1627    throws XWikiException
1628    {
1629  0 if (hasProgrammingRights()) {
1630  0 return this.xwiki.copySpaceBetweenWikis(space, sourceWiki, targetWiki, locale, clean, getXWikiContext());
1631    }
1632   
1633  0 return -1;
1634    }
1635   
1636    /**
1637    * API to include a topic into another The topic is rendered fully in the context of itself
1638    *
1639    * @param topic page name of the topic to include
1640    * @return the content of the included page
1641    * @throws XWikiException if the include failed
1642    */
 
1643  0 toggle public String includeTopic(String topic) throws XWikiException
1644    {
1645  0 return includeTopic(topic, true);
1646    }
1647   
1648    /**
1649    * API to execute a form in the context of an including topic The rendering is evaluated in the context of the
1650    * including topic All velocity variables are the one of the including topic This api is usually called using
1651    * #includeForm in a page, which modifies the behavior of "Edit this page" button to direct for Form mode (inline)
1652    *
1653    * @param topic page name of the form to execute
1654    * @return the content of the included page
1655    * @throws XWikiException if the include failed
1656    */
 
1657  72 toggle public String includeForm(String topic) throws XWikiException
1658    {
1659  72 return includeForm(topic, true);
1660    }
1661   
1662    /**
1663    * API to include a topic into another, optionally surrounding the content with {pre}{/pre} to avoid future wiki
1664    * rendering. The topic is rendered fully in the context of itself.
1665    *
1666    * @param topic page name of the topic to include
1667    * @param pre true to add {pre} {/pre} (only if includer document is 1.0 syntax)
1668    * @return the content of the included page
1669    * @throws XWikiException if the include failed
1670    */
 
1671  78 toggle public String includeTopic(String topic, boolean pre) throws XWikiException
1672    {
1673  78 String result = this.xwiki.include(topic, false, getXWikiContext());
1674   
1675  78 if (pre) {
1676  0 String includerSyntax = this.xwiki.getCurrentContentSyntaxId(null, this.context);
1677   
1678  0 if (includerSyntax != null && Syntax.XWIKI_1_0.toIdString().equals(includerSyntax)) {
1679  0 result = "{pre}" + result + "{/pre}";
1680    }
1681    }
1682   
1683  78 return result;
1684    }
1685   
1686    /**
1687    * API to execute a form in the context of an including topic, optionnaly surrounding the content with {pre}{/pre}
1688    * to avoid future wiki rendering The rendering is evaluated in the context of the including topic All velocity
1689    * variables are the one of the including topic This api is usually called using #includeForm in a page, which
1690    * modifies the behavior of "Edit this page" button to direct for Form mode (inline).
1691    *
1692    * @param topic page name of the form to execute
1693    * @param pre true to add {pre} {/pre} (only if includer document is 1.0 syntax)
1694    * @return the content of the included page
1695    * @throws XWikiException if the include failed
1696    */
 
1697  72 toggle public String includeForm(String topic, boolean pre) throws XWikiException
1698    {
1699  72 String result = this.xwiki.include(topic, true, getXWikiContext());
1700   
1701  72 if (pre) {
1702  72 String includerSyntax = this.xwiki.getCurrentContentSyntaxId(null, this.context);
1703   
1704  72 if (includerSyntax != null && Syntax.XWIKI_1_0.toIdString().equals(includerSyntax)) {
1705  0 result = "{pre}" + result + "{/pre}";
1706    }
1707    }
1708   
1709  72 return result;
1710    }
1711   
1712    /**
1713    * API to check rights on the current document for the current user
1714    *
1715    * @param level right to check (view, edit, comment, delete)
1716    * @return true if right is granted/false if not
1717    */
 
1718  1823 toggle public boolean hasAccessLevel(String level)
1719    {
1720  1823 return hasAccessLevel(level, getXWikiContext().getUser(), getXWikiContext().getDoc().getFullName());
1721    }
1722   
1723    /**
1724    * API to check rights on a document for a given user
1725    *
1726    * @param level right to check (view, edit, comment, delete)
1727    * @param user user for which to check the right
1728    * @param docname document on which to check the rights
1729    * @return true if right is granted/false if not
1730    */
 
1731  2483 toggle public boolean hasAccessLevel(String level, String user, String docname)
1732    {
1733  2483 try {
1734  2483 return this.xwiki.getRightService().hasAccessLevel(level, user, docname, getXWikiContext());
1735    } catch (Exception e) {
1736  0 return false;
1737    }
1738    }
1739   
1740    /**
1741    * API to list all spaces in the current wiki.
1742    * <p>
1743    * Hidden spaces are filtered unless current user enabled them.
1744    *
1745    * @return a list of string representing all non-hidden spaces (ie spaces that have non-hidden pages) for the
1746    * current wiki
1747    * @throws XWikiException if something went wrong
1748    * @deprecated use query service instead
1749    */
 
1750  0 toggle @Deprecated
1751    public List<String> getSpaces() throws XWikiException
1752    {
1753  0 return this.xwiki.getSpaces(getXWikiContext());
1754    }
1755   
1756    /**
1757    * API to list all documents in a space.
1758    * <p>
1759    * Hidden spaces are filtered unless current user enabled them.
1760    *
1761    * @param spaceReference the local reference of the space for which to return all non-hidden documents
1762    * @return the list of document names (in the format {@code Space.Page}) for non-hidden documents in the specified
1763    * space
1764    * @throws XWikiException if the loading went wrong
1765    * @deprecated use query service instead
1766    */
 
1767  0 toggle @Deprecated
1768    public List<String> getSpaceDocsName(String spaceReference) throws XWikiException
1769    {
1770  0 return this.xwiki.getSpaceDocsName(spaceReference, getXWikiContext());
1771    }
1772   
1773    /**
1774    * API to retrieve the current encoding of the wiki engine The encoding is stored in xwiki.cfg Default encoding is
1775    * ISO-8891-1
1776    *
1777    * @return encoding active in this wiki
1778    */
 
1779  1109 toggle public String getEncoding()
1780    {
1781  1109 return this.xwiki.getEncoding();
1782    }
1783   
1784    /**
1785    * API to retrieve the URL of an attached file in a Wiki Document The URL is generated differently depending on the
1786    * environement (Servlet, Portlet, PDF, etc..) The URL generation can be modified by implementing a new
1787    * XWikiURLFactory object For compatibility with any target environement (and especially the portlet environment) It
1788    * is important to always use the URL functions to generate URL and never hardcode URLs
1789    *
1790    * @param fullname page name which includes the attached file
1791    * @param filename attached filename to create a link for
1792    * @return a URL as a string pointing to the filename
1793    * @throws XWikiException if the URL could not be generated properly
1794    */
 
1795  4 toggle public String getAttachmentURL(String fullname, String filename) throws XWikiException
1796    {
1797  4 return this.xwiki.getAttachmentURL(fullname, filename, getXWikiContext());
1798    }
1799   
1800    /**
1801    * API to retrieve the URL of an a Wiki Document in view mode The URL is generated differently depending on the
1802    * environement (Servlet, Portlet, PDF, etc..) The URL generation can be modified by implementing a new
1803    * XWikiURLFactory object For compatibility with any target environement (and especially the portlet environment) It
1804    * is important to always use the URL functions to generate URL and never hardcode URLs
1805    *
1806    * @param fullname the name of the document for which to return the URL for
1807    * @return a URL as a string pointing to the wiki document in view mode
1808    * @throws XWikiException if the URL could not be generated properly
1809    */
 
1810  471 toggle public String getURL(String fullname) throws XWikiException
1811    {
1812  471 return this.xwiki.getURL(fullname, "view", getXWikiContext());
1813    }
1814   
1815    /**
1816    * Retrieve the URL of an entity using the default mode/action for that entity type. The URL is generated
1817    * differently depending on the environement (Servlet, Portlet, PDF, etc..). The URL generation can be modified by
1818    * implementing a new XWikiURLFactory object. For compatibility with any target environement (and especially the
1819    * portlet environment) it is important to always use the URL functions to generate URLs and never hardcode URLs.
1820    *
1821    * @param reference the reference to the entity for which to return the URL
1822    * @return a URL as a string pointing to the specified entity, using the default mode/action for that entity type
1823    * @throws XWikiException if the URL could not be generated properly
1824    * @since 7.2M1
1825    */
 
1826  2410 toggle public String getURL(EntityReference reference) throws XWikiException
1827    {
1828  2409 return this.xwiki.getURL(reference, getXWikiContext());
1829    }
1830   
1831    /**
1832    * API to retrieve the URL of an entity in any mode, optionally adding a query string The URL is generated
1833    * differently depending on the environment (Servlet, Portlet, PDF, etc..) The URL generation can be modified by
1834    * implementing a new XWikiURLFactory object. The query string will be modified to be added in the way the
1835    * environment needs it. It is important to not add the query string parameter manually after a URL. Some
1836    * environments will not accept this (like the Portlet environement).
1837    *
1838    * @param reference the reference to the entity for which to return the URL for
1839    * @param action the mode in which to access the entity (view/edit/save/..). Any valid XWiki action is possible
1840    * @param querystring the Query String to provide in the usual mode ({@code name1=value1&name2=value=2}) including
1841    * encoding
1842    * @return a URL as a string pointing to the entity
1843    * @throws XWikiException if the URL could not be generated properly
1844    * @since 7.2M1
1845    */
 
1846  24 toggle public String getURL(EntityReference reference, String action, String querystring) throws XWikiException
1847    {
1848  24 return this.xwiki.getURL(reference, action, querystring, null, getXWikiContext());
1849    }
1850   
1851    /**
1852    * API to retrieve the URL of an a Wiki Document in view mode The URL is generated differently depending on the
1853    * environement (Servlet, Portlet, PDF, etc..) The URL generation can be modified by implementing a new
1854    * XWikiURLFactory object For compatibility with any target environement (and especially the portlet environment) It
1855    * is important to always use the URL functions to generate URL and never hardcode URLs
1856    *
1857    * @param reference the reference to the document for which to return the URL for
1858    * @return a URL as a string pointing to the wiki document in view mode
1859    * @throws XWikiException if the URL could not be generated properly
1860    * @since 2.3M2
1861    */
 
1862  12249 toggle public String getURL(DocumentReference reference) throws XWikiException
1863    {
1864  12249 return this.xwiki.getURL(reference, "view", getXWikiContext());
1865    }
1866   
1867    /**
1868    * API to retrieve the URL of an a Wiki Document in any mode. The URL is generated differently depending on the
1869    * environment (Servlet, Portlet, PDF, etc..). The URL generation can be modified by implementing a new
1870    * XWikiURLFactory object For compatibility with any target environement (and especially the portlet environment).
1871    * It is important to always use the URL functions to generate URL and never hardcode URLs.
1872    *
1873    * @param fullname the page name which includes the attached file
1874    * @param action the mode in which to access the document (view/edit/save/..). Any valid XWiki action is possible.
1875    * @return a URL as a string pointing to the wiki document in view mode
1876    * @throws XWikiException if the URL could not be generated properly
1877    */
 
1878  3959 toggle public String getURL(String fullname, String action) throws XWikiException
1879    {
1880  3958 return this.xwiki.getURL(fullname, action, getXWikiContext());
1881    }
1882   
1883    /**
1884    * API to retrieve the URL of a Wiki Document in any mode, optionally adding a query string The URL is generated
1885    * differently depending on the environment (Servlet, Portlet, PDF, etc..) The URL generation can be modified by
1886    * implementing a new XWikiURLFactory object. The query string will be modified to be added in the way the
1887    * environment needs it. It is important to not add the query string parameter manually after a URL. Some
1888    * environments will not accept this (like the Portlet environement).
1889    *
1890    * @param fullname the page name which includes the attached file
1891    * @param action the mode in which to access the document (view/edit/save/..). Any valid XWiki action is possible
1892    * @param querystring the Query String to provide in the usual mode ({@code name1=value1&name2=value=2}) including
1893    * encoding
1894    * @return a URL as a string pointing to the wiki document in view mode
1895    * @throws XWikiException if the URL could not be generated properly
1896    */
 
1897  5547 toggle public String getURL(String fullname, String action, String querystring) throws XWikiException
1898    {
1899  5547 return this.xwiki.getURL(fullname, action, querystring, getXWikiContext());
1900    }
1901   
1902    /**
1903    * API to retrieve the URL of a Wiki Document in any mode, optionally adding a query string The URL is generated
1904    * differently depending on the environment (Servlet, Portlet, PDF, etc..) The URL generation can be modified by
1905    * implementing a new XWikiURLFactory object. The query string will be modified to be added in the way the
1906    * environment needs it. It is important to not add the query string parameter manually after a URL. Some
1907    * environments will not accept this (like the Portlet environement).
1908    *
1909    * @param reference the reference to the document for which to return the URL for
1910    * @param action the mode in which to access the document (view/edit/save/..). Any valid XWiki action is possible
1911    * @param querystring the Query String to provide in the usual mode ({@code name1=value1&name2=value=2}) including
1912    * encoding
1913    * @return a URL as a string pointing to the wiki document in view mode
1914    * @throws XWikiException if the URL could not be generated properly
1915    * @since 3.0M3
1916    */
 
1917  1757 toggle public String getURL(DocumentReference reference, String action, String querystring) throws XWikiException
1918    {
1919  1757 return this.xwiki.getURL(reference, action, querystring, null, getXWikiContext());
1920    }
1921   
1922    /**
1923    * API to retrieve the URL of an a Wiki Document in any mode, optionally adding an anchor. The URL is generated
1924    * differently depending on the environement (Servlet, Portlet, PDF, etc..) The URL generation can be modified by
1925    * implementing a new XWikiURLFactory object. The anchor will be modified to be added in the way the environment
1926    * needs it. It is important to not add the anchor parameter manually after a URL. Some environments will not accept
1927    * this (like the Portlet environement).
1928    *
1929    * @param fullname the page name which includes the attached file
1930    * @param action the mode in which to access the document (view/edit/save/..). Any valid XWiki action is possible
1931    * @param querystring the Query String to provide in the usual mode ({@code name1=value1&name2=value=2}) including
1932    * encoding
1933    * @param anchor the anchor that points at a location within the passed document name
1934    * @return a URL as a string pointing to the wiki document in view mode
1935    * @throws XWikiException if the URL could not be generated properly
1936    */
 
1937  0 toggle public String getURL(String fullname, String action, String querystring, String anchor) throws XWikiException
1938    {
1939  0 return this.xwiki.getURL(fullname, action, querystring, anchor, getXWikiContext());
1940    }
1941   
1942    /**
1943    * API to retrieve a viewable referer text for a referer Referers are URL where users have clicked on a link to an
1944    * XWiki page Search engine referer URLs are transformed to a nicer view (Google: search query string) For other URL
1945    * the http:// part is stripped
1946    *
1947    * @param referer referer URL to transform
1948    * @return A viewable string
1949    */
 
1950  0 toggle public String getRefererText(String referer)
1951    {
1952  0 try {
1953  0 return this.xwiki.getRefererText(referer, getXWikiContext());
1954    } catch (Exception e) {
1955  0 return "";
1956    }
1957    }
1958   
1959    /**
1960    * API to retrieve a viewable referer text for a referer with a maximum length Referers are URL where users have
1961    * clicked on a link to an XWiki page Search engine referer URLs are transformed to a nicer view (Google: search
1962    * query string) For other URL the http:// part is stripped
1963    *
1964    * @param referer referer URL to transform
1965    * @param length Maximum length. "..." is added to the end of the text
1966    * @return A viewable string
1967    */
 
1968  0 toggle public String getShortRefererText(String referer, int length)
1969    {
1970  0 try {
1971  0 return this.xwiki.getRefererText(referer, getXWikiContext()).substring(0, length);
1972    } catch (Exception e) {
1973  0 return this.xwiki.getRefererText(referer, getXWikiContext());
1974    }
1975    }
1976   
1977    /**
1978    * Generate and return an unescaped user display name.
1979    *
1980    * @param userReference the user reference
1981    * @return the unescaped display user name
1982    * @since 6.4RC1
1983    */
 
1984  156 toggle public String getPlainUserName(DocumentReference userReference)
1985    {
1986  156 return this.xwiki.getPlainUserName(userReference, getXWikiContext());
1987    }
1988   
1989    /**
1990    * API to retrieve a link to the User Name page displayed for the first name and last name of the user. The link
1991    * will link to the page on the wiki where the user is registered
1992    *
1993    * @param user Fully qualified username as retrieved from $xcontext.user (XWiki.LudovicDubost)
1994    * @return The first name and last name fields surrounded with a link to the user page
1995    */
 
1996  1157 toggle public String getUserName(String user)
1997    {
1998  1157 return this.xwiki.getUserName(user, null, getXWikiContext());
1999    }
2000   
2001    /**
2002    * API to retrieve a link to the User Name page displayed with a custom view. The link will link to the page on the
2003    * wiki where the user is registered. The formating is done using the format parameter which can contain velocity
2004    * scripting and access all properties of the User profile using variables ($first_name $last_name $email $city)
2005    *
2006    * @param user Fully qualified username as retrieved from $xcontext.user (XWiki.LudovicDubost)
2007    * @param format formatting to be used ("$first_name $last_name", "$first_name")
2008    * @return The first name and last name fields surrounded with a link to the user page
2009    */
 
2010  0 toggle public String getUserName(String user, String format)
2011    {
2012  0 return this.xwiki.getUserName(user, format, getXWikiContext());
2013    }
2014   
2015    /**
2016    * API to retrieve a link to the User Name page displayed for the first name and last name of the user. The link
2017    * will link to the page on the local wiki even if the user is registered on a different wiki.
2018    *
2019    * @param user Fully qualified username as retrieved from $xcontext.user (XWiki.LudovicDubost)
2020    * @return The first name and last name fields surrounded with a link to the user page
2021    */
 
2022  0 toggle public String getLocalUserName(String user)
2023    {
2024  0 try {
2025  0 return this.xwiki.getUserName(user.substring(user.indexOf(":") + 1), null, getXWikiContext());
2026    } catch (Exception e) {
2027  0 return this.xwiki.getUserName(user, null, getXWikiContext());
2028    }
2029    }
2030   
2031    /**
2032    * API to retrieve a link to the User Name page displayed with a custom view. The link will link to the page on the
2033    * local wiki even if the user is registered on a different wiki. The formating is done using the format parameter
2034    * which can contain velocity scripting and access all properties of the User profile using variables ($first_name
2035    * $last_name $email $city)
2036    *
2037    * @param user Fully qualified username as retrieved from $xcontext.user (XWiki.LudovicDubost)
2038    * @param format formatting to be used ("$first_name $last_name", "$first_name")
2039    * @return The first name and last name fields surrounded with a link to the user page
2040    */
 
2041  0 toggle public String getLocalUserName(String user, String format)
2042    {
2043  0 try {
2044  0 return this.xwiki.getUserName(user.substring(user.indexOf(":") + 1), format, getXWikiContext());
2045    } catch (Exception e) {
2046  0 return this.xwiki.getUserName(user, format, getXWikiContext());
2047    }
2048    }
2049   
2050    /**
2051    * API to retrieve a text representing the user with the first name and last name of the user. With the link param
2052    * set to false it will not link to the user page With the link param set to true, the link will link to the page on
2053    * the wiki where the user was registered.
2054    *
2055    * @param user Fully qualified username as retrieved from $xcontext.user (XWiki.LudovicDubost)
2056    * @param link false to not add an HTML link to the user profile
2057    * @return The first name and last name fields surrounded with a link to the user page
2058    */
 
2059  4204 toggle public String getUserName(String user, boolean link)
2060    {
2061  4204 return this.xwiki.getUserName(user, null, link, getXWikiContext());
2062    }
2063   
2064    /**
2065    * API to retrieve a text representing the user with a custom view With the link param set to false it will not link
2066    * to the user page. With the link param set to true, the link will link to the page on the wiki where the user was
2067    * registered. The formating is done using the format parameter which can contain velocity scripting and access all
2068    * properties of the User profile using variables ($first_name $last_name $email $city)
2069    *
2070    * @param user Fully qualified username as retrieved from $xcontext.user (XWiki.LudovicDubost)
2071    * @param format formatting to be used ("$first_name $last_name", "$first_name")
2072    * @param link false to not add an HTML link to the user profile
2073    * @return The first name and last name fields surrounded with a link to the user page
2074    */
 
2075  0 toggle public String getUserName(String user, String format, boolean link)
2076    {
2077  0 return this.xwiki.getUserName(user, format, link, getXWikiContext());
2078    }
2079   
2080    /**
2081    * API to retrieve a text representing the user with the first name and last name of the user. With the link param
2082    * set to false it will not link to the user page. With the link param set to true, the link will link to the page
2083    * on the local wiki even if the user is registered on a different wiki.
2084    *
2085    * @param user Fully qualified username as retrieved from $xcontext.user (XWiki.LudovicDubost)
2086    * @param link false to not add an HTML link to the user profile
2087    * @return The first name and last name fields surrounded with a link to the user page
2088    */
 
2089  52 toggle public String getLocalUserName(String user, boolean link)
2090    {
2091  52 try {
2092  52 return this.xwiki.getUserName(user.substring(user.indexOf(":") + 1), null, link, getXWikiContext());
2093    } catch (Exception e) {
2094  0 return this.xwiki.getUserName(user, null, link, getXWikiContext());
2095    }
2096    }
2097   
2098    /**
2099    * API to retrieve a text representing the user with a custom view. The formating is done using the format parameter
2100    * which can contain velocity scripting and access all properties of the User profile using variables ($first_name
2101    * $last_name $email $city). With the link param set to false it will not link to the user page. With the link param
2102    * set to true, the link will link to the page on the local wiki even if the user is registered on a different wiki.
2103    *
2104    * @param user Fully qualified username as retrieved from $xcontext.user (XWiki.LudovicDubost)
2105    * @param format formatting to be used ("$first_name $last_name", "$first_name")
2106    * @param link false to not add an HTML link to the user profile
2107    * @return The first name and last name fields surrounded with a link to the user page
2108    */
 
2109  0 toggle public String getLocalUserName(String user, String format, boolean link)
2110    {
2111  0 try {
2112  0 return this.xwiki.getUserName(user.substring(user.indexOf(":") + 1), format, link, getXWikiContext());
2113    } catch (Exception e) {
2114  0 return this.xwiki.getUserName(user, format, link, getXWikiContext());
2115    }
2116    }
2117   
 
2118  3 toggle public User getUser()
2119    {
2120  3 return this.xwiki.getUser(getXWikiContext());
2121    }
2122   
 
2123  0 toggle public User getUser(String username)
2124    {
2125  0 return this.xwiki.getUser(username, getXWikiContext());
2126    }
2127   
2128    /**
2129    * API allowing to format a date according to the default Wiki setting The date format is provided in the
2130    * 'dateformat' parameter of the XWiki Preferences
2131    *
2132    * @param date date object to format
2133    * @return A string with the date formating from the default Wiki setting
2134    */
 
2135  1042 toggle public String formatDate(Date date)
2136    {
2137  1042 return this.xwiki.formatDate(date, null, getXWikiContext());
2138    }
2139   
2140    /**
2141    * API allowing to format a date according to a custom format The date format is from java.text.SimpleDateFormat
2142    * Example: "dd/MM/yyyy HH:mm:ss" or "d MMM yyyy" If the format is invalid the default format will be used to show
2143    * the date
2144    *
2145    * @param date date to format
2146    * @param format format of the date to be used
2147    * @return the formatted date
2148    * @see java.text.SimpleDateFormat
2149    */
 
2150  176 toggle public String formatDate(Date date, String format)
2151    {
2152  176 return this.xwiki.formatDate(date, format, getXWikiContext());
2153    }
2154   
2155    /*
2156    * Allow to read user setting providing the user timezone All dates will be expressed with this timezone @return the
2157    * timezone
2158    */
 
2159  0 toggle public String getUserTimeZone()
2160    {
2161  0 return this.xwiki.getUserTimeZone(this.context);
2162    }
2163   
2164    /**
2165    * Returns a plugin from the plugin API. Plugin Rights can be verified. Note that although this API is a duplicate
2166    * of {@link #getPlugin(String)} it used to provide an easy access from Velocity to XWiki plugins. Indeed Velocity
2167    * has a feature in that if a class has a get method, using the dot notation will automatically call the get method
2168    * for the class. See http://velocity.apache.org/engine/releases/velocity-1.5/user-guide.html#propertylookuprules.
2169    * This this allows the following constructs: <code>$xwiki.pluginName.somePluginMethod()</code>
2170    *
2171    * @param name Name of the plugin to retrieve (either short of full class name)
2172    * @return a plugin object
2173    */
 
2174  23812 toggle public Api get(String name)
2175    {
2176  23812 return getPlugin(name);
2177    }
2178   
2179    /**
2180    * Returns a plugin from the plugin API. Plugin Rights can be verified.
2181    *
2182    * @param name Name of the plugin to retrieve (either short of full class name)
2183    * @return a plugin object
2184    */
 
2185  23851 toggle public Api getPlugin(String name)
2186    {
2187  23851 return this.xwiki != null ? this.xwiki.getPluginApi(name, getXWikiContext()) : null;
2188    }
2189   
2190    /**
2191    * Returns the Advertisement system from the preferences
2192    *
2193    * @return "google" or "none"
2194    */
 
2195  0 toggle public String getAdType()
2196    {
2197  0 return this.xwiki.getAdType(getXWikiContext());
2198    }
2199   
2200    /**
2201    * Returns the Advertisement client ID from the preferences
2202    *
2203    * @return an Ad affiliate ID
2204    */
 
2205  0 toggle public String getAdClientId()
2206    {
2207  0 return this.xwiki.getAdClientId(getXWikiContext());
2208    }
2209   
2210    /**
2211    * Returns the content of an HTTP/HTTPS URL protected using Basic Authentication
2212    *
2213    * @param surl url to retrieve
2214    * @param username username for the basic authentication
2215    * @param password password for the basic authentication
2216    * @return Content of the specified URL
2217    * @throws IOException
2218    */
 
2219  0 toggle public String getURLContent(String surl, String username, String password) throws IOException
2220    {
2221  0 try {
2222  0 return this.xwiki.getURLContent(surl, username, password, this.context);
2223    } catch (Exception e) {
2224  0 LOGGER.warn("Failed to retrieve content from [" + surl + "]", e);
2225  0 return "";
2226    }
2227    }
2228   
2229    /**
2230    * Returns the content of an HTTP/HTTPS URL
2231    *
2232    * @param surl url to retrieve
2233    * @return Content of the specified URL
2234    * @throws IOException
2235    */
 
2236  0 toggle public String getURLContent(String surl) throws IOException
2237    {
2238  0 try {
2239  0 return this.xwiki.getURLContent(surl, this.context);
2240    } catch (Exception e) {
2241  0 LOGGER.warn("Failed to retrieve content from [" + surl + "]", e);
2242  0 return "";
2243    }
2244    }
2245   
2246    /**
2247    * Returns the content of an HTTP/HTTPS URL protected using Basic Authentication
2248    *
2249    * @param surl url to retrieve
2250    * @param username username for the basic authentication
2251    * @param password password for the basic authentication
2252    * @param timeout manuel timeout in milliseconds
2253    * @return Content of the specified URL
2254    * @throws IOException
2255    */
 
2256  0 toggle public String getURLContent(String surl, String username, String password, int timeout) throws IOException
2257    {
2258  0 try {
2259  0 return this.xwiki.getURLContent(surl, username, password, timeout,
2260    this.xwiki.getHttpUserAgent(this.context));
2261    } catch (Exception e) {
2262  0 return "";
2263    }
2264    }
2265   
2266    /**
2267    * Returns the content of an HTTP/HTTPS URL
2268    *
2269    * @param surl url to retrieve
2270    * @param timeout manuel timeout in milliseconds
2271    * @return Content of the specified URL
2272    * @throws IOException
2273    */
 
2274  0 toggle public String getURLContent(String surl, int timeout) throws IOException
2275    {
2276  0 try {
2277  0 return this.xwiki.getURLContent(surl, timeout, this.xwiki.getHttpUserAgent(this.context));
2278    } catch (Exception e) {
2279  0 return "";
2280    }
2281    }
2282   
2283    /**
2284    * Returns the content of an HTTP/HTTPS URL protected using Basic Authentication as Bytes
2285    *
2286    * @param surl url to retrieve
2287    * @param username username for the basic authentication
2288    * @param password password for the basic authentication
2289    * @return Content of the specified URL
2290    * @throws IOException
2291    */
 
2292  0 toggle public byte[] getURLContentAsBytes(String surl, String username, String password) throws IOException
2293    {
2294  0 try {
2295  0 return this.xwiki.getURLContentAsBytes(surl, username, password, this.context);
2296    } catch (Exception e) {
2297  0 return null;
2298    }
2299    }
2300   
2301    /**
2302    * Returns the content of an HTTP/HTTPS URL as Bytes
2303    *
2304    * @param surl url to retrieve
2305    * @return Content of the specified URL
2306    * @throws IOException
2307    */
 
2308  0 toggle public byte[] getURLContentAsBytes(String surl) throws IOException
2309    {
2310  0 try {
2311  0 return this.xwiki.getURLContentAsBytes(surl, this.context);
2312    } catch (Exception e) {
2313  0 return null;
2314    }
2315    }
2316   
2317    /**
2318    * Returns the list of Macros documents in the specified content
2319    *
2320    * @param defaultSpace Default space to use for relative path names
2321    * @param content Content to parse
2322    * @return ArrayList of document names
2323    */
 
2324  0 toggle public List<String> getIncludedMacros(String defaultSpace, String content)
2325    {
2326  0 return this.xwiki.getIncludedMacros(defaultSpace, content, getXWikiContext());
2327    }
2328   
2329    /**
2330    * returns true if xwiki.readonly is set in the configuration file
2331    *
2332    * @return the value of xwiki.isReadOnly()
2333    * @see com.xpn.xwiki.XWiki
2334    */
 
2335  6832 toggle public boolean isReadOnly()
2336    {
2337  6832 return this.xwiki.isReadOnly();
2338    }
2339   
2340    /**
2341    * Privileged API to set/unset the readonly status of the Wiki After setting this to true no writing to the database
2342    * will be performed All Edit buttons will be removed and save actions disabled This is used for maintenance
2343    * purposes
2344    *
2345    * @param ro true to set read-only mode/false to unset
2346    */
 
2347  0 toggle public void setReadOnly(boolean ro)
2348    {
2349  0 if (hasAdminRights()) {
2350  0 this.xwiki.setReadOnly(ro);
2351    }
2352    }
2353   
2354    /**
2355    * Priviledge API to regenerate the links/backlinks table Normally links and backlinks are stored when a page is
2356    * modified This function will regenerate all the backlinks This function can be long to run
2357    *
2358    * @throws XWikiException exception if the generation fails
2359    */
 
2360  0 toggle public void refreshLinks() throws XWikiException
2361    {
2362  0 if (hasAdminRights()) {
2363  0 this.xwiki.refreshLinks(getXWikiContext());
2364    }
2365    }
2366   
2367    /**
2368    * API to check if the backlinks feature is active Backlinks are activated in xwiki.cfg or in the XWiki Preferences
2369    *
2370    * @return true if the backlinks feature is active
2371    * @throws XWikiException exception if the preference could not be retrieved
2372    */
 
2373  0 toggle public boolean hasBacklinks() throws XWikiException
2374    {
2375  0 return this.xwiki.hasBacklinks(getXWikiContext());
2376    }
2377   
2378    /**
2379    * API to check if the tags feature is active. Tags are activated in xwiki.cfg or in the XWiki Preferences
2380    *
2381    * @return true if the tags feature is active, false otherwise
2382    * @throws XWikiException exception if the preference could not be retrieved
2383    */
 
2384  0 toggle public boolean hasTags() throws XWikiException
2385    {
2386  0 return this.xwiki.hasTags(getXWikiContext());
2387    }
2388   
2389    /**
2390    * API to check if the edit comment feature is active Edit comments are activated in xwiki.cfg or in the XWiki
2391    * Preferences
2392    *
2393    * @return
2394    */
 
2395  118 toggle public boolean hasEditComment()
2396    {
2397  118 return this.xwiki.hasEditComment(this.context);
2398    }
2399   
2400    /**
2401    * API to check if the edit comment field is shown in the edit form Edit comments are activated in xwiki.cfg or in
2402    * the XWiki Preferences
2403    *
2404    * @return
2405    */
 
2406  100 toggle public boolean isEditCommentFieldHidden()
2407    {
2408  100 return this.xwiki.isEditCommentFieldHidden(this.context);
2409    }
2410   
2411    /**
2412    * API to check if the edit comment is suggested (prompted once by Javascript if empty) Edit comments are activated
2413    * in xwiki.cfg or in the XWiki Preferences
2414    *
2415    * @return
2416    */
 
2417  34 toggle public boolean isEditCommentSuggested()
2418    {
2419  34 return this.xwiki.isEditCommentSuggested(this.context);
2420    }
2421   
2422    /**
2423    * API to check if the edit comment is mandatory (prompted by Javascript if empty) Edit comments are activated in
2424    * xwiki.cfg or in the XWiki Preferences
2425    *
2426    * @return
2427    */
 
2428  68 toggle public boolean isEditCommentMandatory()
2429    {
2430  68 return this.xwiki.isEditCommentMandatory(this.context);
2431    }
2432   
2433    /**
2434    * API to check if the minor edit feature is active minor edit is activated in xwiki.cfg or in the XWiki Preferences
2435    */
 
2436  59 toggle public boolean hasMinorEdit()
2437    {
2438  59 return this.xwiki.hasMinorEdit(this.context);
2439    }
2440   
2441    /**
2442    * API to check if the recycle bin feature is active recycle bin is activated in xwiki.cfg or in the XWiki
2443    * Preferences
2444    */
 
2445  18 toggle public boolean hasRecycleBin()
2446    {
2447  18 return this.xwiki.hasRecycleBin(this.context);
2448    }
2449   
2450    /**
2451    * API to rename a page (experimental) Rights are necessary to edit the source and target page All objects and
2452    * attachments ID are modified in the process to link to the new page name
2453    *
2454    * @param doc page to rename
2455    * @param newFullName target page name to move the information to
2456    */
 
2457  0 toggle public boolean renamePage(Document doc, String newFullName)
2458    {
2459  0 try {
2460  0 if (this.xwiki.exists(newFullName, getXWikiContext()) && !this.xwiki.getRightService()
2461    .hasAccessLevel("delete", getXWikiContext().getUser(), newFullName, getXWikiContext())) {
2462  0 return false;
2463    }
2464  0 if (this.xwiki.getRightService().hasAccessLevel("edit", getXWikiContext().getUser(), doc.getFullName(),
2465    getXWikiContext())) {
2466  0 this.xwiki.renamePage(doc.getFullName(), newFullName, getXWikiContext());
2467    }
2468    } catch (XWikiException e) {
2469  0 return false;
2470    }
2471   
2472  0 return true;
2473    }
2474   
2475    /**
2476    * Retrieves the current editor preference for the request The preference is first looked up in the user preference
2477    * and then in the space and wiki preference
2478    *
2479    * @return "wysiwyg" or "text"
2480    */
 
2481  27 toggle public String getEditorPreference()
2482    {
2483  27 return this.xwiki.getEditorPreference(getXWikiContext());
2484    }
2485   
2486    /**
2487    * Privileged API to retrieve an object instantiated from groovy code in a String. Note that Groovy scripts
2488    * compilation is cached.
2489    *
2490    * @param script the Groovy class definition string (public class MyClass { ... })
2491    * @return An object instantiating this class
2492    * @throws XWikiException
2493    */
 
2494  0 toggle public java.lang.Object parseGroovyFromString(String script) throws XWikiException
2495    {
2496  0 if (hasProgrammingRights()) {
2497  0 return this.xwiki.parseGroovyFromString(script, getXWikiContext());
2498    }
2499  0 return "groovy_missingrights";
2500    }
2501   
2502    /**
2503    * Privileged API to retrieve an object instantiated from groovy code in a String, using a classloader including all
2504    * JAR files located in the passed page as attachments. Note that Groovy scripts compilation is cached
2505    *
2506    * @param script the Groovy class definition string (public class MyClass { ... })
2507    * @return An object instantiating this class
2508    * @throws XWikiException
2509    */
 
2510  0 toggle public java.lang.Object parseGroovyFromPage(String script, String jarWikiPage) throws XWikiException
2511    {
2512  0 XWikiDocument doc = this.xwiki.getDocument(script, getXWikiContext());
2513  0 if (this.xwiki.getRightService().hasProgrammingRights(doc, getXWikiContext())) {
2514  0 return this.xwiki.parseGroovyFromString(doc.getContent(), jarWikiPage, getXWikiContext());
2515    }
2516  0 return "groovy_missingrights";
2517    }
2518   
2519    /**
2520    * Privileged API to retrieve an object instanciated from groovy code in a String Groovy scripts compilation is
2521    * cached
2522    *
2523    * @param fullname // script containing a Groovy class definition (public class MyClass { ... })
2524    * @return An object instanciating this class
2525    * @throws XWikiException
2526    */
 
2527  0 toggle public java.lang.Object parseGroovyFromPage(String fullname) throws XWikiException
2528    {
2529  0 XWikiDocument doc = this.xwiki.getDocument(fullname, getXWikiContext());
2530  0 if (this.xwiki.getRightService().hasProgrammingRights(doc, getXWikiContext())) {
2531  0 return this.xwiki.parseGroovyFromString(doc.getContent(), getXWikiContext());
2532    }
2533  0 return "groovy_missingrights";
2534    }
2535   
2536    /**
2537    * API to get the macro list from the XWiki Preferences The macro list are the macros available from the Macro
2538    * Mapping System
2539    *
2540    * @return String with each macro on each line
2541    */
 
2542  0 toggle public String getMacroList()
2543    {
2544  0 return this.xwiki.getMacroList(getXWikiContext());
2545    }
2546   
2547    /**
2548    * API to check if using which toolbars in Wysiwyg editor
2549    *
2550    * @return a string value
2551    */
 
2552  0 toggle public String getWysiwygToolbars()
2553    {
2554  0 return this.xwiki.getWysiwygToolbars(getXWikiContext());
2555    }
2556   
2557    /**
2558    * API to create an object from the request The parameters are the ones that are created from
2559    * doc.display("field","edit") calls
2560    *
2561    * @param className XWiki Class Name to create the object from
2562    * @return a BaseObject wrapped in an Object
2563    * @throws XWikiException exception if the object could not be read
2564    */
 
2565  0 toggle public com.xpn.xwiki.api.Object getObjectFromRequest(String className) throws XWikiException
2566    {
2567  0 return new com.xpn.xwiki.api.Object(this.xwiki.getObjectFromRequest(className, getXWikiContext()),
2568    getXWikiContext());
2569    }
2570   
2571    /**
2572    * API to create an empty document
2573    *
2574    * @return an XWikiDocument wrapped in a Document
2575    */
 
2576  0 toggle public Document createDocument()
2577    {
2578  0 return new XWikiDocument().newDocument(getXWikiContext());
2579    }
2580   
2581    /**
2582    * API to convert the username depending on the configuration The username can be converted from email to a valid
2583    * XWiki page name hidding the email address The username can be then used to login and link to the right user page
2584    *
2585    * @param username username to use for login
2586    * @return converted wiki page name for this username
2587    */
 
2588  0 toggle public String convertUsername(String username)
2589    {
2590  0 return this.xwiki.convertUsername(username, getXWikiContext());
2591    }
2592   
2593    /**
2594    * API to get the Property object from a class based on a property path A property path looks like
2595    * XWiki.ArticleClass_fieldname
2596    *
2597    * @param propPath Property path
2598    * @return a PropertyClass object from a BaseClass object
2599    */
 
2600  0 toggle public com.xpn.xwiki.api.PropertyClass getPropertyClassFromName(String propPath)
2601    {
2602  0 return new PropertyClass(this.xwiki.getPropertyClassFromName(propPath, getXWikiContext()), getXWikiContext());
2603    }
2604   
2605    /**
2606    * Generates a unique page name based on initial page name and already existing pages
2607    *
2608    * @param name
2609    * @return a unique page name
2610    */
 
2611  36 toggle public String getUniquePageName(String name)
2612    {
2613  36 return this.xwiki.getUniquePageName(name, getXWikiContext());
2614    }
2615   
2616    /**
2617    * Generates a unique page name based on initial page name and already existing pages
2618    *
2619    * @param space
2620    * @param name
2621    * @return a unique page name
2622    */
 
2623  0 toggle public String getUniquePageName(String space, String name)
2624    {
2625  0 return this.xwiki.getUniquePageName(space, name, getXWikiContext());
2626    }
2627   
2628    /**
2629    * Inserts a tooltip using toolTip.js
2630    *
2631    * @param html HTML viewed
2632    * @param message HTML Tooltip message
2633    * @param params Parameters in Javascropt added to the tooltip config
2634    * @return HTML with working tooltip
2635    */
 
2636  0 toggle public String addTooltip(String html, String message, String params)
2637    {
2638  0 return this.xwiki.addTooltip(html, message, params, getXWikiContext());
2639    }
2640   
2641    /**
2642    * Inserts a tooltip using toolTip.js
2643    *
2644    * @param html HTML viewed
2645    * @param message HTML Tooltip message
2646    * @return HTML with working tooltip
2647    */
 
2648  0 toggle public String addTooltip(String html, String message)
2649    {
2650  0 return this.xwiki.addTooltip(html, message, getXWikiContext());
2651    }
2652   
2653    /**
2654    * Inserts the tooltip Javascript
2655    *
2656    * @return
2657    */
 
2658  0 toggle public String addTooltipJS()
2659    {
2660  0 return this.xwiki.addTooltipJS(getXWikiContext());
2661    }
2662   
2663    /*
2664    * Inserts a Mandatory asterix
2665    */
 
2666  0 toggle public String addMandatory()
2667    {
2668  0 return this.xwiki.addMandatory(getXWikiContext());
2669    }
2670   
2671    /**
2672    * Get the XWiki Class object defined in the passed Document name.
2673    * <p>
2674    * Note: This method doesn't require any rights for accessing the passed Document (as opposed to the
2675    * {@link com.xpn.xwiki.api.Document#getClass()} method which does require to get a Document object first. This is
2676    * thus useful in cases where the calling code doesn't have the access right to the specified Document. It is safe
2677    * because there are no sensitive data stored in a Class definition.
2678    * </p>
2679    *
2680    * @param documentName the name of the document for which to get the Class object. For example
2681    * "XWiki.XWikiPreferences"
2682    * @return the XWiki Class object defined in the passed Document name. If the passed Document name points to a
2683    * Document with no Class defined then an empty Class object is returned (i.e. a Class object with no
2684    * properties).
2685    * @throws XWikiException if the passed document name doesn't point to a valid Document
2686    */
 
2687  456 toggle public Class getClass(String documentName) throws XWikiException
2688    {
2689    // TODO: The implementation should be done in com.xpn.xwiki.XWiki as this class should
2690    // delegate all implementations to that Class.
2691  456 DocumentReference docReference = getCurrentMixedDocumentReferenceResolver().resolve(documentName);
2692  456 return new Class(this.xwiki.getDocument(docReference, this.context).getXClass(), this.context);
2693    }
2694   
2695    /**
2696    * Provides an absolute counter
2697    *
2698    * @param name Counter name
2699    * @return String
2700    */
 
2701  0 toggle public String getCounter(String name)
2702    {
2703  0 XWikiEngineContext econtext = this.context.getEngineContext();
2704  0 Integer counter = (Integer) econtext.getAttribute(name);
2705  0 if (counter == null) {
2706  0 counter = 0;
2707    }
2708  0 counter = counter.intValue() + 1;
2709  0 econtext.setAttribute(name, counter);
2710   
2711  0 return counter.toString();
2712    }
2713   
2714    /**
2715    * Check authentication from request and set according persitent login information If it fails user is unlogged
2716    *
2717    * @return null if failed, non null XWikiUser if sucess
2718    * @throws XWikiException
2719    */
 
2720  0 toggle public XWikiUser checkAuth() throws XWikiException
2721    {
2722  0 return this.context.getWiki().getAuthService().checkAuth(this.context);
2723    }
2724   
2725    /**
2726    * Check authentication from username and password and set according persitent login information If it fails user is
2727    * unlogged
2728    *
2729    * @param username username to check
2730    * @param password password to check
2731    * @param rememberme "1" if you want to remember the login accross navigator restart
2732    * @return null if failed, non null XWikiUser if sucess
2733    * @throws XWikiException
2734    */
 
2735  0 toggle public XWikiUser checkAuth(String username, String password, String rememberme) throws XWikiException
2736    {
2737  0 return this.context.getWiki().getAuthService().checkAuth(username, password, rememberme, this.context);
2738    }
2739   
2740    /**
2741    * Access statistics api
2742    *
2743    * @return a StatsService instance that can be used to retrieve different xwiki statistics
2744    */
 
2745  0 toggle public StatsService getStatsService()
2746    {
2747  0 return this.statsService;
2748    }
2749   
2750    /**
2751    * API to get the xwiki criteria service which allow to create various criteria : integer ranges, date periods, date
2752    * intervals, etc.
2753    *
2754    * @return the xwiki criteria service
2755    */
 
2756  14 toggle public CriteriaService getCriteriaService()
2757    {
2758  14 return this.criteriaService;
2759    }
2760   
2761    /**
2762    * @return the ids of configured syntaxes for this wiki (eg "xwiki/1.0", "xwiki/2.0", "mediawiki/1.0", etc)
2763    * @deprecated since 8.2M1, use the XWiki Rendering Configuration component or the Rendering Script Service one
2764    * instead
2765    */
 
2766  0 toggle @Deprecated
2767    public List<String> getConfiguredSyntaxes()
2768    {
2769  0 return this.xwiki.getConfiguredSyntaxes();
2770    }
2771   
2772    /**
2773    * API to get the Servlet path for a given wiki. In mono wiki this is "bin/" or "xwiki/". In virtual mode and if
2774    * <tt>xwiki.virtual.usepath</tt> is enabled in xwiki.cfg, it is "wiki/wikiname/".
2775    *
2776    * @param wikiName wiki for which to get the path
2777    * @return The servlet path
2778    */
 
2779  0 toggle public String getServletPath(String wikiName)
2780    {
2781  0 return this.xwiki.getServletPath(wikiName, this.context);
2782    }
2783   
2784    /**
2785    * API to get the Servlet path for the current wiki. In mono wiki this is "bin/" or "xwiki/". In virtual mode and if
2786    * <tt>xwiki.virtual.usepath</tt> is enabled in xwiki.cfg, it is "wiki/wikiname/".
2787    *
2788    * @return The servlet path
2789    */
 
2790  1063 toggle public String getServletPath()
2791    {
2792  1063 return this.xwiki.getServletPath(this.context.getWikiId(), this.context);
2793    }
2794   
2795    /**
2796    * API to get the webapp path for the current wiki. This usually is "xwiki/". It can be configured in xwiki.cfg with
2797    * the config <tt>xwiki.webapppath</tt>.
2798    *
2799    * @return The servlet path
2800    */
 
2801  1063 toggle public String getWebAppPath()
2802    {
2803  1063 return this.xwiki.getWebAppPath(this.context);
2804    }
2805   
2806    /**
2807    * @return the syntax id of the syntax to use when creating new documents.
2808    */
 
2809  0 toggle public String getDefaultDocumentSyntax()
2810    {
2811  0 return this.xwiki.getDefaultDocumentSyntax();
2812    }
2813   
2814    /**
2815    * Find the corresponding available renderer syntax.
2816    * <p>
2817    * If <code>syntaxVersion</code> is null the last version of the available provided syntax type is returned.
2818    *
2819    * @param syntaxType the syntax type
2820    * @param syntaxVersion the syntax version
2821    * @return the available corresponding {@link Syntax}. Null if no available renderer can be found.
2822    */
 
2823  5775 toggle public Syntax getAvailableRendererSyntax(String syntaxType, String syntaxVersion)
2824    {
2825  5775 Syntax syntax = null;
2826   
2827  5775 try {
2828  5775 List<PrintRendererFactory> factories =
2829    Utils.getContextComponentManager().getInstanceList((Type) PrintRendererFactory.class);
2830  5775 for (PrintRendererFactory factory : factories) {
2831  45978 Syntax factorySyntax = factory.getSyntax();
2832  45971 if (syntaxVersion != null) {
2833  7 if (factorySyntax.getType().getId().equalsIgnoreCase(syntaxType)
2834    && factorySyntax.getVersion().equals(syntaxVersion)) {
2835  2 syntax = factorySyntax;
2836  2 break;
2837    }
2838    } else {
2839    // TODO: improve version comparaison since it does not work when comparing 2.0 and 10.0 for example.
2840    // We
2841    // should have a Version which implements Comparable like we have SyntaxId in Syntax
2842  45967 if (factorySyntax.getType().getId().equalsIgnoreCase(syntaxType)
2843    && (syntax == null || factorySyntax.getVersion().compareTo(syntax.getVersion()) > 0)) {
2844  5207 syntax = factorySyntax;
2845    }
2846    }
2847    }
2848    } catch (ComponentLookupException e) {
2849  0 LOGGER.error("Failed to lookup available renderer syntaxes", e);
2850    }
2851   
2852  5774 return syntax;
2853    }
2854   
2855    /**
2856    * @return true if section editing is enabled (can be configured through the {@code xwiki.section.edit}
2857    * configuration property. Defaults to 1 (=enabled) when not defined
2858    */
 
2859  47 toggle public boolean hasSectionEdit()
2860    {
2861  47 return this.xwiki.hasSectionEdit(getXWikiContext());
2862    }
2863   
2864    /**
2865    * @return the section depth for which section editing is available (can be configured through
2866    * {@code xwiki.section.depth} configuration property. Defaults to 2 when not defined
2867    */
 
2868  47 toggle public long getSectionEditingDepth()
2869    {
2870  47 return this.xwiki.getSectionEditingDepth();
2871    }
2872   
2873    /**
2874    * @return true if title handling should be using the compatibility mode or not. When the compatibility mode is
2875    * active, if the document's content first header (level 1 or level 2) matches the document's title the
2876    * first header is stripped.
2877    */
 
2878  212 toggle public boolean isTitleInCompatibilityMode()
2879    {
2880  212 return this.xwiki.isTitleInCompatibilityMode();
2881    }
2882   
2883    /**
2884    * Get the syntax of the content currently being executed.
2885    * <p>
2886    * The document currently being executed is not the same than the actual content syntax since the executed code
2887    * might come from an included page or some macro that change the context syntax. The same logic used inside
2888    * rendering macros is used (see {@link org.xwiki.rendering.macro.MacroContentParser}).
2889    * <p>
2890    * If the current document can't be found, the method assume that the executed document is the context document
2891    * (it's generally the case when a document is directly rendered with
2892    * {@link XWikiDocument#getRenderedContent(XWikiContext)} for example).
2893    *
2894    * @return the syntax identifier
2895    */
 
2896  182 toggle public String getCurrentContentSyntaxId()
2897    {
2898  182 return this.xwiki.getCurrentContentSyntaxId(getXWikiContext());
2899    }
2900    }