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 /** Resource filter that executes a list of resource filters in order. */ 23 public class ChainingResourceFilter implements ResourceFilter { 24 25 /** Registered resource filters. */ 26 private List<ResourceFilter> resourceFilters; 27 28 /** 29 * Constructor. 30 * 31 * @param filters resource filters to execute in order 32 */ 33 public ChainingResourceFilter(List<ResourceFilter> filters) { 34 resourceFilters = filters; 35 } 36 37 /** {@inheritDoc} */ 38 public InputStream applyFilter(InputStream resource) throws ResourceException { 39 if (resourceFilters == null || resourceFilters.isEmpty()) { 40 return resource; 41 } 42 43 for (ResourceFilter filter : resourceFilters) { 44 resource = filter.applyFilter(resource); 45 } 46 47 return resource; 48 } 49 }