1 16 17 package org.apache.tomcat.util.compat; 18 19 import java.io.File ; 20 import java.io.IOException ; 21 import java.io.PrintWriter ; 22 import java.io.StringWriter ; 23 import java.net.MalformedURLException ; 24 import java.net.URL ; 25 import java.util.Vector ; 26 27 28 39 public class JdkCompat { 40 41 43 46 static final String JAVA14_SUPPORT = 47 "org.apache.tomcat.util.compat.Jdk14Compat"; 48 49 51 public static String getJavaVersion() { 52 return javaVersion; 53 } 54 55 public static boolean isJava2() { 56 return java2; 57 } 58 59 public static boolean isJava14() { 60 return java14; 61 } 62 63 public static boolean isJava15() { 64 return java15; 65 } 66 67 69 public static final String JAVA_1_0 = "1.0"; 71 public static final String JAVA_1_1 = "1.1"; 72 public static final String JAVA_1_2 = "1.2"; 73 public static final String JAVA_1_3 = "1.3"; 74 public static final String JAVA_1_4 = "1.4"; 75 public static final String JAVA_1_5 = "1.5"; 76 77 static String javaVersion; 78 static boolean java2=false; 79 static boolean java14=false; 80 static boolean java15=false; 81 static JdkCompat jdkCompat; 82 83 static { 84 init(); 85 } 86 87 private static void init() { 88 try { 89 javaVersion = JAVA_1_0; 90 Class.forName("java.lang.Void"); 91 javaVersion = JAVA_1_1; 92 Class.forName("java.lang.ThreadLocal"); 93 java2=true; 94 javaVersion = JAVA_1_2; 95 Class.forName("java.lang.StrictMath"); 96 javaVersion = JAVA_1_3; 97 Class.forName("java.lang.CharSequence"); 98 javaVersion = JAVA_1_4; 99 java14=true; 100 Class.forName("java.lang.Appendable"); 101 javaVersion = JAVA_1_5; 102 java15=true; 103 } catch (ClassNotFoundException cnfe) { 104 } 106 if( java14 ) { 107 try { 108 Class c=Class.forName(JAVA14_SUPPORT); 109 jdkCompat=(JdkCompat)c.newInstance(); 110 } catch( Exception ex ) { 111 jdkCompat=new JdkCompat(); 112 } 113 } else { 114 jdkCompat=new JdkCompat(); 115 } 117 } 118 119 123 protected JdkCompat() { 124 } 125 126 127 131 public static JdkCompat getJdkCompat() { 132 return jdkCompat; 133 } 134 135 143 public URL getURI(File file) 144 throws MalformedURLException { 145 146 File realFile = file; 147 try { 148 realFile = realFile.getCanonicalFile(); 149 } catch (IOException e) { 150 } 152 153 return realFile.toURL(); 154 } 155 156 157 160 public long getMaxMemory() { 161 return (-1L); 162 } 163 164 165 169 public String getPartialServletStackTrace(Throwable t) { 170 StringWriter stackTrace = new StringWriter (); 171 t.printStackTrace(new PrintWriter (stackTrace)); 172 String st = stackTrace.toString(); 173 int i = st.lastIndexOf 174 ("org.apache.catalina.core.ApplicationFilterChain.internalDoFilter"); 175 if (i > -1) { 176 return st.substring(0, i - 4); 177 } else { 178 return st; 179 } 180 } 181 182 188 public String [] split(String path, String pat) { 189 Vector comps = new Vector (); 190 int pos = path.indexOf(pat); 191 int start = 0; 192 while( pos >= 0 ) { 193 if(pos > start ) { 194 String comp = path.substring(start,pos); 195 comps.add(comp); 196 } 197 start = pos + pat.length(); 198 pos = path.indexOf(pat,start); 199 } 200 if( start < path.length()) { 201 comps.add(path.substring(start)); 202 } 203 String [] result = new String [comps.size()]; 204 for(int i=0; i < comps.size(); i++) { 205 result[i] = (String )comps.elementAt(i); 206 } 207 return result; 208 } 209 210 211 217 public void chainException(Throwable wrapper, Throwable wrapped) { 218 } 220 221 } 222 | Popular Tags |