Example usage for org.apache.wicket.protocol.http WebApplication setName

List of usage examples for org.apache.wicket.protocol.http WebApplication setName

Introduction

In this page you can find the example usage for org.apache.wicket.protocol.http WebApplication setName.

Prototype

public final void setName(final String name) 

Source Link

Document

Sets application name.

Usage

From source file:org.apache.openmeetings.db.util.ApplicationHelper.java

License:Apache License

public static IApplication ensureApplication(Long langId) {
    IApplication a = null;//from w w  w. j  a va2 s  . c  o  m
    if (Application.exists()) {
        a = (IApplication) Application.get();
    } else {
        WebApplication app = (WebApplication) Application.get(wicketApplicationName);
        LabelDao.initLanguageMap();
        if (app == null) {
            try {
                app = (WebApplication) LabelDao.getAppClass().newInstance();
            } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
                log.error("Failed to create Application");
                return null;
            }
            app.setServletContext(new MockServletContext(app, null));
            app.setName(wicketApplicationName);
            ServletContext sc = app.getServletContext();
            OMContextListener omcl = new OMContextListener();
            omcl.contextInitialized(new ServletContextEvent(sc));
            XmlWebApplicationContext xmlContext = new XmlWebApplicationContext();
            xmlContext.setConfigLocation("classpath:openmeetings-applicationContext.xml");
            xmlContext.setServletContext(sc);
            xmlContext.refresh();
            sc.setAttribute(ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, xmlContext);
            app.setConfigurationType(RuntimeConfigurationType.DEPLOYMENT);
            ThreadContext.setApplication(app);
            app.initApplication();
        } else {
            ThreadContext.setApplication(app);
        }
        a = (IApplication) Application.get(wicketApplicationName);
    }
    if (ThreadContext.getRequestCycle() == null) {
        ServletWebRequest req = new ServletWebRequest(new MockHttpServletRequest((Application) a,
                new MockHttpSession(a.getServletContext()), a.getServletContext()), "");
        RequestCycleContext rctx = new RequestCycleContext(req, new MockWebResponse(), a.getRootRequestMapper(),
                a.getExceptionMapperProvider().get());
        ThreadContext.setRequestCycle(new RequestCycle(rctx));
    }
    if (ThreadContext.getSession() == null) {
        WebSession s = WebSession.get();
        if (langId > 0) {
            ((IWebSession) s).setLanguage(langId);
        }
    }
    return a;
}