List of usage examples for javax.servlet ServletContext getAttribute
public Object getAttribute(String name);
null
if there is no attribute by that name. From source file:org.apache.myfaces.custom.stylesheet.TextResourceFilter.java
/** * Return the application-singleton instance of this class. *//* w w w . j av a 2 s. c om*/ 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:com.telefonica.iot.perseo.Utils.java
/** * Delete the EPServiceProvider from the ServletContext * * @param sc ServleContext to add ESPServiceProvider *//* ww w . j av a2s . c o m*/ public static synchronized void destroyEPService(ServletContext sc) { EPServiceProvider epService = (EPServiceProvider) sc.getAttribute(EPSERV_ATTR_NAME); if (epService != null) { epService.destroy(); sc.removeAttribute(EPSERV_ATTR_NAME); } }
From source file:edu.cornell.mannlib.vitro.webapp.email.FreemarkerEmailFactory.java
private static FreemarkerEmailFactory getFactory(HttpServletRequest req) { ServletContext ctx = req.getSession().getServletContext(); return (FreemarkerEmailFactory) ctx.getAttribute(ATTRIBUTE_NAME); }
From source file:com.telefonica.iot.perseo.Utils.java
/** * Add an initialized EPServiceProvider to an ServletContext if it is not * already/* w w w .j a va 2 s .com*/ * * @param sc ServleContext to add ESPServiceProvider * @return the initialized EPServiceProvider */ 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); def.put(Constants.SUBSERVICE_FIELD, String.class); def.put(Constants.SERVICE_FIELD, String.class); ConfigurationOperations cfg = epService.getEPAdministrator().getConfiguration(); cfg.addEventType(Constants.IOT_EVENT, def); sc.setAttribute(EPSERV_ATTR_NAME, epService); } return epService; }
From source file:edu.cornell.mannlib.vitro.webapp.auth.permissions.PermissionRegistry.java
/** * Get the registry from the context. If there isn't one, throw an * exception./*w w w . j a v a2 s. c om*/ */ public static PermissionRegistry getRegistry(ServletContext ctx) { if (ctx == null) { throw new NullPointerException("ctx may not be null."); } Object o = ctx.getAttribute(ATTRIBUTE_NAME); if (o == null) { throw new IllegalStateException("PermissionRegistry has not been set."); } else if (!(o instanceof PermissionRegistry)) { throw new IllegalStateException("PermissionRegistry was set to an " + "invalid object: " + o); } return (PermissionRegistry) o; }
From source file:com.bank.manager.configs.ContextCleanupListener.java
/** * Find all ServletContext attributes which implement {@link DisposableBean} * and destroy them, removing all affected ServletContext attributes eventually. * @param sc the ServletContext to check *//*from w w w . j av a 2 s. c o m*/ static void cleanupAttributes(ServletContext sc) { Enumeration<String> attrNames = sc.getAttributeNames(); while (attrNames.hasMoreElements()) { String attrName = attrNames.nextElement(); if (attrName.startsWith("org.springframework.")) { Object attrValue = sc.getAttribute(attrName); if (attrValue instanceof DisposableBean) { try { ((DisposableBean) attrValue).destroy(); } catch (Throwable ex) { logger.error("Couldn't invoke destroy method of attribute with name '" + attrName + "'", ex); } } } } }
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); }/* w w w. j a v a 2 s .c o m*/ }
From source file:com.manydesigns.portofino.logic.SecurityLogic.java
public static boolean isAdministrator(ServletRequest request) { ServletContext servletContext = ElementsThreadLocals.getServletContext(); Configuration conf = (Configuration) servletContext.getAttribute(BaseModule.PORTOFINO_CONFIGURATION); return isAdministrator(conf); }
From source file:org.apache.tiles.servlet.context.ServletUtil.java
/** * Returns a specific Tiles container./*ww w.j a v a 2s . c o m*/ * * @param context The servlet context to use. * @param key The key under which the container is stored. If null, the * default container will be returned. * @return The requested Tiles container. * @since 2.1.2 */ public static TilesContainer getContainer(ServletContext context, String key) { if (key == null) { key = TilesAccess.CONTAINER_ATTRIBUTE; } return (TilesContainer) context.getAttribute(key); }
From source file:edu.cornell.mannlib.vitro.webapp.startup.StartupStatus.java
public static StartupStatus getBean(ServletContext ctx) { StartupStatus ss;//from ww w . j ava2 s.c o m Object o = ctx.getAttribute(ATTRIBUTE_NAME); if (o instanceof StartupStatus) { ss = (StartupStatus) o; } else { ss = new StartupStatus(); ctx.setAttribute(ATTRIBUTE_NAME, ss); } return ss; }