Search in sources :

Example 56 with WikiDescriptor

use of org.xwiki.wiki.descriptor.WikiDescriptor 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 57 with WikiDescriptor

use of org.xwiki.wiki.descriptor.WikiDescriptor 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 58 with WikiDescriptor

use of org.xwiki.wiki.descriptor.WikiDescriptor 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 59 with WikiDescriptor

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

the class PathWikiReferenceExtractor method resolvePathBasedWikiReference.

private String resolvePathBasedWikiReference(String alias) {
    String wikiId;
    // Look for a Wiki Descriptor
    WikiDescriptor wikiDescriptor = getWikiDescriptorByAlias(alias);
    if (wikiDescriptor != null) {
        // Get the wiki id from the wiki descriptor
        wikiId = wikiDescriptor.getId();
    } else {
        wikiId = normalizeWikiIdForNonExistentWikiDescriptor(alias);
    }
    return wikiId;
}
Also used : WikiDescriptor(org.xwiki.wiki.descriptor.WikiDescriptor)

Example 60 with WikiDescriptor

use of org.xwiki.wiki.descriptor.WikiDescriptor 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

WikiDescriptor (org.xwiki.wiki.descriptor.WikiDescriptor)60 Test (org.junit.Test)40 WikiManagerException (org.xwiki.wiki.manager.WikiManagerException)28 AccessDeniedException (org.xwiki.security.authorization.AccessDeniedException)17 WikiReference (org.xwiki.model.reference.WikiReference)11 XWikiContext (com.xpn.xwiki.XWikiContext)9 WikiTemplateManagerException (org.xwiki.wiki.template.WikiTemplateManagerException)9 ArrayList (java.util.ArrayList)7 DocumentReference (org.xwiki.model.reference.DocumentReference)6 WikiDescriptorManager (org.xwiki.wiki.descriptor.WikiDescriptorManager)6 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)5 BaseObject (com.xpn.xwiki.objects.BaseObject)5 DefaultWikiDescriptor (org.xwiki.wiki.internal.descriptor.DefaultWikiDescriptor)5 WikiCreationRequest (org.xwiki.platform.wiki.creationjob.WikiCreationRequest)3 AuthorizationException (org.xwiki.security.authorization.AuthorizationException)3 WikiCopiedEvent (org.xwiki.bridge.event.WikiCopiedEvent)2 WikiCreatedEvent (org.xwiki.bridge.event.WikiCreatedEvent)2 WikiCreatingEvent (org.xwiki.bridge.event.WikiCreatingEvent)2 WikiCreationException (org.xwiki.platform.wiki.creationjob.WikiCreationException)2 WikiDescriptorBuilderException (org.xwiki.wiki.internal.descriptor.builder.WikiDescriptorBuilderException)2