001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.wicket.markup.head.filter;
018
019import org.apache.wicket.markup.head.HeaderItem;
020import org.apache.wicket.markup.head.filter.FilteringHeaderResponse.IHeaderResponseFilter;
021
022/**
023 * A filter that takes another filter and always returns the opposite of another filter. This is
024 * useful where you have two filters (i.e. one for header and one for footer) and want to ensure
025 * that nothing ever has false returned for both cases.
026 * 
027 * @author Jeremy Thomerson
028 */
029public class OppositeHeaderResponseFilter implements IHeaderResponseFilter
030{
031
032        private final String name;
033        private final IHeaderResponseFilter other;
034
035        /**
036         * Construct.
037         * 
038         * @param name
039         *            the name used by this filter for its bucket o' stuff
040         * @param other
041         *            the other filter to return the opposite of
042         */
043        public OppositeHeaderResponseFilter(String name, IHeaderResponseFilter other)
044        {
045                this.name = name;
046                this.other = other;
047        }
048
049        @Override
050        public String getName()
051        {
052                return name;
053        }
054
055        @Override
056        public boolean accepts(HeaderItem item)
057        {
058                return !other.accepts(item);
059        }
060}