001/* 002 * (C) Copyright 2006-2010 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * Thierry Delprat 018 */ 019package org.nuxeo.apidoc.filter; 020 021import java.io.IOException; 022import java.util.ArrayList; 023import java.util.List; 024 025import javax.servlet.Filter; 026import javax.servlet.FilterChain; 027import javax.servlet.FilterConfig; 028import javax.servlet.ServletException; 029import javax.servlet.ServletRequest; 030import javax.servlet.ServletResponse; 031 032import org.nuxeo.runtime.api.Framework; 033 034public abstract class BaseApiDocFilter implements Filter { 035 036 public static final String APIDOC_FILTERS_ACTIVATED = "org.nuxeo.apidoc.activatefilter"; 037 038 protected List<String> allowedConnectUrls = new ArrayList<String>(); 039 040 protected Boolean activated; 041 042 protected boolean isFilterActivated() { 043 if (activated == null) { 044 // don't activate by default 045 activated = Boolean.valueOf(Framework.isBooleanPropertyTrue(APIDOC_FILTERS_ACTIVATED)); 046 } 047 return activated.booleanValue(); 048 } 049 050 protected abstract void internalDoFilter(ServletRequest request, ServletResponse response, FilterChain chain) 051 throws IOException, ServletException; 052 053 @Override 054 public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, 055 ServletException { 056 057 if (!isFilterActivated()) { 058 chain.doFilter(request, response); 059 return; 060 } 061 internalDoFilter(request, response, chain); 062 } 063 064 @Override 065 public void destroy() { 066 } 067 068 @Override 069 public void init(FilterConfig filterConfig) throws ServletException { 070 } 071 072}