Example usage for javax.servlet FilterConfig getServletContext

List of usage examples for javax.servlet FilterConfig getServletContext

Introduction

In this page you can find the example usage for javax.servlet FilterConfig getServletContext.

Prototype

public ServletContext getServletContext();

Source Link

Document

Returns a reference to the ServletContext in which the caller is executing.

Usage

From source file:com.meltmedia.cadmium.servlets.MaintenanceFilter.java

@Override
public void init(FilterConfig config) throws ServletException {
    if (config.getInitParameter("ignorePrefix") != null) {
        ignorePath = config.getInitParameter("ignorePrefix");
    }/*from www  .  j a va  2s  .  c o  m*/
    config.getServletContext().setAttribute(this.getClass().getName(), this);
    ((MaintSiteDownService) siteDown).setMaintenanceFilter(this);
}

From source file:de.thorstenberger.taskmodel.view.webapp.filter.ExportPDFFilter.java

/**
 * {@inheritDoc}//from  w ww  .  j a va  2  s  .  co m
 */
public void init(final FilterConfig filterConfig) {
    this.fontPath = filterConfig.getServletContext().getRealPath("/WEB-INF/lsansuni.ttf");
    if (this.fontPath == null) {
        log.error("Could not locate lsansuni.ttf font file, is needed for utf-8 glyphs in PDFs!");
    }
}

From source file:org.bonitasoft.console.common.server.login.filter.AuthenticationFilter.java

/**
 * @see javax.servlet.Filter#init(javax.servlet.FilterConfig)
 */// ww  w  .  j a  v  a 2s. c  o m
@Override
public void init(final FilterConfig filterConfig) throws ServletException {

    final String contextPath = filterConfig.getServletContext().getContextPath();
    String webappName;
    if (contextPath.length() > 0) {
        webappName = contextPath.substring(1);
    } else {
        webappName = "";
    }
    excludePattern = compilePattern(StringUtils.isBlank(filterConfig.getInitParameter("excludePattern"))
            ? getDefaultExcludedPages().replace("bonita", webappName)
            : filterConfig.getInitParameter("excludePattern"));
}

From source file:org.osaf.cosmo.log.HttpLoggingFilter.java

public void init(FilterConfig config) throws ServletException {

    WebApplicationContext wac = WebApplicationContextUtils
            .getRequiredWebApplicationContext(config.getServletContext());

    this.securityManager = (CosmoSecurityManager) wac.getBean(BEAN_SECURITY_MANAGER,
            CosmoSecurityManager.class);

    if (this.securityManager == null) {
        throw new ServletException(
                "Could not initialize HttpLoggingFilter: " + "Could not find security manager.");
    }//from   www. ja v  a2 s. c  o  m

    String format = (String) wac.getBean(BEAN_HTTP_LOGGING_FORMAT, String.class);

    if (format != null) {
        try {
            this.format = (String) format;
        } catch (ClassCastException e) {
            throw new ServletException(
                    "Could not initialize HttpLoggingFilter: " + "httpLoggingFormat is not a string.");
        }
    }
}

From source file:org.archive.wayback.webapp.RequestFilter.java

public void init(FilterConfig config) throws ServletException {

    LOGGER.info("Wayback Filter initializing...");
    TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
    try {/*www.j  av  a 2 s .c o  m*/
        mapper = new RequestMapper(config.getServletContext());
    } catch (ConfigurationException e) {
        throw new ServletException(e.getMessage());
    }
    LOGGER.info("Wayback Filter initialization complete.");
}

From source file:org.sakaiproject.tool.gradebook.ui.RoleFilter.java

public void init(FilterConfig filterConfig) throws ServletException {
    if (logger.isInfoEnabled())
        logger.info("Initializing gradebook role filter");

    ac = (ApplicationContext) filterConfig.getServletContext()
            .getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);

    authnServiceBeanName = filterConfig.getInitParameter("authnServiceBean");
    authzServiceBeanName = filterConfig.getInitParameter("authzServiceBean");
    contextManagementServiceBeanName = filterConfig.getInitParameter("contextManagementServiceBean");
    authorizationFilterConfigurationBeanName = filterConfig
            .getInitParameter("authorizationFilterConfigurationBean");
    selectGradebookRedirect = filterConfig.getInitParameter("selectGradebookRedirect");
}

From source file:com.ait.tooling.server.core.servlet.filter.HeaderInjectorFilter.java

@Override
public void init(final FilterConfig fc) throws ServletException {
    try {/*from  w ww  .  j a  v  a2 s . c  o m*/
        final String name = StringOps.toTrimOrNull(fc.getInitParameter("config"));

        if (null != name) {
            final InputStream in = fc.getServletContext().getResourceAsStream(name);

            try {
                final HeaderInjectorParser parser = new HeaderInjectorParser();

                parser.parse(in);

                addHeaderInjectors(parser.getInjectors());
            } catch (Throwable t) {
                logger.error("Could not create injectors", t);
            } finally {
                IOUtils.closeQuietly(in);
            }
        }
    } catch (Throwable t) {
        logger.error("Could not create injectors", t);
    }
}

From source file:org.mikha.utils.web.multipart.MultiparFilter.java

public void init(FilterConfig config) throws ServletException {
    File dir;/* www  .  j a  v a  2  s . c  o m*/
    String s = config.getInitParameter("uploadDir");
    if (s != null) {
        dir = new File(s);
    } else {
        dir = (File) config.getServletContext().getAttribute("javax.servlet.context.tempdir");
        if (dir == null) {
            throw new ServletException("Cannot determine temporary upload directory. Set an uploadDir "
                    + "init parameter or ensure the javax.servlet.context.tempdir " + "directory is valid");
        }
    }

    int maxSize = Integer.MAX_VALUE;
    s = config.getInitParameter("maxSize");
    if (s != null) {

        try {
            maxSize = Integer.parseInt(s);
            if (maxSize <= 0) {
                throw new IllegalArgumentException("Must be positive");
            }
        } catch (IllegalArgumentException iaex) {
            throw new ServletException("Value \"" + s + "\" is not valid for maxSize parameter", iaex);
        }

    }

    fileItemFactory = new DiskFileItemFactory(maxSize, dir);
}

From source file:com.someco.servlets.AuthenticationFilter.java

public void init(FilterConfig config) throws ServletException {
    this.context = config.getServletContext();
    WebApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(context);
    ServiceRegistry serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY);
    transactionService = serviceRegistry.getTransactionService();
    nodeService = serviceRegistry.getNodeService();

    authComponent = (AuthenticationComponent) ctx.getBean("AuthenticationComponent");
    authService = (AuthenticationService) ctx.getBean("AuthenticationService");
    personService = (PersonService) ctx.getBean("personService");

    // Get a list of the available locales
    ConfigService configServiceService = (ConfigService) ctx.getBean("webClientConfigService");
    LanguagesConfigElement configElement = (LanguagesConfigElement) configServiceService.getConfig("Languages")
            .getConfigElement(LanguagesConfigElement.CONFIG_ELEMENT_ID);

    m_languages = configElement.getLanguages();

    casUserSessionAttributeName = config.getInitParameter(CAS_USER_INIT_PARAM_NAME);
    if (casUserSessionAttributeName == null) {
        logger.error("CAS : Filter init-param named " + CAS_USER_INIT_PARAM_NAME + " not found in web.xml");
        Enumeration enumNames = context.getInitParameterNames();
        while (enumNames.hasMoreElements()) {
            String name = enumNames.nextElement().toString();
            logger.error("init param " + name + ": " + context.getInitParameter(name));
        }//w  w  w  .  j  av  a 2s  .  c om
        // last resort - hack in the default CAS attribute name. At least it prevents 
        // NPEs later.
        casUserSessionAttributeName = "edu.yale.its.tp.cas.client.filter.user";
    }
}