+
/**
* @since 2.2M1
*/
@@ -375,7 +378,9 @@
@Deprecated
public XWikiDocument()
{
-
this(Utils.getComponent(DocumentReferenceResolver.class).resolve(""));
+ // TODO: Replace this with the following when we find a way to not generate a
cycle:
+ //
this(Utils.getComponent(DocumentReferenceResolver.class).resolve(""));
+ this(new DocumentReference("xwiki", "Main",
"WebHome"));
}
/**
@@ -397,25 +402,18 @@
*
* @param wiki The wiki this document belongs to.
* @param space The space this document belongs to.
- * @param name The name of the document.
+ * @param name The name of the document (can contain either the page name or the
space and page name)
* @deprecated since 2.2M1 use {@link
#XWikiDocument(org.xwiki.model.reference.DocumentReference)} instead
*/
@Deprecated
public XWikiDocument(String wiki, String space, String name)
{
- String normalizedPage;
- String normalizedSpace;
- int i1 = name.indexOf(".");
- if (i1 == -1) {
- normalizedPage = name;
- normalizedSpace = space;
- } else {
- normalizedSpace = name.substring(0, i1);
- normalizedPage = name.substring(i1 + 1);
- }
-
- init(Utils.getComponent(DocumentReferenceResolver.class,
"current/reference").resolve(
- new DocumentReference(wiki, normalizedSpace, normalizedPage)));
+ // We allow to specify the space in the name (eg name = "space.page").
In this case the passed space is
+ // ignored.
+ DocumentReference reference = resolveReference(name, new DocumentReference(wiki,
space, null));
+ // Replace the resolved wiki by the passed wiki
+ reference.setWikiReference(new WikiReference(wiki));
+ init(reference);
}
public XWikiStoreInterface getStore(XWikiContext context)
@@ -5846,4 +5844,21 @@
return syntaxId;
}
+
+ private DocumentReference resolveReference(String referenceAsString,
DocumentReference defaultReference)
+ {
+ XWikiContext xcontext = getXWikiContext();
+ XWikiDocument originalCurentDocument = xcontext.getDoc();
+ try {
+ xcontext.setDoc(new XWikiDocument(defaultReference));
+ return this.currentDocumentReferenceResolver.resolve(referenceAsString);
+ } finally {
+ xcontext.setDoc(originalCurentDocument);
+ }
+ }
+
How is this different from XWikiDocument#getContext() introduced in 23506?
Is the only difference that the context is the one from when the document was
created/loaded rather than the
current context? If so this probably ought to be commented since it is a major trap for
anyone who expects
getXWikiContext().getUser() to yield the current user (for example).
Indeed getContext() and getXWikiContext() are doing exactly the same
thing, one of them should be removed, probably getContext() which is
less explicit (but getXWikiContext() should probably protect from
uninitialized Execution like getContext() do).