001/** 002 * 003 * Copyright (c) 2014, the Railo Company Ltd. All rights reserved. 004 * 005 * This library is free software; you can redistribute it and/or 006 * modify it under the terms of the GNU Lesser General Public 007 * License as published by the Free Software Foundation; either 008 * version 2.1 of the License, or (at your option) any later version. 009 * 010 * This library is distributed in the hope that it will be useful, 011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 013 * Lesser General Public License for more details. 014 * 015 * You should have received a copy of the GNU Lesser General Public 016 * License along with this library. If not, see <http://www.gnu.org/licenses/>. 017 * 018 **/ 019package lucee.runtime.tag; 020 021import lucee.commons.io.res.Resource; 022import lucee.commons.io.res.util.ResourceUtil; 023import lucee.commons.lang.StringUtil; 024import lucee.runtime.PageContext; 025import lucee.runtime.exp.ApplicationException; 026import lucee.runtime.exp.PageException; 027 028public class VideoPlayerParamBean { 029 030 031 public static final int NONE = 0; 032 //public static final int YES = 1; 033 //public static final int NO = 2; 034 035 private Resource video=null; 036 private Resource flash=null; 037 private lucee.runtime.video.Range show=lucee.runtime.video.Range.TRUE; 038 private int index=0; 039 private String pathVideo; 040 private String pathFlash; 041 private String title; 042 private String link; 043 private String author; 044 //private int autostart=NONE; 045 046 private Resource image; 047 048 049 050 051 public void release() { 052 video=null; 053 flash=null; 054 pathVideo=null; 055 pathFlash=null; 056 show=lucee.runtime.video.Range.TRUE; 057 index=1; 058 } 059 060 /** 061 * @return the video 062 */ 063 public Resource getVideo() { 064 return video; 065 } 066 067 public Resource getResource() { 068 return video!=null?video:flash; 069 } 070 071 /** 072 * @param video the video to set 073 * @param pathVideo 074 * @throws PageException 075 */ 076 public void setVideo(Resource video, String pathVideo) throws PageException { 077 if(!"flv".equalsIgnoreCase(getExtension(video))) 078 throw new ApplicationException("only flv movies are supported"); 079 this.video = video; 080 this.pathVideo = pathVideo; 081 } 082 083 public void setVideo(PageContext pc,String video) throws PageException { 084 setVideo(toResource(pc,video),video); 085 } 086 087 /** 088 * @return the flash 089 */ 090 public Resource getFlash() { 091 return flash; 092 } 093 094 /** 095 * @param flash the flash to set 096 * @throws PageException 097 */ 098 public void setFlash(Resource flash, String pathFlash) throws PageException { 099 if(!"swf".equalsIgnoreCase(getExtension(flash))) 100 throw new ApplicationException("only swf movies are supported"); 101 this.flash = flash; 102 this.pathFlash = pathFlash; 103 } 104 105 /** 106 * @param flash the flash to set 107 * @throws PageException 108 */ 109 public void setFlash(PageContext pc,String flash) throws PageException { 110 setFlash(toResource(pc,flash),flash); 111 } 112 113 /** 114 * @return the show 115 */ 116 public lucee.runtime.video.Range getShow() { 117 return show; 118 } 119 120 public void setShow(String show) throws PageException { 121 this.show=lucee.runtime.video.Range.toRange(show); 122 } 123 124 public void setShow(lucee.runtime.video.Range show) { 125 this.show=show; 126 } 127 128 /** 129 * @return the index 130 */ 131 public int getIndex() { 132 return index; 133 } 134 135 /** 136 * @param index the index to set 137 */ 138 public void setIndex(int index) throws PageException { 139 if(index<0) 140 throw new ApplicationException("index have to be a a none negative integer"); 141 this.index = index; 142 } 143 144 145 private Resource toResource(PageContext pc,String str) throws PageException { 146 Resource res=ResourceUtil.toResourceNotExisting(pc ,str); 147 148 //Resource res = Caster.toResource(str,false); 149 //print.out(res); 150 if(res.getResourceProvider().getScheme().equalsIgnoreCase("file") && !res.exists()) 151 throw new ApplicationException("Resource ["+res+"] does not exist"); 152 return res; 153 } 154 155 156 private static String getExtension(Resource res) { 157 String strFile = res.getName(); 158 int pos=strFile.lastIndexOf('.'); 159 if(pos==-1)return null; 160 return strFile.substring(pos+1); 161 } 162 163 /** 164 * @return the pathVideo 165 */ 166 public String getPathVideo() { 167 return pathVideo; 168 } 169 170 /** 171 * @return the pathFlash 172 */ 173 public String getPathFlash() { 174 return pathFlash; 175 } 176 177 public String getPath() { 178 return StringUtil.isEmpty(pathVideo)?pathFlash:pathVideo; 179 } 180 181 @Override 182 public String toString() { 183 return "video:"+pathVideo+";flash:"+pathFlash+";index:"+index+";show:"+show; 184 } 185 186 /* * 187 * @return the autostart 188 * / 189 public int getAutostart() { 190 return autostart; 191 } 192 193 /* * 194 * @param autostart the autostart to set 195 * / 196 public void setAutostart(boolean autostart) { 197 this.autostart = autostart?YES:NO; 198 }*/ 199 200 /** 201 * @return the title 202 */ 203 public String getTitle() { 204 return title; 205 } 206 207 /** 208 * @param title the title to set 209 */ 210 public void setTitle(String title) { 211 this.title = title; 212 } 213 214 public void setImage(PageContext pc,String image) throws PageException { 215 this.image=toResource(pc,image); 216 } 217 218 /** 219 * @return the image 220 */ 221 public Resource getImage() { 222 return image; 223 } 224 225 /** 226 * @return the link 227 */ 228 public String getLink() { 229 return link; 230 } 231 232 /** 233 * @param link the link to set 234 */ 235 public void setLink(String link) { 236 this.link = link; 237 } 238 239 /** 240 * @return the author 241 */ 242 public String getAuthor() { 243 return author; 244 } 245 246 /** 247 * @param author the author to set 248 */ 249 public void setAuthor(String author) { 250 this.author = author; 251 } 252 253 254}