1 package com.mvnforum.jaxb.util; 2 3 import java.sql.Timestamp ; 4 import java.text.ParseException ; 5 import java.text.SimpleDateFormat ; 6 import java.util.Date ; 7 import java.util.Hashtable ; 8 9 import net.myvietnam.mvncore.filter.DisableHtmlTagFilter; 10 11 public class ImportExportUtil { 12 13 static SimpleDateFormat datetimefmt = new SimpleDateFormat ("yyyy-MM-dd kk:mm:ss"); 14 15 static SimpleDateFormat datefmt = new SimpleDateFormat ("yyyy-MM-dd"); 16 17 static Hashtable str2hex = new Hashtable (); 18 static { 19 str2hex.put("0", new Integer (0)); 20 str2hex.put("1", new Integer (1)); 21 str2hex.put("2", new Integer (2)); 22 str2hex.put("3", new Integer (3)); 23 str2hex.put("4", new Integer (4)); 24 str2hex.put("5", new Integer (5)); 25 str2hex.put("6", new Integer (6)); 26 str2hex.put("7", new Integer (7)); 27 str2hex.put("8", new Integer (8)); 28 str2hex.put("9", new Integer (9)); 29 str2hex.put("A", new Integer (10)); 30 str2hex.put("B", new Integer (11)); 31 str2hex.put("C", new Integer (12)); 32 str2hex.put("D", new Integer (13)); 33 str2hex.put("E", new Integer (14)); 34 str2hex.put("F", new Integer (15)); 35 str2hex.put("a", new Integer (10)); 36 str2hex.put("b", new Integer (11)); 37 str2hex.put("c", new Integer (12)); 38 str2hex.put("d", new Integer (13)); 39 str2hex.put("e", new Integer (14)); 40 str2hex.put("f", new Integer (15)); 41 } 42 43 58 59 public static String wrapit(String text) { 60 StringBuffer strbuf = new StringBuffer (); 61 for (int i = 0; i < text.length(); i++) { 63 if (text.charAt(i) == '\'') 64 strbuf.append("\'\'"); 65 else 66 strbuf.append(text.charAt(i)); 67 } 68 70 String result = strbuf.toString(); 71 result = DisableHtmlTagFilter.filter(result); 72 result = result.replaceAll("(.*):\\)(.*)", "$1\\[:\\)\\]$2"); 75 result = result.replaceAll("(.*):\\((.*)", "$1\\[:\\(\\]$2"); 77 result = result.replaceAll("(.*):D(.*)", "$1\\[:D\\]$2"); 79 result = result.replaceAll("(.*):lol:(.*)", "$1\\[:\\)\\)\\]$2"); 81 result = result.replaceAll("(.*):cry:(.*)", "$1\\[:\\(\\(\\]$2"); 83 result = result.replaceAll("(.*):wink:(.*)", "$1\\[;\\)\\]$2"); 85 result = result.replaceAll("(.*):oops:(.*)", "$1\\[:\">\\]$2"); 87 result = result.replaceAll("(.*):p(.*)", "$1\\[:p\\]$2"); 89 result = result.replaceAll("(.*)8\\)(.*)", "$1\\[B-\\)\\]$2"); 91 result = result.replaceAll("(.*):\\?(.*)", "$1\\[:-/\\]$2"); 93 result = result.replaceAll("(.*):shock:(.*)", "$1\\[:O\\]$2"); 95 result = result.replaceAll("(.*):evil:(.*)", "$1\\[>:\\)\\]$2"); 97 98 result = result.replaceAll("(.*)\\[url\\](.*)\\[/url\\](.*)", "$1\\[url=$2\\]$2\\[/url\\]$3"); 101 result = result.replaceAll("(.*)\\[b:[0-9,abcdef]*\\](.*)\\[/b:[0-9,abcdef]*\\](.*)", "$1\\[b\\]$2\\[/b\\]$3"); 103 result = result.replaceAll("(.*)\\[u:[0-9,abcdef]*\\](.*)\\[/u:[0-9,abcdef]*\\](.*)", "$1\\[u\\]$2\\[/u\\]$3"); 105 result = result.replaceAll("(.*)\\[i:[0-9,abcdef]*\\](.*)\\[/i:[0-9,abcdef]*\\](.*)", "$1\\[i\\]$2\\[/i\\]$3"); 107 result = result.replaceAll("(.*)\\[color=([a-z]*):[0-9,abcdef]*\\](.*)\\[/color:[0-9,abcdef]*\\](.*)", 109 "$1\\[color=$2\\]$3\\[/color\\]$4"); 110 result = result.replaceAll("(.*)\\[quote:[0-9,abcdef]*\\](.*)\\[/quote:[0-9,abcdef]*\\](.*)", 112 "$1\\[quote=\\]$2\\[/quote\\]$3"); 113 result = result.replaceAll("(.*)\\[quote:[0-9,abcdef]*=\\\"(.*)\\\"\\](.*)\\[/quote:[0-9,abcdef]*\\](.*)", 115 "$1\\[quote=\\\"$2\\\"\\]$3\\[/quote\\]$4"); 116 return result; 117 } 118 119 public static String HexIPtoString(String hexrep) { 120 if (hexrep.length() < 8) 121 return "0.0.0.0"; 122 123 byte[] ipaddr = new byte[8]; 124 for (int i = 0; i < ipaddr.length; i++) { 125 String letter = "" + hexrep.charAt(i); 126 int val = ((Integer ) str2hex.get(letter)).intValue(); 127 ipaddr[i] = (byte) val; 128 } 129 130 String strrep = ""; 131 int A = 0; 132 A |= ipaddr[0]; 133 A = A << 4; 134 A |= ipaddr[1]; 135 int B = 0; 136 B |= ipaddr[2]; 137 B = B << 4; 138 B |= ipaddr[3]; 139 int C = 0; 140 C |= ipaddr[4]; 141 C = C << 4; 142 C |= ipaddr[5]; 143 int D = 0; 144 D |= ipaddr[6]; 145 D = D << 4; 146 D |= ipaddr[7]; 147 148 return "" + A + "." + B + "." + C + "." + D; 149 } 150 151 public static String stripPHPBBQuotes(String in) { 152 boolean err = false; 153 StringBuffer endstr = new StringBuffer (); 154 155 do { 156 int firstquote = in.indexOf("[quote:"); 157 if (firstquote == -1) { 158 err = true; 159 break; 160 } 161 162 int firstclosebrace = in.indexOf(']', firstquote); 163 if (firstclosebrace == -1) { 164 err = true; 165 break; 166 } 167 168 endstr.append(in.substring(0, firstquote)); 169 endstr.append("[quote]"); 170 171 int endquote = in.indexOf("[/quote:"); 172 if (endquote == -1) { 173 err = true; 174 break; 175 } 176 177 int endclosebrace = in.indexOf(']', endquote); 178 if (endclosebrace == -1) { 179 err = true; 180 break; 181 } 182 183 endstr.append(in.substring(firstclosebrace + 1, endquote)); 184 endstr.append("[/quote]"); 185 endstr.append(in.substring(endclosebrace + 1)); 186 } while (false); 187 188 if (err) 189 return in; 190 else 191 return endstr.toString(); 192 } 193 194 public static String dateTimeFormat(long s) { 195 Date d = new Date (s * 1000); 196 return datetimefmt.format(d); 197 } 198 199 public static String dateFormat(long s) { 200 Date d = new Date (s * 1000); 201 return datefmt.format(d); 202 } 203 204 public static String dateTimeFormat(Timestamp timestamp) { 205 return datetimefmt.format(timestamp); 206 } 207 208 public static String dateFormat(Timestamp timestamp) { 209 return datefmt.format(timestamp); 210 } 211 212 public static String getFormatDate(Date date) { 213 return datefmt.format(date); 214 } 215 216 public static Timestamp getTimeStamp(long data) { 217 return new Timestamp (data * 1000); 218 } 219 220 public static Timestamp string2TimeStamp(String value) 221 throws ParseException { 222 Date d = datetimefmt.parse(value); 223 return new Timestamp (d.getTime()); 224 } 225 226 public static java.sql.Date string2Date (String value) throws ParseException { 227 return new java.sql.Date (datetimefmt.parse(value).getTime()); 228 229 } 230 } 231 | Popular Tags |