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