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.autentia.wuija.web.LocaleContextFilter.java

public void init(FilterConfig config) throws ServletException {
    final WebApplicationContext wac = WebApplicationContextUtils
            .getRequiredWebApplicationContext(config.getServletContext());
    try {/*from  www.java2s  .  c  o m*/
        localeResolver = (LocaleResolver) wac.getBean("localeResolver", LocaleResolver.class);
        log.info("LocaleResolver defined: " + localeResolver.getClass().getSimpleName());

    } catch (NoSuchBeanDefinitionException e) {
        log.info("No LocaleResolver defined. Using " + CookieLocaleResolver.class.getSimpleName()
                + " by default");
        localeResolver = new CookieLocaleResolver();
    }
}

From source file:org.primefaces.webapp.filter.FileUploadFilter.java

public void init(FilterConfig filterConfig) throws ServletException {
    boolean isAtLeastJSF22 = detectJSF22();
    String uploader = filterConfig.getServletContext().getInitParameter(Constants.ContextParams.UPLOADER);

    if (uploader == null || uploader.equals("auto")) {
        bypass = isAtLeastJSF22 ? true : false;
    } else if (uploader.equals("native")) {
        bypass = true;/*w w  w .j av  a2s  .c  o m*/
    } else if (uploader.equals("commons")) {
        bypass = false;
    }

    thresholdSize = filterConfig.getInitParameter(THRESHOLD_SIZE_PARAM);
    uploadDir = filterConfig.getInitParameter(UPLOAD_DIRECTORY_PARAM);

    if (logger.isLoggable(Level.FINE)) {
        logger.fine("FileUploadFilter initiated successfully");
    }
}

From source file:ru.org.linux.site.TemplateFilter.java

@Override
public void init(FilterConfig filterConfig) throws ServletException {
    this.filterConfig = filterConfig;

    WebApplicationContext ctx = WebApplicationContextUtils
            .getWebApplicationContext(filterConfig.getServletContext());

    properties = (Properties) ctx.getBean("properties");
    userDao = (UserDao) ctx.getBean("userDao");

    MemCachedSettings.setMainUrl(properties.getProperty("MainUrl"));
}

From source file:com.leixl.easyframework.web.filter.VcaptchaFilter.java

public void init(FilterConfig config) throws ServletException {
    WebApplicationContext appCtx = WebApplicationContextUtils
            .getWebApplicationContext(config.getServletContext());
    captchaService = (ImageCaptchaService) BeanFactoryUtils.beanOfTypeIncludingAncestors(appCtx,
            ImageCaptchaService.class);
    session = (SessionProvider) BeanFactoryUtils.beanOfTypeIncludingAncestors(appCtx, SessionProvider.class);

    initIncludeURIs(config);//from ww  w.  jav a  2  s .com
    initResultJson();
}

From source file:com.graphaware.server.foundation.bootstrap.GraphAwareBootstrappingFilter.java

private HandlerList findHandlerList(FilterConfig filterConfig) {
    Server server = ((ContextHandler.Context) filterConfig.getServletContext()).getContextHandler().getServer();

    if (server.getHandler().getClass().equals(RequestLogHandler.class)) {
        return (HandlerList) ((RequestLogHandler) server.getHandler()).getHandler();
    }//  ww  w .  ja  va2s .  c o  m

    return (HandlerList) server.getHandler();
}

From source file:org.sakaiproject.util.ResponseHeaderFilter.java

@SuppressWarnings("unchecked")
public void init(FilterConfig filterConfig) throws ServletException {
    String webappName = filterConfig.getServletContext().getServletContextName();
    // storing the header information in a local map
    for (Enumeration<String> paramNames = filterConfig.getInitParameterNames(); paramNames.hasMoreElements();) {
        String paramName = paramNames.nextElement();
        String paramValue = filterConfig.getInitParameter(paramName);
        if (paramName != null && paramValue != null) {
            this.headerMap.put(paramName, paramValue);
        }//www . j  a  v  a2s .  c  o  m
    }
    // adding the configured ones from sakai config
    ServerConfigurationService serverConfigurationService = org.sakaiproject.component.cover.ServerConfigurationService
            .getInstance();
    if (serverConfigurationService != null) {
        String[] headerStrings = serverConfigurationService.getStrings("response.headers");
        if (headerStrings != null) {
            for (String headerString : headerStrings) {
                if (headerString != null && !"".equals(headerString)) {
                    int loc = headerString.indexOf("::");
                    if (loc <= 0) {
                        log.warn("Invalid header string in sakai config (must contain '::', e.g. key::value): "
                                + headerString);
                        continue;
                    }
                    String name = headerString.substring(0, loc);
                    if (name == null || "".equals(name)) {
                        log.warn("Invalid header string in sakai config (name must not be empty): "
                                + headerString);
                        continue;
                    }
                    String value = null;
                    if (headerString.length() > loc + 2) {
                        value = headerString.substring(loc + 2);
                    }
                    addHeader(name, value);
                    if (value == null) {
                        log.info("Removing header (" + name + ") from all responses for current webapp: "
                                + webappName);
                    } else {
                        log.info("Adding header (" + name + " -> " + value
                                + ") to all responses for current webapp: " + webappName);
                    }
                }
            }
        }
    }
    log.info("INIT: for webapp " + webappName);
}

From source file:org.codelibs.fess.filter.FessEncodingFilter.java

@Override
public void init(final FilterConfig config) throws ServletException {
    super.init(config);
    servletContext = config.getServletContext();

    encoding = config.getInitParameter(ENCODING);
    if (encoding == null) {
        encoding = DEFAULT_ENCODING;//from   w  ww  .  j  ava  2s  . c  om
    }

    // ex. sjis:Shift_JIS,eucjp:EUC-JP
    final String value = config.getInitParameter(ENCODING_MAP);
    if (StringUtil.isNotBlank(value)) {
        final String[] encodingPairs = value.split(",");
        for (final String pair : encodingPairs) {
            final String[] encInfos = pair.trim().split(":");
            if (encInfos.length == 2) {
                encodingMap.put("/" + encInfos[0] + "/", encInfos[1]);
            }
        }
    }
}

From source file:org.apache.brooklyn.rest.filter.BrooklynPropertiesSecurityFilter.java

@Override
public void init(FilterConfig config) throws ServletException {
    ManagementContext mgmt = OsgiCompat.getManagementContext(config.getServletContext());
    provider = new DelegatingSecurityProvider(mgmt);
}

From source file:org.mfr.web.PrivateContentAccessManager.java

@Override
public void init(FilterConfig config) throws ServletException {
    springContext = WebApplicationContextUtils.getWebApplicationContext(config.getServletContext());
    siteDao = (SiteDao) springContext.getBean("siteDao");
    userManager = (UserManager) springContext.getBean("userManager");
    permissionDao = (PermissionDao) springContext.getBean("permissionDao");
}

From source file:org.topazproject.ambra.auth.web.UsernameReplacementWithGuidFilter.java

public void init(final FilterConfig filterConfig) throws ServletException {
    try {//from www .j a v  a  2  s  . co m
        userService = (UserService) filterConfig.getServletContext().getAttribute(AuthConstants.USER_SERVICE);
    } catch (final Exception ex) {
        log.error("UsernameReplacementWithGuidFilter init failed:", ex);
        throw new ServletException(ex);
    }
}