public static String repairContent(String content, String replaceHttp) {
String patternStr = "<img\\s*([^>]*)\\s*src=\\\"(.*?)\\\"\\s*([^>]*)>";
Pattern pattern = Pattern.compile(patternStr, Pattern.CASE_INSENSITIVE);
Matcher matcher = pattern.matcher(content);
String result = content;
while (matcher.find()) {
String src = matcher.group(2);
String img = matcher.group(0);
String img2 = matcher.group(0);
// System.out.println("pattern string:"+src);
String replaceSrc = "";
if (!src.startsWith("http:")) {
replaceSrc = replaceHttp + src;
img = img.replaceAll(src, replaceSrc);
result = result.replaceAll(img2, img);
}
}
// System.out.println(" content == " +content);
// System.out.println(" result == " + result);
return result;
}
String patternStr = "<img\\s*([^>]*)\\s*src=\\\"(.*?)\\\"\\s*([^>]*)>";
Pattern pattern = Pattern.compile(patternStr, Pattern.CASE_INSENSITIVE);
Matcher matcher = pattern.matcher(content);
String result = content;
while (matcher.find()) {
String src = matcher.group(2);
String img = matcher.group(0);
String img2 = matcher.group(0);
// System.out.println("pattern string:"+src);
String replaceSrc = "";
if (!src.startsWith("http:")) {
replaceSrc = replaceHttp + src;
img = img.replaceAll(src, replaceSrc);
result = result.replaceAll(img2, img);
}
}
// System.out.println(" content == " +content);
// System.out.println(" result == " + result);
return result;
}