List of usage examples for javax.servlet ServletContext setAttribute
public void setAttribute(String name, Object object);
From source file:com.concursive.connect.web.portal.PortletManager.java
public static synchronized String checkRegistryService(ServletContext context, ServletConfig config, HttpServletRequest request) throws PortletContainerException { // Add the registry service which preloads all of the portlets String contextPath = (String) context.getAttribute("PortletContextPath"); if (contextPath == null) { PortletContextManager registryService = PortletContextManager.getManager(); registryService.register(config); contextPath = request.getContextPath(); if (!StringUtils.hasText(contextPath)) { // Pluto corrects for using a "/" as the context path contextPath = "/"; }//from w w w . ja va 2 s . c o m context.setAttribute("PortletContextPath", contextPath); } return contextPath; }
From source file:com.oneops.metrics.admin.MetricsContextListener.java
@Override public void contextInitialized(ServletContextEvent sce) { logger.info("Initializing the Metrics Servlet Context Listener."); final ServletContext context = sce.getServletContext(); // Autowire this context listener WebApplicationContextUtils.getWebApplicationContext(context).getAutowireCapableBeanFactory() .autowireBean(this); context.setAttribute(METRICS_REGISTRY, ooMetricsRegistry); context.setAttribute(FILTER_REGISTRY, ooMetricsRegistry); context.setAttribute(HEALTH_CHECK_REGISTRY, ooHealthRegistry); context.setAttribute(RATE_UNIT, getRateUnit()); context.setAttribute(DURATION_UNIT, getDurationUnit()); context.setAttribute(ALLOWED_ORIGIN, getAllowedOrigin()); context.setAttribute(HEALTH_CHECK_EXECUTOR, getExecutorService()); MetricsElasticsearchModule.context.put("appName", context.getServletContextName()); MetricsElasticsearchModule.context.put("oo.version", version.getGitVersion()); }
From source file:com.ikon.servlet.admin.MimeTypeServlet.java
/** * List registered mime types/*from www . j a v a 2 s . c o m*/ */ private void list(String userId, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, DatabaseException { log.debug("list({}, {}, {})", new Object[] { userId, request, response }); ServletContext sc = getServletContext(); sc.setAttribute("mimeTypes", MimeTypeDAO.findAll("mt.name")); sc.getRequestDispatcher("/admin/mime_list.jsp").forward(request, response); log.debug("list: void"); }
From source file:com.ikon.servlet.admin.CronTabServlet.java
@Override public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { log.debug("doGet({}, {})", request, response); request.setCharacterEncoding("UTF-8"); String action = WebUtils.getString(request, "action"); updateSessionManager(request);// w w w .java2s . co m try { Map<String, String> types = new LinkedHashMap<String, String>(); types.put(CronTab.BSH, "BSH"); types.put(CronTab.JAR, "JAR"); if (action.equals("create")) { ServletContext sc = getServletContext(); CronTab ct = new CronTab(); sc.setAttribute("action", action); sc.setAttribute("types", types); sc.setAttribute("ct", ct); sc.getRequestDispatcher("/admin/crontab_edit.jsp").forward(request, response); } else if (action.equals("edit")) { ServletContext sc = getServletContext(); int ctId = WebUtils.getInt(request, "ct_id"); CronTab ct = CronTabDAO.findByPk(ctId); sc.setAttribute("action", action); sc.setAttribute("types", types); sc.setAttribute("ct", ct); sc.getRequestDispatcher("/admin/crontab_edit.jsp").forward(request, response); } else if (action.equals("delete")) { ServletContext sc = getServletContext(); int ctId = WebUtils.getInt(request, "ct_id"); CronTab ct = CronTabDAO.findByPk(ctId); sc.setAttribute("action", action); sc.setAttribute("types", types); sc.setAttribute("ct", ct); sc.getRequestDispatcher("/admin/crontab_edit.jsp").forward(request, response); } else if (action.equals("execute")) { execute(request, response); list(request, response); } else { list(request, response); } } catch (DatabaseException e) { log.error(e.getMessage(), e); sendErrorRedirect(request, response, e); } catch (EvalError e) { log.error(e.getMessage(), e); sendErrorRedirect(request, response, e); } }
From source file:com.ikon.servlet.admin.PropertyGroupsServlet.java
/** * Edit property groups//w ww .ja v a2s. c om * @throws RepositoryException * @throws ParseException */ private void edit(String pgLabel, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, DatabaseException, ParseException, RepositoryException { log.debug("edit({}, {})", new Object[] { request, response }); String pgName = "okg:" + pgLabel.toLowerCase().replace(" ", ""); List<FormElement> mData = OKMPropertyGroup.getInstance().getPropertyGroupForm(null, pgName); List<Map<String, String>> propertyMap = new ArrayList<Map<String, String>>(); for (FormElement fe : mData) { propertyMap.add(FormUtils.toString(fe)); } ServletContext sc = getServletContext(); sc.setAttribute("propertyMap", propertyMap); sc.setAttribute("pgLabel", pgLabel); request.getRequestDispatcher("/admin/property_groups_edit.jsp").forward(request, response); log.debug("edit: void"); }
From source file:org.infoglue.deliver.portal.information.InformationProviderServiceFactoryIG.java
public StaticInformationProvider getStaticProvider() { // TODO stolen from portalImpl log.debug("getStaticProvider(): using default from portalImpl, fix this!"); javax.servlet.ServletContext context = config.getServletContext(); StaticInformationProvider provider = (StaticInformationProvider) context.getAttribute(STATIC); if (provider == null) { provider = new StaticInformationProviderImpl(config); context.setAttribute(STATIC, provider); }/*from w ww. j ava2 s . c o m*/ return provider; }
From source file:com.liangc.hq.base.web.ConfiguratorListener.java
private void loadTablePreferences(ServletContext ctx) { try {//ww w .j a va2 s . co m Properties tableProps = loadProperties(ctx, Constants.PROPS_TAGLIB); ctx.setAttribute(Constants.PROPS_TAGLIB_NAME, tableProps); } catch (Exception e) { error("loading table properties file " + Constants.PROPS_TAGLIB + "failed: ", e); } }
From source file:org.sindice.core.analytics.commons.webapps.SparqledContextListener.java
private void addToContext(ServletContext context, Map<?, ?> map) { for (Object key : map.keySet()) { if (context.getAttribute(key.toString()) == null) { context.setAttribute(key.toString(), map.get(key)); }//from w w w .j a v a 2 s . co m } }
From source file:com.ikon.servlet.admin.ReportServlet.java
/** * List registered reports//from www . j a v a 2s. c o m */ private void list(String userId, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, DatabaseException { log.debug("list({}, {}, {})", new Object[] { userId, request, response }); ServletContext sc = getServletContext(); List<Report> list = ReportDAO.findAll(); sc.setAttribute("reports", list); sc.getRequestDispatcher("/admin/report_list.jsp").forward(request, response); log.debug("list: void"); }
From source file:org.springframework.test.context.web.AbstractGenericWebContextLoader.java
/** * Configures web resources for the supplied web application context (WAC). * <h4>Implementation Details</h4> * <p>If the supplied WAC has no parent or its parent is not a WAC, the * supplied WAC will be configured as the Root WAC (see "<em>Root WAC * Configuration</em>" below)./* w w w . j ava2 s . co m*/ * <p>Otherwise the context hierarchy of the supplied WAC will be traversed * to find the top-most WAC (i.e., the root); and the {@link ServletContext} * of the Root WAC will be set as the {@code ServletContext} for the supplied * WAC. * <h4>Root WAC Configuration</h4> * <ul> * <li>The resource base path is retrieved from the supplied * {@code WebMergedContextConfiguration}.</li> * <li>A {@link ResourceLoader} is instantiated for the {@link MockServletContext}: * if the resource base path is prefixed with "{@code classpath:}", a * {@link DefaultResourceLoader} will be used; otherwise, a * {@link FileSystemResourceLoader} will be used.</li> * <li>A {@code MockServletContext} will be created using the resource base * path and resource loader.</li> * <li>The supplied {@link GenericWebApplicationContext} is then stored in * the {@code MockServletContext} under the * {@link WebApplicationContext#ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE} key.</li> * <li>Finally, the {@code MockServletContext} is set in the * {@code WebApplicationContext}.</li> * @param context the web application context for which to configure the web resources * @param webMergedConfig the merged context configuration to use to load the web application context */ protected void configureWebResources(GenericWebApplicationContext context, WebMergedContextConfiguration webMergedConfig) { ApplicationContext parent = context.getParent(); // If the WebApplicationContext has no parent or the parent is not a WebApplicationContext, // set the current context as the root WebApplicationContext: if (parent == null || (!(parent instanceof WebApplicationContext))) { String resourceBasePath = webMergedConfig.getResourceBasePath(); ResourceLoader resourceLoader = (resourceBasePath.startsWith(ResourceLoader.CLASSPATH_URL_PREFIX) ? new DefaultResourceLoader() : new FileSystemResourceLoader()); ServletContext servletContext = new MockServletContext(resourceBasePath, resourceLoader); servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, context); context.setServletContext(servletContext); } else { ServletContext servletContext = null; // Find the root WebApplicationContext while (parent != null) { if (parent instanceof WebApplicationContext && !(parent.getParent() instanceof WebApplicationContext)) { servletContext = ((WebApplicationContext) parent).getServletContext(); break; } parent = parent.getParent(); } Assert.state(servletContext != null, "Failed to find root WebApplicationContext in the context hierarchy"); context.setServletContext(servletContext); } }