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:org.apache.hadoop.hdfs.server.namenode.NameNodeHttpServer.java

public static NameNode getNameNodeFromContext(ServletContext context) {
    return (NameNode) context.getAttribute(NAMENODE_ATTRIBUTE_KEY);
}

From source file:org.impalaframework.web.helper.WebServletUtils.java

public static ModuleManagementFacade getModuleManagementFacade(ServletContext servletContext) {

    Assert.notNull(servletContext);//from  w w w.j  a v a2s.co m
    final String attributeName = WebConstants.IMPALA_FACTORY_ATTRIBUTE;
    final Object attribute = servletContext.getAttribute(attributeName);

    if (logger.isDebugEnabled()) {
        logger.debug("Retrieved ModuleManagementFacade from ServletContext with attribute name '"
                + attributeName + "': " + attribute);
    }

    return ObjectUtils.cast(attribute, ModuleManagementFacade.class);
}

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 {//from w  w w .  ja  v  a2s. c o m
        ContextModelAccess access = factory.buildContextModelAccess(ctx);
        ctx.setAttribute(ATTRIBUTE_NAME, access);
        return access;
    }
}

From source file:org.apache.hadoop.hdfs.server.namenode.NameNodeHttpServer.java

public static InetSocketAddress getNameNodeAddressFromContext(ServletContext context) {
    return (InetSocketAddress) context.getAttribute(NAMENODE_ADDRESS_ATTRIBUTE_KEY);
}

From source file:edu.cornell.mannlib.vitro.webapp.auth.permissions.PermissionRegistry.java

/**
 * Has the registry been created yet?//from   w  ww  .j a v a2s .  c  o  m
 */
public static boolean isRegistryCreated(ServletContext ctx) {
    return ctx.getAttribute(ATTRIBUTE_NAME) instanceof PermissionRegistry;
}

From source file:es.tid.cep.esperanza.Utils.java

public static synchronized void destroyEPService(ServletContext sc) {
    EPServiceProvider epService = (EPServiceProvider) sc.getAttribute(EPSERV_ATTR_NAME);
    if (epService != null) {
        epService.destroy();/*from  ww w . j a va 2s . c o  m*/
        sc.removeAttribute(EPSERV_ATTR_NAME);
    }
}

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

/**
 * Get the bean from the servlet context. If there is no bean, create one.
 * /*from   w w  w . j  a v  a 2s  .co  m*/
 * Never returns null.
 */
public static ExternalAuthHelper getHelper(ServletRequest request) {
    if (!(request instanceof HttpServletRequest)) {
        log.trace("Not an HttpServletRequest: " + request);
        return DUMMY_HELPER;
    }

    HttpSession session = ((HttpServletRequest) request).getSession(false);
    if (session == null) {
        log.trace("No session; no need to create one.");
        return DUMMY_HELPER;
    }

    ServletContext ctx = session.getServletContext();

    Object attr = ctx.getAttribute(BEAN_ATTRIBUTE);
    if (attr instanceof ExternalAuthHelper) {
        log.trace("Found a bean: " + attr);
        return (ExternalAuthHelper) attr;
    }

    ExternalAuthHelper bean = buildBean(ctx);
    log.debug("Created a bean: " + bean);
    setBean(ctx, bean);
    return bean;
}

From source file:es.tid.cep.esperanza.Utils.java

public static synchronized EPServiceProvider initEPService(ServletContext sc) {
    EPServiceProvider epService = (EPServiceProvider) sc.getAttribute(EPSERV_ATTR_NAME);
    if (epService == null) {
        epService = EPServiceProviderManager.getDefaultProvider();
        Map<String, Object> def = new HashMap<String, Object>();
        def.put("id", String.class);
        def.put("type", String.class);
        ConfigurationOperations cfg = epService.getEPAdministrator().getConfiguration();
        cfg.addEventType("iotEvent", def);
        sc.setAttribute(EPSERV_ATTR_NAME, epService);
    }//from w w  w.  j  a v  a2s .  c  o m
    return epService;
}

From source file:edu.cornell.mannlib.vitro.webapp.search.solr.SolrSetup.java

public static SolrServer getSolrServer(ServletContext ctx) {
    return (SolrServer) ctx.getAttribute(SOLR_SERVER);
}

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

/**
 * Get the list of selectable Locales from the servlet context. May return
 * an empty list, but never returns null.
 *//*ww w  . jav a  2 s .c  o m*/
public static List<Locale> getSelectableLocales(ServletContext ctx) {
    Object ctxInfo = ctx.getAttribute(ATTRIBUTE_NAME);
    if (ctxInfo instanceof ContextSelectedLocale) {
        List<Locale> selectableLocales = ((ContextSelectedLocale) ctxInfo).getSelectableLocales();
        if (selectableLocales != null) {
            log.debug("Returning selectable locales: " + selectableLocales);
            return selectableLocales;
        }
    }

    log.debug("No selectable locales were found. Returning an empty list.");
    return Collections.emptyList();
}