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.html.media.video;
018
019import org.apache.wicket.markup.ComponentTag;
020import org.apache.wicket.markup.html.media.MediaComponent;
021import org.apache.wicket.model.IModel;
022import org.apache.wicket.request.cycle.RequestCycle;
023import org.apache.wicket.request.mapper.parameter.PageParameters;
024import org.apache.wicket.request.resource.ResourceReference;
025
026/**
027 * A video media component to display videos.
028 *
029 * @author Tobias Soloschenko
030 * @author Andrew Lombardi
031 * @since 7.0.0
032 */
033public class Video extends MediaComponent
034{
035        private static final long serialVersionUID = 1L;
036
037        private Integer width;
038
039        private Integer height;
040
041        private ResourceReference poster;
042
043        private PageParameters posterPageParameters;
044
045        /**
046         * Creates a video component
047         *
048         * @param id
049         *            the component id
050         */
051        public Video(String id)
052        {
053                super(id);
054        }
055
056        /**
057         * Creates a video component
058         *
059         * @param id
060         *            the component id
061         * @param model
062         *            the internally used model
063         */
064        public Video(String id, IModel<?> model)
065        {
066                super(id, model);
067        }
068
069        /**
070         * Creates a video component
071         *
072         * @param id
073         *            the component id
074         * @param resourceReference
075         *            the resource reference of the video file
076         */
077        public Video(String id, ResourceReference resourceReference)
078        {
079                super(id, resourceReference);
080        }
081
082        /**
083         * Creates a video component
084         *
085         * @param id
086         *            the component id
087         * @param model
088         *            the internally used model
089         * @param resourceReference
090         *            the resource reference of the video file
091         */
092        public Video(String id, IModel<?> model, ResourceReference resourceReference)
093        {
094                super(id, model, resourceReference);
095        }
096
097        /**
098         * Creates a media component
099         *
100         * @param id
101         *            the component id
102         * @param resourceReference
103         *            the resource reference of the video file
104         * @param pageParameters
105         *            the page parameters to be used to be prepended to the video URL
106         */
107        public Video(String id, ResourceReference resourceReference, PageParameters pageParameters)
108        {
109                super(id, resourceReference, pageParameters);
110        }
111
112        /**
113         * Creates a video component
114         *
115         * @param id
116         *            the component id
117         * @param model
118         *            the internally used model
119         * @param resourceReference
120         *            the resource reference of the video file
121         * @param pageParameters
122         *            the page parameters to be used to be prepended to the video URL
123         */
124        public Video(String id, IModel<?> model, ResourceReference resourceReference,
125                PageParameters pageParameters)
126        {
127                super(id, model, resourceReference, pageParameters);
128        }
129
130        /**
131         * Creates a video component
132         *
133         * @param id
134         *            the component id
135         * @param url
136         *            an external URL to be used for the video component
137         */
138        public Video(String id, String url)
139        {
140                super(id, url);
141        }
142
143        /**
144         * Creates a video component
145         *
146         * @param id
147         *            the component id
148         * @param model
149         *            the internally used model
150         * @param url
151         *            an external URL to be used for the video component
152         */
153        public Video(String id, IModel<?> model, String url)
154        {
155                super(id, model, url);
156        }
157
158        /**
159         * Creates a video component
160         *
161         * @param id
162         *            the component id
163         * @param url
164         *            an external URL to be used for the video component
165         * @param pageParameters
166         *            the page parameters to be used to be prepended to the video URL
167         */
168        public Video(String id, String url, PageParameters pageParameters)
169        {
170                super(id, null, url, pageParameters);
171        }
172
173        /**
174         * Creates a video component
175         *
176         * @param id
177         *            the component id
178         * @param model
179         *            the internally used model
180         * @param url
181         *            an external URL to be used for the video component
182         * @param pageParameters
183         *            the page parameters to be used to be prepended to the video URL
184         */
185        public Video(String id, IModel<?> model, String url, PageParameters pageParameters)
186        {
187                super(id, model, url, pageParameters);
188        }
189
190        @Override
191        protected void onComponentTag(ComponentTag tag)
192        {
193                checkComponentTag(tag, "video");
194                super.onComponentTag(tag);
195
196                Integer _width = getWidth();
197                if (_width != null)
198                {
199                        tag.put("width", _width);
200                }
201
202                Integer _height = getHeight();
203                if (_height != null)
204                {
205                        tag.put("height", _height);
206                }
207
208                ResourceReference _poster = getPoster();
209                if (_poster != null)
210                {
211                        tag.put("poster", RequestCycle.get().urlFor(_poster, getPosterPageParameters()));
212                }
213        }
214
215        /**
216         * The image to be displayed if the video isn't available
217         *
218         * @return the resource reference of the image
219         */
220        public ResourceReference getPoster()
221        {
222                return poster;
223        }
224
225        /**
226         * Gets the posters page parameters
227         *
228         * @return the page parameters for the poster
229         */
230        public PageParameters getPosterPageParameters()
231        {
232                return posterPageParameters;
233        }
234
235        /**
236         * Sets the posters page parameters
237         * 
238         * @param posterPageParameters
239         *            the page parameters for the poster
240         */
241        public void setPosterPageParameters(PageParameters posterPageParameters)
242        {
243                this.posterPageParameters = posterPageParameters;
244        }
245
246        /**
247         * Sets the image to be displayed if the video isn't available
248         *
249         * @param poster
250         *            the resource reference of the image used if the video isn't available
251         */
252        public void setPoster(ResourceReference poster)
253        {
254                this.poster = poster;
255        }
256
257        /**
258         * Sets the image to be displayed if the video isn't available
259         *
260         * @param poster
261         *            the resource reference of the image used if the video isn't available
262         * @param posterPageParameters
263         *            the page parameters for the poster
264         */
265        public void setPoster(ResourceReference poster, PageParameters posterPageParameters)
266        {
267                this.poster = poster;
268                this.posterPageParameters = posterPageParameters;
269        }
270
271        /**
272         * Gets the width of the video area
273         *
274         * @return the width of the video area
275         */
276        public Integer getWidth()
277        {
278                return width;
279        }
280
281        /**
282         * Sets the width of the video area
283         *
284         * @param width
285         *            the width of the video area
286         */
287        public void setWidth(Integer width)
288        {
289                this.width = width;
290        }
291
292        /**
293         * Gets the height of the video area
294         *
295         * @return the height of the video area
296         */
297        public Integer getHeight()
298        {
299                return height;
300        }
301
302        /**
303         * Sets the height of the video area
304         *
305         * @param height
306         *            the height of the video area
307         */
308        public void setHeight(Integer height)
309        {
310                this.height = height;
311        }
312}