001    package railo.runtime.tag;
002    
003    import railo.commons.io.res.Resource;
004    import railo.commons.io.res.util.ResourceUtil;
005    import railo.commons.lang.StringUtil;
006    import railo.runtime.PageContext;
007    import railo.runtime.exp.ApplicationException;
008    import railo.runtime.exp.PageException;
009    
010    public class VideoPlayerParamBean {
011            
012    
013            public static final int NONE = 0;
014            //public static final int YES = 1;
015            //public static final int NO = 2;
016            
017            private Resource video=null;
018            private Resource flash=null;
019            private railo.runtime.video.Range show=railo.runtime.video.Range.TRUE;
020            private int index=0;
021            private String pathVideo;
022            private String pathFlash;
023            private String title;
024            private String link;
025            private String author;
026            //private int autostart=NONE;
027    
028            private Resource image;
029            
030            
031            
032            
033            public void release() {
034                    video=null;
035                    flash=null;
036                    pathVideo=null;
037                    pathFlash=null;
038                    show=railo.runtime.video.Range.TRUE;
039                    index=1;
040            }
041    
042            /**
043             * @return the video
044             */
045            public Resource getVideo() {
046                    return video;
047            }
048            
049            public Resource getResource() {
050                    return video!=null?video:flash;
051            }
052    
053            /**
054             * @param video the video to set
055             * @param pathVideo 
056             * @throws PageException 
057             */
058            public void setVideo(Resource video, String pathVideo) throws PageException {
059                    if(!"flv".equalsIgnoreCase(getExtension(video)))
060                            throw new ApplicationException("only flv movies are supported");
061                    this.video = video;
062                    this.pathVideo = pathVideo;
063            }
064    
065            public void setVideo(PageContext pc,String video) throws PageException {
066                    setVideo(toResource(pc,video),video);
067            }
068    
069            /**
070             * @return the flash
071             */
072            public Resource getFlash() {
073                    return flash;
074            }
075    
076            /**
077             * @param flash the flash to set
078             * @throws PageException 
079             */
080            public void setFlash(Resource flash, String pathFlash) throws PageException {
081                    if(!"swf".equalsIgnoreCase(getExtension(flash)))
082                            throw new ApplicationException("only swf movies are supported");
083                    this.flash = flash;
084                    this.pathFlash = pathFlash;
085            }
086    
087            /**
088             * @param flash the flash to set
089             * @throws PageException 
090             */
091            public void setFlash(PageContext pc,String flash) throws PageException {
092                    setFlash(toResource(pc,flash),flash);
093            }
094    
095            /**
096             * @return the show
097             */
098            public railo.runtime.video.Range getShow() {
099                    return show;
100            }
101    
102            public void setShow(String show) throws PageException {
103                    this.show=railo.runtime.video.Range.toRange(show);
104            }
105    
106            public void setShow(railo.runtime.video.Range show) {
107                    this.show=show;
108            }
109    
110            /**
111             * @return the index
112             */
113            public int getIndex() {
114                    return index;
115            }
116    
117            /**
118             * @param index the index to set
119             */
120            public void setIndex(int index) throws PageException {
121                    if(index<0)
122                            throw new ApplicationException("index have to be a a none negative integer");
123                    this.index = index;
124            }
125            
126    
127            private Resource toResource(PageContext pc,String str) throws PageException {
128                    Resource res=ResourceUtil.toResourceNotExisting(pc ,str);
129            
130                    //Resource res = Caster.toResource(str,false);
131                    //print.out(res);
132                    if(res.getResourceProvider().getScheme().equalsIgnoreCase("file") && !res.exists())
133                            throw new ApplicationException("Resource ["+res+"] does not exist");
134                    return res;
135            }
136            
137    
138        private static String getExtension(Resource res) {
139            String strFile = res.getName();
140            int pos=strFile.lastIndexOf('.');
141            if(pos==-1)return null;
142            return strFile.substring(pos+1);
143        }
144    
145            /**
146             * @return the pathVideo
147             */
148            public String getPathVideo() {
149                    return pathVideo;
150            }
151    
152            /**
153             * @return the pathFlash
154             */
155            public String getPathFlash() {
156                    return pathFlash;
157            }
158    
159            public String getPath() {
160                    return StringUtil.isEmpty(pathVideo)?pathFlash:pathVideo;
161            }
162    
163            @Override
164            public String toString() {
165                    return "video:"+pathVideo+";flash:"+pathFlash+";index:"+index+";show:"+show;
166            }
167    
168            /* *
169             * @return the autostart
170             * /
171            public int getAutostart() {
172                    return autostart;
173            }
174    
175            /* *
176             * @param autostart the autostart to set
177             * /
178            public void setAutostart(boolean autostart) {
179                    this.autostart = autostart?YES:NO;
180            }*/
181    
182            /**
183             * @return the title
184             */
185            public String getTitle() {
186                    return title;
187            }
188    
189            /**
190             * @param title the title to set
191             */
192            public void setTitle(String title) {
193                    this.title = title;
194            }
195    
196            public void setImage(PageContext pc,String image) throws PageException {
197                    this.image=toResource(pc,image);
198            }
199    
200            /**
201             * @return the image
202             */
203            public Resource getImage() {
204                    return image;
205            }
206    
207            /**
208             * @return the link
209             */
210            public String getLink() {
211                    return link;
212            }
213    
214            /**
215             * @param link the link to set
216             */
217            public void setLink(String link) {
218                    this.link = link;
219            }
220    
221            /**
222             * @return the author
223             */
224            public String getAuthor() {
225                    return author;
226            }
227    
228            /**
229             * @param author the author to set
230             */
231            public void setAuthor(String author) {
232                    this.author = author;
233            }
234    
235    
236    }