Browse Source

KERNEL-594 版本信息

bugfix/10.0
richie 6 years ago
parent
commit
d2588b02dd
  1. 5
      designer-base/src/main/java/com/fr/design/ui/Assistant.java
  2. 43
      designer-base/src/main/java/com/fr/design/ui/EmbProtocolHandler.java
  3. 2
      designer-base/src/main/java/com/fr/design/upm/UpmShowPane.java
  4. 21
      designer-base/src/main/java/com/fr/design/upm/UpmUtils.java

5
designer-base/src/main/java/com/fr/design/ui/Assistant.java

@ -41,6 +41,9 @@ public class Assistant {
if (path.endsWith(".js")) {
return "text/javascript";
}
if (path.endsWith(".svg")) {
return "image/svg+xml";
}
return "text/html";
}
@ -49,6 +52,6 @@ public class Assistant {
ProtocolService protocolService = browserContext.getProtocolService();
// 支持读取jar包中文件的自定义协议————emb:/com/fr/design/images/bbs.png
protocolService.setProtocolHandler("emb", handler);
//protocolService.setProtocolHandler("file", handler);
protocolService.setProtocolHandler("file", handler);
}
}

43
designer-base/src/main/java/com/fr/design/ui/EmbProtocolHandler.java

@ -2,6 +2,8 @@ package com.fr.design.ui;
import com.fr.base.TemplateUtils;
import com.fr.general.IOUtils;
import com.fr.log.FineLoggerFactory;
import com.fr.stable.EncodeConstants;
import com.fr.stable.StringUtils;
import com.fr.third.org.apache.commons.codec.net.URLCodec;
import com.fr.third.org.apache.commons.io.FileUtils;
@ -15,11 +17,14 @@ import com.teamdev.jxbrowser.chromium.ProtocolHandler;
import com.teamdev.jxbrowser.chromium.URLRequest;
import com.teamdev.jxbrowser.chromium.URLResponse;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.StringReader;
import java.net.URI;
import java.nio.charset.StandardCharsets;
import java.util.Map;
/**
@ -51,21 +56,20 @@ public class EmbProtocolHandler implements ProtocolHandler {
@Override
public URLResponse onRequest(URLRequest req) {
InputStream inputStream = null;
try {
String path = req.getURL();
if (path.startsWith("file:")) {
String url = new URLCodec().decode(path);
String filePath = TemplateUtils.renderParameter4Tpl(url, map);
File file = new File(URI.create(filePath).getPath());
InputStream inputStream = new FileInputStream(file);
if (path.endsWith(".svg")) {
System.out.println(path);
}
return Assistant.inputStream2Response(inputStream, "file:///" + file.getAbsolutePath());
}
else if (path.startsWith("emb:dynamic")) {
inputStream = IOUtils.readResource(file.getAbsolutePath());
String text = IOUtils.inputStream2String(inputStream, EncodeConstants.ENCODING_UTF_8);
text = TemplateUtils.renderParameter4Tpl(text, map);
return Assistant.inputStream2Response(new ByteArrayInputStream(text.getBytes(StandardCharsets.UTF_8)), path);
} else if (path.startsWith("emb:dynamic")) {
URLResponse response = new URLResponse();
response.setData(htmlText().getBytes());
response.setData(htmlText(map).getBytes());
response.getHeaders().setHeader("Content-Type", "text/html");
return response;
} else {
@ -75,16 +79,24 @@ public class EmbProtocolHandler implements ProtocolHandler {
} else {
path = path.substring(4);
}
InputStream inputStream = IOUtils.readResource(path);
inputStream = IOUtils.readResource(path);
return Assistant.inputStream2Response(inputStream, path);
}
} catch (Exception ignore) {
ignore.printStackTrace();
} catch (Exception e) {
FineLoggerFactory.getLogger().info(e.getMessage());
} finally {
if (inputStream != null) {
try {
inputStream.close();
} catch (IOException e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
}
}
return null;
}
private String htmlText() {
private String htmlText(Map<String, String> map) {
PathGroup pathGroup = AtomBuilder.create().buildAssembleFilePath(ModernRequestClient.KEY, component);
StylePath[] stylePaths = pathGroup.toStylePathGroup();
StringBuilder styleText = new StringBuilder();
@ -106,6 +118,13 @@ public class EmbProtocolHandler implements ProtocolHandler {
}
}
result = result.replaceAll("##script##", scriptText.toString());
if (map != null) {
for (Map.Entry<String, String> entry : map.entrySet()) {
String key = entry.getKey();
String value = entry.getValue();
result = result.replaceAll("\\$\\{" + key + "}", value);
}
}
return result;
}
}

2
designer-base/src/main/java/com/fr/design/upm/UpmShowPane.java

@ -38,7 +38,7 @@ public class UpmShowPane extends BasicPane {
window.asObject().setProperty("PluginHelper", UpmBridge.getBridge(event.getBrowser()));
}
})
.withURL(UpmFinder.getMainResourcePath())
.withURL(UpmFinder.getMainResourcePath(), UpmUtils.renderMap())
.build();
} else {
modernUIPane = new ModernUIPane.Builder<>()

21
designer-base/src/main/java/com/fr/design/upm/UpmUtils.java

@ -1,7 +1,13 @@
package com.fr.design.upm;
import com.fr.config.ServerPreferenceConfig;
import com.fr.general.CloudCenter;
import com.fr.stable.StringUtils;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @author richie
@ -18,4 +24,19 @@ public class UpmUtils {
}
return list.toArray(new String[0]);
}
public static Map<String, String> renderMap() {
Map<String, String> map4Tpl = new HashMap<>();
map4Tpl.put("version", ServerPreferenceConfig.getInstance().getOptimizedUPMVersion());
map4Tpl.put("new_version", fetchLatestVersion());
return map4Tpl;
}
private static String fetchLatestVersion() {
String version = CloudCenter.getInstance().acquireUrlByKind("upm.script.version");
if (StringUtils.isBlank(version)) {
version = "1.0";
}
return version;
}
}

Loading…
Cancel
Save