1 2 3 24 package com.geinuke.util; 25 26 import java.io.BufferedReader ; 27 import java.security.MessageDigest ; 28 import java.util.StringTokenizer ; 29 import java.util.regex.Matcher ; 30 import java.util.regex.Pattern ; 31 32 import com.geinuke.vo.ModuleDBVO; 33 34 import sun.misc.BASE64Encoder; 35 public class TextUtil { 36 37 38 39 public static String [] badChars={"-","'","\"",";","'",">","<","(",")"}; 40 41 42 private static Pattern ampPt = Pattern.compile("&"); 43 44 private static Pattern quotPt = Pattern.compile("\""); 45 46 private static Pattern ltPt = Pattern.compile("<"); 47 48 private static Pattern gtPt = Pattern.compile(">"); 49 private static Pattern wikiLink = Pattern.compile("gikiPage-"); 50 51 public static String normHTML(String inputText) { 52 String tmp = ampPt.matcher(inputText).replaceAll("&"); 53 tmp = quotPt.matcher(tmp).replaceAll("""); 54 tmp = ltPt.matcher(tmp).replaceAll("<"); 55 tmp = gtPt.matcher(tmp).replaceAll(">"); 56 return tmp; 57 } 58 59 public static String removeHTML(String inputText) { 60 String tmp = "<([^<>]*)>"; 61 String res=null; 62 res=inputText.replaceAll(tmp,""); 63 return res; 64 } 65 66 public static String trunc(String it,int max) { 67 if(it!=null && it.length()>max){ 68 it=it.substring(0,max-1); 69 } 70 return it; 71 } 72 73 74 public static String getString(BufferedReader in) throws Exception { 75 String res=null,aux=null; 76 res=""; 77 while( (aux=in.readLine())!=null ) 78 res=res+aux+"\n"; 79 return res; 80 } 81 82 public static String getModuleNameByLinkModule(String li) throws Exception { 83 String res=null; 84 res=li.substring(ModuleDBVO.LINK_MODULE.length()); 85 int pos=res.indexOf("."); 86 res=res.substring(0,pos); 87 88 89 return res; 90 } 91 92 public static String normIfWin(String c) throws Exception { 93 c=c.replace('\\','/'); 94 c=c.replaceAll("C:",""); 95 return c; 96 } 97 98 public static String solveWikiLink(String inputText) { 99 String tmp = wikiLink.matcher(inputText).replaceAll("Giki.jhtm?op=showA&name="); 100 101 return tmp; 102 } 103 104 105 public static String replaceAmp(String input) { 106 if(input==null) 107 return null; 108 else{ 109 Matcher matcher = ampPt.matcher(input); 110 return matcher.replaceAll("&"); 111 } 112 } 113 114 public static String replaceTags(String input) { 115 116 if(input==null) 117 return null; 118 else{ 119 Matcher matcher = ltPt.matcher(input); 120 input = matcher.replaceAll("<"); 121 matcher = gtPt.matcher(input); 122 return matcher.replaceAll(">"); 123 } 124 } 125 126 127 128 public static String encr(String passw)throws Exception { 129 String crypted=passw; 130 return crypted; 131 } 132 133 public static String encr1(String passw)throws Exception { 134 MessageDigest md = null; 135 md = MessageDigest.getInstance("SHA-1"); md.update(passw.getBytes("UTF-8")); byte raw[] = md.digest(); String crypted = (new BASE64Encoder()).encode(raw); return crypted; 140 } 141 142 public static boolean hasChars(String target,String []chars){ 143 boolean flag=false; 144 for(int i=0;i<chars.length && !flag;i++){ 145 if(target.indexOf(chars[i])>-1) 146 flag=true; 147 } 148 return flag; 149 } 150 151 public static String [] tokenize(String source,String chars){ 152 String [] res=null; 153 StringTokenizer st=new StringTokenizer (source,chars); 154 res=new String [st.countTokens()]; 155 int ind=0; 156 while(st.hasMoreTokens()){ 157 res[ind++]=st.nextToken(); 158 } 159 return res; 160 } 161 162 public static boolean isInteger(String s){ 163 boolean flag=true; 164 try{ 165 Integer.parseInt(s); 166 }catch(Exception e){ 167 flag=false; 168 } 169 return flag; 170 } 171 172 public static String convert(String []chars){ 173 String res=null; 174 res=""; 175 for(int i=0;i<chars.length;i++){ 176 res+=chars[i]; 177 } 178 return res; 179 } 180 181 public static int splitAt(String date,int pos){ 182 int aux=-1; 183 String [] ar=date.split("_"); 184 aux = Integer.parseInt( ar[pos] ); 185 return aux; 186 } 187 188 public static boolean isEmpty(String s){ 189 boolean b=false; 190 b=(s==null) || s.trim().equals(""); 191 return b; 192 } 193 194 public static String normString(String s){ 195 196 boolean b=(s==null) || s.trim().equals(""); 197 if(b) 198 return ""; 199 else 200 return s.trim(); 201 202 } 203 204 205 } 206
| Popular Tags
|