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:com.openkm.servlet.admin.StampServlet.java

/**
 * New image stamp//from  w  ww .j a  v  a2 s  .co m
 */
private void imageCreate(Session session, HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException, DatabaseException {
    log.debug("imageCreate({}, {}, {})", new Object[] { session, request, response });
    ServletContext sc = getServletContext();
    sc.setAttribute("action", WebUtils.getString(request, "action"));
    sc.setAttribute("persist", true);
    sc.setAttribute("users", AuthDAO.findAllUsers(true));
    sc.setAttribute("stamp", new StampImage());
    sc.getRequestDispatcher("/admin/stamp_image_edit.jsp").forward(request, response);
    log.debug("imageCreate: void");
}

From source file:org.apache.synapse.core.axis2.SynapseStartUpServlet.java

public void init() throws ServletException {
    ServletConfig servletConfig = getServletConfig();
    ServletContext servletContext = servletConfig.getServletContext();
    if (Boolean.TRUE.equals(servletContext.getAttribute(ALREADY_INITED))) {
        return;/*  w w w. j  a va2s.com*/
    }
    ServerManager serverManager = new ServerManager();
    ServerConfigurationInformation information = ServerConfigurationInformationFactory
            .createServerConfigurationInformation(servletConfig);
    serverManager.init(information, null);
    serverManager.start();
    servletContext.setAttribute(ALREADY_INITED, Boolean.TRUE);

    servletContext.setAttribute(SYNAPSE_SERVER_MANAGER, serverManager);
}

From source file:org.springframework.boot.web.servlet.support.SpringBootServletInitializer.java

protected WebApplicationContext createRootApplicationContext(ServletContext servletContext) {
    SpringApplicationBuilder builder = createSpringApplicationBuilder();
    builder.main(getClass());//from  ww  w.  j a  v a 2  s  . c  o m
    ApplicationContext parent = getExistingRootWebApplicationContext(servletContext);
    if (parent != null) {
        this.logger.info("Root context already created (using as parent).");
        servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, null);
        builder.initializers(new ParentContextApplicationContextInitializer(parent));
    }
    builder.initializers(new ServletContextApplicationContextInitializer(servletContext));
    builder.contextClass(AnnotationConfigServletWebServerApplicationContext.class);
    builder = configure(builder);
    builder.listeners(new WebEnvironmentPropertySourceInitializer(servletContext));
    SpringApplication application = builder.build();
    if (application.getAllSources().isEmpty()
            && AnnotationUtils.findAnnotation(getClass(), Configuration.class) != null) {
        application.addPrimarySources(Collections.singleton(getClass()));
    }
    Assert.state(!application.getAllSources().isEmpty(),
            "No SpringApplication sources have been defined. Either override the "
                    + "configure method or add an @Configuration annotation");
    // Ensure error pages are registered
    if (this.registerErrorPageFilter) {
        application.addPrimarySources(Collections.singleton(ErrorPageFilterConfiguration.class));
    }
    return run(application);
}

From source file:com.ikon.servlet.admin.ConfigServlet.java

/**
 * Create config/*from   ww w .j  a va 2  s  .c om*/
 */
private void create(String userId, Map<String, String> types, HttpServletRequest request,
        HttpServletResponse response) throws ServletException, IOException, DatabaseException {
    ServletContext sc = getServletContext();
    Config cfg = new Config();
    sc.setAttribute("action", WebUtils.getString(request, "action"));
    sc.setAttribute("filter", WebUtils.getString(request, "filter"));
    sc.setAttribute("persist", true);
    sc.setAttribute("types", types);
    sc.setAttribute("cfg", cfg);
    sc.getRequestDispatcher("/admin/config_edit.jsp").forward(request, response);
}

From source file:com.esd.ps.LoginController.java

/**
 * ??//from w  w  w  .  j  a va  2 s.  c  om
 * @param loginName
 * @param request
 * @return
 */
public int loginName(String loginName, HttpServletRequest request) {
    ServletContext servletContext = request.getSession().getServletContext();
    if (servletContext.getAttribute(loginName) == null) {
        servletContext.setAttribute(loginName, loginName);
        return 1;
    }
    return 0;
}

From source file:com.openkm.servlet.admin.StampServlet.java

/**
 * New text stamp/*from  www.  j  a  v  a 2  s  .  com*/
 */
private void textCreate(Session session, HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException, DatabaseException {
    log.debug("textCreate({}, {}, {})", new Object[] { session, request, response });

    if (WebUtils.getBoolean(request, "persist")) {
        StampText st = new StampText();
        st.setName(WebUtils.getString(request, "st_name"));
        st.setDescription(WebUtils.getString(request, "st_description"));
        st.setText(WebUtils.getString(request, "st_text"));
        st.setLayer(WebUtils.getInt(request, "st_layer"));
        st.setOpacity(WebUtils.getFloat(request, "st_opacity"));
        st.setSize(WebUtils.getInt(request, "st_size"));
        st.setColor(WebUtils.getString(request, "st_color"));
        st.setAlign(WebUtils.getInt(request, "st_align"));
        st.setRotation(WebUtils.getInt(request, "st_rotation"));
        st.setExprX(WebUtils.getString(request, "st_expr_x"));
        st.setExprY(WebUtils.getString(request, "st_expr_y"));
        st.setActive(WebUtils.getBoolean(request, "st_active"));
        st.setUsers(new HashSet<String>(WebUtils.getStringList(request, "st_users")));

        int id = StampTextDAO.create(st);

        // Activity log
        UserActivity.log(session.getUserID(), "ADMIN_STAMP_TEXT_CREATE", Integer.toString(id), st.toString());
    } else {
        ServletContext sc = getServletContext();
        sc.setAttribute("action", WebUtils.getString(request, "action"));
        sc.setAttribute("persist", true);
        sc.setAttribute("users", AuthDAO.findAllUsers(true));
        sc.setAttribute("stamp", new StampText());
        sc.getRequestDispatcher("/admin/stamp_text_edit.jsp").forward(request, response);
    }

    log.debug("textCreate: void");
}

From source file:jeeves.monitor.MonitorManager.java

private HealthCheckRegistry lookUpHealthCheckRegistry(ServletContext context, String attributeKey) {
    HealthCheckRegistry tmpHealthCheckRegistry = (HealthCheckRegistry) context.getAttribute(attributeKey);
    if (tmpHealthCheckRegistry == null) {
        tmpHealthCheckRegistry = new HealthCheckRegistry();
    }//from ww w.  j a  v a2s.com
    context.setAttribute(attributeKey, tmpHealthCheckRegistry);
    return tmpHealthCheckRegistry;
}

From source file:com.ibm.util.merge.web.InitializeServlet.java

private void initializeApp(ServletContext servletContext) {
    getRuntimeProperties(servletContext);
    log.warn("Initilized root from " + this.rootFrom + " as " + this.rootFolder);
    PropertyConfigurator.configure(this.runtimeProperties.getProperty(PARAMETER_LOGGING_PROPS));
    handlerChain.clear();/*from  w  w w .j  a  v  a 2 s  .c  om*/
    handlerChain.addAll(createHandlerInstances());
    TemplateFactory tf = new TemplateFactory(this.runtimeProperties);
    servletContext.setAttribute("TemplateFactory", tf);
    for (RequestHandler handler : handlerChain) {
        log.info("Initializing handler " + handler.getClass().getName());
        handler.initialize(this.runtimeProperties, tf);
    }
    servletContext.setAttribute("handlerChain", handlerChain);
}

From source file:nl.strohalm.cyclos.utils.SettingsHelper.java

@Override
public void setServletContext(final ServletContext servletContext) {
    // Store a proxy for each setting type

    final Object accessProxy = new SettingsProxyMap() {
        @Override/*w  ww. j av  a2 s  . c om*/
        protected Object getSetting() {
            return getAccessSettings();
        }
    };
    servletContext.setAttribute(ACCESS_KEY, accessProxy);

    final Object alertProxy = new SettingsProxyMap() {
        @Override
        protected Object getSetting() {
            return getAlertSettings();
        }
    };
    servletContext.setAttribute(ALERT_KEY, alertProxy);

    final Object localProxy = new SettingsProxyMap() {
        @Override
        protected Object getSetting() {
            return getLocalSettings();
        }
    };
    servletContext.setAttribute(LOCAL_KEY, localProxy);

    final Object logProxy = new SettingsProxyMap() {
        @Override
        protected Object getSetting() {
            return getLogSettings();
        }
    };
    servletContext.setAttribute(LOG_KEY, logProxy);

    final Object mailProxy = new SettingsProxyMap() {
        @Override
        protected Object getSetting() {
            return getMailSettings();
        }
    };
    servletContext.setAttribute(MAIL_KEY, mailProxy);

    final Object mailTranslationProxy = new SettingsProxyMap() {
        @Override
        protected Object getSetting() {
            return getMailTranslation();
        }
    };
    servletContext.setAttribute(MAIL_TRANSLATION_KEY, mailTranslationProxy);

    final Object messageProxy = new SettingsProxyMap() {
        @Override
        protected Object getSetting() {
            return getMessageSettings();
        }
    };
    servletContext.setAttribute(MESSAGE_KEY, messageProxy);
}