From 94113f6b0e258a98a749fda50d6a9572f154db6e Mon Sep 17 00:00:00 2001 From: kerry Date: Sat, 27 May 2017 14:31:21 +0800 Subject: [PATCH] REPORT-235 --- .../fr/design/extra/PluginOperateUtils.java | 81 +++++++++++++++++++ .../com/fr/design/extra/PluginWebBridge.java | 20 ++--- .../callback/AbstractPluginTaskCallback.java | 1 - .../extra/exe/callback/DownloadCallback.java | 1 - .../exe/callback/InstallFromDiskCallback.java | 6 +- .../exe/callback/InstallOnlineCallback.java | 1 - 6 files changed, 94 insertions(+), 16 deletions(-) diff --git a/designer_base/src/com/fr/design/extra/PluginOperateUtils.java b/designer_base/src/com/fr/design/extra/PluginOperateUtils.java index beb84b9c6..00e610eb0 100644 --- a/designer_base/src/com/fr/design/extra/PluginOperateUtils.java +++ b/designer_base/src/com/fr/design/extra/PluginOperateUtils.java @@ -1,11 +1,14 @@ package com.fr.design.extra; import com.fr.base.FRContext; +import com.fr.design.DesignerEnvManager; import com.fr.design.extra.exe.callback.*; import com.fr.design.extra.exe.extratask.InstallPluginTask; import com.fr.design.extra.exe.extratask.UpdatePluginTask; import com.fr.general.FRLogger; import com.fr.general.Inter; +import com.fr.general.SiteCenter; +import com.fr.general.http.HttpClient; import com.fr.json.JSONObject; import com.fr.plugin.context.PluginContext; import com.fr.plugin.context.PluginMarker; @@ -17,6 +20,7 @@ import com.fr.stable.ArrayUtils; import com.fr.stable.StringUtils; import javafx.scene.web.WebEngine; import netscape.javascript.JSObject; +import org.json.JSONArray; import sun.plugin2.main.server.Plugin; import javax.swing.*; @@ -96,6 +100,83 @@ public class PluginOperateUtils { PluginManager.getController().uninstall(pluginMarker, isForce, new UnistallPluginCallback()); } + public static void readUpdateOnline(JSCallback jsCallback){ + try { + String [] plugins = PluginReaderForDesigner.readPluginsForUpdate(); + JSONArray jsonArray = new JSONArray(); + for (String plugin : plugins) { + org.json.JSONObject jsonObject = new org.json.JSONObject(); + jsonObject.put("pluginid", plugin); + jsonArray.put(jsonObject); + } + String result = jsonArray.toString(); + jsCallback.execute(result); + } catch (Exception e) { + FRLogger.getLogger().error(e.getMessage()); + } + + } + + public static void searchPlugin(String keyword, JSCallback jsCallback) { + try { + HttpClient httpClient = new HttpClient(SiteCenter.getInstance().acquireUrlByKind("plugin.plist") + "&keyword=" + keyword); + String result = httpClient.getResponseText(); + jsCallback.execute(result); + } catch (Exception e) { + FRLogger.getLogger().error(e.getMessage()); + } + } + + public static void getPluginFromStore(String category, String seller, String fee, JSCallback jsCallback){ + 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()); + String result = httpClient.getResponseText(); + jsCallback.execute(result); + } catch (Exception e) { + FRLogger.getLogger().error(e.getMessage()); + } + } else { + String result = PluginConstants.CONNECTION_404; + jsCallback.execute(result); + } + } + + public static void getPluginCategories(JSCallback jsCallback){ + String result; + String url = SiteCenter.getInstance().acquireUrlByKind("plugin.category"); + if (url != null) { + HttpClient httpClient = new HttpClient(url); + result = httpClient.getResponseText(); + } else { + result = PluginConstants.CONNECTION_404; + } + jsCallback.execute(result); + } + + public static void getLoginInfo(JSCallback jsCallback){ + String username = BBSPluginLogin.getInstance().getUserInfo().getUserName(); + String inShowUsername = DesignerEnvManager.getEnvManager().getInShowBBsName(); + if (StringUtils.isEmpty(username) && StringUtils.isEmpty(inShowUsername)) { + return; + }else { + String result = StringUtils.isEmpty(inShowUsername) ? username : inShowUsername; + jsCallback.execute(result); + } + } + private static String[] jsObjectToStringArray(JSObject obj) { if (obj == null) { return ArrayUtils.EMPTY_STRING_ARRAY; diff --git a/designer_base/src/com/fr/design/extra/PluginWebBridge.java b/designer_base/src/com/fr/design/extra/PluginWebBridge.java index 808eabfe1..5f5caac5d 100644 --- a/designer_base/src/com/fr/design/extra/PluginWebBridge.java +++ b/designer_base/src/com/fr/design/extra/PluginWebBridge.java @@ -209,8 +209,8 @@ public class PluginWebBridge { * 已安装插件检查更新 */ public void readUpdateOnline(final JSObject callback) { - Task task = new PluginTask<>(webEngine, callback, new ReadUpdateOnlineExecutor()); - new Thread(task).start(); + JSCallback jsCallback = new JSCallback(webEngine, callback); + PluginOperateUtils.readUpdateOnline(jsCallback); } /** @@ -303,8 +303,8 @@ public class PluginWebBridge { * @param keyword 关键字 */ public void searchPlugin(String keyword, final JSObject callback) { - Task task = new PluginTask<>(webEngine, callback, new SearchOnlineExecutor(keyword)); - new Thread(task).start(); + JSCallback jsCallback = new JSCallback(webEngine, callback); + PluginOperateUtils.searchPlugin(keyword, jsCallback); } /** @@ -316,8 +316,8 @@ public class PluginWebBridge { * @param callback 回调函数 */ public void getPluginFromStore(String category, String seller, String fee, final JSObject callback) { - Task task = new PluginTask<>(webEngine, callback, new GetPluginFromStoreExecutor(category, seller, fee)); - new Thread(task).start(); + JSCallback jsCallback = new JSCallback(webEngine, callback); + PluginOperateUtils.getPluginFromStore(category, seller, fee, jsCallback); } /** @@ -326,8 +326,8 @@ public class PluginWebBridge { * @param callback 回调函数 */ public void getPluginCategories(final JSObject callback) { - Task task = new PluginTask<>(webEngine, callback, new GetPluginCategoriesExecutor()); - new Thread(task).start(); + JSCallback jsCallback = new JSCallback(webEngine, callback); + PluginOperateUtils.getPluginCategories(jsCallback); } /** @@ -377,8 +377,8 @@ public class PluginWebBridge { * @param callback */ public void getLoginInfo(final JSObject callback) { - Task task = new PluginTask<>(webEngine, callback, new GetLoginInfoExecutor()); - new Thread(task).start(); + JSCallback jsCallback = new JSCallback(webEngine, callback); + PluginOperateUtils.getLoginInfo(jsCallback); } /** diff --git a/designer_base/src/com/fr/design/extra/exe/callback/AbstractPluginTaskCallback.java b/designer_base/src/com/fr/design/extra/exe/callback/AbstractPluginTaskCallback.java index b0d4813cf..c641c622f 100644 --- a/designer_base/src/com/fr/design/extra/exe/callback/AbstractPluginTaskCallback.java +++ b/designer_base/src/com/fr/design/extra/exe/callback/AbstractPluginTaskCallback.java @@ -3,7 +3,6 @@ package com.fr.design.extra.exe.callback; import com.fr.plugin.context.PluginMarker; import com.fr.plugin.manage.control.ProgressCallback; -import java.io.File; /** * Created by ibm on 2017/5/26. diff --git a/designer_base/src/com/fr/design/extra/exe/callback/DownloadCallback.java b/designer_base/src/com/fr/design/extra/exe/callback/DownloadCallback.java index 405a41528..d12f50592 100644 --- a/designer_base/src/com/fr/design/extra/exe/callback/DownloadCallback.java +++ b/designer_base/src/com/fr/design/extra/exe/callback/DownloadCallback.java @@ -3,7 +3,6 @@ package com.fr.design.extra.exe.callback; import com.fr.design.extra.exe.extratask.ExtraPluginTask; import com.fr.general.Inter; import com.fr.plugin.manage.control.PluginTaskResult; -import com.fr.plugin.manage.control.ProgressCallback; import javax.swing.*; diff --git a/designer_base/src/com/fr/design/extra/exe/callback/InstallFromDiskCallback.java b/designer_base/src/com/fr/design/extra/exe/callback/InstallFromDiskCallback.java index 4c64d1426..bd2f3bec1 100644 --- a/designer_base/src/com/fr/design/extra/exe/callback/InstallFromDiskCallback.java +++ b/designer_base/src/com/fr/design/extra/exe/callback/InstallFromDiskCallback.java @@ -11,9 +11,10 @@ import java.io.File; /** * Created by ibm on 2017/5/26. */ -public class InstallFromDiskCallback extends AbstractPluginTaskCallback{ +public class InstallFromDiskCallback extends AbstractPluginTaskCallback { private File zipFile; - public InstallFromDiskCallback(File zipFile, JSCallback jsCallback){ + + public InstallFromDiskCallback(File zipFile, JSCallback jsCallback) { this.zipFile = zipFile; this.jsCallback = jsCallback; } @@ -44,7 +45,6 @@ public class InstallFromDiskCallback extends AbstractPluginTaskCallback{ return; } PluginManager.getController().install(zipFile, new InstallFromDiskCallback(zipFile, jsCallback)); -// jsCallback.execute("installDependence"); } else { JOptionPane.showMessageDialog(null, result.getMessage(), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE); } diff --git a/designer_base/src/com/fr/design/extra/exe/callback/InstallOnlineCallback.java b/designer_base/src/com/fr/design/extra/exe/callback/InstallOnlineCallback.java index ef96acf72..253ea4005 100644 --- a/designer_base/src/com/fr/design/extra/exe/callback/InstallOnlineCallback.java +++ b/designer_base/src/com/fr/design/extra/exe/callback/InstallOnlineCallback.java @@ -45,7 +45,6 @@ public class InstallOnlineCallback extends AbstractPluginTaskCallback { } //执行JS回调 PluginManager.getController().install(pluginMarker, new InstallOnlineCallback(pluginMarker, jsCallback)); -// jsCallback.execute("installDependence"); } else { JOptionPane.showMessageDialog(null, result.getMessage(), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE); }