Search in sources :

Example 1 with XWikiEngineContext

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);
    }
}
Also used : XWikiStubContextProvider(com.xpn.xwiki.util.XWikiStubContextProvider) DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType) EntityType(org.xwiki.model.EntityType) ResourceType(org.xwiki.resource.ResourceType) Type(java.lang.reflect.Type) ParseGroovyFromString(com.xpn.xwiki.internal.render.groovy.ParseGroovyFromString) IncludeServletAsString(com.xpn.xwiki.web.includeservletasstring.IncludeServletAsString) XWikiEngineContext(com.xpn.xwiki.web.XWikiEngineContext) WikiManagerException(org.xwiki.wiki.manager.WikiManagerException) IOException(java.io.IOException) JobException(org.xwiki.job.JobException) ParseException(org.xwiki.rendering.parser.ParseException) QueryException(org.xwiki.query.QueryException) URIException(org.apache.commons.httpclient.URIException) InvocationTargetException(java.lang.reflect.InvocationTargetException) HibernateException(org.hibernate.HibernateException) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) NamingException(javax.naming.NamingException) FileNotFoundException(java.io.FileNotFoundException) MalformedURLException(java.net.MalformedURLException)

Example 2 with XWikiEngineContext

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();
}
Also used : XWikiEngineContext(com.xpn.xwiki.web.XWikiEngineContext)

Aggregations

XWikiEngineContext (com.xpn.xwiki.web.XWikiEngineContext)2 ParseGroovyFromString (com.xpn.xwiki.internal.render.groovy.ParseGroovyFromString)1 XWikiStubContextProvider (com.xpn.xwiki.util.XWikiStubContextProvider)1 IncludeServletAsString (com.xpn.xwiki.web.includeservletasstring.IncludeServletAsString)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Type (java.lang.reflect.Type)1 MalformedURLException (java.net.MalformedURLException)1 NamingException (javax.naming.NamingException)1 URIException (org.apache.commons.httpclient.URIException)1 HibernateException (org.hibernate.HibernateException)1 ComponentLookupException (org.xwiki.component.manager.ComponentLookupException)1 DefaultParameterizedType (org.xwiki.component.util.DefaultParameterizedType)1 JobException (org.xwiki.job.JobException)1 EntityType (org.xwiki.model.EntityType)1 QueryException (org.xwiki.query.QueryException)1 ParseException (org.xwiki.rendering.parser.ParseException)1 ResourceType (org.xwiki.resource.ResourceType)1 WikiManagerException (org.xwiki.wiki.manager.WikiManagerException)1