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