Browse Source

代码修改

master
kerry 7 years ago
parent
commit
1070f78c4d
  1. 57
      designer-base/src/com/fr/design/extra/PluginWebPane.java

57
designer-base/src/com/fr/design/extra/PluginWebPane.java

@ -1,5 +1,6 @@
package com.fr.design.extra; package com.fr.design.extra;
import com.fr.base.FRContext;
import com.fr.base.TemplateUtils; import com.fr.base.TemplateUtils;
import com.fr.general.IOUtils; import com.fr.general.IOUtils;
import com.fr.stable.StableUtils; import com.fr.stable.StableUtils;
@ -28,7 +29,7 @@ import java.util.Map;
* Created by richie on 16/3/19. * Created by richie on 16/3/19.
*/ */
public class PluginWebPane extends JFXPanel { public class PluginWebPane extends JFXPanel {
private static final String RESOURCE_URL = "resourceURL";
private WebEngine webEngine; private WebEngine webEngine;
public PluginWebPane(final String installHome, final String mainJs) { public PluginWebPane(final String installHome, final String mainJs) {
@ -42,29 +43,8 @@ public class PluginWebPane extends JFXPanel {
WebView webView = new WebView(); WebView webView = new WebView();
webEngine = webView.getEngine(); webEngine = webView.getEngine();
try{ try{
InputStream inp = IOUtils.readResource(StableUtils.pathJoin(installHome, mainJs)); String htmlString = getRenderedHtml(installHome, mainJs);
if (inp == null) {
throw new IOException("Not found template: " + mainJs);
}
BufferedReader reader = new BufferedReader(new InputStreamReader(inp, StableUtils.RESOURCE_ENCODER));
BufferedReader read = new BufferedReader(reader);
StringBuffer sb = new StringBuffer();
String line;
Map<String, Object> map4Tpl = new HashMap<String, Object>();
map4Tpl.put("servletURL", "file:///" + URLEncoder.encode(installHome, "UTF-8"));
while ((line = read.readLine()) != null) {
if (sb.length() > 0) {
sb.append('\n');
}
sb.append(line);
}
String htmlString = TemplateUtils.renderParameter4Tpl(sb.toString(), map4Tpl);
reader.close();
inp.close();
webEngine.loadContent(htmlString); webEngine.loadContent(htmlString);
webEngine.setOnAlert(new EventHandler<WebEvent<String>>() { webEngine.setOnAlert(new EventHandler<WebEvent<String>>() {
@Override @Override
public void handle(WebEvent<String> event) { public void handle(WebEvent<String> event) {
@ -76,13 +56,42 @@ public class PluginWebPane extends JFXPanel {
webView.setContextMenuEnabled(false);//屏蔽右键 webView.setContextMenuEnabled(false);//屏蔽右键
root.setCenter(webView); root.setCenter(webView);
}catch (Exception e){ }catch (Exception e){
FRContext.getLogger().error(e.getMessage(), e);
} }
} }
}); });
} }
private String getRenderedHtml(String installHome, String mainJs) throws IOException {
InputStream inp = IOUtils.readResource(StableUtils.pathJoin(installHome, mainJs));
if (inp == null) {
throw new IOException("Not found template: " + mainJs);
}
BufferedReader reader = new BufferedReader(new InputStreamReader(inp, StableUtils.RESOURCE_ENCODER));
BufferedReader read = new BufferedReader(reader);
StringBuffer sb = new StringBuffer();
String line;
Map<String, Object> map4Tpl = new HashMap<String, Object>();
map4Tpl.put(RESOURCE_URL, "file:///" + URLEncoder.encode(installHome, "UTF-8"));
while ((line = read.readLine()) != null) {
if (sb.length() > 0) {
sb.append('\n');
}
sb.append(line);
}
String htmlString = StringUtils.EMPTY;
try{
htmlString = TemplateUtils.renderParameter4Tpl(sb.toString(), map4Tpl);
}catch (Exception e){
FRContext.getLogger().error(e.getMessage(), e);
}
reader.close();
inp.close();
return htmlString;
}
private void showAlert(final String message) { private void showAlert(final String message) {
SwingUtilities.invokeLater(new Runnable() { SwingUtilities.invokeLater(new Runnable() {
@Override @Override

Loading…
Cancel
Save