Example usage for javax.servlet ServletConfig ServletConfig

List of usage examples for javax.servlet ServletConfig ServletConfig

Introduction

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

Prototype

ServletConfig

Source Link

Usage

From source file:org.withinsea.izayoi.adapter.springmvc.SpringIzayoiDispatcherFilter.java

@Override
public void init(final FilterConfig filterConfig) throws ServletException {

    cloister = new Cloister();
    glowworm = new Glowworm();
    cortile = new Cortile();
    izayoiInterceptor = new SpringGlowwormInterceptor(glowworm);
    izayoiViewResolver = new SpringCloisterCortileViewResolver(cortile, cloister);

    super.init(new ServletConfig() {

        @Override//  w w w.jav a2 s  . c om
        public String getInitParameter(String s) {
            return filterConfig.getInitParameter(s);
        }

        @Override
        public String getServletName() {
            return filterConfig.getFilterName();
        }

        @Override
        public ServletContext getServletContext() {
            return filterConfig.getServletContext();
        }

        @Override
        @SuppressWarnings("unchecked")
        public Enumeration<String> getInitParameterNames() {
            return filterConfig.getInitParameterNames();
        }
    });

    ApplicationContext appctx = getWebApplicationContext();
    ServletContext servletContext = filterConfig.getServletContext();
    Map<String, String> overriddenProperties = ServletFilterUtils.getParamsMap(filterConfig);

    IzayoiContainer container = new IzayoiContainerFactory().addBeanSource(new SpringBeanSource(appctx))
            .addModule("org.withinsea.izayoi.core").addModule("org.withinsea.izayoi.cloister")
            .addModule("org.withinsea.izayoi.glowworm").addModule("org.withinsea.izayoi.cortile")
            .addModule("org.withinsea.izayoi.adapter.springmvc").create(servletContext, overriddenProperties);

    cloister.init(container);
    glowworm.init(container);
    cortile.init(container);
}

From source file:org.bpmscript.web.TemplateController.java

/**
 * Gets the sitemesh HTMLPage and passes that information to the right view
 * along with the following parameters://  w  ww . jav a2s .com
 * 
 * <ul>
 * <li>base - the context path</li>
 * <li>locale - the locale for the page</li>
 * <li>req - the http request</li>
 * <li>res - the http response</li>
 * </ul>
 */
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response)
        throws Exception {

    HTMLPage htmlPage = (HTMLPage) request.getAttribute(RequestConstants.PAGE);

    Map<String, Object> context = new HashMap<String, Object>(templateModel);

    context.put("base", request.getContextPath());
    context.put("locale", request.getLocale());

    // For backwards compatability with apps that used the old VelocityDecoratorServlet
    // that extended VelocityServlet instead of VelocityViewServlet
    context.put("req", request);
    context.put("res", response);

    if (htmlPage == null) {
        context.put("title", "Title?");
        context.put("body", "<p>Body?</p>");
        context.put("head", "<!-- head -->");
    } else {
        context.put("title", OutputConverter.convert(htmlPage.getTitle()));
        {
            StringWriter buffer = new StringWriter();
            htmlPage.writeBody(OutputConverter.getWriter(buffer));
            context.put("body", buffer.toString());
        }
        {
            StringWriter buffer = new StringWriter();
            htmlPage.writeHead(OutputConverter.getWriter(buffer));
            context.put("head", buffer.toString());
        }
        context.put("page", htmlPage);
        Factory factory = Factory.getInstance(new Config(new ServletConfig() {
            public ServletContext getServletContext() {
                return TemplateController.this.getServletContext();
            }

            public String getInitParameter(String name) {
                return null;
            }

            public String getServletName() {
                return null;
            }

            public Enumeration<?> getInitParameterNames() {
                return null;
            }
        }));
        Decorator decorator = factory.getDecoratorMapper().getDecorator(request, htmlPage);
        context.put("decorator", decorator);
    }
    return new ModelAndView(getViewName(), context);
}

From source file:com.enonic.cms.server.service.dwr.DwrServletWrapper.java

@Override
public void init(final ServletConfig config) throws ServletException {
    final ConfigProperties configProperties = getConfigProperties(config.getServletContext());

    final Map<String, String> params = new HashMap<String, String>();
    params.put("debug", configProperties.getProperty("cms.admin.dwr.debug", "false"));
    params.put("crossDomainSessionSecurity",
            configProperties.getProperty("cms.admin.dwr.crossDomainSessionSecurity", "false"));
    params.put("classes", this.classes.toString());

    final ServletConfig wrapper = new ServletConfig() {
        public String getServletName() {
            return config.getServletName();
        }/*  w  w w. j av a2  s. co  m*/

        public ServletContext getServletContext() {
            return config.getServletContext();
        }

        public String getInitParameter(final String name) {
            return params.get(name);
        }

        public Enumeration getInitParameterNames() {
            return Collections.enumeration(params.keySet());
        }
    };

    super.init(wrapper);
}

From source file:org.jnap.core.mvc.async.AsyncRequestInterceptor.java

@Override
public void afterPropertiesSet() throws Exception {
    Assert.notNull(servletContext);//  w ww. jav a  2s.  c om
    final ServletContext sc = servletContext;

    final Map<String, String> params = new HashMap<String, String>();
    params.put(ApplicationConfig.WEBSOCKET_SUPPORT, Boolean.toString(this.useWebSocket));
    params.put(ApplicationConfig.PROPERTY_NATIVE_COMETSUPPORT, Boolean.toString(this.useNative));
    params.put(ApplicationConfig.PROPERTY_BLOCKING_COMETSUPPORT, Boolean.toString(this.useBlocking));
    params.put(ApplicationConfig.PROPERTY_USE_STREAM, Boolean.toString(this.useStream));
    //      atmosphere = new AtmosphereServlet(true);
    atmosphere = new AtmosphereServlet();
    atmosphere.addAtmosphereHandler("/*", this);
    atmosphere.init(new ServletConfig() {

        @Override
        public String getServletName() {
            return AsyncRequestInterceptor.class.getSimpleName();
        }

        @Override
        public ServletContext getServletContext() {
            return sc;
        }

        @Override
        public Enumeration getInitParameterNames() {
            return new IteratorEnumeration(params.keySet().iterator());
        }

        @Override
        public String getInitParameter(String name) {
            return params.get(name);
        }
    });
}

From source file:org.jahia.services.atmosphere.AtmosphereServlet.java

@Override
public void init(final ServletConfig sc) throws ServletException {
    ServletConfig scFacade;//from  ww  w.  j a  v  a2  s  .c  om

    String asyncSupport = SettingsBean.getInstance().getAtmosphereAsyncSupport();
    // override asyncSupport only if explicitly set via jahia.properties or not set at all
    if (StringUtils.isNotEmpty(asyncSupport) || sc.getInitParameter(PROPERTY_COMET_SUPPORT) == null) {
        final String implName = StringUtils.defaultIfBlank(asyncSupport, DEFAULT_ASYNC_SUPPORT);
        scFacade = new ServletConfig() {
            @Override
            public String getInitParameter(String name) {
                return PROPERTY_COMET_SUPPORT.equals(name) ? implName : sc.getInitParameter(name);
            }

            @Override
            public Enumeration<String> getInitParameterNames() {
                ArrayList<String> names = Lists.newArrayList(PROPERTY_COMET_SUPPORT);
                CollectionUtils.addAll(names, sc.getInitParameterNames());
                return Collections.enumeration(names);
            }

            @Override
            public ServletContext getServletContext() {
                return sc.getServletContext();
            }

            @Override
            public String getServletName() {
                return sc.getServletName();
            }
        };
    } else {
        scFacade = sc;
    }

    super.init(scFacade);
}

From source file:org.kuali.rice.ksb.messaging.servlet.KSBDispatcherServlet.java

/**
 * This is a workaround after upgrading to CXF 2.7.0 whereby we could no longer just call "setHideServiceList" on
 * the ServletController. Instead, it is now reading this information from the ServletConfig, so wrapping the base
 * ServletContext to return true or false for hide service list depending on whether or not we are in dev mode.
 *///from  w  w  w .ja  va2s.c  om
protected ServletConfig getCXFServletConfig(final ServletConfig baseServletConfig) {
    // disable handling of URLs ending in /services which display CXF generated service lists if we are not in dev mode
    final String shouldHide = Boolean
            .toString(!ConfigContext.getCurrentContextConfig().getDevMode().booleanValue());
    return new ServletConfig() {
        private static final String HIDE_SERVICE_LIST_PAGE_PARAM = "hide-service-list-page";

        @Override
        public String getServletName() {
            return baseServletConfig.getServletName();
        }

        @Override
        public ServletContext getServletContext() {
            return baseServletConfig.getServletContext();
        }

        @Override
        public String getInitParameter(String parameter) {
            if (HIDE_SERVICE_LIST_PAGE_PARAM.equals(parameter)) {
                return shouldHide;
            }
            return baseServletConfig.getInitParameter(parameter);
        }

        @Override
        public Enumeration<String> getInitParameterNames() {
            List<String> initParameterNames = EnumerationUtils
                    .toList(baseServletConfig.getInitParameterNames());
            initParameterNames.add(HIDE_SERVICE_LIST_PAGE_PARAM);
            return new Vector<String>(initParameterNames).elements();
        }
    };
}

From source file:org.polymap.service.geoserver.GeoServerWms.java

protected void initGeoServer() throws Exception {

    context = new PluginServletContext(getServletContext());
    log.debug("initGeoServer(): contextPath=" + context.getContextPath());

    ClassLoader threadLoader = Thread.currentThread().getContextClassLoader();
    Thread.currentThread().setContextClassLoader(context.cl);

    try {/*from w w  w.j a  v  a 2s .co  m*/
        File cacheDir = GeoServerPlugin.getDefault().getCacheDir();
        dataDir = new File(cacheDir, Stringer.on(map.getLabel()).toFilename("_").toString());
        log.debug("    dataDir=" + dataDir.getAbsolutePath());
        dataDir.mkdirs();
        FileUtils.forceDeleteOnExit(dataDir);

        // web.xml
        context.setAttribute("serviceStrategy", "SPEED");
        context.setAttribute("contextConfigLocation",
                "classpath*:/applicationContext.xml classpath*:/applicationSecurityContext.xml");
        context.setAttribute("enableVersioning", "false");
        context.setAttribute("GEOSERVER_DATA_DIR", dataDir.getAbsoluteFile());

        try {
            servers.set(this);

            loaders.add(new LoggingStartupContextListener());
            loaders.add(new ContextLoaderListener());

            ServletContextEvent ev = new ServletContextEvent(context);
            for (Object loader : loaders) {
                ((ServletContextListener) loader).contextInitialized(ev);
            }
        } finally {
            servers.set(null);
        }

        dispatcher = new DispatcherServlet();
        log.debug("Dispatcher: " + dispatcher.getClass().getClassLoader());
        dispatcher.init(new ServletConfig() {

            public String getInitParameter(String name) {
                return GeoServerWms.this.getInitParameter(name);
            }

            public Enumeration getInitParameterNames() {
                return GeoServerWms.this.getInitParameterNames();
            }

            public ServletContext getServletContext() {
                return context;
            }

            public String getServletName() {
                return "dispatcher";
            }
        });
    } finally {
        Thread.currentThread().setContextClassLoader(threadLoader);
    }
}