1 12 package org.openbravo.utils; 13 14 import javax.servlet.ServletException ; 15 import org.apache.log4j.Logger ; 16 17 public class FormatUtilities { 18 static Logger log4j = Logger.getLogger(FormatUtilities.class); 19 20 public static String truncate(String s, int i) { 21 if(s == null && s.length() == 0) return ""; 22 if(i < s.length()) s = s.substring(0, i) + "..."; 23 return s; 24 } 25 26 public static String replaceTildes(String strIni) { 27 return Replace.replace( Replace.replace( Replace.replace( Replace.replace( Replace.replace( Replace.replace( Replace.replace( Replace.replace( Replace.replace( Replace.replace( strIni, "á", "a"), "é", "e"), "Ã", "i"), "ó", "o"), "ú", "u"), "Ã?", "A"), "É", "E"), "Ã?", "I"), "Ó", "O"), "Ú", "U"); 29 } 30 31 public static String replace(String strIni) { 32 return Replace.replace( Replace.replace( Replace.replace( Replace.replace( Replace.replace( Replace.replace( Replace.replace( Replace.replace( replaceTildes(strIni), "-",""), "/", ""), "#", ""), " ", ""), "&", ""), ",", ""), "(", ""), ")", ""); 34 } 35 36 public static String replaceJS(String strIni) { 37 return replaceJS(strIni, true); 38 } 39 40 public static String replaceJS(String strIni, boolean isUnderQuotes) { 41 return Replace.replace( Replace.replace(Replace.replace(Replace.replace(strIni, "'", (isUnderQuotes?"\\'":"'")), "\"", "\\\""), "\n", "\\n"), "\r", ""); 42 } 43 44 public static String sha1Base64(String text) throws ServletException { 45 if (text==null || text.trim().equals("")) return ""; 46 String result = text; 47 result = CryptoSHA1BASE64.encriptar(text); 48 return result; 49 } 50 51 public static String encryptDecrypt(String text, boolean encrypt) throws ServletException { 52 if (text==null || text.trim().equals("")) return ""; 53 String result = text; 54 if (encrypt) result = CryptoUtility.encrypt(text); 55 else result = CryptoUtility.decrypt(text); 56 return result; 57 } 58 } 59 | Popular Tags |