1 package org.jahia.tools; 2 3 import java.text.*; 4 import java.util.*; 5 6 9 10 11 16 public class Tools 17 { 18 private static final boolean debug = false; 20 21 22 23 public static String getCurrentDate() 24 { 26 return getCurrentDate("dd/MM/yyyy"); 27 } 28 36 public static String replace(String str, String token, 37 String replaceValue) { 38 39 String result = ""; 40 int i = str.indexOf(token); 41 while (i != -1) { 42 result += str.substring(0,i) + replaceValue; 43 str = str.substring(i + token.length(), str.length()); 44 i = str.indexOf(token); 45 } 46 return result + str; 47 } 48 49 50 public static String getCurrentDate(String format) 51 { 53 Date today = new Date(); 54 SimpleDateFormat formatter = new SimpleDateFormat(format); 55 String datenewformat = formatter.format(today); 56 return datenewformat; 57 } 58 59 static public String toHtml(String input) { 60 StringBuffer sb = new StringBuffer (input); 61 for (int i = 0; i < sb.length(); i++) { 62 63 char c = sb.charAt(i); 64 if (c == '\''){ 65 sb.deleteCharAt(i); 66 sb.insert(i,"'"); 67 } 68 if (c == '"') { 69 sb.deleteCharAt(i); 70 sb.insert(i,"""); 71 } 72 if (c == '<') { 73 sb.deleteCharAt(i); 74 sb.insert(i,"<"); 75 } 76 if (c == '>') { 77 sb.deleteCharAt(i); 78 sb.insert(i,">"); 79 } 80 if (c == 'à') { 81 sb.deleteCharAt(i); 82 sb.insert(i,"à"); 83 } 84 if (c == 'â') { 85 sb.deleteCharAt(i); 86 sb.insert(i,"â"); 87 } 88 if (c == 'é') { 89 sb.deleteCharAt(i); 90 sb.insert(i,"é"); 91 } 92 if (c == 'è') { 93 sb.deleteCharAt(i); 94 sb.insert(i,"è"); 95 } 96 if (c == 'ê') { 97 sb.deleteCharAt(i); 98 sb.insert(i,"ê"); 99 } 100 if (c == 'ë') { 101 sb.deleteCharAt(i); 102 sb.insert(i,"ë"); 103 } 104 if (c == 'ä') { 105 sb.deleteCharAt(i); 106 sb.insert(i,"ä"); 107 } 108 if (c == 'ù') { 109 sb.deleteCharAt(i); 110 sb.insert(i,"ù"); 111 } 112 if (c == 'û') { 113 sb.deleteCharAt(i); 114 sb.insert(i,"û"); 115 } 116 if (c == 'ü') { 117 sb.deleteCharAt(i); 118 sb.insert(i,"ü"); 119 } 120 if (c == 'ö') { 121 sb.deleteCharAt(i); 122 sb.insert(i,"ö"); 123 } 124 if (c == 'ï') { 125 sb.deleteCharAt(i); 126 sb.insert(i,"ï"); 127 } 128 if (c == 'î') { 129 sb.deleteCharAt(i); 130 sb.insert(i,"î"); 131 } 132 if (c == 'ç') { 133 sb.deleteCharAt(i); 134 sb.insert(i,"ç"); 135 } 136 } 137 return sb.toString(); 138 } 139 140 141 142 } 143 | Popular Tags |