Search in sources :

Example 36 with WikiDescriptorManager

use of org.xwiki.wiki.descriptor.WikiDescriptorManager in project xwiki-platform by xwiki.

the class DomainWikiReferenceExtractorTest method extractWhenWikiDescriptor.

@Test
public void extractWhenWikiDescriptor() throws Exception {
    setUpConfiguration(WikiNotFoundBehavior.REDIRECT_TO_MAIN_WIKI);
    WikiDescriptorManager wikiDescriptorManager = mocker.getInstance(WikiDescriptorManager.class);
    when(wikiDescriptorManager.getByAlias("wiki.server.com")).thenReturn(new WikiDescriptor("wikiid", "wiki"));
    testAndAssert("http://wiki.server.com/xwiki/bin/view/Main/WebHome", "wikiid");
}
Also used : WikiDescriptorManager(org.xwiki.wiki.descriptor.WikiDescriptorManager) WikiDescriptor(org.xwiki.wiki.descriptor.WikiDescriptor) Test(org.junit.Test)

Example 37 with WikiDescriptorManager

use of org.xwiki.wiki.descriptor.WikiDescriptorManager in project xwiki-platform by xwiki.

the class PathWikiReferenceExtractorTest method extractWhenWikiDescriptorButEmptyServerName.

@Test
public void extractWhenWikiDescriptorButEmptyServerName() throws Exception {
    setUpConfiguration(WikiNotFoundBehavior.REDIRECT_TO_MAIN_WIKI);
    WikiDescriptorManager wikiDescriptorManager = mocker.getInstance(WikiDescriptorManager.class);
    when(wikiDescriptorManager.getByAlias("someWiki")).thenReturn(new WikiDescriptor("", "someWiki"));
    testAndAssert("http://localhost/xwiki/wiki/someWiki/view/Main/WebHome", "xwiki");
}
Also used : WikiDescriptorManager(org.xwiki.wiki.descriptor.WikiDescriptorManager) WikiDescriptor(org.xwiki.wiki.descriptor.WikiDescriptor) Test(org.junit.Test)

Example 38 with WikiDescriptorManager

use of org.xwiki.wiki.descriptor.WikiDescriptorManager in project xwiki-platform by xwiki.

the class PathWikiReferenceExtractorTest method extractWhenWikiDescriptor.

@Test
public void extractWhenWikiDescriptor() throws Exception {
    setUpConfiguration(WikiNotFoundBehavior.REDIRECT_TO_MAIN_WIKI);
    WikiDescriptorManager wikiDescriptorManager = mocker.getInstance(WikiDescriptorManager.class);
    when(wikiDescriptorManager.getByAlias("someWiki")).thenReturn(new WikiDescriptor("wikiid", "someWiki"));
    testAndAssert("http://localhost/xwiki/wiki/someWiki/view/Main/WebHome", "wikiid");
}
Also used : WikiDescriptorManager(org.xwiki.wiki.descriptor.WikiDescriptorManager) WikiDescriptor(org.xwiki.wiki.descriptor.WikiDescriptor) Test(org.junit.Test)

Example 39 with WikiDescriptorManager

use of org.xwiki.wiki.descriptor.WikiDescriptorManager in project xwiki-platform by xwiki.

the class CurrentColorThemeGetterTest method setUp.

@Before
public void setUp() throws Exception {
    wikiDescriptorManager = mocker.getInstance(WikiDescriptorManager.class);
    authorizationManager = mocker.getInstance(AuthorizationManager.class);
    documentReferenceResolver = mocker.getInstance(new DefaultParameterizedType(null, DocumentReferenceResolver.class, String.class));
    entityReferenceSerializer = mocker.getInstance(new DefaultParameterizedType(null, EntityReferenceSerializer.class, String.class));
    xcontextProvider = mocker.registerMockComponent(XWikiContext.TYPE_PROVIDER);
    xcontext = mock(XWikiContext.class);
    when(xcontextProvider.get()).thenReturn(xcontext);
    xwiki = mock(XWiki.class);
    when(xcontext.getWiki()).thenReturn(xwiki);
    when(wikiDescriptorManager.getCurrentWikiId()).thenReturn("wikiId");
    request = mock(XWikiRequest.class);
    when(xcontext.getRequest()).thenReturn(request);
    DocumentReference colorThemeReference = new DocumentReference("wikiId", "XWiki", "MyColorTheme");
    WikiReference mainWikiReference = new WikiReference("wikiId");
    when(documentReferenceResolver.resolve(eq("myColorTheme"), eq(mainWikiReference))).thenReturn(colorThemeReference);
    when(entityReferenceSerializer.serialize(colorThemeReference)).thenReturn("wikiId:ColorTheme.MyColorTheme");
    when(xwiki.exists(colorThemeReference, xcontext)).thenReturn(true);
    DocumentReference currentUser = new DocumentReference("xwiki", "XWiki", "CurrentUser");
    when(xcontext.getUserReference()).thenReturn(currentUser);
    when(authorizationManager.hasAccess(eq(Right.VIEW), any(DocumentReference.class), any(DocumentReference.class))).thenReturn(true);
}
Also used : XWikiRequest(com.xpn.xwiki.web.XWikiRequest) WikiDescriptorManager(org.xwiki.wiki.descriptor.WikiDescriptorManager) XWikiContext(com.xpn.xwiki.XWikiContext) XWiki(com.xpn.xwiki.XWiki) AuthorizationManager(org.xwiki.security.authorization.AuthorizationManager) DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType) WikiReference(org.xwiki.model.reference.WikiReference) DocumentReference(org.xwiki.model.reference.DocumentReference) Before(org.junit.Before)

Example 40 with WikiDescriptorManager

use of org.xwiki.wiki.descriptor.WikiDescriptorManager in project xwiki-platform by xwiki.

the class XWiki method getXWiki.

/**
 * Return the XWiki object (as in "the Wiki API") corresponding to the requested wiki.
 * <p>
 * Unless <code>wait</code> is false the method return right away null if XWiki is not yet initialized.
 *
 * @param wait wait until XWiki is initialized
 * @param xcontext see {@link XWikiContext}
 * @return an XWiki object configured for the wiki corresponding to the current request
 * @throws XWikiException if the requested URL does not correspond to a real wiki, or if there's an error in the
 *             storage
 */
public static XWiki getXWiki(boolean wait, XWikiContext xcontext) throws XWikiException {
    XWiki xwiki = getMainXWiki(wait, xcontext);
    if (xwiki == null) {
        return null;
    }
    // Extract Entity Resource from URL and put it in the Execution Context
    EntityResourceReference entityResourceReference = initializeResourceFromURL(xcontext);
    // If not an entity resource reference assume main wiki
    if (entityResourceReference == null) {
        return xwiki;
    }
    // Get the wiki id
    String wikiId = entityResourceReference.getEntityReference().extractReference(EntityType.WIKI).getName();
    if (wikiId.equals(xcontext.getMainXWiki())) {
        // The main wiki was requested.
        return xwiki;
    }
    // Check if the wiki exists by checking if a descriptor exists for the wiki id.
    WikiDescriptorManager wikiDescriptorManager = Utils.getComponent(WikiDescriptorManager.class);
    WikiDescriptor descriptor;
    try {
        descriptor = wikiDescriptorManager.getById(wikiId);
    } catch (WikiManagerException e) {
        throw new XWikiException(XWikiException.MODULE_XWIKI, XWikiException.ERROR_XWIKI_STORE_MISC, String.format("Failed find wiki descriptor for wiki id [%s]", wikiId), e);
    }
    if (descriptor == null) {
        throw new XWikiException(XWikiException.MODULE_XWIKI, XWikiException.ERROR_XWIKI_DOES_NOT_EXIST, String.format("The wiki [%s] does not exist", wikiId));
    }
    // Initialize wiki
    xcontext.setWikiId(wikiId);
    xcontext.setOriginalWikiId(wikiId);
    if (!xwiki.initializeWiki(wikiId, wait, xcontext)) {
        // The wiki is still initializing
        return null;
    }
    return xwiki;
}
Also used : WikiManagerException(org.xwiki.wiki.manager.WikiManagerException) WikiDescriptorManager(org.xwiki.wiki.descriptor.WikiDescriptorManager) EntityResourceReference(org.xwiki.resource.entity.EntityResourceReference) ParseGroovyFromString(com.xpn.xwiki.internal.render.groovy.ParseGroovyFromString) IncludeServletAsString(com.xpn.xwiki.web.includeservletasstring.IncludeServletAsString) WikiDescriptor(org.xwiki.wiki.descriptor.WikiDescriptor)

Aggregations

WikiDescriptorManager (org.xwiki.wiki.descriptor.WikiDescriptorManager)40 Test (org.junit.Test)17 DocumentReference (org.xwiki.model.reference.DocumentReference)14 Before (org.junit.Before)13 XWikiContext (com.xpn.xwiki.XWikiContext)11 Execution (org.xwiki.context.Execution)9 ExecutionContext (org.xwiki.context.ExecutionContext)9 XWiki (com.xpn.xwiki.XWiki)8 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)8 ExtensionId (org.xwiki.extension.ExtensionId)6 AuthorizationManager (org.xwiki.security.authorization.AuthorizationManager)6 WikiDescriptor (org.xwiki.wiki.descriptor.WikiDescriptor)6 WikiManagerException (org.xwiki.wiki.manager.WikiManagerException)6 DefaultParameterizedType (org.xwiki.component.util.DefaultParameterizedType)5 ExtendedURL (org.xwiki.url.ExtendedURL)5 WebJarsResourceReference (org.xwiki.webjars.internal.WebJarsResourceReference)5 InstalledExtension (org.xwiki.extension.InstalledExtension)4 LocalDocumentReference (org.xwiki.model.reference.LocalDocumentReference)4 Query (org.xwiki.query.Query)4 BaseObject (com.xpn.xwiki.objects.BaseObject)3