use of com.xpn.xwiki.web.XWikiEngineContext in project xwiki-platform by xwiki.
the class XWiki method getMainXWiki.
/**
* @param wait true if the method should way for {@link XWiki} instance to be initialized
* @param context see {@link XWikiContext}
*/
public static XWiki getMainXWiki(boolean wait, XWikiContext context) throws XWikiException {
String xwikiname = DEFAULT_MAIN_WIKI;
context.setMainXWiki(xwikiname);
XWiki xwiki;
try {
XWikiEngineContext econtext = context.getEngineContext();
xwiki = (XWiki) econtext.getAttribute(xwikiname);
if (xwiki == null) {
// Start XWiki initialization
synchronized (XWiki.class) {
xwiki = (XWiki) econtext.getAttribute(xwikiname);
if (xwiki == null && job == null) {
job = Utils.getComponent((Type) Job.class, XWikiInitializerJob.JOBTYPE);
if (job.getStatus() == null) {
// "Pre-initialize" XWikiStubContextProvider so that XWiki initializer can find one
Utils.<XWikiStubContextProvider>getComponent(XWikiStubContextProvider.class).initialize(context);
job.startAsync();
}
}
}
// Wait until XWiki is initialized
if (wait) {
job.join();
xwiki = (XWiki) econtext.getAttribute(xwikiname);
}
}
context.setWiki(xwiki);
return xwiki;
} catch (Exception e) {
throw new XWikiException(XWikiException.MODULE_XWIKI, XWikiException.ERROR_XWIKI_INIT_FAILED, "Could not initialize main XWiki instance", e);
}
}
use of com.xpn.xwiki.web.XWikiEngineContext in project xwiki-platform by xwiki.
the class XWiki method getCounter.
/**
* Provides an absolute counter
*
* @param name Counter name
* @return String
*/
public String getCounter(String name) {
XWikiEngineContext econtext = this.context.getEngineContext();
Integer counter = (Integer) econtext.getAttribute(name);
if (counter == null) {
counter = 0;
}
counter = counter.intValue() + 1;
econtext.setAttribute(name, counter);
return counter.toString();
}
Aggregations