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 /** 164 * 165 * @see java.lang.Object#toString() 166 */ 167 public String toString() { 168 return "video:"+pathVideo+";flash:"+pathFlash+";index:"+index+";show:"+show; 169 } 170 171 /* * 172 * @return the autostart 173 * / 174 public int getAutostart() { 175 return autostart; 176 } 177 178 /* * 179 * @param autostart the autostart to set 180 * / 181 public void setAutostart(boolean autostart) { 182 this.autostart = autostart?YES:NO; 183 }*/ 184 185 /** 186 * @return the title 187 */ 188 public String getTitle() { 189 return title; 190 } 191 192 /** 193 * @param title the title to set 194 */ 195 public void setTitle(String title) { 196 this.title = title; 197 } 198 199 public void setImage(PageContext pc,String image) throws PageException { 200 this.image=toResource(pc,image); 201 } 202 203 /** 204 * @return the image 205 */ 206 public Resource getImage() { 207 return image; 208 } 209 210 /** 211 * @return the link 212 */ 213 public String getLink() { 214 return link; 215 } 216 217 /** 218 * @param link the link to set 219 */ 220 public void setLink(String link) { 221 this.link = link; 222 } 223 224 /** 225 * @return the author 226 */ 227 public String getAuthor() { 228 return author; 229 } 230 231 /** 232 * @param author the author to set 233 */ 234 public void setAuthor(String author) { 235 this.author = author; 236 } 237 238 239 }