View Javadoc
1 /*** 2 Copyright (C) 2002-2003 Together 3 4 This library is free software; you can redistribute it and/or 5 modify it under the terms of the GNU Lesser General Public 6 License as published by the Free Software Foundation; either 7 version 2.1 of the License, or (at your option) any later version. 8 9 This library is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 Lesser General Public License for more details. 13 14 You should have received a copy of the GNU Lesser General Public 15 License along with this library; if not, write to the Free Software 16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 18 */ 19 package org.webdocwf.util.loader.generator; 20 21 22 /*** 23 * Utility methods for csv jdbc. 24 * 25 * @author Zoran Milakovic 26 */ 27 28 public class Utils { 29 30 /*** 31 * Replace all occurence of forReplace with replaceWith in input string. 32 * @param input 33 * @param forReplace 34 * @param replaceWith 35 * @return new string with replaced values 36 */ 37 public static String replaceAll(String input, String forReplace, 38 String replaceWith) { 39 StringBuffer result = new StringBuffer(); 40 boolean hasMore = true; 41 while (hasMore) { 42 int start = input.indexOf(forReplace); 43 int end = start + forReplace.length(); 44 if (start != -1) { 45 result.append(input.substring(0, start) + replaceWith); 46 input = input.substring(end); 47 } 48 else { 49 hasMore = false; 50 result.append(input); 51 } 52 } 53 if (result.toString().equals("")) 54 return input; //nothing is changed 55 else 56 return result.toString(); 57 } 58 59 60 public static String handleQuotedString(String quotedString) { 61 String retVal = quotedString; 62 if ( (retVal.startsWith("'") && retVal.endsWith("'"))) { 63 if (!retVal.equals("''")) { 64 retVal = retVal.substring(retVal.indexOf("'") + 1, 65 retVal.lastIndexOf("'")); 66 } 67 else { 68 retVal = ""; 69 } 70 } 71 return retVal; 72 } 73 74 public static String[] replaceLineBrakesAndCarrReturn( 75 String[] toReplace, 76 String lineBreakEscape, 77 String carriageReturnEscape) { 78 String[] retVal = new String[toReplace.length]; 79 for (int i = 0; i < toReplace.length; i++) { 80 if (toReplace[i] != null) { 81 retVal[i] = replaceAll(toReplace[i], "\n", lineBreakEscape); 82 retVal[i] = replaceAll(retVal[i], "\r", carriageReturnEscape); 83 } 84 } 85 return retVal; 86 } 87 88 89 90 91 92 }

This page was automatically generated by Maven