Example usage for org.springframework.web.context.support WebApplicationContextUtils getRequiredWebApplicationContext

List of usage examples for org.springframework.web.context.support WebApplicationContextUtils getRequiredWebApplicationContext

Introduction

In this page you can find the example usage for org.springframework.web.context.support WebApplicationContextUtils getRequiredWebApplicationContext.

Prototype

public static WebApplicationContext getRequiredWebApplicationContext(ServletContext sc)
        throws IllegalStateException 

Source Link

Document

Find the root WebApplicationContext for this web app, typically loaded via org.springframework.web.context.ContextLoaderListener .

Usage

From source file:kz.supershiny.web.wicket.TiresApplication.java

/**
 * Init data in required distionaries// w  w  w. j  a  v a2s .  c  om
 */
private void initDictData() {
    ApplicationContext applicationContext = WebApplicationContextUtils
            .getRequiredWebApplicationContext(getServletContext());
    TireService ts = applicationContext.getBean(TireService.class);

    List<TireType> types = Arrays.asList(new TireType("?"),
            new TireType(" "), new TireType("?"),
            new TireType("?"), new TireType("???"),
            new TireType("??"), new TireType("??"));
    for (TireType t : types) {
        try {
            ts.save(t);
        } catch (Exception ex) {
            LOG.error("Failed to save tire type: " + t.getTypeName());
        }
    }
}

From source file:net.hedtech.banner.filters.ZKPageFilter2.java

@Override
public void init(FilterConfig fc) {
    super.init(fc);
    this.filterConfig = fc;
    containerTweaks = new ContainerTweaks();
    Config config = new Config(fc);

    Grails5535Factory defaultFactory = new Grails5535Factory(config); // TODO revert once Sitemesh bug is fixed
    fc.getServletContext().setAttribute(FACTORY_SERVLET_CONTEXT_ATTRIBUTE, defaultFactory);
    defaultFactory.refresh();//from w w w .  j a  va 2 s. c o  m
    FactoryHolder.setFactory(defaultFactory);

    contentProcessor = new PageParser2ContentProcessor(defaultFactory);
    decoratorMapper = defaultFactory.getDecoratorMapper();

    applicationContext = WebApplicationContextUtils.getRequiredWebApplicationContext(fc.getServletContext());
    layoutViewResolver = WebUtils.lookupViewResolver(applicationContext);

    final GrailsApplication grailsApplication = GrailsWebUtil.lookupApplication(fc.getServletContext());
    String encoding = (String) grailsApplication.getFlatConfig().get(CONFIG_OPTION_GSP_ENCODING);
    if (encoding != null) {
        defaultEncoding = encoding;
    }

    Map<String, PersistenceContextInterceptor> interceptors = applicationContext
            .getBeansOfType(PersistenceContextInterceptor.class);
    if (!interceptors.isEmpty()) {
        persistenceInterceptor = interceptors.values().iterator().next();
    }
}

From source file:org.zkoss.zk.grails.web.ZULUrlMappingsFilter.java

@Override
protected void initFilterBean() throws ServletException {
    super.initFilterBean();
    urlHelper.setUrlDecode(false);//from   w w w.  j  a va  2s.  c o  m
    final ServletContext servletContext = getServletContext();
    final WebApplicationContext applicationContext = WebApplicationContextUtils
            .getRequiredWebApplicationContext(servletContext);
    handlerInterceptors = WebUtils.lookupHandlerInterceptors(servletContext);
    application = WebUtils.lookupApplication(servletContext);
    viewResolver = WebUtils.lookupViewResolver(servletContext);
    ApplicationContext mainContext = application.getMainContext();
    urlConverter = mainContext.getBean(UrlConverter.BEAN_NAME, UrlConverter.class);
    if (application != null) {
        grailsConfig = new GrailsConfig(application);
    }

    if (applicationContext.containsBean(MimeType.BEAN_NAME)) {
        this.mimeTypes = applicationContext.getBean(MimeType.BEAN_NAME, MimeType[].class);
    }

    composerMapping = applicationContext.getBean(ComposerMapping.BEAN_NAME, ComposerMapping.class);

    createStackTraceFilterer();
}

From source file:org.jumpmind.vaadin.ui.common.AbstractSpringUI.java

public WebApplicationContext getWebApplicationContext() {
    return WebApplicationContextUtils
            .getRequiredWebApplicationContext(VaadinServlet.getCurrent().getServletContext());
}

From source file:org.lamsfoundation.lams.admin.web.CacheAction.java

private ICacheManager getCacheManager() {
    if (cacheManager == null) {
        WebApplicationContext ctx = WebApplicationContextUtils
                .getRequiredWebApplicationContext(getServlet().getServletContext());
        cacheManager = (CacheManager) ctx.getBean("cacheManager");
    }//from  ww  w  . ja va  2  s . c om
    return cacheManager;
}

From source file:org.carewebframework.ui.spring.FrameworkAppContext.java

/**
 * Constructor for creating an application context. Disallows bean overrides by default.
 * //  w  w  w  .jav  a  2 s  .  c o  m
 * @param desktop The desktop associated with this application context. Will be null for the
 *            root application context.
 * @param testConfig If true, use test profiles.
 * @param locations Optional list of configuration file locations. If not specified, defaults to
 *            the default configuration locations ({@link #getDefaultConfigLocations}).
 */
public FrameworkAppContext(Desktop desktop, boolean testConfig, String... locations) {
    super();
    setAllowBeanDefinitionOverriding(false);
    this.desktop = desktop;
    ConfigurableEnvironment env = getEnvironment();
    Set<String> aps = new LinkedHashSet<String>();
    Collections.addAll(aps, env.getActiveProfiles());

    if (desktop != null) {
        desktop.setAttribute(APP_CONTEXT_ATTRIB, this);
        final Session session = desktop.getSession();
        final ServletContext sc = session.getWebApp().getServletContext();
        final WebApplicationContext rootContext = WebApplicationContextUtils
                .getRequiredWebApplicationContext(sc);
        setDisplayName("Child XmlWebApplicationContext " + desktop);
        setParent(rootContext);
        setServletContext(sc);
        this.ctxListener = new ContextClosedListener();
        getParent().getBean(APPLICATION_EVENT_MULTICASTER_BEAN_NAME, ApplicationEventMulticaster.class)
                .addApplicationListener(this.ctxListener);
        // Set up profiles (remove root profiles merged from parent)
        aps.removeAll(Arrays.asList(Constants.PROFILES_ROOT));
        Collections.addAll(aps, testConfig ? Constants.PROFILES_DESKTOP_TEST : Constants.PROFILES_DESKTOP_PROD);
    } else {
        AppContextFinder.rootContext = this;
        Collections.addAll(aps, testConfig ? Constants.PROFILES_ROOT_TEST : Constants.PROFILES_ROOT_PROD);
        env.getPropertySources().addLast(new LabelPropertySource(this));
        env.getPropertySources().addLast(new DomainPropertySource(this));
    }

    env.setActiveProfiles(aps.toArray(new String[aps.size()]));
    setConfigLocations(locations == null || locations.length == 0 ? null : locations);
}

From source file:com.netpace.cms.sso.filter.AlfrescoFacade.java

public AlfrescoFacade(ServletContext servletContext) {
    WebApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
    ServiceRegistry serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY);
    transactionService = serviceRegistry.getTransactionService();
    nodeService = serviceRegistry.getNodeService();
    authComponent = (AuthenticationComponent) ctx.getBean("AuthenticationComponent");
    authService = (AuthenticationService) ctx.getBean("AuthenticationService");
    personService = (PersonService) ctx.getBean("personService");
    permissionService = (PermissionService) ctx.getBean("permissionService");
    authenticationService = (AuthenticationService) ctx.getBean("authenticationService");
    authorityService = (AuthorityService) ctx.getBean("authorityService");
    wpService = serviceRegistry.getWebProjectService();
    transactionalHelper = new TransactionalHelper(transactionService);

}

From source file:com.healthcit.cacure.web.tag.AnswerPresenterTag.java

@Override
public int doStartTag() throws JspException {
    try {//from w  ww.ja va 2s  .c o  m

        FormElement fe = formElement;
        if (formElement instanceof LinkElement) {
            ApplicationContext ctx = WebApplicationContextUtils
                    .getRequiredWebApplicationContext(pageContext.getServletContext());
            fe = ctx.getBean(QuestionAnswerManager.class).getFantom(fe.getId());
        }

        String controlHtml = "";

        // TABLE Questions
        if (fe.isTable()) {
            controlHtml = processComplexControls(fe);
        }

        //Non-TABLE Questions
        else {
            Answer.AnswerType[] array = new Answer.AnswerType[] { AnswerType.TEXT, AnswerType.NUMBER,
                    AnswerType.INTEGER, AnswerType.POSITIVE_INTEGER, AnswerType.DATE, AnswerType.YEAR,
                    AnswerType.MONTHYEAR, AnswerType.CHECKBOX, AnswerType.RADIO, AnswerType.DROPDOWN,
                    AnswerType.TEXTAREA };

            if (ArrayUtils.contains(array, fe.getAnswerType())) {
                /*
                 * At this point we will be in this method only if
                 * FormElement is either QuestionElement,
                 * ExternalQuestionElement or LinkElement that is linked to
                 * one of the above
                 */
                List<? extends BaseQuestion> questions = fe.getQuestions();
                if (questions != null && questions.size() > 0) {
                    BaseQuestion question = questions.get(0);
                    controlHtml = processSimpleControls(fe, question.getAnswer());
                }
            } else {
                throw new JspException("Ansert type '" + fe.getAnswerType() + "' is not handled. Please see '"
                        + this.getClass().getSimpleName() + "' to verify");
            }
        }

        pageContext.getOut().print(controlHtml);
    } catch (IOException ioe) {
        throw new JspTagException("Error: IOException while writing to the user");
    }
    return SKIP_BODY;
}

From source file:com.edgenius.wiki.webapp.servlet.StatusServlet.java

private Queue getJmsQueue() {
    ApplicationContext ctx = WebApplicationContextUtils
            .getRequiredWebApplicationContext(this.getServletContext());
    return (Queue) ctx.getBean("notifyDestination");
}

From source file:jp.terasoluna.fw.web.taglib.DefineCodeListTag.java

/**
 * ^O]Jn?\bh?B//from w w w. ja  va 2  s. c  o  m
 *
 * <p>
 * T?[ubgReLXg?AApplicationContext?A
 * &quot;page&quot; ?w id
 *  CodeListLoader ?A
 * R?[hXg pageContext o^?B
 *
 * R?[hXg???AArrayList
 *  pageContext o^?B
 * ?Ao^XR?[v &quot;page&quot; ??B
 * </p>
 *
 * @return ???w?B? EVAL_BODY_INCLUDE
 * @throws JspException JSP O
 */
@Override
public int doStartTag() throws JspException {
    if (log.isDebugEnabled()) {
        log.debug("doStartTag() called.");
    }

    if ("".equals(id)) {
        // id???
        log.error("id is required.");
        throw new JspTagException("id is required.");
    }
    // T?[ubgReLXg?AApplicationContext?B
    ServletContext sc = pageContext.getServletContext();
    ApplicationContext context = WebApplicationContextUtils.getRequiredWebApplicationContext(sc);

    CodeListLoader loader = null;

    try {
        loader = (CodeListLoader) context.getBean(id);
    } catch (ClassCastException e) {
        //BeanCodeListLoaderOX??[
        String errorMessage = "bean id:" + id + " is not instance of CodeListLoader.";
        log.error(errorMessage);
        throw new JspTagException(errorMessage, e);
    }

    // ?P?[
    Locale locale = RequestUtils.getUserLocale((HttpServletRequest) pageContext.getRequest(),
            Globals.LOCALE_KEY);

    CodeBean[] codeBeanArray = loader.getCodeBeans(locale);
    if (codeBeanArray == null) {
        // codeBeanListnull??ArrayList??B
        if (log.isWarnEnabled()) {
            log.warn("Codebean is null. CodeListLoader(bean id:" + id + ")");
        }
        pageContext.setAttribute(id, new ArrayList(), PageContext.PAGE_SCOPE);
    } else {
        // R?[hXgo^?B
        pageContext.setAttribute(id, codeBeanArray, PageContext.PAGE_SCOPE);
    }

    return EVAL_BODY_INCLUDE;
}