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");
}
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");
}
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");
}
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;
}
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;
}
Aggregations