001 package railo.runtime.video; 002 003 import railo.runtime.exp.PageException; 004 import railo.runtime.op.Caster; 005 import railo.runtime.op.Decision; 006 007 public class Range { 008 009 public static final Range TRUE=new Range(0,-1); 010 public static final Range FALSE=new Range(0,0); 011 private double from; 012 private double to; 013 014 public Range(double from, double to) { 015 this.from=from; 016 this.to=to; 017 } 018 019 020 public static Range toRange(String def) throws PageException { 021 def=def.trim(); 022 // boolean 023 if(Decision.isBoolean(def)) { 024 return Caster.toBooleanValue(def)?TRUE:FALSE; 025 } 026 027 int index = def.indexOf(','); 028 // single value 029 if(index==-1) { 030 return new Range(toSeconds(def),-1); 031 } 032 033 // double value 034 if(def.startsWith(","))def="0"+def; 035 if(def.endsWith(","))def+="-1"; 036 037 return new Range(toSeconds(def.substring(0,index)),toSeconds(def.substring(index+1))); 038 039 040 } 041 042 private static double toSeconds(String str) throws PageException { 043 str=str.trim().toLowerCase(); 044 045 if(str.endsWith("ms")) return Caster.toDoubleValue(str.substring(0,str.length()-2))/1000D; 046 else if(str.endsWith("s")) return Caster.toDoubleValue(str.substring(0,str.length()-1)); 047 else return Caster.toDoubleValue(str)/1000D; 048 // TODO if(str.endsWith("f")) this.startFrame=VideoConfig.toLong(str.substring(0,str.length()-1)); 049 050 } 051 052 /** 053 * @return the from 054 */ 055 public double getFrom() { 056 return from; 057 } 058 059 public String getFromAsString() { 060 return Caster.toString(from); 061 } 062 063 064 /** 065 * @return the to 066 */ 067 public double getTo() { 068 return to; 069 } 070 071 public String getToAsString() { 072 return Caster.toString(to); 073 } 074 075 076 /** 077 * 078 * @see java.lang.Object#equals(java.lang.Object) 079 */ 080 public boolean equals(Object obj) { 081 if(obj==this) return true; 082 if(!(obj instanceof Range)) return false; 083 Range other=(Range) obj; 084 return other.from==from && other.to==to; 085 } 086 087 /** 088 * 089 * @see java.lang.Object#toString() 090 */ 091 public String toString() { 092 return ""+from+":"+to+""; 093 } 094 095 096 public boolean show() { 097 return !equals(Range.FALSE); 098 } 099 }