Browse Source

REPORT-102243 修复图表富文本编辑器自定义样式图标异常

new-design
vito 1 year ago
parent
commit
77632dba9f
  1. 11
      designer-base/src/main/java/com/fr/design/jxbrowser/MimeType.java
  2. 14
      designer-base/src/main/java/com/fr/design/jxbrowser/NxInterceptRequestCallback.java

11
designer-base/src/main/java/com/fr/design/jxbrowser/MimeType.java

@ -83,21 +83,20 @@ public enum MimeType {
* 如果没有尝试使用 Files.probeContentType 检测 * 如果没有尝试使用 Files.probeContentType 检测
* 如果没有默认返回 text/html * 如果没有默认返回 text/html
* *
* @param url url路径 * @param resourcePath 资源路径
* @return MimeType * @return MimeType
*/ */
public static String parseMimeType(String url) { public static String parseMimeType(String resourcePath) {
if (StringUtils.isBlank(url)) { if (StringUtils.isBlank(resourcePath)) {
return HTML.mimeType; return HTML.mimeType;
} }
String finalPath = url.split("\\?")[0];
Optional<MimeType> mimeType = Arrays.stream(values()) Optional<MimeType> mimeType = Arrays.stream(values())
.filter(type -> finalPath.endsWith(type.suffix)) .filter(type -> resourcePath.endsWith(type.suffix))
.findFirst(); .findFirst();
if (mimeType.isPresent()) { if (mimeType.isPresent()) {
return mimeType.get().mimeType; return mimeType.get().mimeType;
} else { } else {
return getFileMimeType(finalPath); return getFileMimeType(resourcePath);
} }
} }

14
designer-base/src/main/java/com/fr/design/jxbrowser/NxInterceptRequestCallback.java

@ -20,6 +20,7 @@ import com.teamdev.jxbrowser.net.callback.InterceptUrlRequestCallback;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.io.InputStream; import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder; import java.net.URLDecoder;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.Map; import java.util.Map;
@ -80,8 +81,9 @@ public class NxInterceptRequestCallback implements InterceptUrlRequestCallback {
protected Optional<UrlRequestJob> generateFileProtocolUrlRequestJob(Params params, String path) { protected Optional<UrlRequestJob> generateFileProtocolUrlRequestJob(Params params, String path) {
try { try {
InputStream inputStream = getResourceStream(path); String resourcePath = getResourcePath(path);
String mimeType = MimeType.parseMimeType(path); InputStream inputStream = getResourceStream(resourcePath);
String mimeType = MimeType.parseMimeType(resourcePath);
byte[] bytes; byte[] bytes;
if (isHtml(mimeType)) { if (isHtml(mimeType)) {
String text = IOUtils.inputStream2String(inputStream, EncodeConstants.ENCODING_UTF_8); String text = IOUtils.inputStream2String(inputStream, EncodeConstants.ENCODING_UTF_8);
@ -104,7 +106,11 @@ public class NxInterceptRequestCallback implements InterceptUrlRequestCallback {
* @return 输入流 * @return 输入流
* @throws Exception IO异常 * @throws Exception IO异常
*/ */
private InputStream getResourceStream(String path) throws Exception { private InputStream getResourceStream(String path) {
return IOUtils.readResource(path);
}
private static String getResourcePath(String path) throws UnsupportedEncodingException {
int index = path.indexOf("="); int index = path.indexOf("=");
if (index > 0) { if (index > 0) {
path = path.substring(index + 1); path = path.substring(index + 1);
@ -115,7 +121,7 @@ public class NxInterceptRequestCallback implements InterceptUrlRequestCallback {
// 通过自定义协议之后的url会自动encode一些中文字符,这里做一个decode,否则会导致路径访问失败 // 通过自定义协议之后的url会自动encode一些中文字符,这里做一个decode,否则会导致路径访问失败
path = URLDecoder.decode(path, StandardCharsets.UTF_8.name()); path = URLDecoder.decode(path, StandardCharsets.UTF_8.name());
} }
return IOUtils.readResource(path); return path;
} }
private boolean isHtml(String mimeType) { private boolean isHtml(String mimeType) {

Loading…
Cancel
Save