use of org.xwiki.model.reference.SpaceReference in project xwiki-platform by xwiki.
the class AbstractResourceReferenceEntityReferenceResolver method resolveDocumentReference.
protected DocumentReference resolveDocumentReference(EntityReference sourceReference, DocumentReference reference, EntityReference baseReference, boolean trySpaceSibling, String defaultDocumentName) {
DocumentReference finalReference = reference;
if (!this.documentAccessBridge.exists(reference)) {
// It does not exist, make it a space home page.
SpaceReference spaceReference = new SpaceReference(reference.getName(), (SpaceReference) reference.getParent());
finalReference = new DocumentReference(defaultDocumentName, spaceReference);
if (trySpaceSibling && trySpaceSiblingFallback(sourceReference, finalReference, baseReference, defaultDocumentName)) {
// Try as a space sibling.
DocumentReference siblingReference = resolveSiblingSpaceDocumentReference(sourceReference, reference, baseReference, defaultDocumentName);
// performing the exists check now). Otherwise, the default will remain the child non-terminal document.
if (!siblingReference.getName().equals(defaultDocumentName) || documentAccessBridge.exists(siblingReference)) {
finalReference = siblingReference;
}
}
}
return finalReference;
}
use of org.xwiki.model.reference.SpaceReference in project xwiki-platform by xwiki.
the class AbstractResourceReferenceEntityReferenceResolver method resolveSiblingSpaceDocumentReference.
protected DocumentReference resolveSiblingSpaceDocumentReference(EntityReference sourceReference, DocumentReference reference, EntityReference baseReference, String defaultDocumentName) {
DocumentReference finalReference;
// Create space sibling
EntityReference parentReference = reference.getParent().getParent();
if (parentReference instanceof SpaceReference) {
finalReference = new DocumentReference(reference.getName(), (SpaceReference) parentReference);
finalReference = resolveDocumentReference(sourceReference, finalReference, baseReference, false, defaultDocumentName);
} else {
SpaceReference spaceReference = new SpaceReference(reference.getName(), (WikiReference) parentReference);
finalReference = new DocumentReference(defaultDocumentName, spaceReference);
}
return finalReference;
}
use of org.xwiki.model.reference.SpaceReference in project xwiki-platform by xwiki.
the class DefaultWikiMacroTest method setUp.
@Override
@Before
public void setUp() throws Exception {
super.setUp();
// Script setup.
ScriptMockSetup scriptMockSetup = new ScriptMockSetup(getMockery(), getComponentManager());
final DocumentAccessBridge mockDocBridge = scriptMockSetup.bridge;
this.mockWikiModel = scriptMockSetup.wikiModel;
this.wikiMacroDocumentReference = new DocumentReference("wiki", "space", "macroPage");
this.wikiMacroManager = getComponentManager().getInstance(WikiMacroManager.class);
// Make sure the old XWiki Context is set up in the Execution Context since it's used in
// DefaultWikiMacro.execute().
this.xcontext = new HashMap<String, Object>();
Execution execution = getComponentManager().getInstance(Execution.class);
execution.getContext().setProperty("xwikicontext", this.xcontext);
ScriptContextManager scm = getComponentManager().getInstance(ScriptContextManager.class);
scm.getCurrentScriptContext().setAttribute("xcontext", this.xcontext, ScriptContext.ENGINE_SCOPE);
getMockery().checking(new Expectations() {
{
allowing(mockWikiDescriptorManager).getCurrentWikiId();
will(returnValue("wiki"));
allowing(mockCurrentDocumentReferenceProvider).get();
will(returnValue(new DocumentReference("wiki", "space", "document")));
allowing(mockCurrentSpaceReferenceProvider).get();
will(returnValue(new SpaceReference("space", new WikiReference("wiki"))));
allowing(mockDocBridge).getCurrentUser();
will(returnValue("dummy"));
allowing(mockDocBridge).setCurrentUser(with(any(String.class)));
allowing(mockDocBridge).getCurrentUserReference();
will(returnValue(new DocumentReference("wiki", "XWiki", "dummy")));
allowing(mockWikiMacroFactory).isAllowed(with(any(DocumentReference.class)), with(any(WikiMacroVisibility.class)));
will(returnValue(true));
// This is the document containing the wiki macro that will be put in the context available in the macro
// Since we're not testing it here, it can be null.
allowing(mockDocBridge).getDocumentInstance(wikiMacroDocumentReference);
will(returnValue(null));
}
});
}
use of org.xwiki.model.reference.SpaceReference in project xwiki-platform by xwiki.
the class SolrEntityReferenceResolverTest method resolve.
@Test
public void resolve() throws Exception {
WikiReference wikiReference = new WikiReference("chess");
assertReference(wikiReference);
assertReference(new SpaceReference("Success", new SpaceReference("To", new SpaceReference("Path", wikiReference))));
DocumentReference documentReference = new DocumentReference("chess", Arrays.asList("Path", "To", "Success"), "WebHome", Locale.FRENCH);
assertReference(documentReference);
assertReference(new AttachmentReference("image.png", documentReference));
ObjectReference objectReference = new ObjectReference("App.Code.PlayerClass[13]", documentReference);
assertReference(objectReference);
assertReference(new ObjectPropertyReference("age", objectReference));
}
use of org.xwiki.model.reference.SpaceReference in project xwiki-platform by xwiki.
the class DefaultSecurityCacheTest method configure.
@Before
public void configure() throws Exception {
if (cache == null) {
cache = new TestCache<Object>();
final CacheManager cacheManager = securityCacheMocker.getInstance(CacheManager.class);
when(cacheManager.createNewCache(any(CacheConfiguration.class))).thenReturn(cache);
}
XWikiBridge xwikiBridge = securityReferenceFactoryMocker.getInstance(XWikiBridge.class);
when(xwikiBridge.getMainWikiReference()).thenReturn(new WikiReference("xwiki"));
this.factory = securityReferenceFactoryMocker.getComponentUnderTest();
this.securityCache = securityCacheMocker.getComponentUnderTest();
aMissingParentRef = factory.newEntityReference(new SpaceReference("space", new WikiReference("missing")));
aMissingEntityRef = factory.newEntityReference(new DocumentReference("missingPage", xspaceRef.getOriginalSpaceReference()));
aMissingUserRef = factory.newUserReference(new DocumentReference("missingUser", xXWikiSpace.getOriginalSpaceReference()));
aMissingGroupRef = factory.newGroupReference(new DocumentReference("missingGroup", xXWikiSpace.getOriginalSpaceReference()));
aMissingWikiRef = factory.newEntityReference(new WikiReference("missingWiki"));
}
Aggregations