001 package railo.runtime; 002 003 import java.io.InputStream; 004 import java.util.Map; 005 006 import railo.commons.date.TimeZoneConstants; 007 import railo.commons.io.IOUtil; 008 import railo.commons.io.ini.IniFile; 009 import railo.commons.lang.StringUtil; 010 import railo.runtime.exp.PageException; 011 import railo.runtime.exp.PageRuntimeException; 012 import railo.runtime.op.Caster; 013 import railo.runtime.op.date.DateCaster; 014 import railo.runtime.type.dt.DateTime; 015 import railo.runtime.type.util.ListUtil; 016 017 /** 018 * Info to this Version 019 */ 020 public final class Info { 021 022 /** 023 * @return the level 024 */ 025 public static String getLevel() { 026 return level; 027 } 028 029 public static final int STATE_ALPHA = 2*100000000; 030 public static final int STATE_BETA = 1*100000000; 031 public static final int STATE_RC = 3*100000000; 032 public static final int STATE_FINAL = 0; 033 034 // Mod this 035 private static DateTime releaseDate;//=DateUtil.toDateTime(TimeZone.getDefault(),2009,6,29,0,0,0,null); 036 037 private static String versionName;//="Barry"; 038 private static String versionNameExplanation;//="http://en.wikipedia.org/wiki/Barry_(dog)"; 039 040 // 3.1 041 private static int state;//=STATE_BETA; 042 private static int major;//=3; 043 private static int minor;//=1; 044 private static int releases;//=0; 045 private static int patches;//=18; 046 047 048 private static final long releaseTime;//=releaseDate.getTime(); 049 private static String version; 050 private static String level; 051 private static final String strState;//=toStringState(state); 052 private static final int intVersion; 053 private static final int fullVersion; 054 055 static { 056 InputStream is = Info.class.getClassLoader().getResourceAsStream("railo/runtime/Info.ini"); 057 try{ 058 IniFile ini=new IniFile(is); 059 Map verIni=ini.getSection("version"); 060 versionName=(String) verIni.get("name"); 061 versionNameExplanation=(String) verIni.get("name-explanation"); 062 releaseDate=DateCaster.toDateAdvanced((String) verIni.get("release-date"), TimeZoneConstants.EUROPE_ZURICH); 063 state=toIntState((String) verIni.get("state")); 064 level=(String) verIni.get("level"); 065 version=(String) verIni.get("number"); 066 String[] aVersion = ListUtil.toStringArray(ListUtil.listToArrayRemoveEmpty(version,'.')); 067 068 major=Caster.toIntValue(aVersion[0]); 069 minor=Caster.toIntValue(aVersion[1]); 070 releases=Caster.toIntValue(aVersion[2]); 071 patches=Caster.toIntValue(aVersion[3]); 072 } 073 catch (Throwable t) { 074 t.printStackTrace(); 075 throw new PageRuntimeException(Caster.toPageException(t)); 076 } 077 finally{ 078 IOUtil.closeEL(is); 079 } 080 081 releaseTime=releaseDate.getTime(); 082 strState=toStringState(state); 083 version=StringUtil.addZeros(major,1)+'.'+ 084 StringUtil.addZeros(minor,1)+'.'+ 085 StringUtil.addZeros(releases,1)+'.'+ 086 StringUtil.addZeros(patches,3); 087 intVersion=(major*1000000)+(minor*10000)+(releases*100)+patches; 088 fullVersion=intVersion+state; 089 } 090 091 public static int toIntVersion(String version, int defaultValue) { 092 try{ 093 String[] aVersion = ListUtil.toStringArray(ListUtil.listToArrayRemoveEmpty(version,'.')); 094 int ma = Caster.toIntValue(aVersion[0]); 095 int mi = Caster.toIntValue(aVersion[1]); 096 int re = Caster.toIntValue(aVersion[2]); 097 int pa = Caster.toIntValue(aVersion[3]); 098 return (ma*1000000)+(mi*10000)+(re*100)+pa; 099 } 100 catch(Throwable t){ 101 return defaultValue; 102 } 103 } 104 105 // Version <version>.<major>.<minor>.<patches> 106 107 /** 108 * @return Returns the releaseDate. 109 */ 110 public static DateTime getRealeaseDate() { 111 return releaseDate; 112 } 113 114 /** 115 * @return Returns the releaseTime. 116 */ 117 public static long getRealeaseTime() { 118 return releaseTime; 119 } 120 121 /** 122 * @return Returns the version. 123 */ 124 public static String getVersionAsString() { 125 return version; 126 } 127 128 /** 129 * @return Returns the intVersion. 130 */ 131 public static int getVersionAsInt() { 132 return intVersion; 133 } 134 135 /** 136 * @return returns the state 137 */ 138 public static int getStateAsInt() { 139 return state; 140 } 141 142 /** 143 * @return returns the state 144 */ 145 public static String getStateAsString() { 146 return strState; 147 } 148 149 150 /** 151 * @return returns the state 152 */ 153 public static String toStringState(int state) { 154 if(state==STATE_FINAL) return "final"; 155 else if(state==STATE_BETA) return "beta"; 156 else if(state==STATE_RC) return "rc"; 157 else return "alpha"; 158 } 159 160 /** 161 * @return returns the state 162 */ 163 public static int toIntState(String state) { 164 state=state.trim().toLowerCase(); 165 if("final".equals(state)) return STATE_FINAL; 166 else if("beta".equals(state)) return STATE_BETA; 167 else if("rc".equals(state)) return STATE_RC; 168 else return STATE_ALPHA; 169 } 170 171 172 public static int getFullVersionInfo() { 173 return fullVersion; 174 } 175 176 public static String getVersionName() { 177 return versionName; 178 } 179 public static int getMajorVersion() { 180 return major; 181 } 182 public static int getMinorVersion() { 183 return minor; 184 } 185 186 public static String getVersionNameExplanation() { 187 return versionNameExplanation; 188 } 189 190 /*public static void main(String[] args) { 191 print.out("getFullVersionInfo(103010018):"+getFullVersionInfo()); 192 print.out("getStateAsString(beta):"+getStateAsString()); 193 print.out("getStateAsInt(100000000):"+getStateAsInt()); 194 print.out("getVersionAsInt(3010018):"+getVersionAsInt()); 195 print.out("getVersionAsString(3.1.0.018):"+getVersionAsString()); 196 print.out("getVersionName(Barry):"+getVersionName()); 197 print.out("getVersionNameExplanation(http://en.wikipedia.org/wiki/Barry_(dog)):"+getVersionNameExplanation()); 198 print.out("getRealeaseDate({ts '2009-06-29 00:00:00'}):"+getRealeaseDate()); 199 print.out("getRealeaseTime(1246226400000):"+getRealeaseTime()); 200 print.out("getLevel():"+getLevel()); 201 202 203 204 205 }*/ 206 207 208 }