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

File Document.java

 

Coverage histogram

../../../../img/srcFileCovDistChart6.png
72% of files have more coverage

Code metrics

214
695
246
1
3,140
1,795
401
0.58
2.83
246
1.63

Classes

Class Line # Actions
Document 90 695 0% 401 558
0.5168831351.7%
 

Contributing tests

This file is covered by 63 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.io.InputStream;
24    import java.util.ArrayList;
25    import java.util.Collections;
26    import java.util.Date;
27    import java.util.HashMap;
28    import java.util.List;
29    import java.util.Locale;
30    import java.util.Map;
31    import java.util.Vector;
32   
33    import org.apache.commons.fileupload.FileItem;
34    import org.apache.commons.lang3.StringUtils;
35    import org.slf4j.Logger;
36    import org.slf4j.LoggerFactory;
37    import org.suigeneris.jrcs.diff.DifferentiationFailedException;
38    import org.suigeneris.jrcs.diff.delta.Delta;
39    import org.suigeneris.jrcs.rcs.Version;
40    import org.xwiki.context.Execution;
41    import org.xwiki.context.ExecutionContext;
42    import org.xwiki.display.internal.DocumentDisplayerParameters;
43    import org.xwiki.model.reference.DocumentReference;
44    import org.xwiki.model.reference.DocumentReferenceResolver;
45    import org.xwiki.model.reference.EntityReferenceSerializer;
46    import org.xwiki.model.reference.PageReference;
47    import org.xwiki.rendering.block.XDOM;
48    import org.xwiki.rendering.parser.ParseException;
49    import org.xwiki.rendering.syntax.Syntax;
50    import org.xwiki.security.authorization.Right;
51    import org.xwiki.stability.Unstable;
52   
53    import com.xpn.xwiki.XWiki;
54    import com.xpn.xwiki.XWikiConstant;
55    import com.xpn.xwiki.XWikiContext;
56    import com.xpn.xwiki.XWikiException;
57    import com.xpn.xwiki.criteria.impl.Period;
58    import com.xpn.xwiki.criteria.impl.PeriodFactory;
59    import com.xpn.xwiki.criteria.impl.Range;
60    import com.xpn.xwiki.criteria.impl.RangeFactory;
61    import com.xpn.xwiki.criteria.impl.RevisionCriteria;
62    import com.xpn.xwiki.criteria.impl.Scope;
63    import com.xpn.xwiki.criteria.impl.ScopeFactory;
64    import com.xpn.xwiki.doc.DocumentRevisionProvider;
65    import com.xpn.xwiki.doc.MetaDataDiff;
66    import com.xpn.xwiki.doc.XWikiAttachment;
67    import com.xpn.xwiki.doc.XWikiDocument;
68    import com.xpn.xwiki.doc.XWikiDocumentArchive;
69    import com.xpn.xwiki.doc.XWikiLink;
70    import com.xpn.xwiki.doc.XWikiLock;
71    import com.xpn.xwiki.objects.BaseObject;
72    import com.xpn.xwiki.objects.BaseProperty;
73    import com.xpn.xwiki.objects.ObjectDiff;
74    import com.xpn.xwiki.objects.classes.BaseClass;
75    import com.xpn.xwiki.plugin.fileupload.FileUploadPlugin;
76    import com.xpn.xwiki.stats.api.XWikiStatsService;
77    import com.xpn.xwiki.stats.impl.DocumentStats;
78    import com.xpn.xwiki.stats.impl.RefererStats;
79    import com.xpn.xwiki.util.TOCGenerator;
80    import com.xpn.xwiki.util.Util;
81    import com.xpn.xwiki.web.Utils;
82   
83    /**
84    * This class represents a document or page in the wiki. This is a security and usability wrapper which wraps
85    * {@link com.xpn.xwiki.doc.XWikiDocument} In scripting, an object representing the document in which the script resides
86    * will be bound to a variable called doc.
87    *
88    * @version $Id: bfda9bbab9daca87c434cf3b3909063258ae8e6a $
89    */
 
90    public class Document extends Api
91    {
92    /** Logging helper object. */
93    private static final Logger LOGGER = LoggerFactory.getLogger(Document.class);
94   
95    /**
96    * The XWikiDocument object wrapped by this API.
97    */
98    protected XWikiDocument initialDoc;
99   
100    /**
101    * The XWikiDocument object wrapped by this API.
102    */
103    protected XWikiDocument doc;
104   
105    /**
106    * Convenience object used by object related methods.
107    */
108    protected Object currentObj;
109   
110    /**
111    * Used to resolve a string into a proper Document Reference using the current document's reference to fill the
112    * blanks, except for the page name for which the default page name is used instead and for the wiki name for which
113    * the current wiki is used instead of the current document reference's wiki.
114    */
115    private DocumentReferenceResolver<String> currentMixedDocumentReferenceResolver;
116   
117    /**
118    * Used to convert a proper Document Reference to string (standard form).
119    */
120    private EntityReferenceSerializer<String> defaultEntityReferenceSerializer;
121   
122    /**
123    * Used to convert a proper Document Reference to a string but without the wiki name.
124    */
125    private EntityReferenceSerializer<String> localEntityReferenceSerializer;
126   
127    /**
128    * Used to convert user references to string.
129    */
130    private EntityReferenceSerializer<String> compactWikiEntityReferenceSerializer;
131   
132    private DocumentRevisionProvider documentRevisionProvider;
133   
 
134  0 toggle private DocumentReferenceResolver<String> getCurrentMixedDocumentReferenceResolver()
135    {
136  0 if (this.currentMixedDocumentReferenceResolver == null) {
137  0 this.currentMixedDocumentReferenceResolver =
138    Utils.getComponent(DocumentReferenceResolver.TYPE_STRING, "currentmixed");
139    }
140   
141  0 return this.currentMixedDocumentReferenceResolver;
142    }
143   
 
144  3466 toggle private EntityReferenceSerializer<String> getDefaultEntityReferenceSerializer()
145    {
146  3466 if (this.defaultEntityReferenceSerializer == null) {
147  2415 this.defaultEntityReferenceSerializer = Utils.getComponent(EntityReferenceSerializer.TYPE_STRING);
148    }
149   
150  3466 return this.defaultEntityReferenceSerializer;
151    }
152   
 
153  98475 toggle private EntityReferenceSerializer<String> getLocalEntityReferenceSerializer()
154    {
155  98475 if (this.localEntityReferenceSerializer == null) {
156  41319 this.localEntityReferenceSerializer = Utils.getComponent(EntityReferenceSerializer.TYPE_STRING, "local");
157    }
158   
159  98476 return this.localEntityReferenceSerializer;
160    }
161   
 
162  0 toggle private EntityReferenceSerializer<String> getCompactWikiEntityReferenceSerializer()
163    {
164  0 if (this.compactWikiEntityReferenceSerializer == null) {
165  0 this.compactWikiEntityReferenceSerializer =
166    Utils.getComponent(EntityReferenceSerializer.TYPE_STRING, "compactwiki");
167    }
168   
169  0 return this.compactWikiEntityReferenceSerializer;
170    }
171   
 
172  35 toggle private DocumentRevisionProvider getDocumentRevisionProvider()
173    {
174  35 if (this.documentRevisionProvider == null) {
175  34 this.documentRevisionProvider = Utils.getComponent(DocumentRevisionProvider.class);
176    }
177   
178  35 return this.documentRevisionProvider;
179    }
180   
181    /**
182    * Document constructor.
183    *
184    * @param doc The XWikiDocument object to wrap.
185    * @param context The current request context.
186    */
 
187  2393838 toggle public Document(XWikiDocument doc, XWikiContext context)
188    {
189  2393557 super(context);
190   
191  2393673 this.initialDoc = doc;
192  2393786 this.doc = this.initialDoc;
193    }
194   
195    /**
196    * Get the XWikiDocument wrapped by this API. This function is accessible only if you have the programming rights
197    * give access to the priviledged API of the Document.
198    *
199    * @return The XWikiDocument wrapped by this API.
200    */
 
201  395 toggle public XWikiDocument getDocument()
202    {
203  395 if (hasProgrammingRights()) {
204  395 return this.doc;
205    } else {
206  0 return null;
207    }
208    }
209   
210    /**
211    * Get a clone of the XWikiDocument wrapped by this API.
212    *
213    * @return A clone of the XWikiDocument wrapped by this API.
214    */
 
215  332520 toggle protected XWikiDocument getDoc()
216    {
217  332686 if (this.initialDoc == this.doc) {
218  194369 this.doc = this.initialDoc.clone();
219    }
220   
221  332747 return this.doc;
222    }
223   
224    /**
225    * return the ID of the document. this ID is unique across the wiki.
226    *
227    * @return the id of the document.
228    */
 
229  0 toggle public long getId()
230    {
231  0 return this.doc.getId();
232    }
233   
234    /**
235    * returns the DocumentReference for the current document
236    *
237    * @return the DocumentReference of the current document
238    * @since 2.3M1
239    */
 
240  326018 toggle public DocumentReference getDocumentReference()
241    {
242  326427 return this.doc.getDocumentReference();
243    }
244   
245    /**
246    * @return the {@link DocumentReference} of the document also containing the document {@link Locale}
247    * @since 9.3RC1
248    */
 
249  12994 toggle public DocumentReference getDocumentReferenceWithLocale()
250    {
251  12994 return this.doc.getDocumentReferenceWithLocale();
252    }
253   
254    /**
255    * @return the reference of the document as {@link PageReference} without the {@link Locale}
256    * @since 10.6RC1
257    */
 
258  23451 toggle @Unstable
259    public PageReference getPageReference()
260    {
261  23451 return this.doc.getPageReference();
262    }
263   
264    /**
265    * @return the reference of the document as {@link PageReference} including the {@link Locale}
266    * @since 10.6RC1
267    */
 
268  0 toggle @Unstable
269    public PageReference getPageReferenceWithLocale()
270    {
271  0 return this.doc.getPageReferenceWithLocale();
272    }
273   
274    /**
275    * @return the last part of the document's reference. For example if the reference of a document is
276    * {@code MySpace.Mydoc}, the returned name is {@code MyDoc}. For a nested document, the last part of the
277    * reference is always {@code WebHome} and thus the returned name is {@code Webhome}. It's better to use
278    * {@link #getPageReference()} or {@link #getDocumentReference()}, e.g. with
279    * {@code getPageReference().getName()} or {@code getDocumentReference().getName()}. To get the space name
280    * of the nested document you can use {@code getPageReference().getName()} or
281    * {@code getDocumentReference().getParent().getName()}.
282    * @see #getPageReference()
283    * @see #getDocumentReference()
284    * @deprecated since 11.0, use {@link #getDocumentReference()} instead
285    */
 
286  125 toggle @Deprecated
287    public String getName()
288    {
289  125 return this.doc.getDocumentReference().getName();
290    }
291   
292    /**
293    * Return the full local space reference of the Document. For example a document located in sub-space
294    * <code>space11</code> of space <code>space1</code> will return <code>space1.space11</code>.
295    *
296    * @return the name of the spaces of the document
297    */
 
298  85580 toggle public String getSpace()
299    {
300  85580 return this.doc.getSpace();
301    }
302   
303    /**
304    * Get the name wiki where the document is stored.
305    *
306    * @return The name of the wiki where this document is stored.
307    * @since 1.1.2
308    * @since 1.2M2
309    */
 
310  17468 toggle public String getWiki()
311    {
312  17468 return this.doc.getDocumentReference().getWikiReference().getName();
313    }
314   
315    /**
316    * Get the fullName of the document. If a document is named "MyDoc" in space "MySpace", the fullname is
317    * "MySpace.MyDoc". In a wiki, all the documents have a different fullName.
318    *
319    * @return fullName of the document.
320    */
 
321  97111 toggle public String getFullName()
322    {
323  97110 return getLocalEntityReferenceSerializer().serialize(this.doc.getDocumentReference());
324    }
325   
326    /**
327    * Get the complete fullName of the document. The real full name of the document containing the name of the wiki
328    * where the document is stored. For a document stored in the wiki "xwiki", in space "MySpace", named "MyDoc", its
329    * complete full name is "xwiki:MySpace.MyDoc".
330    *
331    * @return The complete fullName of the document.
332    * @since 1.1.2
333    * @since 1.2M2
334    */
 
335  3465 toggle public String getPrefixedFullName()
336    {
337  3465 return getDefaultEntityReferenceSerializer().serialize(this.doc.getDocumentReference());
338    }
339   
340    /**
341    * Get a Version object representing the current version of the document.
342    *
343    * @return A Version object representing the current version of the document
344    */
 
345  1094 toggle public Version getRCSVersion()
346    {
347  1094 return this.doc.getRCSVersion();
348    }
349   
350    /**
351    * Get a string representing the current version of the document.
352    *
353    * @return A string representing the current version of the document.
354    */
 
355  13729 toggle public String getVersion()
356    {
357  13729 return this.doc.getVersion();
358    }
359   
360    /**
361    * Get a string representing the previous version of the document.
362    *
363    * @return A string representing the previous version of the document. If this is the first version then it returns
364    * null.
365    */
 
366  25 toggle public String getPreviousVersion()
367    {
368  25 return this.doc.getPreviousVersion();
369    }
370   
371    /**
372    * Get the value of the title field of the document.
373    *
374    * @return The value of the title field of the document.
375    */
 
376  16734 toggle public String getTitle()
377    {
378  16734 return this.doc.getTitle();
379    }
380   
381    /**
382    * Get document title. If a title has not been provided through the title field, it looks for a section title in the
383    * document's content and if not found return the page name. The returned title is also interpreted which means it's
384    * allowed to use Velocity, Groovy, etc syntax within a title.
385    *
386    * @return The document title as XHTML
387    */
 
388  105553 toggle public String getDisplayTitle()
389    {
390  105670 return this.doc.getRenderedTitle(getXWikiContext());
391    }
392   
393    /**
394    * Returns the document title as plain text
395    *
396    * @return the document title as plain text (all markup removed)
397    * @since 3.0M1
398    */
 
399  69457 toggle public String getPlainTitle()
400    {
401  69457 return this.doc.getRenderedTitle(Syntax.PLAIN_1_0, getXWikiContext());
402    }
403   
404    /**
405    * Returns the title of the document rendered through wiki syntax and velocity
406    *
407    * @return the title rendered through wiki syntax and velocity
408    * @see XWikiDocument#getRenderedTitle(Syntax, XWikiContext)
409    */
 
410  18606 toggle public String getRenderedTitle(String syntaxId) throws XWikiException
411    {
412  18606 try {
413  18606 return this.doc.getRenderedTitle(Syntax.valueOf(syntaxId), getXWikiContext());
414    } catch (ParseException e) {
415  0 LOGGER.error("Failed to parse provided syntax identifier [" + syntaxId + "]", e);
416   
417  0 throw new XWikiException(XWikiException.MODULE_XWIKI_RENDERING, XWikiException.ERROR_XWIKI_UNKNOWN,
418    "Failed to parse syntax identifier [" + syntaxId + "]", e);
419    } catch (Exception e) {
420  0 LOGGER.error("Failed to render document [" + getPrefixedFullName() + "] title content", e);
421   
422  0 throw new XWikiException(XWikiException.MODULE_XWIKI_RENDERING, XWikiException.ERROR_XWIKI_UNKNOWN,
423    "Failed to render document [" + getPrefixedFullName() + "] content title", e);
424    }
425    }
426   
427    /**
428    * TODO document this or mark it deprecated
429    */
 
430  0 toggle public String getFormat()
431    {
432  0 return this.doc.getFormat();
433    }
434   
435    /**
436    * Get fullName of the profile document of the author of the current version of the document. Example: XWiki.Admin.
437    *
438    * @return The fullName of the profile document of the author of the current version of the document.
439    */
 
440  20485 toggle public String getAuthor()
441    {
442  20485 return this.doc.getAuthor();
443    }
444   
445    /**
446    * @return the document author reference
447    * @since 6.4RC1
448    */
 
449  524 toggle public DocumentReference getAuthorReference()
450    {
451  524 return this.doc.getAuthorReference();
452    }
453   
454    /**
455    * Get fullName of the profile document of the author of the content modification of this document version. Example:
456    * XWiki.Admin.
457    *
458    * @return The fullName of the profile document of the author of the content modification in this document version.
459    */
 
460  572 toggle public String getContentAuthor()
461    {
462  572 return this.doc.getContentAuthor();
463    }
464   
465    /**
466    * @return the document content author reference
467    * @since 6.4RC1
468    */
 
469  6 toggle public DocumentReference getContentAuthorReference()
470    {
471  6 return this.doc.getContentAuthorReference();
472    }
473   
474    /**
475    * @return The date when this document version has been modified.
476    */
 
477  8843 toggle public Date getDate()
478    {
479  8843 return this.doc.getDate();
480    }
481   
482    /**
483    * Get the date when the content modification has been done on this document version. A content update excludes
484    * modifications to meta data fields or comments of the document.
485    *
486    * @return The date where the content modification has been done on this document version.
487    */
 
488  511 toggle public Date getContentUpdateDate()
489    {
490  511 return this.doc.getContentUpdateDate();
491    }
492   
493    /**
494    * @return the original creation date of the document.
495    */
 
496  8344 toggle public Date getCreationDate()
497    {
498  8344 return this.doc.getCreationDate();
499    }
500   
501    /**
502    * Get the name of the parent of this document.
503    *
504    * @return The name of the parent of this document.
505    */
 
506  51302 toggle public String getParent()
507    {
508  51323 return this.doc.getParent();
509    }
510   
511    /**
512    * @return the parent reference or null if the parent is not set
513    * @since 7.3M1
514    */
 
515  649 toggle public DocumentReference getParentReference()
516    {
517  649 return this.doc.getParentReference();
518    }
519   
520    /**
521    * Get fullName of the profile document of the document creator.
522    *
523    * @return The fullName of the profile document of the document creator.
524    */
 
525  8047 toggle public String getCreator()
526    {
527  8047 return this.doc.getCreator();
528    }
529   
530    /**
531    * @return the document creator reference
532    * @since 6.4RC1
533    */
 
534  490 toggle public DocumentReference getCreatorReference()
535    {
536  490 return this.doc.getCreatorReference();
537    }
538   
539    /**
540    * Get raw content of the document, i.e. the content that is visible through the wiki editor.
541    *
542    * @return The raw content of the document.
543    */
 
544  1283 toggle public String getContent()
545    {
546  1283 return this.doc.getContent();
547    }
548   
549    /**
550    * NOTE: This method caches the XDOM and returns a clone that can be safely modified.
551    *
552    * @return the XDOM corresponding to the document's string content
553    * @since 7.0RC1
554    */
 
555  0 toggle public XDOM getXDOM()
556    {
557  0 return this.doc.getXDOM();
558    }
559   
560    /**
561    * @return The syntax representing the syntax used for the document's content
562    * @since 2.3M1
563    */
 
564  77542 toggle public Syntax getSyntax()
565    {
566  77542 return this.doc.getSyntax();
567    }
568   
569    /**
570    * Get the Syntax id representing the syntax used for the document. For example "xwiki/1.0" represents the first
571    * version XWiki syntax while "xwiki/2.0" represents version 2.0 of the XWiki Syntax.
572    *
573    * @return The syntax id representing the syntax used for the document.
574    * @deprecated since 2.3M1 use {@link #getSyntax()} instead
575    */
 
576  3 toggle @Deprecated
577    public String getSyntaxId()
578    {
579  3 return this.doc.getSyntax().toIdString();
580    }
581   
582    /**
583    * Same as {@link #getLocale()} but as String.
584    *
585    * @return the locale of the document.
586    * @deprecated since 5.4M1 use {@link #getLocale()} instead
587    */
 
588  4 toggle @Deprecated
589    public String getLanguage()
590    {
591  4 return this.doc.getLanguage();
592    }
593   
594    /**
595    * Get the locale of the document. If the document is a translation it returns the locale set for it, otherwise, it
596    * returns the root locale.
597    *
598    * @return the locale of the document
599    * @since 5.4M1
600    */
 
601  26208 toggle public Locale getLocale()
602    {
603  26208 return this.doc.getLocale();
604    }
605   
606    /**
607    * TODO document this or mark it deprecated
608    */
 
609  0 toggle public String getTemplate()
610    {
611  0 String templateReferenceAsString = "";
612  0 DocumentReference templateDocumentReference = this.doc.getTemplateDocumentReference();
613  0 if (templateDocumentReference != null) {
614  0 templateReferenceAsString = getLocalEntityReferenceSerializer().serialize(templateDocumentReference);
615    }
616  0 return templateReferenceAsString;
617    }
618   
619    /**
620    * Same as {@link #getRealLocale()} but as String.
621    *
622    * @return the real locale
623    * @deprecated since 8.0M1, use {@link #getRealLocale()} instead
624    */
 
625  194 toggle @Deprecated
626    public String getRealLanguage() throws XWikiException
627    {
628  194 return this.doc.getRealLanguage(getXWikiContext());
629    }
630   
631    /**
632    * Gets the real locale of the document. The real locale is either the default locale field when the locale field is
633    * empty (when the document is the default document) or the locale field otherwise when the document is a
634    * translation document
635    *
636    * @return the actual locale of the document
637    * @since 8.0M1
638    */
 
639  47034 toggle public Locale getRealLocale()
640    {
641  47034 return this.doc.getRealLocale();
642    }
643   
644    /**
645    * Same as {@link #getDefaultLocale()} but as String.
646    *
647    * @return the locale of the default document
648    * @deprecated since 8.0M1, use {@link #getDefaultLocale()} instead
649    */
 
650  19 toggle @Deprecated
651    public String getDefaultLanguage()
652    {
653  19 return this.doc.getDefaultLanguage();
654    }
655   
656    /**
657    * @return the Locale of the default version of the document (usually {@link Locale#ROOT} or {@link Locale#ENGLISH})
658    * @since 8.0M1
659    */
 
660  5767 toggle public Locale getDefaultLocale()
661    {
662  5767 return this.doc.getDefaultLocale();
663    }
664   
665    /**
666    * TODO document this or mark it deprecated
667    */
 
668  0 toggle public String getDefaultTemplate()
669    {
670  0 return this.doc.getDefaultTemplate();
671    }
672   
673    /**
674    * @return the comment of of the document version
675    */
 
676  525 toggle public String getComment()
677    {
678  525 return this.doc.getComment();
679    }
680   
681    /**
682    * @return true if the this document version was a minor edit.
683    */
 
684  0 toggle public boolean isMinorEdit()
685    {
686  0 return this.doc.isMinorEdit();
687    }
688   
689    /**
690    * @return the list of existing translations for this document.
691    */
 
692  7975 toggle public List<String> getTranslationList() throws XWikiException
693    {
694  7975 return this.doc.getTranslationList(getXWikiContext());
695    }
696   
697    /**
698    * @return the translated document's content if the wiki is multilingual, the locale is first checked in the URL,
699    * the cookie, the user profile and finally the wiki configuration if not, the locale is the one on the wiki
700    * configuration.
701    */
 
702  421 toggle public String getTranslatedContent() throws XWikiException
703    {
704  421 return this.doc.getTranslatedContent(getXWikiContext());
705    }
706   
707    /**
708    * @return the translated content in the given locale
709    */
 
710  0 toggle public String getTranslatedContent(String locale) throws XWikiException
711    {
712  0 return this.doc.getTranslatedContent(locale, getXWikiContext());
713    }
714   
715    /**
716    * @return the translated document in the given locale
717    */
 
718  6232 toggle public Document getTranslatedDocument(String locale) throws XWikiException
719    {
720  6232 return this.doc.getTranslatedDocument(locale, getXWikiContext()).newDocument(getXWikiContext());
721    }
722   
723    /**
724    * @return the tranlated Document if the wiki is multilingual, the locale is first checked in the URL, the cookie,
725    * the user profile and finally the wiki configuration if not, the locale is the one on the wiki
726    * configuration.
727    */
 
728  134175 toggle public Document getTranslatedDocument() throws XWikiException
729    {
730  134180 return this.doc.getTranslatedDocument(getXWikiContext()).newDocument(getXWikiContext());
731    }
732   
733    /**
734    * @return the content of the document rendered.
735    */
 
736  12675 toggle public String getRenderedContent() throws XWikiException
737    {
738  12676 return this.doc.getRenderedContent(getXWikiContext());
739    }
740   
741    /**
742    * Execute and render the document in the current context.
743    * <p>
744    * The code is executed with right of this document content author.
745    *
746    * @param transformationContextIsolated see {@link DocumentDisplayerParameters#isTransformationContextIsolated()}
747    * @return the result
748    * @throws XWikiException when failing to display the document
749    * @since 8.4RC1
750    */
 
751  2 toggle public String getRenderedContent(boolean transformationContextIsolated) throws XWikiException
752    {
753  2 return this.doc.getRenderedContent(transformationContextIsolated, getXWikiContext());
754    }
755   
756    /**
757    * @param text the text to render
758    * @return the given text rendered in the context of this document
759    * @deprecated since 1.6M1 use {@link #getRenderedContent(String, String)}
760    */
 
761  0 toggle @Deprecated
762    public String getRenderedContent(String text) throws XWikiException
763    {
764  0 return getRenderedContent(text, Syntax.XWIKI_1_0.toIdString());
765    }
766   
767    /**
768    * @param text the text to render
769    * @param syntaxId the id of the Syntax used by the passed text (for example: "xwiki/1.0")
770    * @return the given text rendered in the context of this document using the passed Syntax
771    * @since 1.6M1
772    */
 
773  122 toggle public String getRenderedContent(String text, String syntaxId) throws XWikiException
774    {
775  122 return getRenderedContent(text, syntaxId, false);
776    }
777   
778    /**
779    * Render a text in a restricted mode, where script macros are completely disabled.
780    *
781    * @param text the text to render
782    * @param syntaxId the id of the Syntax used by the passed text (for example: "xwiki/1.0")
783    * @return the given text rendered in the context of this document using the passed Syntax
784    * @since 4.2M1
785    */
 
786  28 toggle public String getRenderedContentRestricted(String text, String syntaxId) throws XWikiException
787    {
788  28 return getRenderedContent(text, syntaxId, true);
789    }
790   
791    /**
792    * Render a text in a restricted mode, where script macros are completely disabled.
793    *
794    * @param text the text to render
795    * @param syntaxId the id of the Syntax used by the passed text (for example: "xwiki/1.0")
796    * @param restrictedTransformationContext see {@link DocumentDisplayerParameters#isTransformationContextRestricted}.
797    * @return the given text rendered in the context of this document using the passed Syntax
798    */
 
799  150 toggle private String getRenderedContent(String text, String syntaxId, boolean restricted) throws XWikiException
800    {
801    // Make sure we keep using current author as passed content author
802  150 return this.doc.getRenderedContent(text, syntaxId, restricted, getCallerDocument(getXWikiContext()),
803    getXWikiContext());
804    }
805   
806    /**
807    * @param text the text to render
808    * @param sourceSyntaxId the id of the Syntax used by the passed text (for example: "xwiki/1.0")
809    * @param targetSyntaxId the id of the syntax in which to render the document content
810    * @return the given text rendered in the context of this document using the passed Syntax
811    * @since 2.0M3
812    */
 
813  91 toggle public String getRenderedContent(String text, String sourceSyntaxId, String targetSyntaxId) throws XWikiException
814    {
815    // Make sure we keep using current author as passed content author
816  91 return this.doc.getRenderedContent(text, sourceSyntaxId, targetSyntaxId, false,
817    getCallerDocument(getXWikiContext()), getXWikiContext());
818    }
819   
 
820  241 toggle private XWikiDocument getCallerDocument(XWikiContext xcontext)
821    {
822  241 XWikiDocument sdoc = (XWikiDocument) xcontext.get("sdoc");
823  241 if (sdoc == null) {
824  7 sdoc = xcontext.getDoc();
825    }
826   
827  241 return sdoc;
828    }
829   
830    /**
831    * @param targetSyntax the syntax in which to render the document content
832    * @return the rendered content
833    * @throws XWikiException error when rendering content
834    */
 
835  9898 toggle public String getRenderedContent(Syntax targetSyntax) throws XWikiException
836    {
837  9900 return this.doc.getRenderedContent(targetSyntax, getXWikiContext());
838    }
839   
840    /**
841    * Get the document's content XML-escaped.
842    *
843    * @return an XML-escaped version of the content of this document.
844    */
 
845  0 toggle public String getEscapedContent() throws XWikiException
846    {
847  0 return this.doc.getEscapedContent(getXWikiContext());
848    }
849   
850    /**
851    * @return the archive of this document's history in string format
852    */
 
853  0 toggle public String getArchive() throws XWikiException
854    {
855  0 return this.doc.getDocumentArchive(getXWikiContext()).getArchive(getXWikiContext());
856    }
857   
858    /**
859    * Get the archive of this document's history. This function is accessible only if you have the programming rights.
860    *
861    * @return the archive of this document's history as an {@link XWikiDocumentArchive}.
862    */
 
863  20 toggle public XWikiDocumentArchive getDocumentArchive() throws XWikiException
864    {
865  20 if (hasProgrammingRights()) {
866  20 return this.doc.getDocumentArchive(getXWikiContext());
867    }
868  0 return null;
869    }
870   
871    /**
872    * @return true if the document is a new one (ie it has never been saved) or false otherwise
873    */
 
874  140064 toggle public boolean isNew()
875    {
876  140064 return this.doc.isNew();
877    }
878   
879    /**
880    * Return the relative URL of download for the the given attachment name.
881    *
882    * @param filename the name of the attachment
883    * @return A String with the URL or null if the file name is empty
884    */
 
885  11394 toggle public String getAttachmentURL(String filename)
886    {
887  11394 return this.doc.getAttachmentURL(filename, getXWikiContext());
888    }
889   
890    /**
891    * Get the relative URL of the given action for the the given attachment name.
892    *
893    * @param filename the name of the attachment.
894    * @param action what to do to the file for example "delattachment", "download" or "downloadrev".
895    * @return a string representation of a URL to do the given operation or null if the file name is empty
896    */
 
897  1 toggle public String getAttachmentURL(String filename, String action)
898    {
899  1 return this.doc.getAttachmentURL(filename, action, getXWikiContext());
900    }
901   
902    /**
903    * Get the relative URL of an action on an attachment. the given action for the the given attachment name with
904    * "queryString" parameters
905    *
906    * @param filename the name of the attachment.
907    * @param action what to do to the file for example "delattachment", "download" or "downloadrev"
908    * @param queryString parameters added to the URL, the "rev" parameter is used to specify a revision if using the
909    * "downloadrev" action. The query string must not begin with an ? character.
910    * @return a string representation of a URL to do the given operation or null if the file name is empty
911    */
 
912  19 toggle public String getAttachmentURL(String filename, String action, String queryString)
913    {
914  19 return this.doc.getAttachmentURL(filename, action, queryString, getXWikiContext());
915    }
916   
917    /**
918    * Get an old revision of an attachment.
919    *
920    * @param filename the name of the attachment.
921    * @param version a revision number such as "1.1" or "1.2".
922    * @return the URL for accessing to the archive of the attachment "filename" at the version "version" or null if the
923    * file name is empty
924    */
 
925  0 toggle public String getAttachmentRevisionURL(String filename, String version)
926    {
927  0 return this.doc.getAttachmentRevisionURL(filename, version, getXWikiContext());
928    }
929   
930    /**
931    * Get an old revision of an attachment.
932    *
933    * @param filename the name of the attachment.
934    * @param version a revision number such as "1.1" or "1.2".
935    * @param queryString additional query parameters to pass in the request.
936    * @return the URL for accessing to the archive of the attachment "filename" at the version "version" with the given
937    * queryString parameters or null if the file name is empty
938    */
 
939  0 toggle public String getAttachmentRevisionURL(String filename, String version, String queryString)
940    {
941  0 return this.doc.getAttachmentRevisionURL(filename, version, queryString, getXWikiContext());
942    }
943   
944    /**
945    * Get the URL of this document.
946    *
947    * @return the URL to view this document, this will be a relative URL for example: /xwiki/bin/view/Main/WebHome
948    * @see #getExternalURL() for an absolute URL which can used outside of the site.
949    */
 
950  68043 toggle public String getURL()
951    {
952  68045 return this.doc.getURL("view", getXWikiContext());
953    }
954   
955    /**
956    * Get the URL to do a given action on this document.
957    *
958    * @param action what to do to the document for example "view", "edit" or "inline".
959    * @return the URL of this document with the given action.
960    * @see #getExternalURL(String) for an absolute URL which can used outside of the site.
961    */
 
962  196979 toggle public String getURL(String action)
963    {
964  197138 return this.doc.getURL(action, getXWikiContext());
965    }
966   
967    /**
968    * Get the URL to do a given action on this document.
969    *
970    * @param action what to do to the document for example "view", "edit" or "inline".
971    * @param queryString parameters to pass in the request eg: {@code paramA=value1&paramB=value2}
972    * @return the URL of this document with the given action and queryString as parameters.
973    * @see #getExternalURL(String, String) for an absolute URL which can used outside of the site.
974    */
 
975  355113 toggle public String getURL(String action, String queryString)
976    {
977  355113 return this.doc.getURL(action, queryString, getXWikiContext());
978    }
979   
980    /**
981    * Get the external URL to do a given action on this document.
982    *
983    * @return the full URL of the document, sutable for use at external websites for example:
984    * http://www.xwiki.org/xwiki/bin/view/Main/WebHome
985    * @see #getURL() for a relative URL which can only be used inside of the site.
986    */
 
987  156 toggle public String getExternalURL()
988    {
989  156 return this.doc.getExternalURL("view", getXWikiContext());
990    }
991   
992    /**
993    * Get the external URL to do a given action on this document.
994    *
995    * @param action what to do to the document for example "view", "edit" or "inline".
996    * @return the URL of this document with the given action.
997    * @see #getURL() for a relative URL which can only be used inside of the site.
998    */
 
999  653 toggle public String getExternalURL(String action)
1000    {
1001  653 return this.doc.getExternalURL(action, getXWikiContext());
1002    }
1003   
1004    /**
1005    * Get the URL to do a given action on this document.
1006    *
1007    * @param action what to do to the document for example "view", "edit" or "inline".
1008    * @param queryString parameters to pass in the request eg: {@code paramA=value1&paramB=value2}
1009    * @return the URL of this document with the given action and queryString as parameters.
1010    * @see #getURL() for a relative URL which can only be used inside of the site.
1011    */
 
1012  221 toggle public String getExternalURL(String action, String queryString)
1013    {
1014  221 return this.doc.getExternalURL(action, queryString, getXWikiContext());
1015    }
1016   
1017    /**
1018    * @return the relative URL of the parent document of this document
1019    */
 
1020  0 toggle public String getParentURL() throws XWikiException
1021    {
1022  0 return this.doc.getParentURL(getXWikiContext());
1023    }
1024   
1025    /**
1026    * @return the XClass associated to this document when the document represents an XWiki Class
1027    */
 
1028  8392 toggle public Class getxWikiClass()
1029    {
1030  8392 BaseClass bclass = this.getDoc().getXClass();
1031  8392 if (bclass == null) {
1032  0 return null;
1033    } else {
1034  8392 return new Class(bclass, getXWikiContext());
1035    }
1036    }
1037   
1038    /**
1039    * @return the array of XClasses representing the objects of this document
1040    */
 
1041  216 toggle public Class[] getxWikiClasses()
1042    {
1043  216 List<BaseClass> list = this.getDoc().getXClasses(getXWikiContext());
1044  216 if (list == null) {
1045  0 return null;
1046    }
1047  216 Class[] result = new Class[list.size()];
1048  487 for (int i = 0; i < list.size(); i++) {
1049  271 result[i] = new Class(list.get(i), getXWikiContext());
1050    }
1051  216 return result;
1052    }
1053   
1054    /**
1055    * Creates a New XWiki Object of the given classname
1056    *
1057    * @param classname the classname used
1058    * @return the number of the object created
1059    */
 
1060  261 toggle public int createNewObject(String classname) throws XWikiException
1061    {
1062  261 int index = getDoc().createNewObject(classname, getXWikiContext());
1063   
1064  261 updateAuthor();
1065   
1066  261 return index;
1067    }
1068   
1069    /**
1070    * Creates a New XWiki Object of the given classname
1071    *
1072    * @param classname the classname used
1073    * @return the object created
1074    */
 
1075  258 toggle public Object newObject(String classname) throws XWikiException
1076    {
1077  258 int nb = createNewObject(classname);
1078  258 return getObject(classname, nb);
1079    }
1080   
1081    /**
1082    * @return true of the document has been loaded from cache
1083    */
 
1084  0 toggle public boolean isFromCache()
1085    {
1086  0 return this.doc.isFromCache();
1087    }
1088   
1089    /**
1090    * @param classname the classname used
1091    * @return the number of objects available for a given classname
1092    */
 
1093  484 toggle public int getObjectNumbers(String classname)
1094    {
1095  484 return this.doc.getObjectNumbers(classname);
1096    }
1097   
1098    /**
1099    * Get the list of all objects available in this document organized in a Map by classname
1100    *
1101    * @return the map of objects
1102    */
 
1103  1772 toggle public Map<String, Vector<Object>> getxWikiObjects()
1104    {
1105  1772 Map<DocumentReference, List<BaseObject>> map = this.getDoc().getXObjects();
1106  1772 Map<String, Vector<Object>> resultmap = new HashMap<String, Vector<Object>>();
1107  1772 for (Map.Entry<DocumentReference, List<BaseObject>> entry : map.entrySet()) {
1108  1365 List<BaseObject> objects = entry.getValue();
1109  1365 if (objects != null) {
1110  1365 resultmap.put(getLocalEntityReferenceSerializer().serialize(entry.getKey()), getXObjects(objects));
1111    }
1112    }
1113  1772 return resultmap;
1114    }
1115   
 
1116  37559 toggle protected Vector<Object> getXObjects(List<BaseObject> objects)
1117    {
1118  37559 if (objects == null) {
1119  0 return new Vector<Object>(0);
1120    }
1121  37559 Vector<Object> result = new Vector<Object>(objects.size());
1122  37559 for (BaseObject bobj : objects) {
1123  182338 if (bobj != null) {
1124  91464 result.add(newObjectApi(bobj, getXWikiContext()));
1125    }
1126    }
1127  37559 return result;
1128    }
1129   
1130    /**
1131    * Get the list of objects for a given classname classname
1132    *
1133    * @return the vector of objects
1134    */
 
1135  34643 toggle public Vector<Object> getObjects(String className)
1136    {
1137  34643 List<BaseObject> objects = this.getDoc().getXObjects(this.doc.resolveClassReference(className));
1138  34643 return getXObjects(objects);
1139    }
1140   
1141    /**
1142    * Get the first object that contains the given fieldname
1143    *
1144    * @param fieldname name of the field to find in the object
1145    * @return the XWiki Object
1146    */
 
1147  30 toggle public Object getFirstObject(String fieldname)
1148    {
1149  30 try {
1150  30 BaseObject obj = this.getDoc().getFirstObject(fieldname, getXWikiContext());
1151  30 if (obj == null) {
1152  12 return null;
1153    } else {
1154  18 return newObjectApi(obj, getXWikiContext());
1155    }
1156    } catch (Exception e) {
1157  0 return null;
1158    }