|
|
|
@ -2,6 +2,7 @@ package com.fr.design.extra;
|
|
|
|
|
|
|
|
|
|
import com.fr.base.TemplateUtils; |
|
|
|
|
import com.fr.design.dialog.FineJOptionPane; |
|
|
|
|
import com.fr.design.i18n.Toolkit; |
|
|
|
|
import com.fr.general.CloudCenter; |
|
|
|
|
import com.fr.general.http.HttpClient; |
|
|
|
|
import com.fr.json.JSONArray; |
|
|
|
@ -12,8 +13,8 @@ import com.fr.plugin.basic.version.Version;
|
|
|
|
|
import com.fr.plugin.basic.version.VersionIntervalFactory; |
|
|
|
|
import com.fr.plugin.context.PluginContext; |
|
|
|
|
import com.fr.plugin.context.PluginMarker; |
|
|
|
|
import com.fr.plugin.error.PluginErrorCode; |
|
|
|
|
import com.fr.plugin.error.PluginBaseErrorCode; |
|
|
|
|
import com.fr.plugin.error.PluginErrorCode; |
|
|
|
|
import com.fr.plugin.manage.PluginManager; |
|
|
|
|
import com.fr.plugin.view.PluginView; |
|
|
|
|
import com.fr.stable.EncodeConstants; |
|
|
|
@ -21,11 +22,12 @@ import com.fr.stable.ProductConstants;
|
|
|
|
|
import com.fr.stable.StableUtils; |
|
|
|
|
import com.fr.stable.StringUtils; |
|
|
|
|
|
|
|
|
|
import javax.swing.JOptionPane; |
|
|
|
|
import javax.swing.*; |
|
|
|
|
import java.io.File; |
|
|
|
|
import java.io.FileOutputStream; |
|
|
|
|
import java.io.IOException; |
|
|
|
|
import java.io.InputStream; |
|
|
|
|
import java.io.UnsupportedEncodingException; |
|
|
|
|
import java.net.HttpURLConnection; |
|
|
|
|
import java.net.URLDecoder; |
|
|
|
|
import java.text.SimpleDateFormat; |
|
|
|
@ -38,7 +40,7 @@ import java.util.Map;
|
|
|
|
|
* Created by ibm on 2017/5/25. |
|
|
|
|
*/ |
|
|
|
|
public class PluginUtils { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static final String ERROR_CODE_I18N_PREFIX = "FR-Plugin_Error_"; |
|
|
|
|
public static final String FR_VERSION = "fr_version"; |
|
|
|
|
|
|
|
|
@ -46,8 +48,7 @@ public class PluginUtils {
|
|
|
|
|
public static PluginMarker createPluginMarker(String pluginInfo) { |
|
|
|
|
//todo 判空
|
|
|
|
|
String[] plugin = pluginInfo.split("_"); |
|
|
|
|
PluginMarker pluginMarker = PluginMarker.create(plugin[0], plugin[1]); |
|
|
|
|
return pluginMarker; |
|
|
|
|
return PluginMarker.create(plugin[0], plugin[1]); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static JSONObject getLatestPluginInfo(String pluginID) throws Exception { |
|
|
|
@ -90,7 +91,11 @@ public class PluginUtils {
|
|
|
|
|
InputStream reader = null; |
|
|
|
|
FileOutputStream writer = null; |
|
|
|
|
try { |
|
|
|
|
HttpClient httpClient = new HttpClient(getDownloadPath(id)); |
|
|
|
|
String downloadPath = getDownloadPath(id); |
|
|
|
|
if (StringUtils.isBlank(downloadPath)) { |
|
|
|
|
throw new PluginVerifyException(Toolkit.i18nText("Fine-Design_Basic_Plugin_Connect_Server_Error")); |
|
|
|
|
} |
|
|
|
|
HttpClient httpClient = new HttpClient(downloadPath); |
|
|
|
|
if (httpClient.getResponseCode() == HttpURLConnection.HTTP_OK) { |
|
|
|
|
int totalSize = httpClient.getContentLength(); |
|
|
|
|
reader = httpClient.getResponseStream(); |
|
|
|
@ -108,12 +113,12 @@ public class PluginUtils {
|
|
|
|
|
p.process(totalBytesRead / (double) totalSize); |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
throw new com.fr.plugin.PluginVerifyException(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Plugin_Connect_Server_Error")); |
|
|
|
|
throw new PluginVerifyException(Toolkit.i18nText("Fine-Design_Basic_Plugin_Connect_Server_Error")); |
|
|
|
|
} |
|
|
|
|
} catch (PluginVerifyException e) { |
|
|
|
|
FineJOptionPane.showMessageDialog(null, e.getMessage(), com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Plugin_Warning"), JOptionPane.ERROR_MESSAGE); |
|
|
|
|
return false; |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
} catch (IOException e) { |
|
|
|
|
FineLoggerFactory.getLogger().error(e.getMessage(), e); |
|
|
|
|
return false; |
|
|
|
|
} finally { |
|
|
|
@ -122,7 +127,7 @@ public class PluginUtils {
|
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private static void closeStream(InputStream reader, FileOutputStream writer){ |
|
|
|
|
private static void closeStream(InputStream reader, FileOutputStream writer) { |
|
|
|
|
try { |
|
|
|
|
if (null != reader) { |
|
|
|
|
reader.close(); |
|
|
|
@ -136,18 +141,26 @@ public class PluginUtils {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private static String getDownloadPath(String id) throws Exception { |
|
|
|
|
HashMap<String, String> map = new HashMap<String, String>(); |
|
|
|
|
map.put("id", id); |
|
|
|
|
HttpClient httpClient = new HttpClient(CloudCenter.getInstance().acquireUrlByKind("shop.script.download")+ "?" + FR_VERSION + "=" + ProductConstants.VERSION); |
|
|
|
|
private static String getDownloadPath(String id) { |
|
|
|
|
String url = CloudCenter.getInstance().acquireUrlByKind("shop.script.download"); |
|
|
|
|
if (StringUtils.isBlank(url)) { |
|
|
|
|
return StringUtils.EMPTY; |
|
|
|
|
} |
|
|
|
|
HttpClient httpClient = new HttpClient(url + "?" + FR_VERSION + "=" + ProductConstants.VERSION); |
|
|
|
|
httpClient.asGet(); |
|
|
|
|
String resText = httpClient.getResponseText(); |
|
|
|
|
JSONObject resultJSONObject = new JSONObject(resText); |
|
|
|
|
String scriptUrl = resultJSONObject.optString("result"); |
|
|
|
|
String charSet = EncodeConstants.ENCODING_UTF_8; |
|
|
|
|
scriptUrl = URLDecoder.decode(URLDecoder.decode(scriptUrl, charSet), charSet); |
|
|
|
|
|
|
|
|
|
return scriptUrl; |
|
|
|
|
if (httpClient.getResponseCode() == HttpURLConnection.HTTP_OK) { |
|
|
|
|
String resText = httpClient.getResponseText(); |
|
|
|
|
JSONObject resultJSONObject = new JSONObject(resText); |
|
|
|
|
String scriptUrl = resultJSONObject.optString("result"); |
|
|
|
|
String charSet = EncodeConstants.ENCODING_UTF_8; |
|
|
|
|
try { |
|
|
|
|
scriptUrl = URLDecoder.decode(URLDecoder.decode(scriptUrl, charSet), charSet); |
|
|
|
|
} catch (UnsupportedEncodingException e) { |
|
|
|
|
FineLoggerFactory.getLogger().error(e.getMessage(), e); |
|
|
|
|
} |
|
|
|
|
return scriptUrl; |
|
|
|
|
} |
|
|
|
|
return StringUtils.EMPTY; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static boolean isPluginMatch(PluginView pluginView, String text) { |
|
|
|
@ -194,22 +207,22 @@ public class PluginUtils {
|
|
|
|
|
return StringUtils.EMPTY; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static String getMessageByErrorCode(PluginBaseErrorCode errorCode) { |
|
|
|
|
if(errorCode == PluginErrorCode.None){ |
|
|
|
|
if (errorCode == PluginErrorCode.None) { |
|
|
|
|
return ""; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return com.fr.design.i18n.Toolkit.i18nCompatibleServerText(getInterKeyByErrorCode(errorCode)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static String getInterKeyByErrorCode(PluginBaseErrorCode errorCode) { |
|
|
|
|
|
|
|
|
|
return errorCode.getDescription(); |
|
|
|
|
|
|
|
|
|
return errorCode.getDescription(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static PluginMarker getInstalledPluginMarkerByID(String pluginID) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PluginContext context = PluginManager.getContext(pluginID); |
|
|
|
|
if (context != null) { |
|
|
|
|
return context.getMarker(); |
|
|
|
@ -219,29 +232,30 @@ public class PluginUtils {
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 在不同设计器版本下展示不同插件 |
|
|
|
|
* |
|
|
|
|
* @return 插件 |
|
|
|
|
*/ |
|
|
|
|
public static JSONArray filterPluginsFromVersion(JSONArray oriJSONArray) throws Exception{ |
|
|
|
|
JSONArray resultJSONArray = JSONArray.create(); |
|
|
|
|
for(int i = 0; i < oriJSONArray.length(); i++){ |
|
|
|
|
public static JSONArray filterPluginsFromVersion(JSONArray oriJSONArray) { |
|
|
|
|
JSONArray resultJSONArray = JSONArray.create(); |
|
|
|
|
for (int i = 0; i < oriJSONArray.length(); i++) { |
|
|
|
|
JSONObject jo = oriJSONArray.getJSONObject(i); |
|
|
|
|
String envVersion = jo.optString("envversion"); |
|
|
|
|
if(isCompatibleCurrentEnv(envVersion)){ |
|
|
|
|
if (isCompatibleCurrentEnv(envVersion)) { |
|
|
|
|
resultJSONArray.put(jo); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return resultJSONArray; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private static boolean isCompatibleCurrentEnv(String envVersion){ |
|
|
|
|
private static boolean isCompatibleCurrentEnv(String envVersion) { |
|
|
|
|
return VersionIntervalFactory.create(envVersion).contain(Version.currentEnvVersion()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static JSONArray transferStorePluginToJson(PluginContext [] pluginContexts){ |
|
|
|
|
public static JSONArray transferStorePluginToJson(PluginContext[] pluginContexts) { |
|
|
|
|
JSONArray ja = JSONArray.create(); |
|
|
|
|
try { |
|
|
|
|
for(PluginContext pluginContext : pluginContexts){ |
|
|
|
|
for (PluginContext pluginContext : pluginContexts) { |
|
|
|
|
JSONObject jo = JSONObject.create(); |
|
|
|
|
jo.put("id", pluginContext.getID()); |
|
|
|
|
jo.put("name", pluginContext.getName()); |
|
|
|
@ -265,7 +279,7 @@ public class PluginUtils {
|
|
|
|
|
jo.put("switchedReason", pluginContext.getSwitchedReason()); |
|
|
|
|
ja.put(jo); |
|
|
|
|
} |
|
|
|
|
}catch (Exception e){ |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
FineLoggerFactory.getLogger().error(e.getMessage(), e); |
|
|
|
|
} |
|
|
|
|
return ja; |
|
|
|
|