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.image;
018
019import java.io.Serializable;
020import java.util.Collections;
021import java.util.List;
022
023import org.apache.wicket.markup.ComponentTag;
024import org.apache.wicket.markup.html.CrossOrigin;
025import org.apache.wicket.model.IModel;
026import org.apache.wicket.model.Model;
027
028/**
029 * A component which displays external images within a picture tag.
030 * 
031 * @see org.apache.wicket.markup.html.image.Source
032 * 
033 * @author Tobias Soloschenko
034 * @author Sebastien Briquet
035 * @author Sven Meier
036 * @author Martin Grigorov
037 *
038 */
039public class ExternalSource extends ExternalImage
040{
041
042        private static final long serialVersionUID = 1L;
043
044        private String media = null;
045
046        /**
047         * Creates an external source
048         * 
049         * @param id
050         *            the component id
051         */
052        public ExternalSource(String id)
053        {
054                super(id, null, Model.ofList(Collections.<Serializable> emptyList()));
055        }
056        
057        /**
058         * Creates an external source
059         * 
060         * @param id
061         *            the component id
062         * @param srcSet
063         *            a list of URLs placed in the srcset attribute
064         */
065        public ExternalSource(String id, List<Serializable> srcSet)
066        {
067                super(id, null, Model.ofList(srcSet));
068        }
069
070        /**
071         * Creates an external source
072         * 
073         * @param id
074         *            the component id
075         * @param srcSetModel
076         *            a model list of URLs placed in the srcset attribute
077         */
078        public ExternalSource(String id, IModel<List<Serializable>> srcSetModel)
079        {
080                super(id, null, srcSetModel);
081        }
082
083        @Override
084        protected void onComponentTag(ComponentTag tag)
085        {
086                checkComponentTag(tag, "source");
087                super.onComponentTag(tag);
088                if (getMedia() != null)
089                {
090                        tag.put("media", getMedia());
091                }
092        }
093
094        /**
095         * Sets the media attribute information
096         *
097         * @param media
098         *            the media attribute information
099         */
100        public void setMedia(String media)
101        {
102                this.media = media;
103        }
104
105        /**
106         * Gets the media attribute information
107         *
108         * @return the media attribute information
109         */
110        public String getMedia()
111        {
112                return media;
113        }
114
115        /**
116         * Unsupported for source tag
117         */
118        @Override
119        public void setCrossOrigin(CrossOrigin crossorigin)
120        {
121                throw new UnsupportedOperationException(
122                        "It is not allowed to set the crossorigin attribute for source tag");
123        }
124
125        /**
126         * Unsupported for source tag
127         */
128        @Override
129        public final CrossOrigin getCrossOrigin()
130        {
131                return null;
132        }
133}