View Javadoc

1   /*
2    * Copyright 2008 University Corporation for Advanced Internet Development, Inc.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.opensaml.util.resource;
18  
19  import java.io.InputStream;
20  import java.util.List;
21  
22  import org.slf4j.Logger;
23  import org.slf4j.LoggerFactory;
24  
25  /** Resource filter that executes a list of resource filters in order. */
26  public class ChainingResourceFilter implements ResourceFilter {
27  
28      /** Class logger. */
29      private Logger log = LoggerFactory.getLogger(ChainingResourceFilter.class);
30      
31      /** Registered resource filters. */
32      private List<ResourceFilter> resourceFilters;
33  
34      /**
35       * Constructor.
36       * 
37       * @param filters resource filters to execute in order
38       */
39      public ChainingResourceFilter(List<ResourceFilter> filters) {
40          resourceFilters = filters;
41      }
42  
43      /** {@inheritDoc} */
44      public InputStream applyFilter(InputStream resource) throws ResourceException {
45          if (resourceFilters == null || resourceFilters.isEmpty()) {
46              log.debug("No resource filters configured, nothing to do");
47              return resource;
48          }
49  
50          for (ResourceFilter filter : resourceFilters) {
51              log.debug("Applying filter '{}'", filter.getClass().getName());
52              resource = filter.applyFilter(resource);
53          }
54  
55          return resource;
56      }
57  }