All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.richfaces.webapp.AbstractServletContainerInitializer Maven / Gradle / Ivy

The newest version!
/*
 * JBoss, Home of Professional Open Source
 * Copyright 2013, Red Hat, Inc. and individual contributors
 * by the @authors tag. See the copyright.txt in the distribution for a
 * full listing of individual contributors.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */

package org.richfaces.webapp;

import java.util.Collection;

import javax.servlet.Filter;
import javax.servlet.FilterRegistration;
import javax.servlet.Servlet;
import javax.servlet.ServletContainerInitializer;
import javax.servlet.ServletContext;
import javax.servlet.ServletRegistration;

/**
 * 

* Provides common functionality for {@link ServletContainerInitializer} implementatios. *

* * @author Lukas Fryc */ public abstract class AbstractServletContainerInitializer implements ServletContainerInitializer { /** * Detects if given {@link Filter} class has been already registered. * * @param filterClass {@link Filter} implementation class * @param context to search for registration * @return true if given {@link Filter} class has been already registered. */ protected boolean hasFilterMapping(Class filterClass, ServletContext context) { Collection filterRegistrations = context.getFilterRegistrations().values(); for (FilterRegistration filterRegistration : filterRegistrations) { if (filterClass.getName().equals(filterRegistration.getClassName())) { return true; } } return false; } /** *

* Returns the servlet registration for given {@link Servlet} class, which has at least one mapping registered. *

* *

* Returns null otherwise. *

* * @param servletClass {@link Servlet} implementation class * @param context to search for registration * @return the servlet registration for given {@link Servlet} class, which has at least one mapping registered, null * otherwise. */ protected ServletRegistration getServletRegistration(Class servletClass, ServletContext context) { Collection servletRegistrations = context.getServletRegistrations().values(); for (ServletRegistration servletRegistration : servletRegistrations) { if (servletClass.getName().equals(servletRegistration.getClassName())) { if (servletRegistration.getMappings() != null && !servletRegistration.getMappings().isEmpty()) { return servletRegistration; } } } return null; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy