From 34709bd740acadac813b417241200a56460e43b9 Mon Sep 17 00:00:00 2001 From: "Mata.Li" Date: Thu, 23 Aug 2018 11:15:39 +0800 Subject: [PATCH] REPORT-10171 --- .../design/actions/community/BBSAction.java | 17 +----- .../design/actions/community/BugAction.java | 17 +----- .../actions/community/CenterAction.java | 17 +----- .../actions/community/CusDemandAction.java | 17 +----- .../design/actions/community/NeedAction.java | 17 +----- .../actions/community/QuestionAction.java | 18 +------ .../design/actions/community/SignAction.java | 17 +----- .../actions/community/TechSolutionAction.java | 17 +----- .../design/actions/community/VideoAction.java | 17 +----- .../java/com/fr/design/utils/BrowseUtils.java | 52 ++++++++++++++++++ .../main/java/com/fr/start/ServerStarter.java | 54 ++----------------- 11 files changed, 74 insertions(+), 186 deletions(-) create mode 100644 designer-base/src/main/java/com/fr/design/utils/BrowseUtils.java diff --git a/designer-base/src/main/java/com/fr/design/actions/community/BBSAction.java b/designer-base/src/main/java/com/fr/design/actions/community/BBSAction.java index 8b7e45047d..3964ac151f 100644 --- a/designer-base/src/main/java/com/fr/design/actions/community/BBSAction.java +++ b/designer-base/src/main/java/com/fr/design/actions/community/BBSAction.java @@ -5,6 +5,7 @@ import com.fr.base.FRContext; import com.fr.design.actions.UpdateAction; import com.fr.design.menu.MenuKeySet; +import com.fr.design.utils.BrowseUtils; import com.fr.general.CloudCenter; import com.fr.log.FineLoggerFactory; import com.fr.stable.StringUtils; @@ -37,21 +38,7 @@ public class BBSAction extends UpdateAction public void actionPerformed(ActionEvent arg0) { String url = CloudCenter.getInstance().acquireUrlByKind("bbs"); - if (StringUtils.isEmpty(url)) { - FRContext.getLogger().info("The URL is empty!"); - return; - } - try { - Desktop.getDesktop().browse(new URI(url)); - } catch (IOException exp) { - JOptionPane.showMessageDialog(null, com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Set_Default_Browser")); - FineLoggerFactory.getLogger().error(exp.getMessage(), exp); - } catch (URISyntaxException exp) { - FineLoggerFactory.getLogger().error(exp.getMessage(), exp); - } catch (Exception exp) { - FineLoggerFactory.getLogger().error(exp.getMessage(), exp); - FineLoggerFactory.getLogger().error("Can not open the browser for URL: " + url); - } + BrowseUtils.browser(url); } public static final MenuKeySet BBS = new MenuKeySet() { @Override diff --git a/designer-base/src/main/java/com/fr/design/actions/community/BugAction.java b/designer-base/src/main/java/com/fr/design/actions/community/BugAction.java index 21afd306e9..9dd9f2ae6e 100644 --- a/designer-base/src/main/java/com/fr/design/actions/community/BugAction.java +++ b/designer-base/src/main/java/com/fr/design/actions/community/BugAction.java @@ -4,6 +4,7 @@ import com.fr.base.BaseUtils; import com.fr.base.FRContext; import com.fr.design.actions.UpdateAction; import com.fr.design.menu.MenuKeySet; +import com.fr.design.utils.BrowseUtils; import com.fr.general.CloudCenter; import com.fr.log.FineLoggerFactory; @@ -31,21 +32,7 @@ public class BugAction extends UpdateAction public void actionPerformed(ActionEvent arg0) { String url = CloudCenter.getInstance().acquireUrlByKind("bbs.bugs"); - if (StringUtils.isEmpty(url)) { - FRContext.getLogger().info("The URL is empty!"); - return; - } - try { - Desktop.getDesktop().browse(new URI(url)); - } catch (IOException exp) { - JOptionPane.showMessageDialog(null, com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Set_Default_Browser")); - FineLoggerFactory.getLogger().error(exp.getMessage(), exp); - } catch (URISyntaxException exp) { - FineLoggerFactory.getLogger().error(exp.getMessage(), exp); - } catch (Exception exp) { - FineLoggerFactory.getLogger().error(exp.getMessage(), exp); - FineLoggerFactory.getLogger().error("Can not open the browser for URL: " + url); - } + BrowseUtils.browser(url); } public static final MenuKeySet BUG = new MenuKeySet() { diff --git a/designer-base/src/main/java/com/fr/design/actions/community/CenterAction.java b/designer-base/src/main/java/com/fr/design/actions/community/CenterAction.java index f8c5ea79c2..f168621915 100644 --- a/designer-base/src/main/java/com/fr/design/actions/community/CenterAction.java +++ b/designer-base/src/main/java/com/fr/design/actions/community/CenterAction.java @@ -3,6 +3,7 @@ package com.fr.design.actions.community; import com.fr.base.BaseUtils; import com.fr.base.FRContext; import com.fr.design.menu.MenuKeySet; +import com.fr.design.utils.BrowseUtils; import com.fr.general.CloudCenter; import com.fr.log.FineLoggerFactory; import com.fr.stable.StringUtils; @@ -32,21 +33,7 @@ public class CenterAction extends UpAction{ public void actionPerformed(ActionEvent arg0) { String url = CloudCenter.getInstance().acquireUrlByKind("bbs.center"); - if (StringUtils.isEmpty(url)) { - FRContext.getLogger().info("The URL is empty!"); - return; - } - try { - Desktop.getDesktop().browse(new URI(url)); - } catch (IOException exp) { - JOptionPane.showMessageDialog(null, com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Set_Default_Browser")); - FineLoggerFactory.getLogger().error(exp.getMessage(), exp); - } catch (URISyntaxException exp) { - FineLoggerFactory.getLogger().error(exp.getMessage(), exp); - } catch (Exception exp) { - FineLoggerFactory.getLogger().error(exp.getMessage(), exp); - FineLoggerFactory.getLogger().error("Can not open the browser for URL: " + url); - } + BrowseUtils.browser(url); } public static final MenuKeySet CENTER = new MenuKeySet() { diff --git a/designer-base/src/main/java/com/fr/design/actions/community/CusDemandAction.java b/designer-base/src/main/java/com/fr/design/actions/community/CusDemandAction.java index df9880857b..c3dd646dd4 100644 --- a/designer-base/src/main/java/com/fr/design/actions/community/CusDemandAction.java +++ b/designer-base/src/main/java/com/fr/design/actions/community/CusDemandAction.java @@ -3,6 +3,7 @@ package com.fr.design.actions.community; import com.fr.base.BaseUtils; import com.fr.base.FRContext; import com.fr.design.menu.MenuKeySet; +import com.fr.design.utils.BrowseUtils; import com.fr.general.CloudCenter; import com.fr.log.FineLoggerFactory; import com.fr.stable.StringUtils; @@ -32,21 +33,7 @@ public class CusDemandAction extends UpAction{ public void actionPerformed(ActionEvent arg0) { String url = CloudCenter.getInstance().acquireUrlByKind("bbs.demand"); - if (StringUtils.isEmpty(url)) { - FRContext.getLogger().info("The URL is empty!"); - return; - } - try { - Desktop.getDesktop().browse(new URI(url)); - } catch (IOException exp) { - JOptionPane.showMessageDialog(null, com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Set_Default_Browser")); - FineLoggerFactory.getLogger().error(exp.getMessage(), exp); - } catch (URISyntaxException exp) { - FineLoggerFactory.getLogger().error(exp.getMessage(), exp); - } catch (Exception exp) { - FineLoggerFactory.getLogger().error(exp.getMessage(), exp); - FineLoggerFactory.getLogger().error("Can not open the browser for URL: " + url); - } + BrowseUtils.browser(url); } public static final MenuKeySet DEMAND = new MenuKeySet() { diff --git a/designer-base/src/main/java/com/fr/design/actions/community/NeedAction.java b/designer-base/src/main/java/com/fr/design/actions/community/NeedAction.java index e6e2cc2153..74c862a760 100644 --- a/designer-base/src/main/java/com/fr/design/actions/community/NeedAction.java +++ b/designer-base/src/main/java/com/fr/design/actions/community/NeedAction.java @@ -4,6 +4,7 @@ import com.fr.base.BaseUtils; import com.fr.base.FRContext; import com.fr.design.actions.UpdateAction; import com.fr.design.menu.MenuKeySet; +import com.fr.design.utils.BrowseUtils; import com.fr.general.CloudCenter; import com.fr.log.FineLoggerFactory; @@ -32,21 +33,7 @@ public class NeedAction extends UpdateAction public void actionPerformed(ActionEvent arg0) { String url = CloudCenter.getInstance().acquireUrlByKind("bbs.needs"); - if (StringUtils.isEmpty(url)) { - FRContext.getLogger().info("The URL is empty!"); - return; - } - try { - Desktop.getDesktop().browse(new URI(url)); - } catch (IOException exp) { - JOptionPane.showMessageDialog(null, com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Set_Default_Browser")); - FineLoggerFactory.getLogger().error(exp.getMessage(), exp); - } catch (URISyntaxException exp) { - FineLoggerFactory.getLogger().error(exp.getMessage(), exp); - } catch (Exception exp) { - FineLoggerFactory.getLogger().error(exp.getMessage(), exp); - FineLoggerFactory.getLogger().error("Can not open the browser for URL: " + url); - } + BrowseUtils.browser(url); } public static final MenuKeySet NEED = new MenuKeySet() { diff --git a/designer-base/src/main/java/com/fr/design/actions/community/QuestionAction.java b/designer-base/src/main/java/com/fr/design/actions/community/QuestionAction.java index 7d349affa9..42cf1130d3 100644 --- a/designer-base/src/main/java/com/fr/design/actions/community/QuestionAction.java +++ b/designer-base/src/main/java/com/fr/design/actions/community/QuestionAction.java @@ -4,6 +4,7 @@ import com.fr.base.BaseUtils; import com.fr.base.FRContext; import com.fr.design.actions.UpdateAction; import com.fr.design.menu.MenuKeySet; +import com.fr.design.utils.BrowseUtils; import com.fr.general.CloudCenter; import com.fr.log.FineLoggerFactory; @@ -31,22 +32,7 @@ public class QuestionAction extends UpdateAction public void actionPerformed(ActionEvent arg0) { String url = CloudCenter.getInstance().acquireUrlByKind("bbs.questions"); - if (StringUtils.isEmpty(url)) { - FRContext.getLogger().info("The URL is empty!"); - return; - } - try { - Desktop.getDesktop().browse(new URI(url)); - } catch (IOException exp) { - JOptionPane.showMessageDialog(null, com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Set_Default_Browser")); - FineLoggerFactory.getLogger().error(exp.getMessage(), exp); - } catch (URISyntaxException exp) { - FineLoggerFactory.getLogger().error(exp.getMessage(), exp); - } catch (Exception exp) { - FineLoggerFactory.getLogger().error(exp.getMessage(), exp); - FineLoggerFactory.getLogger().error("Can not open the browser for URL: " + url); - } - + BrowseUtils.browser(url); } public static final MenuKeySet QUESTIONS = new MenuKeySet() { @Override diff --git a/designer-base/src/main/java/com/fr/design/actions/community/SignAction.java b/designer-base/src/main/java/com/fr/design/actions/community/SignAction.java index d0c9cd434d..986e9d40e5 100644 --- a/designer-base/src/main/java/com/fr/design/actions/community/SignAction.java +++ b/designer-base/src/main/java/com/fr/design/actions/community/SignAction.java @@ -5,6 +5,7 @@ import com.fr.base.FRContext; import com.fr.design.actions.UpdateAction; import com.fr.design.menu.MenuKeySet; +import com.fr.design.utils.BrowseUtils; import com.fr.general.CloudCenter; import com.fr.log.FineLoggerFactory; import com.fr.stable.StringUtils; @@ -32,21 +33,7 @@ public class SignAction extends UpdateAction public void actionPerformed(ActionEvent arg0) { String url = CloudCenter.getInstance().acquireUrlByKind("bbs.aut"); - if (StringUtils.isEmpty(url)) { - FRContext.getLogger().info("The URL is empty!"); - return; - } - try { - Desktop.getDesktop().browse(new URI(url)); - } catch (IOException exp) { - JOptionPane.showMessageDialog(null, com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Set_Default_Browser")); - FineLoggerFactory.getLogger().error(exp.getMessage(), exp); - } catch (URISyntaxException exp) { - FineLoggerFactory.getLogger().error(exp.getMessage(), exp); - } catch (Exception exp) { - FineLoggerFactory.getLogger().error(exp.getMessage(), exp); - FineLoggerFactory.getLogger().error("Can not open the browser for URL: " + url); - } + BrowseUtils.browser(url); } public static final MenuKeySet SIGN = new MenuKeySet() { diff --git a/designer-base/src/main/java/com/fr/design/actions/community/TechSolutionAction.java b/designer-base/src/main/java/com/fr/design/actions/community/TechSolutionAction.java index 6e10d851bf..a67c3d5543 100644 --- a/designer-base/src/main/java/com/fr/design/actions/community/TechSolutionAction.java +++ b/designer-base/src/main/java/com/fr/design/actions/community/TechSolutionAction.java @@ -4,6 +4,7 @@ import com.fr.base.BaseUtils; import com.fr.base.FRContext; import com.fr.design.actions.UpdateAction; import com.fr.design.menu.MenuKeySet; +import com.fr.design.utils.BrowseUtils; import com.fr.general.CloudCenter; import com.fr.log.FineLoggerFactory; import com.fr.stable.StringUtils; @@ -33,21 +34,7 @@ public class TechSolutionAction extends UpdateAction{ public void actionPerformed(ActionEvent arg0) { String url = CloudCenter.getInstance().acquireUrlByKind("bbs.solution"); - if (StringUtils.isEmpty(url)) { - FRContext.getLogger().info("The URL is empty!"); - return; - } - try { - Desktop.getDesktop().browse(new URI(url)); - } catch (IOException exp) { - JOptionPane.showMessageDialog(null, com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Set_Default_Browser")); - FineLoggerFactory.getLogger().error(exp.getMessage(), exp); - } catch (URISyntaxException exp) { - FineLoggerFactory.getLogger().error(exp.getMessage(), exp); - } catch (Exception exp) { - FineLoggerFactory.getLogger().error(exp.getMessage(), exp); - FineLoggerFactory.getLogger().error("Can not open the browser for URL: " + url); - } + BrowseUtils.browser(url); } public static final MenuKeySet TSO = new MenuKeySet() { diff --git a/designer-base/src/main/java/com/fr/design/actions/community/VideoAction.java b/designer-base/src/main/java/com/fr/design/actions/community/VideoAction.java index 6919fab005..9fd0405f28 100644 --- a/designer-base/src/main/java/com/fr/design/actions/community/VideoAction.java +++ b/designer-base/src/main/java/com/fr/design/actions/community/VideoAction.java @@ -4,6 +4,7 @@ import com.fr.base.BaseUtils; import com.fr.base.FRContext; import com.fr.design.actions.UpdateAction; import com.fr.design.menu.MenuKeySet; +import com.fr.design.utils.BrowseUtils; import com.fr.general.CloudCenter; import com.fr.general.GeneralContext; import com.fr.log.FineLoggerFactory; @@ -38,21 +39,7 @@ public class VideoAction extends UpdateAction } else { url = CloudCenter.getInstance().acquireUrlByKind("bbs.video"); } - if (StringUtils.isEmpty(url)) { - FRContext.getLogger().info("The URL is empty!"); - return; - } - try { - Desktop.getDesktop().browse(new URI(url)); - } catch (IOException exp) { - JOptionPane.showMessageDialog(null, com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Set_Default_Browser_Duplicate")); - FineLoggerFactory.getLogger().error(exp.getMessage(), exp); - } catch (URISyntaxException exp) { - FineLoggerFactory.getLogger().error(exp.getMessage(), exp); - } catch (Exception exp) { - FineLoggerFactory.getLogger().error(exp.getMessage(), exp); - FineLoggerFactory.getLogger().error("Can not open the browser for URL: " + url); - } + BrowseUtils.browser(url); } public static final MenuKeySet VIDEO = new MenuKeySet() { diff --git a/designer-base/src/main/java/com/fr/design/utils/BrowseUtils.java b/designer-base/src/main/java/com/fr/design/utils/BrowseUtils.java new file mode 100644 index 0000000000..f9078107f9 --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/utils/BrowseUtils.java @@ -0,0 +1,52 @@ +package com.fr.design.utils; + +import com.fr.base.FRContext; +import com.fr.log.FineLoggerFactory; +import com.fr.stable.OperatingSystem; +import com.fr.stable.StringUtils; + +import javax.swing.JOptionPane; +import java.awt.Desktop; +import java.io.IOException; +import java.net.URI; +import java.net.URISyntaxException; + +/** + * Created by XINZAI on 2018/8/23. + */ +public class BrowseUtils { + public static void startBrowserFromCommand(String uri, IOException e) { + + if (OperatingSystem.isWindows()) { + try { + // win10 内存用到到80%左右的时候, Desktop.browser经常提示"存储空间不足, 无法处理改命令", 用rundll32可以打开. + Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + uri); + } catch (IOException ee) { + JOptionPane.showMessageDialog(null, com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Set_Default_Browser_Duplicate")); + FineLoggerFactory.getLogger().error(e.getMessage(), e); + } + } else { + FineLoggerFactory.getLogger().error(e.getMessage(), e); + } + } + + public static void browser(String url) { + + if (StringUtils.isEmpty(url)) { + FRContext.getLogger().info("The URL is empty!"); + return; + } + try { + Desktop.getDesktop().browse(new URI(url)); + } catch (IOException exp) { + startBrowserFromCommand(url, exp); + } catch (URISyntaxException exp) { + FineLoggerFactory.getLogger().error(exp.getMessage(), exp); + } catch (Exception exp) { + FineLoggerFactory.getLogger().error(exp.getMessage(), exp); + FineLoggerFactory.getLogger().error("Can not open the browser for URL: " + url); + } + } + + +} diff --git a/designer-base/src/main/java/com/fr/start/ServerStarter.java b/designer-base/src/main/java/com/fr/start/ServerStarter.java index b916bd6790..2141870b1c 100644 --- a/designer-base/src/main/java/com/fr/start/ServerStarter.java +++ b/designer-base/src/main/java/com/fr/start/ServerStarter.java @@ -1,25 +1,15 @@ package com.fr.start; -import com.fr.base.FRContext; import com.fr.base.ServerConfig; import com.fr.design.DesignerEnvManager; +import com.fr.design.utils.BrowseUtils; import com.fr.general.ComparatorUtils; import com.fr.general.GeneralContext; - -import com.fr.log.FineLoggerFactory; -import com.fr.stable.OperatingSystem; import com.fr.stable.StableUtils; -import com.fr.stable.StringUtils; import com.fr.start.server.FineEmbedServer; import com.fr.workspace.WorkContext; -import javax.swing.*; -import java.awt.*; -import java.io.IOException; -import java.net.URI; -import java.net.URISyntaxException; - public class ServerStarter { /** @@ -30,7 +20,7 @@ public class ServerStarter { if (!WorkContext.getCurrent().isLocal()) { //有问题,这里拿不到远程的http端口 - browser(WorkContext.getCurrent().getPath()); + BrowseUtils.browser(WorkContext.getCurrent().getPath()); } else if (ComparatorUtils.equals(StableUtils.getInstallHome(), ".")) {//august:供代码使用 String web = GeneralContext.getCurrentAppNameOfEnv(); @@ -48,7 +38,7 @@ public class ServerStarter { FineEmbedServer.start(); } finally { //先访问Demo, 后访问报表, 不需要重置服务器. - browser("http://localhost:" + DesignerEnvManager.getEnvManager().getEmbedServerPort() + "/" + GeneralContext.getCurrentAppNameOfEnv() + "/" + ServerConfig.getInstance().getServletName()); + BrowseUtils.browser("http://localhost:" + DesignerEnvManager.getEnvManager().getEmbedServerPort() + "/" + GeneralContext.getCurrentAppNameOfEnv() + "/" + ServerConfig.getInstance().getServletName()); } } @@ -60,42 +50,6 @@ public class ServerStarter { public static void browserURLWithLocalEnv(String url) { FineEmbedServer.start(); - browser(url); + BrowseUtils.browser(url); } - - private static void browser(String uri) { - - if (StringUtils.isEmpty(uri)) { - FRContext.getLogger().info("The URL is empty!"); - return; - } - try { - Desktop.getDesktop().browse(new URI(uri)); - - } catch (IOException e) { - startBrowserFromCommand(uri, e); - } catch (URISyntaxException e) { - FineLoggerFactory.getLogger().error(e.getMessage(), e); - } catch (Exception e) { - FineLoggerFactory.getLogger().error(e.getMessage(), e); - FineLoggerFactory.getLogger().error("Can not open the browser for URL: " + uri); - } - } - - private static void startBrowserFromCommand(String uri, IOException e) { - - if (OperatingSystem.isWindows()) { - try { - // win10 内存用到到80%左右的时候, Desktop.browser经常提示"存储空间不足, 无法处理改命令", 用rundll32可以打开. - Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + uri); - } catch (IOException ee) { - JOptionPane.showMessageDialog(null, com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Set_Default_Browser_Duplicate")); - FineLoggerFactory.getLogger().error(e.getMessage(), e); - } - } else { - FineLoggerFactory.getLogger().error(e.getMessage(), e); - } - } - - }