public static String getSrc(String mm){
String img = mm.replaceAll("[\\s\\p{Zs}]+", "");
System.out.println("ret=="+img);
int n = img.indexOf("src=\"");
String ret ="";
if(n!=-1){
String strsub = img.substring(n+5);
int m =strsub.indexOf("\"");
if(m!=-1){
ret=strsub.substring(0, m);
} else {
System.out.println("ret=="+img);
}
}
return ret;
}
public static String chuliContent(String content) {
Pattern paa = Pattern.compile("<img.*?>",
Pattern.DOTALL);
String cc =content;
Matcher maa = paa.matcher(content);
while (maa.find()) {
System.out.println("img 匹配"+content);
String gg = maa.group();
String imgsrc=getSrc(gg);
if (!imgsrc.equals("")&&imgsrc!=null) {
// if (imgsrc.contains("[InstallDir_ChannelDir]{$UploadDir}")) {
cc = content.replace(imgsrc, IMG_URL + imgsrc);
content =cc;
}
// }
}
paa = Pattern.compile("<IMG.*?>",
Pattern.DOTALL);
maa = paa.matcher(content);
while (maa.find()) {
String gg = maa.group();
String imgsrc=getSrc(gg);
if (!imgsrc.equals("")&&imgsrc!=null) {
// if (imgsrc.contains("[InstallDir_ChannelDir]{$UploadDir}")) {
cc = content.replace(imgsrc, IMG_URL + imgsrc);
content =cc;
// }
}
}
paa = Pattern.compile("<A[^>]*>.*?</A>",
Pattern.DOTALL);
cc =content;
maa = paa.matcher(content);
while (maa.find()) {
String gg = maa.group();
String ahref=getHref(gg);
if (!ahref.equals("")&&ahref!=null) {
// if (ahref.contains("[InstallDir_ChannelDir]{$UploadDir}")) {
cc = content.replace(ahref, IMG_URL + ahref);
content =cc;
// }
}
}
paa = Pattern.compile("<a[^>]*>.*?</a>",
Pattern.DOTALL);
cc =content;
maa = paa.matcher(content);
while (maa.find()) {
String gg = maa.group();
String ahref=getHref(gg);
if (!ahref.equals("")&&ahref!=null) {
// if (ahref.contains("[InstallDir_ChannelDir]{$UploadDir}")) {
cc = content.replace(ahref, IMG_URL + ahref);
content =cc;
}
// }
}
return cc;
}
public static String getHref(String mm){
String img = mm.replaceAll("[\\s\\p{Zs}]+", "");
int n = img.indexOf("href=\"");
String ret ="";
if(n!=-1){
String strsub = img.substring(n+6);
int m =strsub.indexOf("\"");
if(m!=-1){
ret=strsub.substring(0, m);
}
}
return ret;
}