Example usage for javax.servlet ServletContext getAttribute

List of usage examples for javax.servlet ServletContext getAttribute

Introduction

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

Prototype

public Object getAttribute(String name);

Source Link

Document

Returns the servlet container attribute with the given name, or null if there is no attribute by that name.

Usage

From source file:edu.cornell.mannlib.vitro.webapp.config.ConfigurationProperties.java

public static ConfigurationProperties getBean(ServletContext context) {
    if (context == null) {
        throw new NullPointerException("context may not be null.");
    }/*from  w  w w. j  a  va 2 s .  c  om*/

    Object o = context.getAttribute(ATTRIBUTE_NAME);
    if (o == null) {
        log.error("ConfigurationProperties bean has not been set.");
        return DUMMY_PROPERTIES;
    } else if (!(o instanceof ConfigurationProperties)) {
        log.error("Error: ConfigurationProperties was set to an " + "invalid object: " + o);
        return DUMMY_PROPERTIES;
    }

    return (ConfigurationProperties) o;
}

From source file:org.apache.qpid.server.management.plugin.HttpManagementUtil.java

public static HttpManagementConfiguration getManagementConfiguration(ServletContext servletContext) {
    return (HttpManagementConfiguration) servletContext.getAttribute(ATTR_MANAGEMENT_CONFIGURATION);
}

From source file:edu.cornell.mannlib.vitro.webapp.web.images.PlaceholderUtil.java

/** Get the PlaceholderUtil instance from the context, or null if none. */
private static PlaceholderUtil getPlaceholderUtil(VitroRequest vreq) {
    if (vreq == null) {
        return null;
    }/*from   ww w . j a  va2 s. c om*/
    ServletContext ctx = vreq.getSession().getServletContext();
    Object attrib = ctx.getAttribute(ATTRIBUTE_NAME);
    if (attrib instanceof PlaceholderUtil) {
        return (PlaceholderUtil) attrib;
    } else {
        log.warn("Looked for a PlaceholerUtil, but found " + attrib);
        return null;
    }
}

From source file:edu.cornell.mannlib.vitro.webapp.controller.authenticate.Authenticator.java

/**
 * Ask the currently configured AuthenticatorFactory to give us an
 * Authenticator for this request./*from w  w  w . j  a va2  s.c  om*/
 * 
 * If there is no factory, configure a Basic one.
 */
public static Authenticator getInstance(HttpServletRequest request) {
    ServletContext ctx = request.getSession().getServletContext();
    Object attribute = ctx.getAttribute(FACTORY_ATTRIBUTE_NAME);
    if (!(attribute instanceof AuthenticatorFactory)) {
        setAuthenticatorFactory(new BasicAuthenticator.Factory(), ctx);
        attribute = ctx.getAttribute(FACTORY_ATTRIBUTE_NAME);
    }
    AuthenticatorFactory factory = (AuthenticatorFactory) attribute;

    return factory.getInstance(request);
}

From source file:edu.cornell.mannlib.vitro.webapp.i18n.selection.SelectedLocale.java

/**
 * Do we need to override the Locale in the current request? return the
 * first of these to be found:/* www . j  a v a2  s  . c  o  m*/
 * <ul>
 * <li>The forced Locale in the servlet context</li>
 * <li>The selected Locale in the session</li>
 * <li>The first of the selectable Locales</li>
 * <li>null</li>
 * </ul>
 */
public static Locale getOverridingLocale(HttpServletRequest req) {
    HttpSession session = req.getSession();
    ServletContext ctx = session.getServletContext();

    Object ctxInfo = ctx.getAttribute(ATTRIBUTE_NAME);
    if (ctxInfo instanceof ContextSelectedLocale) {
        Locale forcedLocale = ((ContextSelectedLocale) ctxInfo).getForcedLocale();
        if (forcedLocale != null) {
            log.debug("Found forced locale in the context: " + forcedLocale);
            return forcedLocale;
        }
    }

    Object sessionInfo = session.getAttribute(ATTRIBUTE_NAME);
    if (sessionInfo instanceof SessionSelectedLocale) {
        Locale selectedLocale = ((SessionSelectedLocale) sessionInfo).getSelectedLocale();
        if (selectedLocale != null) {
            log.debug("Found selected locale in the session: " + selectedLocale);
            return selectedLocale;
        }
    }

    if (ctxInfo instanceof ContextSelectedLocale) {
        List<Locale> selectableLocales = ((ContextSelectedLocale) ctxInfo).getSelectableLocales();
        if (selectableLocales != null && !selectableLocales.isEmpty()) {
            Locale defaultLocale = selectableLocales.get(0);
            log.debug("Using first selectable locale as default: " + defaultLocale);
            return defaultLocale;
        }
    }

    return null;
}

From source file:edu.cornell.mannlib.vitro.webapp.servlet.setup.FileGraphSetup.java

private static boolean isUpdateRequired(ServletContext ctx) {
    return (ctx.getAttribute(UpdateKnowledgeBase.KBM_REQURIED_AT_STARTUP) != null);
}

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

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

    try {// w w  w.  j a  v  a2  s.  c om
        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:gov.nih.nci.cabig.ctms.web.WebTools.java

@SuppressWarnings({ "unchecked" })
public static SortedMap<String, Object> servletContextAttributesToMap(final ServletContext context) {
    return namedAttributesToMap(context.getAttributeNames(), new AttributeAccessor<Object>() {
        public Object getAttribute(String name) {
            return context.getAttribute(name);
        }//from   w  w  w .  j ava 2  s. com
    });
}

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

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

    try {/*from w  ww.j av a 2 s .c  o m*/
        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:org.apache.struts.tiles.DefinitionsUtil.java

/**
 * Get definition factory from appropriate servlet context.
 * @return Definitions factory or null if not found.
 * @deprecated Use {@link TilesUtil#getDefinitionsFactory(ServletRequest, ServletContext)}
 * @since 20020708//  w w  w  .j  av  a  2s. com
 */
public static DefinitionsFactory getDefinitionsFactory(ServletContext servletContext) {
    return (DefinitionsFactory) servletContext.getAttribute(DEFINITIONS_FACTORY);
}