1 13 package org.jahia.utils; 14 15 import java.util.Locale ; 16 import java.security.SecureRandom ; 17 18 public class JahiaString { 19 20 public static String adjustStringSize(String str, int size) { 21 if (str == null) return null; 23 if (str.length() > size) { 24 return str.substring(0, size - 2) + ".."; 25 } else { 26 StringBuffer emtpyStr = new StringBuffer (); 27 for (int i = 0; i < size - str.length(); i++) { 28 emtpyStr.append(" "); 29 } 30 return str + emtpyStr; 31 } 32 } 33 34 public static String getProperStr(String str, Locale locale) { 36 return str; 37 } 38 39 public static String generateRandomString(int length) { 40 SecureRandom randomGen = new SecureRandom (); 41 StringBuffer result = new StringBuffer (); 42 int count = 0; 43 while (count < length) { 44 int randomSel = randomGen.nextInt(3); 45 int randomInt = randomGen.nextInt(26); 46 char randomChar = '0'; 47 switch (randomSel) { 48 case 0: randomChar = (char) (((int)'A') + randomInt); break; 49 case 1: randomChar = (char) (((int)'a') + randomInt); break; 50 case 2: randomChar = (char) (((int)'0') + (randomInt % 10)); break; 51 } 52 result.append(randomChar); 53 count++; 54 } 55 return result.toString(); 56 } 57 58 59 60 } | Popular Tags |