1 package com.ca.commons.cbutil; 2 3 import javax.swing.*; 4 import java.awt.*; 5 import java.awt.event.WindowAdapter ; 6 import java.awt.event.WindowEvent ; 7 import java.io.*; 8 import java.net.URL ; 9 import java.util.*; 10 import java.util.logging.Level ; 11 import java.util.logging.Logger ; 12 13 18 19 public class CBUtility 20 { 21 22 private static Cursor savedCursor; 23 private static Frame displayFrame = null; 24 25 private static Logger log = Logger.getLogger(CBUtility.class.getName()); 26 27 private CBUtility() 28 { 29 } 30 31 35 public static class BasicWindowMonitor extends WindowAdapter 36 { 37 public void windowClosing(WindowEvent e) 38 { 39 Window w = e.getWindow(); 40 w.setVisible(false); 41 w.dispose(); 42 } 44 } 45 46 52 53 public static StringBuffer readURLText(URL url) 54 { 55 return readURLText(url, new StringBuffer ("error: can't read URL " + url.toString())); 56 } 57 58 65 66 public static StringBuffer readURLText(URL url, StringBuffer errorText) 67 { 68 StringBuffer page = new StringBuffer (""); 69 String thisLine; 70 try 71 { 72 BufferedReader source = new BufferedReader(new InputStreamReader(url.openStream())); 73 74 while ((thisLine = source.readLine()) != null) 75 { 76 page.append(thisLine + "\n"); 77 } 78 return page; 79 } 80 catch (Exception e) 81 { 82 return errorText; 83 } 84 } 85 86 89 90 public static byte[] readStream(InputStream is) throws IOException 91 { 92 byte[] data = null; 93 byte[] buffer = new byte[16384]; 94 int blockSize = 0; 95 int size = 0; 96 97 while ((blockSize = is.read(buffer)) != -1) { byte[] temp = new byte[size + blockSize]; if (size != 0) System.arraycopy(data, 0, temp, 0, size); 103 System.arraycopy(buffer, 0, temp, size, blockSize); 104 data = temp; 105 size += blockSize; 106 } 107 return data; 108 } 109 110 111 117 118 public static String readTextFile(File file) 119 throws IOException 120 { 121 123 if (Locale.getDefault().getLanguage().equals("en") == false) 124 return readI18NFile(file); 125 126 FileReader in = new FileReader(file); 128 int size = (int) file.length(); 129 char[] data = new char[size]; 130 int chars_read = 0; 131 while (chars_read < size) 132 chars_read += in.read(data, chars_read, size - chars_read); 133 134 return new String (data); } 136 137 150 151 public static String readI18NFile(File file) 152 throws IOException 153 { 154 156 FileInputStream in = new FileInputStream(file); 157 int size = (int) file.length(); 158 byte[] data = new byte[size]; 159 int bytes_read = 0; 160 161 while (bytes_read < size) 162 bytes_read += in.read(data, bytes_read, size - bytes_read); 163 164 return readI18NByteArray(data); 165 } 166 167 public static String readI18NByteArray(byte[] data) 168 { 169 try 173 { 174 if (CBParse.isUnicode(data)) 175 { 176 log.finer("reading unicode 16 bit text"); 177 String text = new String (data, "UTF-16"); if (text.length() > 0) return text; 179 return new String (data); } 181 else 182 { 183 byte[] test = new byte[250]; 185 if (data.length < 250) 186 test = data; 187 else 188 System.arraycopy(data, 0, test, 0, 250); 189 190 if (CBParse.isNonAsciiUTF8(test)) 191 { 192 log.finer("reading utf8 text"); 193 String text = new String (data, "UTF-8"); if (text.length() > 0) return text; 195 return (new String (data)); } 197 else 198 { 199 log.finer("reading local encoding text"); 200 201 String newString = new String (data); 202 if (newString.indexOf("\\u") == -1) 203 { 204 return newString; } 206 207 212 StringBuffer buffer = new StringBuffer (newString); 213 214 int pos = 0; 215 while (pos + 6 < buffer.length()) 216 { 217 if (buffer.charAt(pos) != '\\') 218 pos++; 219 else if (buffer.charAt(pos + 1) != 'u') 220 pos += 2; 221 else 222 { 223 String unicode = buffer.substring(pos + 2, pos + 6); 224 int uni = Integer.parseInt(unicode, 16); 225 buffer = buffer.delete(pos, pos + 6); 226 buffer = buffer.insert(pos, (char) uni); 227 pos++; 228 } 229 230 } 231 232 return buffer.toString(); } 234 } 235 } 236 237 241 242 catch (Exception e) 243 { 244 log.warning("Confused Reading File: " + e.toString() + "\n -> reverting to default encoding"); 245 return new String (data); } 247 } 248 249 250 256 public static String [] readStringArrayFile(String fileName) 257 { 258 Properties props = readPropertyFile(fileName); 259 String [] values = new String [props.size()]; 260 Enumeration en = props.elements(); 261 int count = 0; 262 while (en.hasMoreElements()) 263 { 264 values[count++] = en.nextElement().toString(); 265 } 266 return values; 267 } 268 269 275 276 public static Properties readPropertyFile(String fileName) 277 { 278 Properties propertyList = new Properties(); 279 280 try 281 { 282 File propertyFile = new File(fileName); 283 if (propertyFile == null || propertyFile.exists() == false) 284 { 285 log.warning("No property list:\n" + fileName); 286 return propertyList; } 288 289 FileInputStream in = new FileInputStream(propertyFile); 290 propertyList.load(in); 291 return propertyList; 292 } 293 catch (Exception e) 294 { 295 log.log(Level.WARNING, "Can't read property list:\n" + fileName + "\n", e); 296 return propertyList; 297 } 298 } 299 300 308 public static void writeStringArrayFile(String fileName, String [] strings) 309 { 310 Properties props = new Properties(); 311 for (int i = 0; i < strings.length; i++) 312 props.put(strings[i], strings[i]); 314 writePropertyFile(fileName, props, "generated string array list"); 315 } 316 317 318 324 325 public static void writePropertyFile(String fileName, Properties propertyList, String comments) 326 { 327 329 CBProperties orderedPropertyList = new CBProperties(propertyList); 330 331 try 332 { 333 File propertyFile = new File(fileName); 334 335 FileOutputStream out = new FileOutputStream(propertyFile); 336 337 orderedPropertyList.store(out, "Generated Property List " + fileName + "\n" + ((comments != null) ? comments : "")); 338 } 339 catch (Exception e) 340 { 341 log.log(Level.WARNING, "Can't write property list:\n" + fileName + "\n", e); 342 } 343 } 344 345 354 355 public static String toHTML(String rawText) 356 { 357 String test; 358 if (rawText.length() > 14) 359 test = rawText.substring(0, 14).toLowerCase(); 360 else 361 test = rawText.toLowerCase(); 362 363 if (test.startsWith("<html>") || test.startsWith("<!doctype html>")) 364 { 365 366 if (test.startsWith("<html>")) 368 rawText = rawText.substring(6); 369 else if (test.startsWith("<!doctype html>")) 370 rawText = rawText.substring(15); 371 372 if (rawText.toLowerCase().endsWith("</html>")) 373 { 374 rawText = rawText.substring(0, rawText.length() - 7); 375 } 376 377 379 return rawText; 380 } 381 char C; 382 StringBuffer temp = new StringBuffer (rawText); 383 384 for (int pos = 0; pos < temp.length(); pos++) 385 { 386 C = temp.charAt(pos); 387 388 switch (C) 389 { 390 case '<': 391 CBParse.replaceChar(temp, pos, "<"); 392 break; 393 case '>': 394 CBParse.replaceChar(temp, pos, ">"); 395 break; 396 case '&': 397 CBParse.replaceChar(temp, pos, "&"); 398 break; 399 case '\"': 400 CBParse.replaceChar(temp, pos, """); 401 break; 402 case '#': 403 CBParse.replaceChar(temp, pos, "#"); 404 pos++; 405 break; 406 } 407 } 408 return temp.toString(); 409 } 410 411 420 421 public static int replaceChar(StringBuffer text, int pos, String replacement) 422 { 423 text.deleteCharAt(pos); 424 text.insert(pos, replacement); 425 return (pos + replacement.length()); 426 } 427 428 436 437 public static String replaceAllChar(StringBuffer text, char c, String replacement) 438 { 439 return CBParse.replaceAllBufferChar(text, c, replacement).toString(); 440 } 441 442 450 451 public static StringBuffer replaceAllBufferChar(StringBuffer text, char c, String replacement) 452 { 453 int pos = 0; 454 while (pos != -1) 455 { 456 pos = text.toString().indexOf(c, pos); 457 if (pos != -1) 458 pos = CBParse.replaceChar(text, pos, replacement); 459 } 460 return text; 461 } 462 463 472 473 public static int replaceString(StringBuffer text, int pos, int len, String replacement) 474 { 475 text.replace(pos, pos + len, replacement); 476 return (pos + replacement.length()); 479 } 480 481 490 491 public static String replaceAllString(StringBuffer text, String orig, String replacement) 492 { 493 return CBParse.replaceAllBufferString(text, orig, replacement).toString(); 494 } 495 496 505 506 public static StringBuffer replaceAllBufferString(StringBuffer text, String orig, String replacement) 507 { 508 int pos = 0; 509 while (pos != -1) 510 { 511 pos = text.toString().indexOf(orig, pos); 512 if (pos != -1) 513 pos = CBParse.replaceString(text, pos, orig.length(), replacement); 514 } 515 return text; 516 } 517 518 519 532 533 public static int nextCharIn(int pos, String searchMe, String compare, boolean match) 534 { 535 char test; 536 int length = searchMe.length(); 537 while (pos < length) 538 { 539 test = searchMe.charAt(pos); 540 if ((compare.indexOf(test) != -1) == match) 541 return pos; 542 pos++; 543 } 544 return -1; 545 } 546 547 554 555 public static String [] readFilteredDirectory(String dirPath, String extension) 556 { 557 String [] extensions = new String [1]; 558 extensions[0] = extension; 559 560 return readFilteredDirectory(dirPath, extensions); 561 } 562 563 570 571 public static String [] readFilteredDirectory(String dirPath, String [] fileExtensions) 572 { 573 final String [] extensions = fileExtensions; 574 File dir = new File(dirPath); 575 String [] templates = dir.list(new FilenameFilter() 577 { 578 public boolean accept(File dir, String name) 579 { 580 for (int i = 0; i < extensions.length; i++) 581 { 582 if (name.endsWith(extensions[i])) 583 return true; 584 } 585 return false; 586 } 587 }); 588 589 return templates; 590 } 591 592 593 598 599 public static void setWaitCursor(Component C) 600 { 601 C.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); 602 } 603 604 605 610 611 public static void setNormalCursor(Component C) 612 { 613 C.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); 614 } 615 616 617 622 623 public static void setHandCursor(Component C) 624 { 625 C.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); 626 } 627 628 629 635 636 public static void saveCursor(Component C) 637 { 638 savedCursor = C.getCursor(); 639 } 640 641 642 649 public static void restoreCursor(Component C) 650 { 651 if (savedCursor != null) 652 C.setCursor(savedCursor); 653 else 654 log.info("graphics error: can't restore cursor; no cursor saved..."); 655 } 656 657 661 662 664 667 668 670 671 672 676 678 683 710 713 726 749 755 760 761 788 public static void initDefaultDisplay(Frame owner) 789 { 790 displayFrame = owner; 791 } 792 793 public static Frame getDefaultDisplay() 794 { 795 return displayFrame; 796 } 797 798 799 804 805 public static boolean error(Component owner, String Msg) 806 { 807 return error(getParentFrame(owner), Msg, null); 808 } 809 810 815 816 public static boolean error(Frame owner, String Msg) 817 { 818 if (displayFrame == null) { 820 log.warning("graphics error: error display not initialised! (root error was: " + Msg + ")"); 821 return false; 822 } 823 return error(owner, Msg, null); 824 } 825 826 831 832 public static boolean error(String Msg) 833 { 834 if (displayFrame == null) { 836 log.warning("graphics error: error display not initialised! (error was: " + Msg + ")"); 837 return false; 838 } 839 return error(displayFrame, Msg, null); 840 } 841 842 849 850 851 public static boolean error(String Msg, Exception e) 852 { 853 return error(displayFrame, Msg, e); 854 } 855 856 857 865 866 867 public static boolean error(Component owner, String Msg, Exception e) 868 { 869 return error(getParentFrame(owner), Msg, e); 870 } 871 872 881 882 883 public static boolean error(Frame owner, String Msg, Exception e) 884 { 885 if (owner == null) { 887 if (displayFrame == null) { 889 log.warning("error display not initialised! (error was: " + Msg + ")"); 890 return false; 891 } 892 else 893 { 894 owner = displayFrame; 895 } 896 } 897 898 CBErrorWin errWin = new CBErrorWin(owner, Msg, e); 899 900 log.log(Level.WARNING, "error displayed to user: " + Msg, e); 901 902 return false; 903 } 904 905 906 911 912 public static void confirm(String Msg) 913 { 914 if (displayFrame == null) { 916 log.warning("error display not initialised! (error was: " + Msg + ")"); 917 return; 918 } 919 920 new CBErrorWin(displayFrame, Msg, "Confirmation Message"); 921 } 922 923 924 932 933 public static boolean warning(Component caller, String Msg, String Title) 934 { 935 JOptionPane.showMessageDialog(caller, Msg, 936 Title, JOptionPane.WARNING_MESSAGE); 937 return false; } 939 940 946 public static boolean warning(String Msg) 947 { 948 if (displayFrame == null) { 950 log.warning("warning display not initialised! (error was: " + Msg + ")"); 951 return false; 952 } 953 return warning(displayFrame, Msg, "Warning"); 954 } 955 956 959 960 public static void printEnumeration(Enumeration e) 961 { 962 while (e.hasMoreElements()) 963 { 964 Object raw = e.nextElement(); 965 String value = (raw == null) ? "*null*" : raw.toString(); 966 System.out.println(" " + value); 967 } 968 } 969 970 975 public static Frame getParentFrame(Component c) 976 { 977 if (c == null) return null; 978 979 Component parent = c.getParent(); 980 while (!(parent instanceof Frame) && (parent != null)) 981 parent = parent.getParent(); 982 983 return (parent == null) ? null : (Frame) parent; 984 } 985 986 990 991 public static String convertPathToUnix(String dosPath) 992 { 993 String ret = dosPath.replace('\\', '/'); 994 return ret; 995 } 996 997 998 1013 1014 public static void center(Component centerMe, Component positioner) 1015 { 1016 if (centerMe == null) return; 1017 1018 if (positioner != null && positioner.isShowing()) 1019 { 1020 Rectangle pos = positioner.getBounds(); Point absPos = positioner.getLocationOnScreen(); int centerX = absPos.x + (pos.width / 2); int centerY = absPos.y + (pos.height / 2); pos = centerMe.getBounds(); 1026 int x = 0; 1027 int y = 0; 1028 1029 if (centerMe.isShowing()) { 1031 absPos = centerMe.getLocationOnScreen(); int currentX = absPos.x + (pos.width / 2); int currentY = absPos.y + (pos.height / 2); 1035 int deltaX = centerX - currentX; int deltaY = centerY - currentY; 1038 x = pos.x + deltaX; 1039 y = pos.y + deltaY; 1040 } 1041 else { x = centerX - (pos.width / 2); 1044 y = centerY - (pos.height / 2); 1045 } 1046 1047 Toolkit toolKit = Toolkit.getDefaultToolkit(); 1048 1049 if ((x - 100) < 0 || (x + 100) > toolKit.getScreenSize().width || (y - 100) < 0 || (y + 100) > toolKit.getScreenSize().height) centerOnScreen(centerMe); else 1052 centerMe.setLocation(x, y); } 1054 else 1055 { 1056 centerOnScreen(centerMe); 1057 } 1058 } 1059 1060 1061 1066 1067 private static void centerOnScreen(Component centerMe) 1068 { 1069 Dimension screen = centerMe.getToolkit().getScreenSize(); 1070 Dimension object = centerMe.getSize(); 1071 centerMe.setLocation((int) (screen.getWidth() - object.getWidth()) / 2, (int) (screen.getHeight() - object.getHeight()) / 2); 1072 } 1073 1074 1075 1078 public static String bytes2Hex(byte[] bytes) 1079 { 1080 StringBuffer ret = new StringBuffer (bytes.length * 2); 1081 for (int i = 0; i < bytes.length; i++) 1082 { 1083 ret.append(CBParse.byte2Hex(bytes[i])); 1084 } 1085 return ret.toString(); 1086 } 1087 1088 1089 1092 public static String string2Hex(String orig) 1093 { 1094 StringBuffer ret = new StringBuffer (orig.length() * 2); 1095 char[] c = orig.toCharArray(); 1096 for (int i = 0; i < c.length; i++) 1097 { 1098 ret.append(CBParse.char2Hex(c[i])); 1099 } 1100 return ret.toString(); 1101 } 1102 1103 1106 static public String byte2Hex(byte b) 1107 { 1108 final char hexDigit[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'}; 1110 char[] array = {hexDigit[(b >> 4) & 0x0f], hexDigit[b & 0x0f]}; 1111 return new String (array); 1112 } 1113 1114 1117 static public String char2Hex(char c) 1118 { 1119 byte hi = (byte) (c >>> 8); 1121 byte lo = (byte) (c & 0xff); 1122 return CBParse.byte2Hex(hi) + CBParse.byte2Hex(lo); 1123 } 1124 1125 1128 static public byte hex2Byte(char hex1, char hex2) 1129 { 1130 byte a = CBParse.hexChar2Byte(hex1); 1131 byte b = CBParse.hexChar2Byte(hex2); 1132 return (byte) ((a << 4) + b); 1133 } 1134 1135 1140 1141 static public byte hexChar2Byte(char hex) 1142 { 1143 if (hex <= '9') 1144 return ((byte) (hex - 48)); else if (hex <= 'F') 1146 return ((byte) (hex - 55)); else 1148 return ((byte) (hex - 87)); } 1150 1151 1159 public static String bytes2HexSplit(byte[] in, int wordlength) 1160 { 1161 String hex = CBParse.bytes2Hex(in); 1162 StringBuffer buff = new StringBuffer (); 1163 1164 for (int i = 0; i < hex.length(); i++) 1165 { 1166 buff.append(hex.charAt(i)); 1167 if ((i + 1) % wordlength == 0) 1168 buff.append(" "); 1169 } 1170 1171 return buff.toString(); 1172 } 1173 1174 1185 1186 public static String bytes2HexSplit(byte[] in, int wordlength, int linelength) 1187 { 1188 String hex = CBParse.bytes2Hex(in); 1189 StringBuffer buff = new StringBuffer (); 1190 1191 for (int i = 0; i < hex.length(); i++) 1192 { 1193 buff.append(hex.charAt(i)); 1194 if ((i + 1) % wordlength == 0) 1195 buff.append(" "); 1196 if ((i + 1) % linelength == 0) 1197 buff.append("\n"); 1198 } 1199 1200 return buff.toString(); 1201 } 1202 1203 1213 public static boolean isUTF8(byte[] sequence) 1214 { 1215 boolean debug = false; 1216 if (debug) log.warning("\n\n Starting UTF8 Check\n\n"); 1217 int numberBytesInChar; 1218 1219 for (int i = 0; i < sequence.length; i++) 1220 { 1221 byte b = sequence[i]; 1222 if (debug) System.out.println("testing byte: " + CBParse.byte2Hex(b)); 1223 if (((b >> 6) & 0x03) == 2) 1224 { 1225 if (debug) System.out.println("start byte is invalid utf8 - has 10... start"); 1226 return false; 1227 } 1228 byte test = b; 1229 numberBytesInChar = 0; 1230 while ((test & 0x80) > 0) 1231 { 1232 test <<= 1; 1233 numberBytesInChar++; 1234 } 1235 1236 if (numberBytesInChar > 1) { 1238 for (int j = 1; j < numberBytesInChar; j++) 1239 { 1240 if (i + j >= sequence.length) 1241 { 1242 if (debug) System.out.println("following byte length is invalid - overruns end... "); 1243 return false; } 1245 if (debug) System.out.println("testing byte: " + CBParse.byte2Hex(sequence[i + j])); 1246 if (((sequence[i + j] >> 6) & 0x03) != 2) 1247 { 1248 if (debug) System.out.println("following byte is invalid utf8 - does *not* have 10... start"); 1249 return false; 1250 } 1251 } 1252 i += numberBytesInChar - 1; } 1254 } 1255 1256 return true; 1257 } 1258 1259 1274 1275 public static boolean isNonAsciiUTF8(byte[] sequence) 1276 { 1277 log.finest("testing sequence for utf8: " + CBParse.bytes2Hex(sequence)); 1278 boolean nonAsciiDetected = false; 1279 1280 int numberBytesInChar; 1281 for (int i = 0; i < sequence.length - 3; i++) 1282 { 1283 byte b = sequence[i]; 1284 if (((b >> 6) & 0x03) == 2) return false; 1285 byte test = b; 1286 numberBytesInChar = 0; 1287 while ((test & 0x80) > 0) 1288 { 1289 test <<= 1; 1290 numberBytesInChar++; 1291 } 1292 1293 if (numberBytesInChar > 1) { 1296 nonAsciiDetected = true; 1297 for (int j = 1; j < numberBytesInChar; j++) 1298 { 1299 if (((sequence[i + j] >> 6) & 0x03) != 2) 1300 return false; 1301 } 1302 i += numberBytesInChar - 1; } 1304 } 1305 1306 return nonAsciiDetected; 1307 } 1308 1309 1310 1323 1324 public static boolean isUnicode(byte[] sequence) 1325 { 1326 if (sequence.length >= 2) 1327 { 1328 if (sequence[0] == (byte) 0xFF && sequence[1] == (byte) 0xFE) return true; 1329 if (sequence[0] == (byte) 0xFE && sequence[1] == (byte) 0xFF) return true; 1330 } 1331 return false; 1332 } 1333 1334 1337 1338 1341 public static String chooseFileToSave(Component parent, String title, String [] filter, String fileType) 1342 { 1343 JFileChooser chooser = new JFileChooser(System.getProperty("PKIHOME")); 1344 chooser.setToolTipText(title); 1345 chooser.setDialogTitle(title); 1346 if (filter != null && fileType != null) 1347 { 1348 CBFileFilter filt = new CBFileFilter(filter, fileType); 1349 chooser.setFileFilter(filt); 1350 } 1351 int returnVal = chooser.showSaveDialog(parent); 1352 if (returnVal == JFileChooser.APPROVE_OPTION) 1353 { 1354 if (chooser.getSelectedFile() != null) 1355 return chooser.getSelectedFile().toString(); 1356 } 1357 return null; 1358 } 1359 1360 public static boolean okToWriteFile(Frame parent, String fileName) 1361 { 1362 File f = new File(fileName); 1363 if (f.isDirectory()) 1364 { 1365 JOptionPane.showMessageDialog(parent, fileName + " is a directory.", "Error!", JOptionPane.ERROR_MESSAGE); 1366 return false; 1367 } 1368 else if (f.exists()) 1369 { 1370 int saveAnswer = JOptionPane.showConfirmDialog(parent, 1371 "File " + fileName + " already exists.\nDo you want to overwrite?", 1372 "Question", JOptionPane.OK_CANCEL_OPTION); 1373 return (saveAnswer == JOptionPane.OK_OPTION); 1374 } 1375 return true; 1376 } 1377 1378 1379 1384 1385 public static class IgnoreCaseStringComparator implements Comparator 1386 { 1387 1388 1397 1398 public int compare(Object o1, Object o2) 1399 { 1400 if (o1 == null && o2 != null) 1401 return 1; 1402 else if (o2 == null && o1 != null) 1403 return -1; 1404 else if (o1 == null && o2 == null) 1405 return 0; 1406 1407 try 1408 { 1409 return (o1.toString().toLowerCase()).compareTo(o2.toString().toLowerCase()); 1410 } 1411 catch (ClassCastException e) 1412 { 1413 System.out.println("Error sorting values - invalid string in sort." + e); 1414 return 0; 1415 } 1416 } 1417 } 1418 1419 1429 public static String getPropertyConfigPath(String configFileName) 1430 { 1431 String pathToConfigFile; 1432 1433 String userHomeConfigDir = System.getProperty("user.home") + File.separator + "jxplorer"; 1435 String userHomeConfigFilePath = userHomeConfigDir + File.separator + configFileName; 1436 1437 String defaultConfigFilePath = System.getProperty("user.dir") + File.separator + configFileName; 1439 1440 if (System.getProperty("jxplorer.config") != null) 1442 { 1443 pathToConfigFile = System.getProperty("jxplorer.config"); 1444 1445 if (pathToConfigFile.equalsIgnoreCase("home") || pathToConfigFile.equalsIgnoreCase("user.home")) 1448 { 1449 File configDir = new File(userHomeConfigDir); 1451 if (configDir.exists() == false) 1452 { 1453 configDir.mkdir(); } 1455 1456 return userHomeConfigFilePath; 1457 } 1458 if (pathToConfigFile.endsWith(File.separator)) 1460 return pathToConfigFile + configFileName; 1461 else 1462 return pathToConfigFile + File.separator + configFileName; 1463 } 1464 1465 if (new File(userHomeConfigFilePath).exists()) 1467 { 1468 return userHomeConfigFilePath; 1469 } 1470 1471 return defaultConfigFilePath; 1474 } 1475 1476 1484 public static Level getTrueLogLevel(Logger log) 1485 { 1486 if (log.getLevel() != null) 1487 { 1488 return log.getLevel(); 1489 } 1490 1491 if (log.getParent() != null) 1492 return getTrueLogLevel(log.getParent()); 1493 1494 log.severe("no active log level initialised"); 1496 System.err.println("no active log level initialised"); 1497 1498 return Level.ALL; 1499 } 1500} | Popular Tags |