Search in sources :

Example 61 with SpaceReference

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;
}
Also used : SpaceReference(org.xwiki.model.reference.SpaceReference) DocumentReference(org.xwiki.model.reference.DocumentReference)

Example 62 with SpaceReference

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;
}
Also used : SpaceReference(org.xwiki.model.reference.SpaceReference) EntityReference(org.xwiki.model.reference.EntityReference) DocumentReference(org.xwiki.model.reference.DocumentReference)

Example 63 with SpaceReference

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));
        }
    });
}
Also used : Expectations(org.jmock.Expectations) ScriptMockSetup(org.xwiki.rendering.macro.script.ScriptMockSetup) SpaceReference(org.xwiki.model.reference.SpaceReference) DocumentAccessBridge(org.xwiki.bridge.DocumentAccessBridge) ScriptContextManager(org.xwiki.script.ScriptContextManager) WikiMacroManager(org.xwiki.rendering.macro.wikibridge.WikiMacroManager) Execution(org.xwiki.context.Execution) WikiReference(org.xwiki.model.reference.WikiReference) WikiMacroVisibility(org.xwiki.rendering.macro.wikibridge.WikiMacroVisibility) DocumentReference(org.xwiki.model.reference.DocumentReference) Before(org.junit.Before)

Example 64 with SpaceReference

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));
}
Also used : AttachmentReference(org.xwiki.model.reference.AttachmentReference) ObjectPropertyReference(org.xwiki.model.reference.ObjectPropertyReference) ObjectReference(org.xwiki.model.reference.ObjectReference) SpaceReference(org.xwiki.model.reference.SpaceReference) WikiReference(org.xwiki.model.reference.WikiReference) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 65 with SpaceReference

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"));
}
Also used : SpaceReference(org.xwiki.model.reference.SpaceReference) CacheManager(org.xwiki.cache.CacheManager) XWikiBridge(org.xwiki.security.internal.XWikiBridge) WikiReference(org.xwiki.model.reference.WikiReference) CacheConfiguration(org.xwiki.cache.config.CacheConfiguration) DocumentReference(org.xwiki.model.reference.DocumentReference) Before(org.junit.Before)

Aggregations

SpaceReference (org.xwiki.model.reference.SpaceReference)142 DocumentReference (org.xwiki.model.reference.DocumentReference)96 Test (org.junit.Test)83 WikiReference (org.xwiki.model.reference.WikiReference)58 EntityReference (org.xwiki.model.reference.EntityReference)24 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)21 ArrayList (java.util.ArrayList)11 ResourceReference (org.xwiki.rendering.listener.reference.ResourceReference)11 XWikiException (com.xpn.xwiki.XWikiException)9 QueryRestrictionGroup (com.celements.search.lucene.query.QueryRestrictionGroup)8 Expectations (org.jmock.Expectations)8 XWikiContext (com.xpn.xwiki.XWikiContext)7 DocumentAccessBridge (org.xwiki.bridge.DocumentAccessBridge)7 DefaultComponentDescriptor (org.xwiki.component.descriptor.DefaultComponentDescriptor)7 ComponentManager (org.xwiki.component.manager.ComponentManager)7 NamespacedComponentManager (org.xwiki.component.manager.NamespacedComponentManager)7 DefaultParameterizedType (org.xwiki.component.util.DefaultParameterizedType)7 EntityReferenceResolver (org.xwiki.model.reference.EntityReferenceResolver)7 LocalDocumentReference (org.xwiki.model.reference.LocalDocumentReference)7 DocumentResourceReference (org.xwiki.rendering.listener.reference.DocumentResourceReference)7