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.http2.markup.head;
018
019import java.io.Serializable;
020import java.util.HashMap;
021import java.util.List;
022import java.util.Map;
023
024import org.apache.wicket.Component;
025import org.apache.wicket.request.mapper.parameter.PageParameters;
026
027/**
028 * The object to be pushed. See the urlFor methods of {@link Component} to know what can be used in
029 * addition to {@link String}.
030 * 
031 * @author Tobias Soloschenko
032 */
033public class PushItem implements Serializable
034{
035        private static final long serialVersionUID = 1L;
036
037        private Serializable object;
038
039        private PageParameters pageParameters;
040
041        private String url;
042
043        private Map<String, PushItemHeaderValue> headers = new HashMap<>();
044
045        /**
046         * Creates a push item
047         * 
048         * @param object
049         *            the object to extract the push URL information from
050         * @param pageParameters
051         *            the page parameters
052         * @param headers
053         *            the headers to be applied to the push
054         */
055        public PushItem(Serializable object, PageParameters pageParameters,
056                Map<String, PushItemHeaderValue> headers)
057        {
058                this.object = object;
059                this.pageParameters = pageParameters;
060                if (headers != null)
061                {
062                        this.headers = headers;
063                }
064        }
065
066        /**
067         * Creates a push item
068         * 
069         * @param object
070         *            the object to extract the push URL information from
071         * @param headers
072         *            the headers to be applied to the push
073         */
074        public PushItem(Serializable object, Map<String, PushItemHeaderValue> headers)
075        {
076                this(object, null, headers);
077        }
078
079        /**
080         * Creates a push item
081         *
082         * @param object
083         *            the object to extract the push URL information from
084         * @param pageParameters
085         *            the page parameters
086         */
087        public PushItem(Serializable object, PageParameters pageParameters)
088        {
089                this(object, pageParameters, null);
090        }
091
092        /**
093         * Creates a push item
094         *
095         * @param object
096         *            the object to extract the push URL information from
097         */
098        public PushItem(Serializable object)
099        {
100                this(object, null, null);
101        }
102
103        /**
104         * Creates a push item
105         */
106        public PushItem()
107        {
108        }
109
110        /**
111         * Gets the object which contains the push URL information
112         * 
113         * @return the object to extract the push URL information from
114         */
115        public Object getObject()
116        {
117                return object;
118        }
119
120        /**
121         * Sets the object which contains the push URL information
122         * 
123         * @param object
124         *            the object to extract the push URL information from
125         * @see org.apache.wicket.request.cycle.RequestCycle (urlFor methods)
126         * @return the push item
127         */
128        public PushItem setObject(Serializable object)
129        {
130                this.object = object;
131                return this;
132        }
133
134        /**
135         * Gets the page parameters
136         * 
137         * @return the page parameters
138         */
139        public PageParameters getPageParameters()
140        {
141                return pageParameters;
142        }
143
144        /**
145         * Sets the page parameters
146         * 
147         * @param pageParameters
148         *            the page parameters
149         * @return the push item
150         */
151        public PushItem setPageParameters(PageParameters pageParameters)
152        {
153                this.pageParameters = pageParameters;
154                return this;
155        }
156
157        /**
158         * Gets the URL composed within the push header item
159         *
160         * @see org.apache.wicket.http2.markup.head.PushHeaderItem#push(List)
161         * @return the URL to be pushed
162         */
163        public String getUrl()
164        {
165                return url;
166        }
167
168        /**
169         * Sets the URL composed within the push header item
170         *
171         * @see org.apache.wicket.http2.markup.head.PushHeaderItem#push(List)
172         * @param url
173         *            the URL used to push the resource
174         * @return the push item
175         */
176        public PushItem setUrl(String url)
177        {
178                this.url = url;
179                return this;
180        }
181
182        /**
183         * Gets the headers to be added to the push response
184         *
185         * @return the headers to be added to the push response
186         */
187        public Map<String, PushItemHeaderValue> getHeaders()
188        {
189                return headers;
190        }
191
192        /**
193         * Sets the headers to be added to the push response
194         *
195         * @param headers
196         *            the headers to be added to the push response
197         * @return the push item
198         */
199        public PushItem setHeaders(Map<String, PushItemHeaderValue> headers)
200        {
201                this.headers = headers;
202                return this;
203        }
204}