/
XWikiDocument.java
9476 lines (8355 loc) · 351 KB
/
XWikiDocument.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* See the NOTICE file distributed with this work for additional
* information regarding copyright ownership.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package com.xpn.xwiki.doc;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.StringWriter;
import java.lang.ref.SoftReference;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.lang.reflect.Type;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.Set;
import java.util.SortedMap;
import java.util.TreeMap;
import java.util.Vector;
import java.util.concurrent.ConcurrentSkipListMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
import javax.inject.Provider;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.apache.velocity.VelocityContext;
import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.dom.DOMDocument;
import org.dom4j.io.DocumentResult;
import org.dom4j.io.OutputFormat;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.suigeneris.jrcs.diff.Diff;
import org.suigeneris.jrcs.diff.DifferentiationFailedException;
import org.suigeneris.jrcs.diff.Revision;
import org.suigeneris.jrcs.diff.delta.Delta;
import org.suigeneris.jrcs.rcs.Version;
import org.suigeneris.jrcs.util.ToString;
import org.xwiki.bridge.DocumentModelBridge;
import org.xwiki.component.manager.ComponentLookupException;
import org.xwiki.component.util.DefaultParameterizedType;
import org.xwiki.context.Execution;
import org.xwiki.context.ExecutionContextException;
import org.xwiki.context.ExecutionContextManager;
import org.xwiki.display.internal.DocumentDisplayer;
import org.xwiki.display.internal.DocumentDisplayerParameters;
import org.xwiki.filter.input.DefaultInputStreamInputSource;
import org.xwiki.filter.input.InputSource;
import org.xwiki.filter.input.StringInputSource;
import org.xwiki.filter.instance.input.DocumentInstanceInputProperties;
import org.xwiki.filter.instance.output.DocumentInstanceOutputProperties;
import org.xwiki.filter.output.DefaultOutputStreamOutputTarget;
import org.xwiki.filter.output.DefaultWriterOutputTarget;
import org.xwiki.filter.output.OutputTarget;
import org.xwiki.filter.xar.input.XARInputProperties;
import org.xwiki.filter.xar.output.XAROutputProperties;
import org.xwiki.filter.xml.output.DefaultResultOutputTarget;
import org.xwiki.job.event.status.JobProgressManager;
import org.xwiki.link.LinkException;
import org.xwiki.link.LinkStore;
import org.xwiki.localization.ContextualLocalizationManager;
import org.xwiki.localization.LocaleUtils;
import org.xwiki.model.EntityType;
import org.xwiki.model.document.DocumentAuthors;
import org.xwiki.model.internal.document.DefaultDocumentAuthors;
import org.xwiki.model.internal.reference.DefaultSymbolScheme;
import org.xwiki.model.internal.reference.EntityReferenceFactory;
import org.xwiki.model.internal.reference.LocalStringEntityReferenceSerializer;
import org.xwiki.model.internal.reference.LocalUidStringEntityReferenceSerializer;
import org.xwiki.model.reference.AttachmentReference;
import org.xwiki.model.reference.DocumentReference;
import org.xwiki.model.reference.DocumentReferenceResolver;
import org.xwiki.model.reference.EntityReference;
import org.xwiki.model.reference.EntityReferenceProvider;
import org.xwiki.model.reference.EntityReferenceResolver;
import org.xwiki.model.reference.EntityReferenceSerializer;
import org.xwiki.model.reference.LocalDocumentReference;
import org.xwiki.model.reference.ObjectPropertyReference;
import org.xwiki.model.reference.ObjectReference;
import org.xwiki.model.reference.ObjectReferenceResolver;
import org.xwiki.model.reference.PageReference;
import org.xwiki.model.reference.PageReferenceResolver;
import org.xwiki.model.reference.SpaceReference;
import org.xwiki.model.reference.WikiReference;
import org.xwiki.query.Query;
import org.xwiki.query.QueryException;
import org.xwiki.query.QueryFilter;
import org.xwiki.rendering.block.Block;
import org.xwiki.rendering.block.Block.Axes;
import org.xwiki.rendering.block.HeaderBlock;
import org.xwiki.rendering.block.MacroBlock;
import org.xwiki.rendering.block.SectionBlock;
import org.xwiki.rendering.block.XDOM;
import org.xwiki.rendering.block.match.ClassBlockMatcher;
import org.xwiki.rendering.block.match.MacroBlockMatcher;
import org.xwiki.rendering.internal.parser.LinkParser;
import org.xwiki.rendering.listener.reference.ResourceReference;
import org.xwiki.rendering.listener.reference.ResourceType;
import org.xwiki.rendering.parser.ContentParser;
import org.xwiki.rendering.parser.MissingParserException;
import org.xwiki.rendering.parser.ParseException;
import org.xwiki.rendering.parser.Parser;
import org.xwiki.rendering.renderer.BlockRenderer;
import org.xwiki.rendering.renderer.printer.DefaultWikiPrinter;
import org.xwiki.rendering.renderer.printer.WikiPrinter;
import org.xwiki.rendering.syntax.Syntax;
import org.xwiki.rendering.syntax.SyntaxRegistry;
import org.xwiki.rendering.transformation.RenderingContext;
import org.xwiki.rendering.util.ErrorBlockGenerator;
import org.xwiki.security.authorization.ContextualAuthorizationManager;
import org.xwiki.security.authorization.Right;
import org.xwiki.stability.Unstable;
import org.xwiki.store.TemporaryAttachmentSessionsManager;
import org.xwiki.store.merge.MergeDocumentResult;
import org.xwiki.store.merge.MergeManager;
import org.xwiki.user.GuestUserReference;
import org.xwiki.user.UserConfiguration;
import org.xwiki.user.UserReference;
import org.xwiki.user.UserReferenceResolver;
import org.xwiki.user.UserReferenceSerializer;
import org.xwiki.velocity.VelocityContextFactory;
import org.xwiki.velocity.VelocityManager;
import org.xwiki.velocity.XWikiVelocityContext;
import org.xwiki.velocity.XWikiVelocityException;
import org.xwiki.xar.internal.model.XarDocumentModel;
import org.xwiki.xml.XMLUtils;
import org.xwiki.xml.html.HTMLUtils;
import com.xpn.xwiki.CoreConfiguration;
import com.xpn.xwiki.XWiki;
import com.xpn.xwiki.XWikiConstant;
import com.xpn.xwiki.XWikiContext;
import com.xpn.xwiki.XWikiException;
import com.xpn.xwiki.api.DocumentSection;
import com.xpn.xwiki.criteria.impl.RevisionCriteria;
import com.xpn.xwiki.doc.merge.MergeConfiguration;
import com.xpn.xwiki.doc.merge.MergeResult;
import com.xpn.xwiki.doc.rcs.XWikiRCSNodeInfo;
import com.xpn.xwiki.internal.cache.rendering.RenderingCache;
import com.xpn.xwiki.internal.doc.BaseObjects;
import com.xpn.xwiki.internal.doc.XWikiAttachmentList;
import com.xpn.xwiki.internal.filter.XWikiDocumentFilterUtils;
import com.xpn.xwiki.internal.render.OldRendering;
import com.xpn.xwiki.internal.xml.DOMXMLWriter;
import com.xpn.xwiki.internal.xml.XMLWriter;
import com.xpn.xwiki.objects.BaseCollection;
import com.xpn.xwiki.objects.BaseObject;
import com.xpn.xwiki.objects.BaseObjectReference;
import com.xpn.xwiki.objects.BaseProperty;
import com.xpn.xwiki.objects.LargeStringProperty;
import com.xpn.xwiki.objects.ListProperty;
import com.xpn.xwiki.objects.ObjectDiff;
import com.xpn.xwiki.objects.PropertyInterface;
import com.xpn.xwiki.objects.classes.BaseClass;
import com.xpn.xwiki.objects.classes.ListClass;
import com.xpn.xwiki.objects.classes.PropertyClass;
import com.xpn.xwiki.objects.classes.StaticListClass;
import com.xpn.xwiki.objects.classes.TextAreaClass;
import com.xpn.xwiki.store.AttachmentRecycleBinStore;
import com.xpn.xwiki.store.XWikiAttachmentStoreInterface;
import com.xpn.xwiki.store.XWikiHibernateAttachmentStore;
import com.xpn.xwiki.store.XWikiStoreInterface;
import com.xpn.xwiki.store.XWikiVersioningStoreInterface;
import com.xpn.xwiki.user.api.XWikiRightService;
import com.xpn.xwiki.util.Util;
import com.xpn.xwiki.validation.XWikiValidationInterface;
import com.xpn.xwiki.validation.XWikiValidationStatus;
import com.xpn.xwiki.web.EditForm;
import com.xpn.xwiki.web.ObjectAddForm;
import com.xpn.xwiki.web.ObjectPolicyType;
import com.xpn.xwiki.web.Utils;
import com.xpn.xwiki.web.XWikiRequest;
public class XWikiDocument implements DocumentModelBridge, Cloneable
{
private static final Logger LOGGER = LoggerFactory.getLogger(XWikiDocument.class);
private static final String TM_FAILEDDOCUMENTPARSE = "core.document.error.failedParse";
private static final String CLOSE_HTML_MACRO = "{{/html}}";
/**
* An attachment waiting to be deleted at next document save.
*
* @version $Id$
* @since 5.2M1
*/
public static class XWikiAttachmentToRemove
{
/**
* @see #getAttachment()
*/
private XWikiAttachment attachment;
/**
* @see #isToRecycleBin()
*/
private boolean toRecycleBin;
/**
* @param attachment the attachment to delete
* @param toRecycleBin true of the attachment should be moved to the recycle bin
*/
public XWikiAttachmentToRemove(XWikiAttachment attachment, boolean toRecycleBin)
{
this.attachment = attachment;
this.toRecycleBin = toRecycleBin;
}
/**
* @return the attachment to delete
*/
public XWikiAttachment getAttachment()
{
return this.attachment;
}
/**
* @return true of the attachment should be moved to the recycle bin
*/
public boolean isToRecycleBin()
{
return this.toRecycleBin;
}
@Override
public int hashCode()
{
return this.attachment.hashCode();
}
@Override
public boolean equals(Object obj)
{
if (obj instanceof XWikiAttachmentToRemove) {
return this.attachment.equals(((XWikiAttachmentToRemove) obj).getAttachment());
}
return false;
}
@Override
public String toString()
{
return this.attachment.toString();
}
}
/**
* Regex Pattern to recognize if there's HTML code in a XWiki page.
*/
private static final Pattern HTML_TAG_PATTERN = Pattern.compile(
"</?+(html|img|a|i|br?|embed|script|form|input|textarea|object|font|li|[dou]l|table|center|hr|p) ?([^>]*+)>");
public static final EntityReference COMMENTSCLASS_REFERENCE = new LocalDocumentReference("XWiki", "XWikiComments");
public static final EntityReference SHEETCLASS_REFERENCE = new LocalDocumentReference("XWiki", "SheetClass");
public static final int HAS_ATTACHMENTS = 1;
public static final int HAS_OBJECTS = 2;
public static final int HAS_CLASS = 4;
/**
* The name of the key in the {@link XWikiContext} which contains the document used to check for programming rights.
*/
public static final String CKEY_SDOC = "sdoc";
/**
* The name of the key in the {@link XWikiContext} which contains the current content document.
*
* @since 15.9RC1
*/
public static final String CKEY_CDOC = "cdoc";
/**
* The name of the key in the {@link XWikiContext} which contains the current translation document.
*
* @since 15.9RC1
*/
public static final String CKEY_TDOC = "tdoc";
/**
* Separator string between database name and space name.
*/
public static final String DB_SPACE_SEP = ":";
/**
* Separator string between space name and page name.
*/
public static final String SPACE_NAME_SEP = ".";
private static final LocalStringEntityReferenceSerializer LOCAL_REFERENCE_SERIALIZER =
new LocalStringEntityReferenceSerializer(new DefaultSymbolScheme());
/**
* Used to resolve a string into a proper Document Reference using the current document's reference to fill the
* blanks.
*/
private static DocumentReferenceResolver<String> getCurrentDocumentReferenceResolver()
{
return Utils.getComponent(DocumentReferenceResolver.TYPE_STRING, "current");
}
/**
* Used to resolve a ResourceReference into a proper Entity Reference using the current document to fill the blanks.
*/
private static EntityReferenceResolver<ResourceReference> getResourceReferenceEntityReferenceResolver()
{
return Utils
.getComponent(new DefaultParameterizedType(null, EntityReferenceResolver.class, ResourceReference.class));
}
private static EntityReferenceResolver<String> getXClassEntityReferenceResolver()
{
return Utils.getComponent(EntityReferenceResolver.TYPE_STRING, "xclass");
}
/**
* Used to resolve a string into a proper Document Reference using the current document's reference to fill the
* blanks, except for the page name for which the default page name is used instead and for the wiki name for which
* the current wiki is used instead of the current document reference's wiki.
*/
private static DocumentReferenceResolver<String> getCurrentMixedDocumentReferenceResolver()
{
return Utils.getComponent(DocumentReferenceResolver.TYPE_STRING, "currentmixed");
}
/**
* Used to normalize references.
*/
private static DocumentReferenceResolver<EntityReference> getCurrentReferenceDocumentReferenceResolver()
{
return Utils.getComponent(DocumentReferenceResolver.TYPE_REFERENCE, "current");
}
/**
* Used to resolve parent references in the way they are stored externally (database, xml, etc), ie relative or
* absolute.
*/
private static EntityReferenceResolver<String> getRelativeEntityReferenceResolver()
{
return Utils.getComponent(EntityReferenceResolver.TYPE_STRING, "relative");
}
/**
* Used to convert a proper Document Reference to string (compact form).
*/
private static EntityReferenceSerializer<String> getCompactEntityReferenceSerializer()
{
return Utils.getComponent(EntityReferenceSerializer.TYPE_STRING, "compact");
}
/**
* Used to convert a Document Reference to string (compact form without the wiki part if it matches the current
* wiki).
*/
private static EntityReferenceSerializer<String> getCompactWikiEntityReferenceSerializer()
{
return Utils.getComponent(EntityReferenceSerializer.TYPE_STRING, "compactwiki");
}
/**
* Used to normalize references.
*/
private static ObjectReferenceResolver<EntityReference> getCurrentReferenceObjectReferenceResolver()
{
return Utils.getComponent(ObjectReferenceResolver.TYPE_REFERENCE, "current");
}
/**
* Used to convert a syntax defined as String into a Syntax object.
*/
private static SyntaxRegistry getSyntaxRegistry()
{
return Utils.getComponent(SyntaxRegistry.class);
}
/**
* Used to retrieve backlinks from an XDOM.
*/
private static LinkParser getLinkParser()
{
return Utils.getComponent(LinkParser.class);
}
/**
* @return the user module configuration, used for instance to determine where users are stored
*/
private static UserConfiguration getUserConfiguration()
{
return Utils.getComponent(UserConfiguration.class);
}
private String title;
/**
* Reference to this document's parent.
* <p>
* Note that we're saving the parent reference as a relative reference instead of an absolute one because We want
* the ability (for example) to create a parent reference relative to the current space or wiki so that a copy of
* this XWikiDocument object would retain that relativity. This is for example useful when copying a Wiki into
* another Wiki so that the copied XWikiDcoument's parent reference points to the new wiki.
*/
private EntityReference parentReference;
private DocumentReference documentReference;
private String content;
private String meta;
private String format;
private String customClass;
private Date contentUpdateDate;
private Date updateDate;
private Date creationDate;
protected Version version;
private long id = 0;
private boolean mostRecent = true;
private boolean isNew = true;
/**
* The reference to the document that is the template for the current document.
*
* @todo this field is not used yet since it's not currently saved in the database.
*/
private DocumentReference templateDocumentReference;
private Locale locale;
private Locale defaultLocale;
/**
* Indicates whether the document is 'hidden', meaning that it should not be returned in public search results.
* WARNING: this is a temporary hack until the new data model is designed and implemented. No code should rely on or
* use this property, since it will be replaced with a generic metadata.
*/
private boolean hidden = false;
/**
* Comment on the latest modification.
*/
private String comment;
/**
* Wiki syntax supported by this document. This is used to support different syntaxes inside the same wiki. For
* example a page can use the MediaWiki 1.0 syntax while another one uses the XWiki 2.1 syntax.
*/
private Syntax syntax;
/**
* Is latest modification a minor edit.
*/
private boolean isMinorEdit = false;
/**
* Used to make sure the MetaData String is regenerated.
*/
private boolean isContentDirty = true;
/**
* Used to make sure the MetaData String is regenerated.
*/
private boolean isMetaDataDirty = true;
private int elements = HAS_OBJECTS | HAS_ATTACHMENTS;
// Meta Data
private BaseClass xClass;
private String xClassXML;
/**
* Map holding document objects indexed by XClass references (i.e. Document References since a XClass reference
* points to a document). The preserve index ordering (consistent sorted order for output to XML, rendering in
* velocity, etc.)
*/
private Map<DocumentReference, BaseObjects> xObjects = new ConcurrentSkipListMap<>();
/**
* The publicly exposed Map.
*/
private Map<DocumentReference, List<BaseObject>> publicXObjects = new Map<DocumentReference, List<BaseObject>>()
{
@Override
public List<BaseObject> put(DocumentReference key, List<BaseObject> value)
{
// Makes sure to always insert BaseObjects
return xObjects.put(key, value instanceof BaseObjects ? (BaseObjects) value : new BaseObjects(value));
}
@Override
public void putAll(Map<? extends DocumentReference, ? extends List<BaseObject>> m)
{
m.forEach(this::put);
}
@Override
public int size()
{
return xObjects.size();
}
@Override
public boolean isEmpty()
{
return xObjects.isEmpty();
}
@Override
public boolean containsKey(Object key)
{
return xObjects.containsKey(key);
}
@Override
public boolean containsValue(Object value)
{
return xObjects.containsValue(value);
}
@Override
public List<BaseObject> get(Object key)
{
return xObjects.get(key);
}
@Override
public List<BaseObject> remove(Object key)
{
return xObjects.remove(key);
}
@Override
public void clear()
{
xObjects.clear();
}
@Override
public Set<DocumentReference> keySet()
{
return xObjects.keySet();
}
@Override
public Collection<List<BaseObject>> values()
{
return (Collection) xObjects.values();
}
@Override
public Set<Entry<DocumentReference, List<BaseObject>>> entrySet()
{
return (Set) xObjects.entrySet();
}
};
private final XWikiAttachmentList attachmentList = new XWikiAttachmentList(XWikiDocument.this);
// Caching
private boolean fromCache = false;
private List<BaseObject> xObjectsToRemove = new ArrayList<BaseObject>();
private List<XWikiAttachmentToRemove> attachmentsToRemove = new ArrayList<XWikiAttachmentToRemove>();
/**
* The view template (vm file) to use. When not set the default view template is used.
*
* @see com.xpn.xwiki.web.ViewAction#render(XWikiContext)
*/
private String defaultTemplate;
private String validationScript;
private Object wikiNode;
/**
* We are using a SoftReference which will allow the archive to be discarded by the Garbage collector as long as the
* context is closed (usually during the request)
*/
private SoftReference<XWikiDocumentArchive> archive;
private XWikiStoreInterface store;
/**
* @see #getOriginalDocument()
*/
private XWikiDocument originalDocument;
/**
* If the document should always be rendered in restricted mode.
*/
private boolean restricted;
/**
* Used to display the title and the content of this document. Do not inject the component here to avoid any simple
* new XWikiDocument to cause many useless initialization, in particular, during initialization of the stub context
* and other fake documents in tests.
*/
private DocumentDisplayer documentDisplayer;
/**
* @see #getDefaultEntityReferenceSerializer()
*/
private EntityReferenceSerializer<String> defaultEntityReferenceSerializer;
/**
* @see #getExplicitDocumentReferenceResolver()
*/
private DocumentReferenceResolver<String> explicitDocumentReferenceResolver;
/**
* @see #getExplicitReferenceDocumentReferenceResolver()
*/
private DocumentReferenceResolver<EntityReference> explicitReferenceDocumentReferenceResolver;
/**
* @see #getPageReferenceResolver()
*/
private PageReferenceResolver<EntityReference> pageReferenceResolver;
/**
* @see #getUidStringEntityReferenceSerializer()
*/
private EntityReferenceSerializer<String> uidStringEntityReferenceSerializer;
private Provider<OldRendering> oldRenderingProvider;
private JobProgressManager progress;
private ContextualLocalizationManager localization;
private VelocityContextFactory velocityContextFactory;
private EntityReferenceFactory entityReferenceFactory;
/**
* The document structure expressed as a tree of Block objects. We store it for performance reasons since parsing is
* a costly operation that we don't want to repeat whenever some code ask for the XDOM information.
*/
private XDOM xdomCache;
/**
* Use to store rendered documents in #getRenderedContent(). Do not inject the component here to avoid any simple
* new XWikiDocument to cause many useless initialization, in particular, during initialization of the stub context
* and other fake documents in tests.
*/
private RenderingCache renderingCache;
/**
* Cache the parent reference resolved as an absolute reference for improved performance (so that we don't have to
* resolve the relative reference every time getParentReference() is called.
*/
private DocumentReference parentReferenceCache;
/**
* Cache the document reference with locale resolved kept for improved performance (so that we don't have to resolve
* it every time getPageReference() is called.
*/
private DocumentReference documentReferenceWithLocaleCache;
/**
* Cache the page reference resolved kept for improved performance (so that we don't have to resolve it every time
* getPageReference() is called.
*/
private PageReference pageReferenceCache;
/**
* Cache the page reference with locale resolved kept for improved performance (so that we don't have to resolve it
* every time getPageReference() is called.
*/
private PageReference pageReferenceWithLocaleCache;
/**
* @see #getKey()
*/
private String keyCache;
/**
* @see #getLocalKey()
*/
private String localKeyCache;
private RenderingContext renderingContext;
/**
* @see #getAuthors()
*/
private final DefaultDocumentAuthors authors = new DefaultDocumentAuthors(this);
/**
* Create a document for the given reference, with the {@link Locale#ROOT} even if the reference contains a locale.
* If you want to create a document for another locale, use {@link #XWikiDocument(DocumentReference, Locale)}.
*
* @since 2.2M1
*/
public XWikiDocument(DocumentReference reference)
{
init(reference);
}
/**
* @since 6.2
*/
public XWikiDocument(DocumentReference reference, Locale locale)
{
init(reference);
this.locale = locale;
}
/**
* @deprecated use {@link #XWikiDocument(org.xwiki.model.reference.DocumentReference)} instead
*/
@Deprecated(since = "2.2M1")
public XWikiDocument()
{
this(null);
}
/**
* Constructor that specifies the local document identifier: space name, document name. {@link #setDatabase(String)}
* must be called afterwards to specify the wiki name.
*
* @param space the space this document belongs to
* @param name the name of the document
* @deprecated use {@link #XWikiDocument(org.xwiki.model.reference.DocumentReference)} instead
*/
@Deprecated(since = "2.2M1")
public XWikiDocument(String space, String name)
{
this(null, space, name);
}
/**
* Constructor that specifies the full document identifier: wiki name, space name, document name.
*
* @param wiki The wiki this document belongs to.
* @param space The space this document belongs to.
* @param name The name of the document (can contain either the page name or the space and page name)
* @deprecated use {@link #XWikiDocument(org.xwiki.model.reference.DocumentReference)} instead
*/
@Deprecated(since = "2.2M1")
public XWikiDocument(String wiki, String space, String name)
{
// We allow to specify the space in the name (eg name = "space.page"). In this case the passed space is
// ignored.
// Build an entity reference that will serve as a current context reference against which to resolve if the
// passed name doesn't contain a space.
EntityReference contextReference = null;
if (!StringUtils.isEmpty(space)) {
contextReference = new EntityReference(space, EntityType.SPACE);
}
DocumentReference reference = getCurrentDocumentReferenceResolver().resolve(name, contextReference);
if (!StringUtils.isEmpty(wiki)) {
reference = reference.replaceParent(reference.getWikiReference(), new WikiReference(wiki));
}
init(reference);
}
/**
* Used to resolve a string into a proper Document Reference.
*/
private DocumentReferenceResolver<String> getExplicitDocumentReferenceResolver()
{
if (this.explicitDocumentReferenceResolver == null) {
this.explicitDocumentReferenceResolver =
Utils.getComponent(DocumentReferenceResolver.TYPE_STRING, "explicit");
}
return this.explicitDocumentReferenceResolver;
}
/**
* Used to normalize references.
*/
private DocumentReferenceResolver<EntityReference> getExplicitReferenceDocumentReferenceResolver()
{
if (this.explicitReferenceDocumentReferenceResolver == null) {
this.explicitReferenceDocumentReferenceResolver =
Utils.getComponent(DocumentReferenceResolver.TYPE_REFERENCE, "explicit");
}
return this.explicitReferenceDocumentReferenceResolver;
}
private PageReferenceResolver<EntityReference> getPageReferenceResolver()
{
if (this.pageReferenceResolver == null) {
this.pageReferenceResolver = Utils.getComponent(PageReferenceResolver.TYPE_REFERENCE);
}
return this.pageReferenceResolver;
}
/**
* Used to convert a proper Document Reference to string (standard form).
*/
private EntityReferenceSerializer<String> getDefaultEntityReferenceSerializer()
{
if (this.defaultEntityReferenceSerializer == null) {
this.defaultEntityReferenceSerializer = Utils.getComponent(EntityReferenceSerializer.TYPE_STRING);
}
return this.defaultEntityReferenceSerializer;
}
/**
* Used to compute document identifier.
*/
private EntityReferenceSerializer<String> getUidStringEntityReferenceSerializer()
{
if (this.uidStringEntityReferenceSerializer == null) {
this.uidStringEntityReferenceSerializer = Utils.getComponent(EntityReferenceSerializer.TYPE_STRING, "uid");
}
return this.uidStringEntityReferenceSerializer;
}
private ContextualLocalizationManager getLocalization()
{
if (this.localization == null) {
this.localization = Utils.getComponent(ContextualLocalizationManager.class);
}
return this.localization;
}
private OldRendering getOldRendering()
{
if (this.oldRenderingProvider == null) {
this.oldRenderingProvider = Utils.getComponent(OldRendering.TYPE_PROVIDER);
}
return this.oldRenderingProvider.get();
}
private JobProgressManager getProgress()
{
if (this.progress == null) {
this.progress = Utils.getComponent(JobProgressManager.class);
}
return this.progress;
}
private VelocityContextFactory getVelocityContextFactory()
{
if (this.velocityContextFactory == null) {
this.velocityContextFactory = Utils.getComponent(VelocityContextFactory.class);
}
return this.velocityContextFactory;
}
private EntityReferenceFactory getEntityReferenceFactory()
{
if (this.entityReferenceFactory == null && Utils.getRootComponentManager() != null) {
try {
this.entityReferenceFactory = Utils.getRootComponentManager().getInstance(EntityReferenceFactory.class);
} catch (ComponentLookupException e) {
// Not a big deal
}
}
return this.entityReferenceFactory;
}
private <E extends EntityReference> E intern(E reference)
{
EntityReferenceFactory factory = getEntityReferenceFactory();
return factory != null ? factory.getReference(reference) : reference;
}
private String localizePlainOrKey(String key, Object... parameters)
{
return StringUtils.defaultString(getLocalization().getTranslationPlain(key, parameters), key);
}
private UserReferenceSerializer<DocumentReference> getUserReferenceDocumentReferenceSerializer()
{
return Utils.getComponent(UserReferenceSerializer.TYPE_DOCUMENT_REFERENCE, "document");
}
private UserReferenceResolver<DocumentReference> getUserReferenceDocumentReferenceResolver()
{
return Utils.getComponent(UserReferenceResolver.TYPE_DOCUMENT_REFERENCE, "document");
}
private UserReferenceSerializer<String> getUserReferenceStringSerializer()
{
return Utils.getComponent(UserReferenceSerializer.TYPE_STRING);
}
private UserReferenceResolver<String> getUserReferenceStringResolver()
{
return Utils.getComponent(UserReferenceResolver.TYPE_STRING);
}
private UserReferenceSerializer<String> getUserReferenceCompactWikiSerializer()
{
return Utils.getComponent(UserReferenceSerializer.TYPE_STRING, "compactwiki/document");
}
private LinkStore getLinkStore()
{
return Utils.getComponent(LinkStore.class);
}
public XWikiStoreInterface getStore(XWikiContext context)
{
return context.getWiki().getStore();
}
/**
* @deprecated use {@link XWiki#getDefaultAttachmentContentStore()} instead
*/
@Deprecated(since = "9.9RC1")
public XWikiAttachmentStoreInterface getAttachmentStore(XWikiContext context)
{
return context.getWiki().getAttachmentStore();
}
public XWikiVersioningStoreInterface getVersioningStore(XWikiContext context)
{
return context.getWiki().getVersioningStore();
}
public XWikiStoreInterface getStore()
{
return this.store;
}
public void setStore(XWikiStoreInterface store)
{
this.store = store;
}
private RenderingContext getRenderingContext()
{
if (this.renderingContext == null) {
this.renderingContext = Utils.getComponent(RenderingContext.class);
}