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 java.util.Arrays;
020
021import org.apache.wicket.markup.head.IHeaderResponse;
022
023/**
024 * A header response that creates two buckets. The header bucket will contain all references to CSS
025 * and markup from the <head> section from the page. The other bucket will contain all other
026 * header items, and you will need to add a {@link HeaderResponseContainer} to the footer of your
027 * page (typically just before the end body tag) to render those items.
028 * 
029 * @author Jeremy Thomerson
030 */
031public class JavaScriptFilteredIntoFooterHeaderResponse extends FilteringHeaderResponse
032{
033
034        /**
035         * Construct.
036         * 
037         * @param response
038         *            the response you are wrapping
039         * @param footerBucketName
040         *            the name of the bucket that you will use for your footer container (see the class
041         *            javadocs for a reminder about putting this container in your footer)
042         */
043        public JavaScriptFilteredIntoFooterHeaderResponse(IHeaderResponse response,
044                String footerBucketName)
045        {
046                super(response);
047                setFilters(createFilters(footerBucketName));
048        }
049
050        private Iterable<? extends IHeaderResponseFilter> createFilters(String footerBucketName)
051        {
052                IHeaderResponseFilter footer = createFooterFilter(footerBucketName);
053                IHeaderResponseFilter header = createHeaderFilter(DEFAULT_HEADER_FILTER_NAME, footer);
054                return Arrays.asList(header, footer);
055        }
056
057        protected IHeaderResponseFilter createFooterFilter(String footerBucketName)
058        {
059                return new JavaScriptAcceptingHeaderResponseFilter(footerBucketName);
060        }
061
062        protected IHeaderResponseFilter createHeaderFilter(String headerFilterName, IHeaderResponseFilter footerFilter)
063        {
064                return new OppositeHeaderResponseFilter(headerFilterName, footerFilter);
065        }
066
067}