fix 通知图片自适应问题

master
luoyang 6 years ago
parent 5307167a37
commit f40804411e

@ -9,7 +9,7 @@
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<artifactId>manage</artifactId> <artifactId>manage</artifactId>
<version>1.4.11</version> <version>1.4.12</version>
<properties> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<jib-maven-plugin.version>1.8.0</jib-maven-plugin.version> <jib-maven-plugin.version>1.8.0</jib-maven-plugin.version>

@ -12,6 +12,8 @@ import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/** /**
* Created by yishuqian on 28/09/2016. * Created by yishuqian on 28/09/2016.
@ -54,6 +56,9 @@ public class NoticeInfo {
} }
res.put("merchants_type",merchants_type); res.put("merchants_type",merchants_type);
if (content != null){ if (content != null){
if (content.contains("<img")) {
initImgAutoSize();
}
res.put("content",content); res.put("content",content);
} }
if (status != null && status != "0"){ if (status != null && status != "0"){
@ -106,6 +111,31 @@ public class NoticeInfo {
} }
return res; return res;
} }
private void initImgAutoSize() {
String regxpForIMGTag = "<\\s*img\\s+([^>]*)\\s*/>";
Pattern pattern = Pattern.compile(regxpForIMGTag);
Matcher matcher = pattern.matcher(content);
while (matcher.find()) {
String imgStr = matcher.group(1);
String regxpForWidth = "width=\"([^\"]+)\"";
String regxpForHeight = "height=\"([^\"]+)\"";
Matcher matcherForWidth = Pattern.compile(regxpForWidth).matcher(imgStr);
if (matcherForWidth.find()){
setContent(content.replaceAll("(<img[^>]*?)\\s+width\\s*=\\s*\\S+", "$1 width=100%"));
}else {
String regex = "(?i)(\\<img)([^\\>]+\\>)";
setContent(content.replaceAll(regex, "$1 width =\"100%\"$2"));
}
Matcher matcherForHeight = Pattern.compile(regxpForHeight).matcher(imgStr);
if (matcherForHeight.find()){
setContent(content.replaceAll("(<img[^>]*?)\\s+height\\s*=\\s*\\S+", "$1 height=100%"));
}else {
String regex = "(?i)(\\<img)([^\\>]+\\>)";
setContent(content.replaceAll(regex, "$1 height =\"100%\"$2"));
}
}
}
public String getTitle() { public String getTitle() {
return title; return title;
} }

Loading…
Cancel
Save