From 9326872cf3de145789b973bc6c62d8baf116a342 Mon Sep 17 00:00:00 2001 From: vito Date: Mon, 17 Oct 2016 15:26:55 +0800 Subject: [PATCH] =?UTF-8?q?=E6=97=A0jira=E4=BB=BB=E5=8A=A1=EF=BC=8C?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=97=A0=E7=BD=91=E7=9A=84=E6=97=B6=E5=80=99?= =?UTF-8?q?=E6=8A=A54=E4=B8=AAnul=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/com/fr/design/extra/PluginHelper.java | 13 +-- .../design/extra/PluginsReaderFromStore.java | 88 +++++++++---------- .../exe/GetPluginCategoriesExecutor.java | 11 ++- .../extra/exe/GetPluginFromStoreExecutor.java | 37 ++++---- 4 files changed, 82 insertions(+), 67 deletions(-) diff --git a/designer_base/src/com/fr/design/extra/PluginHelper.java b/designer_base/src/com/fr/design/extra/PluginHelper.java index 5d0c9fa1a9..ed35251db5 100644 --- a/designer_base/src/com/fr/design/extra/PluginHelper.java +++ b/designer_base/src/com/fr/design/extra/PluginHelper.java @@ -38,6 +38,7 @@ public class PluginHelper { //插件依赖的下载位置 public static final String DEPENDENCE_DOWNLOAD_PATH = System.getProperty("user.dir") + "/download/dependence"; public static final String TEMP_FILE = "temp.zip"; + public static final String CONNECTION_404 = "404"; /** * 下载插件 @@ -130,7 +131,7 @@ public class PluginHelper { //将所有未配置好的资源文件依赖准备好 private static void checkDependenceEnv(Plugin plugin) throws PluginDependenceException { PluginDependence dependence = plugin.getDependence(); - if (dependence == null){ + if (dependence == null) { return; } @@ -138,14 +139,14 @@ public class PluginHelper { String currentID = dependence.getCurrentPluginID(); List list = dependence.getDependPlugins(); - for (int i = 0;list != null && i < list.size(); i++){ + for (int i = 0; list != null && i < list.size(); i++) { PluginDependenceUnit dependenceUnit = list.get(i); - if (!dependenceUnit.checkFileEnv()){ + if (!dependenceUnit.checkFileEnv()) { needInstallDependence.add(dependenceUnit); } } - if (needInstallDependence.isEmpty()){ + if (needInstallDependence.isEmpty()) { return; } @@ -156,14 +157,16 @@ public class PluginHelper { /** * 构造一个下载UI + * * @param currentID * @param list * @throws PluginDependenceException */ - private static void installDependenceOnline(String currentID, List list) throws PluginDependenceException{ + private static void installDependenceOnline(String currentID, List list) throws PluginDependenceException { DownLoadDependenceUI ui = new DownLoadDependenceUI(currentID, list); ui.installOnline(); } + /** * 从选中的压缩文件中安装插件 * diff --git a/designer_base/src/com/fr/design/extra/PluginsReaderFromStore.java b/designer_base/src/com/fr/design/extra/PluginsReaderFromStore.java index 8c77141ca7..abd053362a 100644 --- a/designer_base/src/com/fr/design/extra/PluginsReaderFromStore.java +++ b/designer_base/src/com/fr/design/extra/PluginsReaderFromStore.java @@ -31,30 +31,30 @@ public class PluginsReaderFromStore { * @return 插件信息 */ public static Plugin[] readPlugins() throws Exception { - String resText; + String resText; + try { + HttpClient httpClient = new HttpClient(SiteCenter.getInstance().acquireUrlByKind("plugin.store")); + resText = httpClient.getResponseText(); + String charSet = EncodeConstants.ENCODING_UTF_8; + resText = URLDecoder.decode(URLDecoder.decode(resText, charSet), charSet); + } catch (Exception e) { + throw new Exception(Inter.getLocText("FR-Designer-Plugin_PluginMarket_Coding")); + } + if (StringUtils.isNotEmpty(resText)) { try { - HttpClient httpClient = new HttpClient(SiteCenter.getInstance().acquireUrlByKind("plugin.store")); - resText = httpClient.getResponseText(); - String charSet = EncodeConstants.ENCODING_UTF_8; - resText = URLDecoder.decode(URLDecoder.decode(resText, charSet), charSet); - } catch (Exception e) { - throw new Exception(Inter.getLocText("FR-Designer-Plugin_PluginMarket_Coding")); - } - if (StringUtils.isNotEmpty(resText)) { - try { - plugins.clear();//先清空set - JSONArray jsonArray = new JSONArray(resText); - for (int i = 0, size = jsonArray.length(); i < size; i++) { - Plugin plugin = new Plugin(); - plugin.parseJSON(jsonArray.optJSONObject(i)); - if (plugin.isValidate()) { - plugins.add(plugin); - } + plugins.clear();//先清空set + JSONArray jsonArray = new JSONArray(resText); + for (int i = 0, size = jsonArray.length(); i < size; i++) { + Plugin plugin = new Plugin(); + plugin.parseJSON(jsonArray.optJSONObject(i)); + if (plugin.isValidate()) { + plugins.add(plugin); } - } catch (JSONException e) { - throw new Exception(Inter.getLocText("FR-Designer-Plugin_Read_Plugin_List_Error")); } + } catch (JSONException e) { + throw new Exception(Inter.getLocText("FR-Designer-Plugin_Read_Plugin_List_Error")); } + } return plugins.toArray(new Plugin[plugins.size()]); } @@ -65,35 +65,33 @@ public class PluginsReaderFromStore { * @return 插件信息 */ public static Plugin[] readPluginsForUpdate() throws Exception { - String resText; + String resText = null; + String url = SiteCenter.getInstance().acquireUrlByKind("plugin.update"); + if (StringUtils.isNotEmpty(url)) { + HashMap para = new HashMap(); + para.put("plugins", PluginLoader.getLoader().pluginsToString()); + //只有当前设计器的jar高于插件新版本需要的jarTime时, 才提示更新该插件. + para.put("jarTime", GeneralUtils.readBuildNO()); + HttpClient httpClient = new HttpClient(url, para); + resText = httpClient.getResponseText(); + String charSet = EncodeConstants.ENCODING_UTF_8; + resText = URLDecoder.decode(URLDecoder.decode(resText, charSet), charSet); + } + if (StringUtils.isNotEmpty(resText)) { try { - HashMap para = new HashMap(); - para.put("plugins", PluginLoader.getLoader().pluginsToString()); - //只有当前设计器的jar高于插件新版本需要的jarTime时, 才提示更新该插件. - para.put("jarTime", GeneralUtils.readBuildNO()); - HttpClient httpClient = new HttpClient(SiteCenter.getInstance().acquireUrlByKind("plugin.update"), para); - resText = httpClient.getResponseText(); - String charSet = EncodeConstants.ENCODING_UTF_8; - resText = URLDecoder.decode(URLDecoder.decode(resText, charSet), charSet); - } catch (Exception e) { - throw new Exception(Inter.getLocText("FR-Designer-Plugin_PluginMarket_Coding")); - } - if (StringUtils.isNotEmpty(resText)) { - try { - pluginsToUpdate.clear(); - JSONArray jsonArray = new JSONArray(resText); - for (int i = 0, size = jsonArray.length(); i < size; i++) { - Plugin plugin = new Plugin(); - plugin.parseJSON(jsonArray.optJSONObject(i)); - if (plugin.isValidate()) { - pluginsToUpdate.add(plugin); - } + pluginsToUpdate.clear(); + JSONArray jsonArray = new JSONArray(resText); + for (int i = 0, size = jsonArray.length(); i < size; i++) { + Plugin plugin = new Plugin(); + plugin.parseJSON(jsonArray.optJSONObject(i)); + if (plugin.isValidate()) { + pluginsToUpdate.add(plugin); } - } catch (JSONException e) { - throw new Exception(Inter.getLocText("FR-Designer-Plugin_Read_Plugin_List_Error")); } + } catch (JSONException e) { + throw new Exception(Inter.getLocText("FR-Designer-Plugin_Read_Plugin_List_Error")); } - + } return pluginsToUpdate.toArray(new Plugin[pluginsToUpdate.size()]); } diff --git a/designer_base/src/com/fr/design/extra/exe/GetPluginCategoriesExecutor.java b/designer_base/src/com/fr/design/extra/exe/GetPluginCategoriesExecutor.java index 81bdb8f8c7..92aa0bbe81 100644 --- a/designer_base/src/com/fr/design/extra/exe/GetPluginCategoriesExecutor.java +++ b/designer_base/src/com/fr/design/extra/exe/GetPluginCategoriesExecutor.java @@ -1,5 +1,6 @@ package com.fr.design.extra.exe; +import com.fr.design.extra.PluginHelper; import com.fr.design.extra.Process; import com.fr.general.SiteCenter; import com.fr.general.http.HttpClient; @@ -26,8 +27,14 @@ public class GetPluginCategoriesExecutor implements Executor { @Override public void run(Process process) { - HttpClient httpClient = new HttpClient(SiteCenter.getInstance().acquireUrlByKind("plugin.category")); - result = httpClient.getResponseText(); + String url = SiteCenter.getInstance().acquireUrlByKind("plugin.category"); + if (url != null) { + HttpClient httpClient = new HttpClient(url); + result = httpClient.getResponseText(); + } else { + result = PluginHelper.CONNECTION_404; + } + } } }; diff --git a/designer_base/src/com/fr/design/extra/exe/GetPluginFromStoreExecutor.java b/designer_base/src/com/fr/design/extra/exe/GetPluginFromStoreExecutor.java index 35fde2e139..9bd7e2bbef 100644 --- a/designer_base/src/com/fr/design/extra/exe/GetPluginFromStoreExecutor.java +++ b/designer_base/src/com/fr/design/extra/exe/GetPluginFromStoreExecutor.java @@ -1,5 +1,6 @@ package com.fr.design.extra.exe; +import com.fr.design.extra.PluginHelper; import com.fr.design.extra.Process; import com.fr.general.FRLogger; import com.fr.general.SiteCenter; @@ -38,21 +39,27 @@ public class GetPluginFromStoreExecutor implements Executor { @Override public void run(Process process) { - StringBuilder url = new StringBuilder(SiteCenter.getInstance().acquireUrlByKind("plugin.plist")); - if (StringUtils.isNotBlank(category)) { - url.append("&cid=").append(category.split("-")[1]); - } - if (StringUtils.isNotBlank(seller)) { - url.append("&seller=").append(seller.split("-")[1]); - } - if (StringUtils.isNotBlank(fee)) { - url.append("&fee=").append(fee.split("-")[1]); - } - try { - HttpClient httpClient = new HttpClient(url.toString()); - result = httpClient.getResponseText(); - } catch (Exception e) { - FRLogger.getLogger().error(e.getMessage()); + String plistUrl = SiteCenter.getInstance().acquireUrlByKind("plugin.plist"); + if (StringUtils.isNotBlank(plistUrl)) { + StringBuilder url = new StringBuilder(); + url.append(plistUrl); + if (StringUtils.isNotBlank(category)) { + url.append("&cid=").append(category.split("-")[1]); + } + if (StringUtils.isNotBlank(seller)) { + url.append("&seller=").append(seller.split("-")[1]); + } + if (StringUtils.isNotBlank(fee)) { + url.append("&fee=").append(fee.split("-")[1]); + } + try { + HttpClient httpClient = new HttpClient(url.toString()); + result = httpClient.getResponseText(); + } catch (Exception e) { + FRLogger.getLogger().error(e.getMessage()); + } + } else { + result = PluginHelper.CONNECTION_404; } } }