1 19 package org.webdocwf.util.loader; 20 21 import java.io.*; 22 import java.util.*; 23 24 29 30 public class Utils { 31 32 39 public static String replaceAll(String input, String forReplace, 40 String replaceWith) { 41 if( input == null ) 42 return "null"; 43 StringBuffer result = new StringBuffer (); 45 boolean hasMore = true; 46 while (hasMore) { 47 int start = input.indexOf(forReplace); 48 int end = start + forReplace.length(); 49 if (start != -1) { 50 result.append(input.substring(0, start) + replaceWith); 51 input = input.substring(end); 52 } 53 else { 54 hasMore = false; 55 result.append(input); 56 } 57 } 58 if (result.toString().equals("")) 59 return input; else 61 return result.toString(); 62 } 63 64 65 public static String handleQuotedString(String quotedString) { 66 if( quotedString == null ) 67 return "null"; 68 String retVal = quotedString; 70 if ( (retVal.startsWith("'") && retVal.endsWith("'"))) { 71 if (!retVal.equals("''")) { 72 retVal = retVal.substring(retVal.indexOf("'") + 1, 73 retVal.lastIndexOf("'")); 74 } 75 else { 76 retVal = ""; 77 } 78 } 79 return retVal; 84 } 85 86 87 public static String getAbsolutePathFromDatabaseURL(String urlPrefix, 88 String loaderJobFile, String urlToDatabase, boolean fileSystemDatabase) { 89 90 if(fileSystemDatabase==true){ 91 String pathToDatabase=urlToDatabase.substring(urlPrefix.length()); 92 File file=new File(pathToDatabase); 93 if (!file.isAbsolute()){ 94 pathToDatabase=loaderJobFile + pathToDatabase; 95 File absolutePath=new File(pathToDatabase); 96 try { 97 pathToDatabase=absolutePath.getCanonicalPath(); 98 } 99 catch (Exception ex) { 100 ex.printStackTrace(); 101 } 102 urlToDatabase = urlToDatabase.substring(0, (urlPrefix.length())) + 103 pathToDatabase; 104 } 105 } 106 return urlToDatabase; 107 } 108 109 public static void log(String msg) { 110 try { 111 File file = new File("c:/log.txt"); 112 if (!file.exists()) { 113 file.createNewFile(); 114 } 115 RandomAccessFile fileLogr = new RandomAccessFile("c:/log.txt", "rw"); 116 fileLogr.seek(fileLogr.length()); 117 fileLogr.writeBytes( msg + "\r\n"); 118 fileLogr.close(); 119 } 120 catch (Exception ex) { 121 ex.printStackTrace(); 122 } 123 } 124 125 126 127 128 } 129 | Popular Tags |