Example usage for javax.servlet ServletContext setAttribute

List of usage examples for javax.servlet ServletContext setAttribute

Introduction

In this page you can find the example usage for javax.servlet ServletContext setAttribute.

Prototype

public void setAttribute(String name, Object object);

Source Link

Document

Binds an object to a given attribute name in this ServletContext.

Usage

From source file:edu.cornell.mannlib.vitro.webapp.utils.pageDataGetter.DataGetterUtils.java

public static void setupDataGetters(ServletContext context) {
    if (context != null && context.getAttribute(DATA_GETTER_MAP) == null) {
        context.setAttribute(DATA_GETTER_MAP, new HashMap<String, PageDataGetter>());

        /* register all page data getters with the PageController servlet.  
         * There should be a better way of doing this. */
        ClassGroupPageData cgpd = new ClassGroupPageData();
        getPageDataGetterMap(context).put(cgpd.getType(), cgpd);
        BrowseDataGetter bdg = new BrowseDataGetter();
        getPageDataGetterMap(context).put(bdg.getType(), bdg);
        //TODO: Check if can include by type here
        IndividualsForClassesDataGetter cidg = new IndividualsForClassesDataGetter();
        getPageDataGetterMap(context).put(cidg.getType(), cidg);
        InternalClassesDataGetter internalCdg = new InternalClassesDataGetter();
        getPageDataGetterMap(context).put(internalCdg.getType(), internalCdg);

    }/*from  w ww  .  j a v  a  2  s  .  com*/
}

From source file:com.qualogy.qafe.web.ContextLoader.java

private static void handleException(Throwable exception, ServletContext servletContext) {
    if (exception == null) {
        return;//from  ww w .j av  a2  s  . c om
    }
    String message = ExceptionUtils.getRootCauseMessage(exception);
    logger.log(Level.SEVERE, "Context initialization failed", exception);
    servletContext.setAttribute("init_failure", exception);
    servletContext.setAttribute("init_failure_message", message);
}

From source file:org.apache.wiki.WikiSessionTest.java

/**
 * "Scaffolding" method that runs the session security filter on a mock request. We do this by creating a
 * complete mock servlet context and filter chain, and running the request through it. 
 * @param engine the wiki engine//from   w ww  .ja v a 2  s  .  c  om
 * @param request the mock request to pass itnto the 
 * @throws ServletException
 * @throws IOException
 */
private static void runSecurityFilter(WikiEngine engine, HttpServletRequest request)
        throws ServletException, IOException {
    // Create a mock servlet context and stash the wiki engine in it
    ServletContext servletCtx = new MockServletContext("JSPWiki");
    servletCtx.setAttribute("org.apache.wiki.WikiEngine", engine);

    // Create a mock filter configuration and add the servlet context we just created
    MockFilterConfig filterConfig = new MockFilterConfig();
    filterConfig.setFilterName("WikiServletFilter");
    filterConfig.setServletContext(servletCtx);

    // Create the security filter and run the request  through it
    Filter filter = new WikiServletFilter();
    MockFilterChain chain = new MockFilterChain();
    chain.addFilter(filter);
    Servlet servlet = new MockServlet();
    chain.setServlet(servlet);
    filter.init(filterConfig);
    filter.doFilter(request, null, chain);
}

From source file:edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess.java

public static ContextModelAccess on(ServletContext ctx) {
    Object o = ctx.getAttribute(ATTRIBUTE_NAME);
    if (o instanceof ContextModelAccess) {
        return (ContextModelAccess) o;
    } else {/*  www . j  a v  a2  s. c om*/
        ContextModelAccess access = factory.buildContextModelAccess(ctx);
        ctx.setAttribute(ATTRIBUTE_NAME, access);
        return access;
    }
}

From source file:och.chat.web.ChatsAppProvider.java

public static synchronized ChatsApp get(ServletContext servletContext) throws ServletException {

    try {/* ww  w . j ava 2 s  . c o  m*/
        if (servletContext == null)
            throw new IllegalArgumentException("servletContext is null");

        ChatsApp app = (ChatsApp) servletContext.getAttribute("ChatsApp");
        if (app == null) {
            app = createApp(servletContext);
            servletContext.setAttribute("ChatsApp", app);
            lastCreated = app;
        }
        return app;

    } catch (Throwable t) {
        log.error("can't get app", t);
        throw new ServletException("can't init: " + t, t);
    }
}

From source file:org.apache.myfaces.custom.stylesheet.TextResourceFilter.java

/**
 * Return the application-singleton instance of this class.
 *//*from   w  w  w  .j  a  v a  2 s .  c o m*/
public static TextResourceFilter getInstance(ServletContext context) {
    synchronized (TextResourceFilter.class) {
        TextResourceFilter filterText = (TextResourceFilter) context.getAttribute(CONTEXT_KEY);
        if (filterText == null) {
            filterText = create();
            context.setAttribute(CONTEXT_KEY, filterText);
        }
        return filterText;
    }
}

From source file:och.front.web.FrontAppProvider.java

public static synchronized FrontApp get(ServletContext servletContext) throws ServletException {

    try {/* ww w  . ja  v  a  2s  .c  om*/
        if (servletContext == null)
            throw new IllegalArgumentException("servletContext must be not null");

        FrontApp app = (FrontApp) servletContext.getAttribute("FrontApp");

        if (app == null) {
            app = createApp(servletContext);
            servletContext.setAttribute("FrontApp", app);
            lastCreated = app;
        }
        return app;

    } catch (Throwable t) {
        log.error("can't get app", t);
        throw new ServletException("can't init: " + t, t);
    }
}

From source file:be.fedict.eid.idp.webapp.ProtocolEntryServlet.java

private static void setProtocolService(Map<String, IdentityProviderProtocolService> protocolServices,
        ServletContext servletContext) {
    servletContext.setAttribute(PROTOCOL_SERVICES_ATTRIBUTE, protocolServices);
}

From source file:be.fedict.eid.idp.webapp.ProtocolEntryServlet.java

private static void setAttributeServices(Map<String, IdentityProviderAttributeService> attributeServices,
        ServletContext servletContext) {
    servletContext.setAttribute(ATTRIBUTE_SERVICES_ATTRIBUTE, attributeServices);
}

From source file:info.magnolia.cms.i18n.MessagesManager.java

/**
 * Called through the initialization process (startup of the container)
 * @param context servlet context//w w w .j  a v  a2s  .c  o  m
 */
public static void init(ServletContext context) {
    MessagesManager.context = context;

    // setting fallback
    context.setAttribute(Config.FMT_FALLBACK_LOCALE + ".application", FALLBACK_LOCALE); //$NON-NLS-1$
    // setting basename
    context.setAttribute(Config.FMT_LOCALIZATION_CONTEXT + ".application", MessagesManager.DEFAULT_BASENAME); //$NON-NLS-1$
    // for Resin and other J2EE Containers
    context.setAttribute(Config.FMT_LOCALIZATION_CONTEXT, MessagesManager.DEFAULT_BASENAME);

    // setting default language (en)
    MessagesManager.setDefaultLocale(FALLBACK_LOCALE);

    load();
    registerEventListener();
}