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;
018
019import java.util.ArrayList;
020import java.util.Collections;
021import java.util.List;
022
023import org.apache.wicket.request.Response;
024import org.apache.wicket.util.io.IClusterable;
025
026/**
027 * {@code HeaderItem} represents anything that can be rendered into the header. This can, for
028 * example, be a {@linkplain JavaScriptHeaderItem script} or a {@linkplain CssHeaderItem stylesheet}
029 * , but also {@linkplain OnEventHeaderItem event triggers} or {@linkplain StringHeaderItem free
030 * form text}. {@code HeaderItem}s are used by {@link org.apache.wicket.markup.head.ResourceAggregator} to be able to collect all
031 * header sections in a uniform way. All {@code HeaderItem}s are expected to have decent
032 * {@code equals}, {@code hashCode} and {@code toString} (for debugging).
033 * 
034 * @author papegaaij
035 */
036public abstract class HeaderItem implements IClusterable
037{
038        /**
039         * @return The dependencies this {@code HeaderItem} has. Dependencies will always be rendered
040         *         before the item itself.
041         */
042        public List<HeaderItem> getDependencies()
043        {
044                return new ArrayList<>();
045        }
046
047        /**
048         * @return The resources this {@code HeaderItem} provides. As these resources are provided by
049         *         this item, they will no longer be rendered.
050         */
051        public Iterable<? extends HeaderItem> getProvidedResources()
052        {
053                return Collections.emptyList();
054        }
055
056        /**
057         * @return The tokens this {@code HeaderItem} can be identified by. If any of the tokens has
058         *         already been rendered, this {@code HeaderItem} will not be rendered.
059         */
060        public abstract Iterable<?> getRenderTokens();
061
062        /**
063         * Renders the {@code HeaderItem} to the response.
064         * 
065         * @param response
066         */
067        public abstract void render(Response response);
068}