Browse Source
* commit '08f34726a0c3762cb0b9041114d22d3cc62ceb8d': (28 commits) 代码质量 代码质量 包名 rt 代码质量 rt 代码质量 代码质量 代码质量 测试下PMD怎么知道我是读json的 代码质量 代码质量 代码质量 rt rt rt rt 代码质量 代码质量 代码质量 alphafine修改 ...master
superman
8 years ago
40 changed files with 1376 additions and 663 deletions
@ -1,34 +1,57 @@
|
||||
package com.fr.design.mainframe.alphafine; |
||||
|
||||
import com.fr.base.FRContext; |
||||
import com.fr.design.mainframe.DesignerContext; |
||||
import com.fr.design.mainframe.alphafine.component.AlphaFineDialog; |
||||
import com.fr.stable.StableUtils; |
||||
|
||||
import java.io.File; |
||||
import com.fr.stable.StringUtils; |
||||
|
||||
/** |
||||
* Created by XiaXiang on 2017/5/8. |
||||
*/ |
||||
public class AlphaFineHelper { |
||||
|
||||
/** |
||||
* 弹出alphafine搜索面板 |
||||
*/ |
||||
public static void showAlphaFineDialog() { |
||||
AlphaFineDialog dialog = new AlphaFineDialog(DesignerContext.getDesignerFrame()); |
||||
dialog.setVisible(true); |
||||
} |
||||
|
||||
public static File getInfoFile() { |
||||
return new File(StableUtils.pathJoin(FRContext.getCurrentEnv().getPath(), AlphaFineConstants.SAVE_FILE_NAME)); |
||||
/** |
||||
* 获取文件名上级目录 |
||||
* @param text |
||||
* @return |
||||
*/ |
||||
public static String findFolderName (String text) { |
||||
return getSplitText(text, 2); |
||||
} |
||||
|
||||
public static String findFolderName (String text) { |
||||
String[] textArray = text.split(File.separator); |
||||
/** |
||||
* 分割字符串,获取文件名,文件名上级目录等 |
||||
* @param text |
||||
* @param index |
||||
* @return |
||||
*/ |
||||
private static String getSplitText(String text, int index) { |
||||
if (StringUtils.isNotBlank(text)) { |
||||
String[] textArray = text.split("/"); |
||||
if (textArray != null && textArray.length > 1) { |
||||
return textArray[textArray.length - 2]; |
||||
|
||||
return textArray[textArray.length - index]; |
||||
} |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
/** |
||||
* 获取文件名 |
||||
* @param text |
||||
* @return |
||||
*/ |
||||
public static String findFileName (String text) { |
||||
return getSplitText(text, 1); |
||||
} |
||||
|
||||
|
||||
|
||||
|
||||
} |
||||
|
@ -0,0 +1,41 @@
|
||||
package com.fr.design.mainframe.alphafine.cell; |
||||
|
||||
import com.fr.design.mainframe.alphafine.CellType; |
||||
import com.fr.design.mainframe.alphafine.cell.model.*; |
||||
import com.fr.design.mainframe.alphafine.search.manager.ActionSearchManager; |
||||
import com.fr.design.mainframe.alphafine.search.manager.DocumentSearchManager; |
||||
import com.fr.design.mainframe.alphafine.search.manager.FileSearchManager; |
||||
import com.fr.design.mainframe.alphafine.search.manager.PluginSearchManager; |
||||
import com.fr.json.JSONObject; |
||||
|
||||
/** |
||||
* Created by XiaXiang on 2017/5/17. |
||||
*/ |
||||
public class CellModelHelper { |
||||
private static final String RESULT = "result"; |
||||
public static AlphaCellModel getModelFromJson(JSONObject object) { |
||||
int typeValue = object.optInt("cellType"); |
||||
AlphaCellModel cellModel = null; |
||||
switch (CellType.parse(typeValue)) { |
||||
case ACTION: |
||||
cellModel = ActionSearchManager.getModelFromCloud(object.optString(RESULT)); |
||||
break; |
||||
case DOCUMENT: |
||||
cellModel = DocumentSearchManager.getModelFromCloud(object.optJSONObject(RESULT)); |
||||
break; |
||||
case FILE: |
||||
cellModel = FileSearchManager.getModelFromCloud(object.optString(RESULT)); |
||||
break; |
||||
case PLUGIN: |
||||
case REUSE: |
||||
cellModel = PluginSearchManager.getModelFromCloud(object.optJSONObject(RESULT)); |
||||
break; |
||||
|
||||
} |
||||
return cellModel; |
||||
} |
||||
|
||||
public static String getResultValueFromModel(AlphaCellModel cellModel) { |
||||
return cellModel.getStoreInformation(); |
||||
} |
||||
} |
@ -1,30 +0,0 @@
|
||||
package com.fr.design.mainframe.alphafine.cell.cellModel; |
||||
|
||||
import com.fr.design.mainframe.alphafine.CellType; |
||||
|
||||
import javax.swing.*; |
||||
import java.io.Serializable; |
||||
|
||||
/** |
||||
* Created by XiaXiang on 2017/4/20. |
||||
*/ |
||||
public class ActionModel extends AlphaCellModel implements Serializable { |
||||
private Action action; |
||||
|
||||
public ActionModel(String name, String content, CellType type) { |
||||
super(name, content, type); |
||||
} |
||||
|
||||
public ActionModel(String name, Action action) { |
||||
super(name, null, CellType.ACTION); |
||||
this.action = action; |
||||
} |
||||
|
||||
public Action getAction() { |
||||
return action; |
||||
} |
||||
|
||||
public void setAction(Action action) { |
||||
this.action = action; |
||||
} |
||||
} |
@ -1,27 +0,0 @@
|
||||
package com.fr.design.mainframe.alphafine.cell.cellModel; |
||||
|
||||
import com.fr.design.mainframe.alphafine.CellType; |
||||
|
||||
/** |
||||
* Created by XiaXiang on 2017/4/20. |
||||
*/ |
||||
public class DocumentModel extends AlphaCellModel { |
||||
private String documentUrl; |
||||
|
||||
public DocumentModel(String name, String content, CellType type) { |
||||
super(name, content, type); |
||||
} |
||||
|
||||
public DocumentModel(String name, String content, String documentUrl) { |
||||
super(name, content, CellType.DOCUMENT); |
||||
this.documentUrl = documentUrl; |
||||
} |
||||
|
||||
public String getDocumentUrl() { |
||||
return documentUrl; |
||||
} |
||||
|
||||
public void setDocumentUrl(String documentUrl) { |
||||
this.documentUrl = documentUrl; |
||||
} |
||||
} |
@ -1,29 +0,0 @@
|
||||
package com.fr.design.mainframe.alphafine.cell.cellModel; |
||||
|
||||
import com.fr.design.mainframe.alphafine.AlphaFineHelper; |
||||
import com.fr.design.mainframe.alphafine.CellType; |
||||
|
||||
/** |
||||
* Created by XiaXiang on 2017/4/20. |
||||
*/ |
||||
public class FileModel extends AlphaCellModel{ |
||||
private String filePath; |
||||
|
||||
public FileModel(String name, String content, CellType type) { |
||||
super(name, content, type); |
||||
} |
||||
|
||||
public FileModel(String name, String content, String filePath) { |
||||
super(name, content, CellType.FILE); |
||||
this.filePath = filePath; |
||||
setDescription(AlphaFineHelper.findFolderName(content)); |
||||
} |
||||
|
||||
public String getFilePath() { |
||||
return filePath; |
||||
} |
||||
|
||||
public void setFilePath(String filePath) { |
||||
this.filePath = filePath; |
||||
} |
||||
} |
@ -1,77 +0,0 @@
|
||||
package com.fr.design.mainframe.alphafine.cell.cellModel; |
||||
|
||||
import com.fr.design.mainframe.alphafine.CellType; |
||||
import com.fr.general.ComparatorUtils; |
||||
|
||||
/** |
||||
* Created by XiaXiang on 2017/4/20. |
||||
*/ |
||||
public class PluginModel extends AlphaCellModel { |
||||
private String pluginUrl; |
||||
private String imageUrl; |
||||
private String version; |
||||
private String jartime; |
||||
private String link; |
||||
private int price; |
||||
|
||||
public PluginModel(String name, String content, CellType type) { |
||||
super(name, content, type); |
||||
} |
||||
public PluginModel(String name, String content, String pluginUrl, String imageUrl, String version, String jartime, CellType type, int price) { |
||||
super(name, content); |
||||
setType(type); |
||||
this.pluginUrl = pluginUrl; |
||||
this.imageUrl = imageUrl; |
||||
this.jartime = jartime; |
||||
this.version = version; |
||||
this.price = price; |
||||
} |
||||
|
||||
public String getImageUrl() { |
||||
return imageUrl; |
||||
} |
||||
|
||||
public void setImageUrl(String imageUrl) { |
||||
this.imageUrl = imageUrl; |
||||
} |
||||
|
||||
public String getPluginUrl() { |
||||
return pluginUrl; |
||||
} |
||||
|
||||
public void setPluginUrl(String pluginUrl) { |
||||
this.pluginUrl = pluginUrl; |
||||
} |
||||
|
||||
public String getVersion() { |
||||
return version; |
||||
} |
||||
|
||||
public void setVersion(String verSion) { |
||||
this.version = verSion; |
||||
} |
||||
|
||||
public String getJartime() { |
||||
return jartime; |
||||
} |
||||
|
||||
public void setJarTime(String jarTime) { |
||||
this.jartime = jarTime; |
||||
} |
||||
|
||||
public String getLink() { |
||||
return link; |
||||
} |
||||
|
||||
public void setLink(String link) { |
||||
this.link = link; |
||||
} |
||||
|
||||
public int getPrice() { |
||||
return price; |
||||
} |
||||
|
||||
public void setPrice(int price) { |
||||
this.price = price; |
||||
} |
||||
} |
@ -0,0 +1,77 @@
|
||||
package com.fr.design.mainframe.alphafine.cell.model; |
||||
|
||||
import com.fr.design.mainframe.alphafine.CellType; |
||||
import com.fr.general.FRLogger; |
||||
import com.fr.json.JSONException; |
||||
import com.fr.json.JSONObject; |
||||
|
||||
import javax.swing.*; |
||||
import java.io.Serializable; |
||||
|
||||
/** |
||||
* Created by XiaXiang on 2017/4/20. |
||||
*/ |
||||
public class ActionModel extends AlphaCellModel implements Serializable { |
||||
private Action action; |
||||
|
||||
private String actionName; |
||||
|
||||
public ActionModel(String name, String content, CellType type) { |
||||
super(name, content, type); |
||||
} |
||||
|
||||
@Override |
||||
public boolean equals(Object o) { |
||||
if (this == o) { |
||||
return true; |
||||
} |
||||
if (!(o instanceof ActionModel)) { |
||||
return false; |
||||
} |
||||
ActionModel that = (ActionModel) o; |
||||
|
||||
return action != null ? action.equals(that.action) : that.action == null; |
||||
} |
||||
|
||||
@Override |
||||
public int hashCode() { |
||||
return action != null ? action.hashCode() : 0; |
||||
} |
||||
|
||||
public ActionModel(String name, Action action) { |
||||
super(name, null, CellType.ACTION); |
||||
this.action = action; |
||||
} |
||||
|
||||
public Action getAction() { |
||||
return action; |
||||
} |
||||
|
||||
public void setAction(Action action) { |
||||
this.action = action; |
||||
} |
||||
|
||||
@Override |
||||
public JSONObject ModelToJson() { |
||||
JSONObject object = JSONObject.create(); |
||||
try { |
||||
object.put("result", getAction().getClass().getName()).put("cellType", getType().getTypeValue()); |
||||
} catch (JSONException e) { |
||||
FRLogger.getLogger().error(e.getMessage()); |
||||
} |
||||
return object; |
||||
} |
||||
|
||||
@Override |
||||
public String getStoreInformation() { |
||||
return getActionName(); |
||||
} |
||||
|
||||
public String getActionName() { |
||||
return getAction().getClass().getName(); |
||||
} |
||||
|
||||
public void setActionName(String actionName) { |
||||
this.actionName = actionName; |
||||
} |
||||
} |
@ -0,0 +1,87 @@
|
||||
package com.fr.design.mainframe.alphafine.cell.model; |
||||
|
||||
import com.fr.design.mainframe.alphafine.AlphaFineConstants; |
||||
import com.fr.design.mainframe.alphafine.CellType; |
||||
import com.fr.general.FRLogger; |
||||
import com.fr.json.JSONException; |
||||
import com.fr.json.JSONObject; |
||||
|
||||
/** |
||||
* Created by XiaXiang on 2017/4/20. |
||||
*/ |
||||
public class DocumentModel extends AlphaCellModel { |
||||
private String documentUrl; |
||||
private String informationUrl; |
||||
private int documentId; |
||||
|
||||
public DocumentModel(String name, String content, CellType type) { |
||||
super(name, content, type); |
||||
} |
||||
|
||||
public DocumentModel(String name, String content, int documentId) { |
||||
super(name, content, CellType.DOCUMENT); |
||||
this.documentId = documentId; |
||||
this.informationUrl = AlphaFineConstants.DOCUMENT_INFORMATION_URL + documentId; |
||||
this.documentUrl = AlphaFineConstants.DOCUMENT_DOC_URL + documentId + ".html"; |
||||
} |
||||
|
||||
public String getDocumentUrl() { |
||||
return documentUrl; |
||||
} |
||||
|
||||
public void setDocumentUrl(String documentUrl) { |
||||
this.documentUrl = documentUrl; |
||||
} |
||||
|
||||
@Override |
||||
public JSONObject ModelToJson() { |
||||
JSONObject object = JSONObject.create(); |
||||
try { |
||||
JSONObject modelObject = JSONObject.create(); |
||||
modelObject.put("title", getName()).put("summary", getContent()).put("did", getDocumentId()); |
||||
object.put("result", modelObject).put("cellType", getType().getTypeValue()); |
||||
} catch (JSONException e) { |
||||
FRLogger.getLogger().error("DocumentModel: " + e.getMessage()); |
||||
} |
||||
return object; |
||||
} |
||||
|
||||
@Override |
||||
public String getStoreInformation() { |
||||
return getInformationUrl(); |
||||
} |
||||
|
||||
@Override |
||||
public boolean equals(Object o) { |
||||
if (this == o) { |
||||
return true; |
||||
} |
||||
if (!(o instanceof DocumentModel)) { |
||||
return false; |
||||
} |
||||
DocumentModel that = (DocumentModel) o; |
||||
|
||||
return documentUrl != null ? documentUrl.equals(that.documentUrl) : that.documentUrl == null; |
||||
} |
||||
|
||||
@Override |
||||
public int hashCode() { |
||||
return documentUrl != null ? documentUrl.hashCode() : 0; |
||||
} |
||||
|
||||
public int getDocumentId() { |
||||
return documentId; |
||||
} |
||||
|
||||
public void setDocumentId(int documentId) { |
||||
this.documentId = documentId; |
||||
} |
||||
|
||||
public String getInformationUrl() { |
||||
return informationUrl; |
||||
} |
||||
|
||||
public void setInformationUrl(String informationUrl) { |
||||
this.informationUrl = informationUrl; |
||||
} |
||||
} |
@ -0,0 +1,66 @@
|
||||
package com.fr.design.mainframe.alphafine.cell.model; |
||||
|
||||
import com.fr.design.mainframe.alphafine.AlphaFineHelper; |
||||
import com.fr.design.mainframe.alphafine.CellType; |
||||
import com.fr.general.FRLogger; |
||||
import com.fr.json.JSONException; |
||||
import com.fr.json.JSONObject; |
||||
|
||||
/** |
||||
* Created by XiaXiang on 2017/4/20. |
||||
*/ |
||||
public class FileModel extends AlphaCellModel{ |
||||
private String filePath; |
||||
|
||||
public FileModel(String name, String content, CellType type) { |
||||
super(name, content, type); |
||||
} |
||||
|
||||
public FileModel(String name, String content, String filePath) { |
||||
super(name, content, CellType.FILE); |
||||
this.filePath = filePath; |
||||
setDescription(AlphaFineHelper.findFolderName(content)); |
||||
} |
||||
|
||||
public String getFilePath() { |
||||
return filePath; |
||||
} |
||||
|
||||
public void setFilePath(String filePath) { |
||||
this.filePath = filePath; |
||||
} |
||||
|
||||
@Override |
||||
public JSONObject ModelToJson() { |
||||
JSONObject object = JSONObject.create(); |
||||
try { |
||||
object.put("result", getFilePath()).put("cellType", getType().getTypeValue()); |
||||
} catch (JSONException e) { |
||||
FRLogger.getLogger().error(e.getMessage()); |
||||
} |
||||
return object; |
||||
} |
||||
|
||||
@Override |
||||
public String getStoreInformation() { |
||||
return getFilePath(); |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public boolean equals(Object o) { |
||||
if (this == o) { |
||||
return true; |
||||
} |
||||
if (!(o instanceof FileModel)) { |
||||
return false; |
||||
} |
||||
FileModel fileModel = (FileModel) o; |
||||
return filePath != null ? filePath.equals(fileModel.filePath) : fileModel.filePath == null; |
||||
} |
||||
|
||||
@Override |
||||
public int hashCode() { |
||||
return filePath != null ? filePath.hashCode() : 0; |
||||
} |
||||
} |
@ -1,4 +1,4 @@
|
||||
package com.fr.design.mainframe.alphafine.cell.cellModel; |
||||
package com.fr.design.mainframe.alphafine.cell.model; |
||||
|
||||
import com.fr.design.mainframe.alphafine.CellType; |
||||
|
@ -0,0 +1,149 @@
|
||||
package com.fr.design.mainframe.alphafine.cell.model; |
||||
|
||||
import com.fr.design.mainframe.alphafine.AlphaFineConstants; |
||||
import com.fr.design.mainframe.alphafine.CellType; |
||||
import com.fr.general.FRLogger; |
||||
import com.fr.json.JSONException; |
||||
import com.fr.json.JSONObject; |
||||
|
||||
/** |
||||
* Created by XiaXiang on 2017/4/20. |
||||
*/ |
||||
public class PluginModel extends AlphaCellModel { |
||||
private String pluginUrl; |
||||
private String imageUrl; |
||||
private String version; |
||||
private String jartime; |
||||
private String link; |
||||
private String informationUrl; |
||||
private int pluginId; |
||||
private int price; |
||||
private static final String PLUGIN_INFORMATION_URL = "http://shop.finereport.com/ShopServer?pg=plugin&pid="; |
||||
private static final String REUSE_INFORMATION_URL = "http://shop.finereport.com/reuses/"; |
||||
|
||||
public PluginModel(String name, String content, CellType type) { |
||||
super(name, content, type); |
||||
} |
||||
public PluginModel(String name, String content, String imageUrl, String version, String jartime, String link, CellType type, int price, int pluginId) { |
||||
super(name, content); |
||||
this.link = link; |
||||
setType(type); |
||||
this.pluginId = pluginId; |
||||
if (getType() == CellType.PLUGIN) { |
||||
this.pluginUrl = AlphaFineConstants.PLUGIN_URL + pluginId; |
||||
this.informationUrl = PLUGIN_INFORMATION_URL + this.pluginId; |
||||
} else { |
||||
this.pluginUrl = AlphaFineConstants.REUSE_URL + pluginId; |
||||
this.informationUrl = REUSE_INFORMATION_URL + this.pluginId; |
||||
|
||||
} |
||||
this.imageUrl = imageUrl; |
||||
this.jartime = jartime; |
||||
this.version = version; |
||||
this.price = price; |
||||
} |
||||
|
||||
public String getImageUrl() { |
||||
return imageUrl; |
||||
} |
||||
|
||||
public void setImageUrl(String imageUrl) { |
||||
this.imageUrl = imageUrl; |
||||
} |
||||
|
||||
public String getPluginUrl() { |
||||
return pluginUrl; |
||||
} |
||||
|
||||
public void setPluginUrl(String pluginUrl) { |
||||
this.pluginUrl = pluginUrl; |
||||
} |
||||
|
||||
public String getVersion() { |
||||
return version; |
||||
} |
||||
|
||||
public void setVersion(String verSion) { |
||||
this.version = verSion; |
||||
} |
||||
|
||||
public String getJartime() { |
||||
return jartime; |
||||
} |
||||
|
||||
public void setJarTime(String jarTime) { |
||||
this.jartime = jarTime; |
||||
} |
||||
|
||||
public String getLink() { |
||||
return link; |
||||
} |
||||
|
||||
public void setLink(String link) { |
||||
this.link = link; |
||||
} |
||||
|
||||
public int getPrice() { |
||||
return price; |
||||
} |
||||
|
||||
public void setPrice(int price) { |
||||
this.price = price; |
||||
} |
||||
|
||||
@Override |
||||
public JSONObject ModelToJson() { |
||||
JSONObject object = JSONObject.create(); |
||||
try { |
||||
JSONObject modelObject = JSONObject.create(); |
||||
modelObject.put("name", getName()).put("description", getContent()).put("pic", getImageUrl()).put("version", getVersion()).put("jartime", getJartime()).put("type", getType().getTypeValue()).put("price", getPrice()).put("id", getPluginId()).put("link", getLink()); |
||||
object.put("result", modelObject).put("cellType", getType().getTypeValue()); |
||||
} catch (JSONException e) { |
||||
FRLogger.getLogger().error(e.getMessage()); |
||||
} |
||||
|
||||
return object; |
||||
} |
||||
|
||||
@Override |
||||
public String getStoreInformation() { |
||||
return getInformationUrl(); |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public boolean equals(Object o) { |
||||
if (this == o) { |
||||
return true; |
||||
} |
||||
if (!(o instanceof PluginModel)) { |
||||
return false; |
||||
} |
||||
PluginModel that = (PluginModel) o; |
||||
|
||||
return pluginUrl != null ? pluginUrl.equals(that.pluginUrl) : that.pluginUrl == null; |
||||
} |
||||
|
||||
@Override |
||||
public int hashCode() { |
||||
return pluginUrl != null ? pluginUrl.hashCode() : 0; |
||||
} |
||||
|
||||
|
||||
|
||||
public int getPluginId() { |
||||
return pluginId; |
||||
} |
||||
|
||||
public void setPluginId(int pluginId) { |
||||
this.pluginId = pluginId; |
||||
} |
||||
|
||||
public String getInformationUrl() { |
||||
return informationUrl; |
||||
} |
||||
|
||||
public void setInformationUrl(String informationUrl) { |
||||
this.informationUrl = informationUrl; |
||||
} |
||||
} |
After Width: | Height: | Size: 2.7 KiB |
@ -1,4 +1,4 @@
|
||||
package com.fr.design.mainframe.alphafine.previewPane; |
||||
package com.fr.design.mainframe.alphafine.preview; |
||||
|
||||
/** |
||||
* Created by XiaXiang on 2017/5/5. |
@ -1,4 +1,4 @@
|
||||
package com.fr.design.mainframe.alphafine.previewPane; |
||||
package com.fr.design.mainframe.alphafine.preview; |
||||
|
||||
|
||||
import com.fr.design.gui.itextarea.UITextArea; |
@ -1,4 +1,4 @@
|
||||
package com.fr.design.mainframe.alphafine.previewPane; |
||||
package com.fr.design.mainframe.alphafine.preview; |
||||
|
||||
import com.fr.design.gui.ilable.UILabel; |
||||
|
@ -1,4 +1,4 @@
|
||||
package com.fr.design.mainframe.alphafine.previewPane; |
||||
package com.fr.design.mainframe.alphafine.preview; |
||||
|
||||
import com.fr.design.gui.ilable.UILabel; |
||||
import com.fr.design.mainframe.alphafine.AlphaFineConstants; |
@ -0,0 +1,21 @@
|
||||
package com.fr.design.mainframe.alphafine.search.manager; |
||||
|
||||
import com.fr.design.mainframe.alphafine.model.SearchResult; |
||||
|
||||
/** |
||||
* Created by XiaXiang on 2017/3/27. |
||||
*/ |
||||
public interface AlphaFineSearchProcessor { |
||||
/** |
||||
* 获取默认显示条数 |
||||
* @param searchText |
||||
* @return |
||||
*/ |
||||
SearchResult getLessSearchResult(String searchText); |
||||
|
||||
/** |
||||
* 获取剩余条数 |
||||
* @return |
||||
*/ |
||||
SearchResult getMoreSearchResult(); |
||||
} |
@ -0,0 +1,69 @@
|
||||
package com.fr.design.mainframe.alphafine.search.manager; |
||||
|
||||
import com.fr.design.mainframe.alphafine.cell.model.MoreModel; |
||||
import com.fr.design.mainframe.alphafine.model.SearchResult; |
||||
import com.fr.general.Inter; |
||||
|
||||
/** |
||||
* Created by XiaXiang on 2017/3/28. |
||||
*/ |
||||
public class AlphaSearchManager implements AlphaFineSearchProcessor { |
||||
private static AlphaSearchManager searchManager; |
||||
private static PluginSearchManager pluginSearchManager; |
||||
private static DocumentSearchManager documentSearchManager; |
||||
private static FileSearchManager fileSearchManager; |
||||
private static ActionSearchManager actionSearchManager; |
||||
private static RecommendSearchManager recommendSearchManager; |
||||
private static RecentSearchManager recentSearchManager; |
||||
|
||||
public synchronized static AlphaSearchManager getSearchManager() { |
||||
init(); |
||||
return searchManager; |
||||
|
||||
} |
||||
|
||||
private synchronized static void init() { |
||||
if (searchManager == null) { |
||||
searchManager = new AlphaSearchManager(); |
||||
pluginSearchManager = PluginSearchManager.getPluginSearchManager(); |
||||
documentSearchManager = DocumentSearchManager.getDocumentSearchManager(); |
||||
fileSearchManager = FileSearchManager.getFileSearchManager(); |
||||
actionSearchManager = ActionSearchManager.getActionSearchManager(); |
||||
recommendSearchManager = RecommendSearchManager.getRecommendSearchManager(); |
||||
recentSearchManager = RecentSearchManager.getRecentSearchManger(); |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public synchronized SearchResult getLessSearchResult(String searchText) { |
||||
SearchResult recentModelList = recentSearchManager.getLessSearchResult(searchText); |
||||
SearchResult concludeModelList = recommendSearchManager.getLessSearchResult(searchText); |
||||
SearchResult actionModelList = actionSearchManager.getLessSearchResult(searchText); |
||||
SearchResult fileModelList = fileSearchManager.getLessSearchResult(searchText); |
||||
SearchResult documentModelList = documentSearchManager.getLessSearchResult(searchText); |
||||
SearchResult pluginModelList = pluginSearchManager.getLessSearchResult(searchText); |
||||
recentModelList.addAll(concludeModelList); |
||||
recentModelList.addAll(actionModelList); |
||||
recentModelList.addAll(fileModelList); |
||||
recentModelList.addAll(documentModelList); |
||||
recentModelList.addAll(pluginModelList); |
||||
return recentModelList; |
||||
} |
||||
|
||||
public SearchResult showDefaultSearchResult() { |
||||
SearchResult searchResult = new SearchResult(); |
||||
searchResult.add(new MoreModel(Inter.getLocText("FR-Designer_AlphaFine_Latest"))); |
||||
searchResult.add(new MoreModel(Inter.getLocText("FR-Designer_AlphaFine_Conclude"))); |
||||
searchResult.add(new MoreModel(Inter.getLocText("FR-Designer_Set"))); |
||||
searchResult.add(new MoreModel(Inter.getLocText("FR-Designer_Templates"))); |
||||
searchResult.add(new MoreModel(Inter.getLocText("FR-Designer_COMMUNITY_HELP"))); |
||||
searchResult.add(new MoreModel(Inter.getLocText("FR-Designer-Plugin_Addon"))); |
||||
return searchResult; |
||||
} |
||||
|
||||
@Override |
||||
public SearchResult getMoreSearchResult() { |
||||
return null; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,95 @@
|
||||
package com.fr.design.mainframe.alphafine.search.manager; |
||||
|
||||
import com.fr.design.DesignerEnvManager; |
||||
import com.fr.design.mainframe.alphafine.AlphaFineConstants; |
||||
import com.fr.design.mainframe.alphafine.CellType; |
||||
import com.fr.design.mainframe.alphafine.cell.model.DocumentModel; |
||||
import com.fr.design.mainframe.alphafine.cell.model.MoreModel; |
||||
import com.fr.design.mainframe.alphafine.model.SearchResult; |
||||
import com.fr.general.FRLogger; |
||||
import com.fr.general.Inter; |
||||
import com.fr.general.http.HttpClient; |
||||
import com.fr.json.JSONArray; |
||||
import com.fr.json.JSONException; |
||||
import com.fr.json.JSONObject; |
||||
|
||||
/** |
||||
* Created by XiaXiang on 2017/3/27. |
||||
*/ |
||||
public class DocumentSearchManager implements AlphaFineSearchProcessor { |
||||
private static DocumentSearchManager documentSearchManager = null; |
||||
private SearchResult lessModelList; |
||||
private SearchResult moreModelList; |
||||
|
||||
public synchronized static DocumentSearchManager getDocumentSearchManager() { |
||||
if (documentSearchManager == null) { |
||||
documentSearchManager = new DocumentSearchManager(); |
||||
|
||||
} |
||||
return documentSearchManager; |
||||
} |
||||
|
||||
@Override |
||||
public synchronized SearchResult getLessSearchResult(String searchText) { |
||||
lessModelList = new SearchResult(); |
||||
moreModelList = new SearchResult(); |
||||
if (DesignerEnvManager.getEnvManager().getAlphafineConfigManager().isContainDocument()) { |
||||
String result; |
||||
String url = AlphaFineConstants.DOCUMENT_SEARCH_URL + searchText + "-1"; |
||||
HttpClient httpClient = new HttpClient(url); |
||||
httpClient.setTimeout(5000); |
||||
httpClient.asGet(); |
||||
if (!httpClient.isServerAlive()) { |
||||
return lessModelList; |
||||
} |
||||
result = httpClient.getResponseText(); |
||||
try { |
||||
JSONObject jsonObject = new JSONObject(result); |
||||
JSONArray jsonArray = jsonObject.optJSONArray("docdata"); |
||||
if (jsonArray != null && jsonArray.length() > 0) { |
||||
final int length = Math.min(AlphaFineConstants.SHOW_SIZE, jsonArray.length()); |
||||
for (int i = 0; i < length; i++) { |
||||
DocumentModel cellModel = getModelFromCloud(jsonArray.optJSONObject(i)); |
||||
this.lessModelList.add(cellModel); |
||||
} |
||||
for (int i = length; i < jsonArray.length(); i++) { |
||||
DocumentModel cellModel = getModelFromCloud(jsonArray.optJSONObject(i)); |
||||
this.moreModelList.add(cellModel); |
||||
} |
||||
if (jsonArray.length() > AlphaFineConstants.SHOW_SIZE) { |
||||
lessModelList.add(0, new MoreModel(Inter.getLocText("FR-Designer_COMMUNITY_HELP"), Inter.getLocText("FR-Designer_AlphaFine_ShowAll"),true, CellType.DOCUMENT)); |
||||
} else { |
||||
lessModelList.add(0, new MoreModel(Inter.getLocText("FR-Designer_COMMUNITY_HELP"), CellType.DOCUMENT)); |
||||
} |
||||
|
||||
|
||||
} |
||||
|
||||
} catch (JSONException e) { |
||||
FRLogger.getLogger().error(e.getMessage()); |
||||
return lessModelList; |
||||
} |
||||
|
||||
|
||||
} |
||||
return lessModelList; |
||||
} |
||||
|
||||
/** |
||||
* 根据json信息获取文档model |
||||
* @param object |
||||
* @return |
||||
*/ |
||||
public static DocumentModel getModelFromCloud(JSONObject object) { |
||||
String name = object.optString("title"); |
||||
String content = object.optString("summary"); |
||||
int documentId = object.optInt("did"); |
||||
return new DocumentModel(name, content, documentId); |
||||
} |
||||
|
||||
@Override |
||||
public SearchResult getMoreSearchResult() { |
||||
return moreModelList; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,128 @@
|
||||
package com.fr.design.mainframe.alphafine.search.manager; |
||||
|
||||
import com.fr.design.DesignerEnvManager; |
||||
import com.fr.design.mainframe.alphafine.AlphaFineConstants; |
||||
import com.fr.design.mainframe.alphafine.CellType; |
||||
import com.fr.design.mainframe.alphafine.cell.model.PluginModel; |
||||
import com.fr.design.mainframe.alphafine.cell.model.MoreModel; |
||||
import com.fr.design.mainframe.alphafine.model.SearchResult; |
||||
import com.fr.general.ComparatorUtils; |
||||
import com.fr.general.FRLogger; |
||||
import com.fr.general.Inter; |
||||
import com.fr.general.http.HttpClient; |
||||
import com.fr.json.JSONArray; |
||||
import com.fr.json.JSONObject; |
||||
|
||||
import java.io.UnsupportedEncodingException; |
||||
import java.net.URLEncoder; |
||||
|
||||
/** |
||||
* Created by XiaXiang on 2017/3/27. |
||||
*/ |
||||
public class PluginSearchManager implements AlphaFineSearchProcessor { |
||||
private static PluginSearchManager pluginSearchManager = null; |
||||
private SearchResult lessModelList; |
||||
private SearchResult moreModelList; |
||||
|
||||
public synchronized static PluginSearchManager getPluginSearchManager() { |
||||
if (pluginSearchManager == null) { |
||||
pluginSearchManager = new PluginSearchManager(); |
||||
} |
||||
return pluginSearchManager; |
||||
|
||||
} |
||||
|
||||
@Override |
||||
public synchronized SearchResult getLessSearchResult(String searchText) { |
||||
|
||||
this.lessModelList = new SearchResult(); |
||||
this.moreModelList = new SearchResult(); |
||||
if (DesignerEnvManager.getEnvManager().getAlphafineConfigManager().isContainPlugin()) { |
||||
String result; |
||||
try { |
||||
String encodedKey = URLEncoder.encode(searchText, "UTF-8"); |
||||
String url = AlphaFineConstants.PLUGIN_SEARCH_URL + "?keyword=" + encodedKey; |
||||
HttpClient httpClient = new HttpClient(url); |
||||
httpClient.setTimeout(5000); |
||||
httpClient.asGet(); |
||||
if (!httpClient.isServerAlive()) { |
||||
return lessModelList; |
||||
} |
||||
result = httpClient.getResponseText(); |
||||
JSONObject jsonObject = new JSONObject(result); |
||||
JSONArray jsonArray = jsonObject.optJSONArray("result"); |
||||
if (jsonArray != null && jsonArray.length() > 0) { |
||||
int length = Math.min(AlphaFineConstants.SHOW_SIZE, jsonArray.length()); |
||||
for (int i = 0; i < length; i++) { |
||||
PluginModel cellModel = getPluginModel(jsonArray.optJSONObject(i), false); |
||||
this.lessModelList.add(cellModel); |
||||
} |
||||
for (int i = length; i < jsonArray.length(); i++) { |
||||
PluginModel cellModel = getPluginModel(jsonArray.optJSONObject(i), false); |
||||
this.moreModelList.add(cellModel); |
||||
} |
||||
if (jsonArray.length() > AlphaFineConstants.SHOW_SIZE) { |
||||
lessModelList.add(0, new MoreModel(Inter.getLocText("FR-Designer-Plugin_Addon"), Inter.getLocText("FR-Designer_AlphaFine_ShowAll"),true, CellType.PLUGIN)); |
||||
} else { |
||||
lessModelList.add(0, new MoreModel(Inter.getLocText("FR-Designer-Plugin_Addon"), CellType.PLUGIN)); |
||||
} |
||||
|
||||
} |
||||
|
||||
} catch (Exception e) { |
||||
FRLogger.getLogger().error(e.getMessage()); |
||||
return lessModelList; |
||||
} |
||||
} |
||||
return this.lessModelList; |
||||
} |
||||
|
||||
private static PluginModel getPluginModel(JSONObject object, boolean isFromCloud) { |
||||
String name = object.optString("name"); |
||||
String content = object.optString("description"); |
||||
int pluginId = object.optInt("id"); |
||||
String imageUrl = null; |
||||
try { |
||||
imageUrl = AlphaFineConstants.PLUGIN_IMAGE_URL + URLEncoder.encode(object.optString("pic").toString().substring(AlphaFineConstants.PLUGIN_IMAGE_URL.length()), "utf8"); |
||||
} catch (UnsupportedEncodingException e) { |
||||
FRLogger.getLogger().error(e.getMessage()); |
||||
} |
||||
String version = null; |
||||
String jartime = null; |
||||
CellType type; |
||||
String link = object.optString("link"); |
||||
if (ComparatorUtils.equals(link, "plugin")) { |
||||
version = isFromCloud? object.optString("pluginversion") : object.optString("version"); |
||||
jartime = object.optString("jartime"); |
||||
type = CellType.PLUGIN; |
||||
} else { |
||||
type = CellType.REUSE; |
||||
} |
||||
int price = object.optInt("price"); |
||||
return new PluginModel(name, content, imageUrl, version, jartime, link, type, price, pluginId); |
||||
} |
||||
|
||||
@Override |
||||
public SearchResult getMoreSearchResult() { |
||||
return this.moreModelList; |
||||
} |
||||
|
||||
/** |
||||
* 根据json获取对应的插件model |
||||
* @param object |
||||
* @return |
||||
*/ |
||||
public static PluginModel getModelFromCloud(JSONObject object) { |
||||
JSONObject jsonObject = object.optJSONObject("result"); |
||||
if (jsonObject != null) { |
||||
return getPluginModel(jsonObject, true); |
||||
} else { |
||||
return getPluginModel(object, false); |
||||
} |
||||
|
||||
} |
||||
|
||||
|
||||
|
||||
|
||||
} |
@ -0,0 +1,306 @@
|
||||
package com.fr.design.mainframe.alphafine.search.manager; |
||||
|
||||
import com.fr.base.FRContext; |
||||
import com.fr.base.Utils; |
||||
import com.fr.design.mainframe.alphafine.AlphaFineConstants; |
||||
import com.fr.design.mainframe.alphafine.cell.CellModelHelper; |
||||
import com.fr.design.mainframe.alphafine.cell.model.AlphaCellModel; |
||||
import com.fr.design.mainframe.alphafine.cell.model.MoreModel; |
||||
import com.fr.design.mainframe.alphafine.model.SearchResult; |
||||
import com.fr.file.XMLFileManager; |
||||
import com.fr.general.ComparatorUtils; |
||||
import com.fr.general.FRLogger; |
||||
import com.fr.general.IOUtils; |
||||
import com.fr.general.Inter; |
||||
import com.fr.json.JSONException; |
||||
import com.fr.json.JSONObject; |
||||
import com.fr.stable.ProductConstants; |
||||
import com.fr.stable.StableUtils; |
||||
import com.fr.stable.StringUtils; |
||||
import com.fr.stable.project.ProjectConstants; |
||||
import com.fr.stable.xml.XMLPrintWriter; |
||||
import com.fr.stable.xml.XMLReadable; |
||||
import com.fr.stable.xml.XMLTools; |
||||
import com.fr.stable.xml.XMLableReader; |
||||
|
||||
import java.io.*; |
||||
import java.util.ArrayList; |
||||
import java.util.HashMap; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* Created by XiaXiang on 2017/5/15. |
||||
*/ |
||||
public class RecentSearchManager extends XMLFileManager implements AlphaFineSearchProcessor { |
||||
|
||||
private static final String XML_TAG = "AlphafineRecent"; |
||||
private static RecentSearchManager recentSearchManager = null; |
||||
private static File recentFile = null; |
||||
private List<String> fileList; |
||||
private List<String> actionList; |
||||
private List<String> documentList; |
||||
private SearchResult modelList; |
||||
private List<String> pluginList; |
||||
private List<AlphaCellModel> recentModelList = new ArrayList<>(); |
||||
private Map<String, List<AlphaCellModel>> recentKVModelMap = new HashMap<>(); |
||||
|
||||
public synchronized static RecentSearchManager getRecentSearchManger() { |
||||
if (recentSearchManager == null) { |
||||
recentSearchManager = new RecentSearchManager(); |
||||
try { |
||||
XMLTools.readFileXML(recentSearchManager, recentSearchManager.getRecentEnvFile()); |
||||
} catch (Exception e) { |
||||
FRContext.getLogger().error(e.getMessage(), e); |
||||
} |
||||
} |
||||
return recentSearchManager; |
||||
|
||||
} |
||||
|
||||
@Override |
||||
public void readXML(XMLableReader reader) { |
||||
if (reader.isAttr()) { |
||||
reader.readXMLObject(new XMLReadable() { |
||||
public void readXML(XMLableReader reader) { |
||||
if (reader.isChildNode()) { |
||||
String nodeName = reader.getTagName(); |
||||
if (nodeName.equals("RecentModelList")) { |
||||
String key = reader.getAttrAsString("searchKey", StringUtils.EMPTY); |
||||
final ArrayList<AlphaCellModel> list = new ArrayList<AlphaCellModel>(); |
||||
reader.readXMLObject(new XMLReadable() { |
||||
@Override |
||||
public void readXML(XMLableReader reader) { |
||||
readCellModel(reader, list); |
||||
} |
||||
} |
||||
); |
||||
recentKVModelMap.put(key, list); |
||||
} |
||||
} |
||||
} |
||||
}); |
||||
} |
||||
|
||||
} |
||||
|
||||
private void readCellModel(XMLableReader reader, List<AlphaCellModel> list) { |
||||
if (reader.isChildNode()) { |
||||
String nodeName = reader.getTagName(); |
||||
if (nodeName.equals("model")) { |
||||
String name = reader.getAttrAsString("cellModel", StringUtils.EMPTY); |
||||
addModelToList(list, name); |
||||
} |
||||
} |
||||
} |
||||
|
||||
private void addModelToList(List<AlphaCellModel> list, String name) { |
||||
try { |
||||
list.add(CellModelHelper.getModelFromJson(new JSONObject(name))); |
||||
} catch (JSONException e) { |
||||
FRLogger.getLogger().error(e.getMessage()); |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public void writeXML(XMLPrintWriter writer) { |
||||
writer.startTAG(XML_TAG); |
||||
if (!recentKVModelMap.isEmpty()) { |
||||
for (String key : recentKVModelMap.keySet()) { |
||||
writer.startTAG("RecentModelList"); |
||||
writer.attr("searchKey", key); |
||||
for (AlphaCellModel model : recentKVModelMap.get(key)) { |
||||
try { |
||||
String name = model.ModelToJson().toString(); |
||||
writer.startTAG("model"); |
||||
writer.attr("cellModel", name); |
||||
writer.end(); |
||||
} catch (JSONException e) { |
||||
FRLogger.getLogger().error(e.getMessage()); |
||||
} |
||||
} |
||||
writer.end(); |
||||
} |
||||
} |
||||
writer.end(); |
||||
|
||||
} |
||||
|
||||
@Override |
||||
public String fileName() { |
||||
return "alphafine_recent.xml"; |
||||
} |
||||
|
||||
public List<String> getFileList() { |
||||
return fileList; |
||||
} |
||||
|
||||
public void setFileList(List<String> fileList) { |
||||
this.fileList = fileList; |
||||
} |
||||
|
||||
public List<String> getActionList() { |
||||
return actionList; |
||||
} |
||||
|
||||
public void setActionList(List<String> actionList) { |
||||
this.actionList = actionList; |
||||
} |
||||
|
||||
public List<String> getDocumentList() { |
||||
return documentList; |
||||
} |
||||
|
||||
public void setDocumentList(List<String> documentList) { |
||||
this.documentList = documentList; |
||||
} |
||||
|
||||
public List<String> getPluginList() { |
||||
return pluginList; |
||||
} |
||||
|
||||
public void setPluginList(List<String> pluginList) { |
||||
this.pluginList = pluginList; |
||||
} |
||||
|
||||
/** |
||||
* 获取xml |
||||
* @return |
||||
*/ |
||||
private File getRecentFile() { |
||||
if (recentFile == null) { |
||||
recentFile = new File(ProductConstants.getEnvHome() + File.separator + fileName()); |
||||
} |
||||
return recentFile; |
||||
} |
||||
|
||||
private File getRecentEnvFile() { |
||||
File envFile = getRecentFile(); |
||||
if (!envFile.exists()) { |
||||
createRecentFile(envFile); |
||||
} |
||||
|
||||
return envFile; |
||||
} |
||||
|
||||
/** |
||||
* 创建XML |
||||
* @param envFile |
||||
*/ |
||||
private void createRecentFile(File envFile) { |
||||
try { |
||||
FileWriter fileWriter = new FileWriter(envFile); |
||||
StringReader stringReader = new StringReader("<?xml version=\"1.0\" encoding=\"UTF-8\" ?><AlphafineRecent></AlphafineRecent>"); |
||||
Utils.copyCharTo(stringReader, fileWriter); |
||||
stringReader.close(); |
||||
fileWriter.close(); |
||||
} catch (IOException e) { |
||||
FRContext.getLogger().error(e.getMessage(), e); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 保存XML到设计器安装目录 |
||||
*/ |
||||
public void saveXMLFile() { |
||||
File xmlFile = this.getRecentEnvFile(); |
||||
if (xmlFile == null) { |
||||
return; |
||||
} |
||||
if (!xmlFile.getParentFile().exists()) {//建立目录.
|
||||
StableUtils.mkdirs(xmlFile.getParentFile()); |
||||
} |
||||
|
||||
String tempName = xmlFile.getName() + ProjectConstants.TEMP_SUFFIX; |
||||
File tempFile = new File(xmlFile.getParentFile(), tempName); |
||||
|
||||
writeTempFile(tempFile); |
||||
IOUtils.renameTo(tempFile, xmlFile); |
||||
} |
||||
|
||||
private void writeTempFile(File tempFile) { |
||||
try { |
||||
OutputStream fout = new FileOutputStream(tempFile); |
||||
XMLTools.writeOutputStreamXML(this, fout); |
||||
fout.flush(); |
||||
fout.close(); |
||||
} catch (Exception e) { |
||||
FRContext.getLogger().error(e.getMessage()); |
||||
} |
||||
} |
||||
|
||||
|
||||
public List<AlphaCellModel> getRecentModelList() { |
||||
return recentModelList; |
||||
} |
||||
|
||||
public void setRecentModelList(List<AlphaCellModel> recentModelList) { |
||||
this.recentModelList = recentModelList; |
||||
} |
||||
|
||||
/** |
||||
* 根据搜索字段获取对应的model列表 |
||||
* @param searchText |
||||
* @return |
||||
*/ |
||||
public List<AlphaCellModel> getRecentModelList(String searchText) { |
||||
recentModelList = new ArrayList<>(); |
||||
for (String key : recentKVModelMap.keySet()) { |
||||
if (ComparatorUtils.equals(key, searchText)) { |
||||
recentModelList = recentKVModelMap.get(searchText); |
||||
if (recentModelList.size() > 3) { |
||||
return recentModelList.subList(0, 2); |
||||
} |
||||
return recentModelList; |
||||
} |
||||
} |
||||
return recentModelList; |
||||
} |
||||
|
||||
/** |
||||
* 将搜索结果加入到当前MAP中 |
||||
* @param searchKey |
||||
* @param cellModel |
||||
*/ |
||||
public void addRecentModel(String searchKey, AlphaCellModel cellModel) { |
||||
if (recentKVModelMap.keySet().contains(searchKey)) { |
||||
List<AlphaCellModel> cellModels = recentKVModelMap.get(searchKey); |
||||
if (cellModels.contains(cellModel)) { |
||||
cellModels.remove(cellModel); |
||||
cellModels.add(cellModel); |
||||
} else { |
||||
cellModels.add(cellModel); |
||||
} |
||||
trimToSize(cellModels); |
||||
} else { |
||||
List<AlphaCellModel> list = new ArrayList<>(); |
||||
list.add(cellModel); |
||||
recentKVModelMap.put(searchKey, list); |
||||
} |
||||
} |
||||
|
||||
|
||||
private synchronized void trimToSize(List<AlphaCellModel> cellModels) { |
||||
if (cellModels.size() > AlphaFineConstants.MAX_FILE_SIZE) { |
||||
cellModels.remove(0); |
||||
} |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public SearchResult getLessSearchResult(String searchText) { |
||||
this.modelList = new SearchResult(); |
||||
recentModelList = getRecentModelList(searchText); |
||||
if (recentModelList != null && recentModelList.size() > 0) { |
||||
modelList.add(new MoreModel(Inter.getLocText("FR-Designer_AlphaFine_Latest"), false)); |
||||
} |
||||
modelList.addAll(recentModelList); |
||||
return modelList; |
||||
} |
||||
|
||||
@Override |
||||
public SearchResult getMoreSearchResult() { |
||||
return new SearchResult(); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,69 @@
|
||||
package com.fr.design.mainframe.alphafine.search.manager; |
||||
|
||||
import com.fr.design.mainframe.alphafine.cell.CellModelHelper; |
||||
import com.fr.design.mainframe.alphafine.cell.model.AlphaCellModel; |
||||
import com.fr.design.mainframe.alphafine.cell.model.MoreModel; |
||||
import com.fr.design.mainframe.alphafine.model.SearchResult; |
||||
import com.fr.general.FRLogger; |
||||
import com.fr.general.Inter; |
||||
import com.fr.general.http.HttpClient; |
||||
import com.fr.json.JSONArray; |
||||
import com.fr.json.JSONException; |
||||
import com.fr.json.JSONObject; |
||||
import com.fr.stable.CodeUtils; |
||||
|
||||
/** |
||||
* Created by XiaXiang on 2017/3/31. |
||||
*/ |
||||
public class RecommendSearchManager implements AlphaFineSearchProcessor { |
||||
private static RecommendSearchManager recommendSearchManager = null; |
||||
private SearchResult modelList; |
||||
//todo:for test
|
||||
private static final String SEARCHAPI = "http://localhost:8080/monitor/alphafine/search/recommend?searchKey="; |
||||
|
||||
public synchronized static RecommendSearchManager getRecommendSearchManager() { |
||||
if (recommendSearchManager == null) { |
||||
recommendSearchManager = new RecommendSearchManager(); |
||||
} |
||||
return recommendSearchManager; |
||||
} |
||||
@Override |
||||
public synchronized SearchResult getLessSearchResult(String searchText) { |
||||
String result; |
||||
this.modelList = new SearchResult(); |
||||
HttpClient httpClient = new HttpClient(SEARCHAPI + CodeUtils.cjkEncode(searchText)); |
||||
httpClient.asGet(); |
||||
httpClient.setTimeout(5000); |
||||
if (!httpClient.isServerAlive()) { |
||||
return modelList; |
||||
} |
||||
result = httpClient.getResponseText(); |
||||
try { |
||||
JSONObject jsonObject = new JSONObject(result); |
||||
if (jsonObject.optString("status").equals("success")) { |
||||
JSONArray jsonArray = jsonObject.optJSONArray("result"); |
||||
if (jsonArray != null && jsonArray.length() > 0) { |
||||
for (int i = 0; i < jsonArray.length(); i++) { |
||||
AlphaCellModel alphaCellModel = CellModelHelper.getModelFromJson((JSONObject) jsonArray.get(i)); |
||||
if (!RecentSearchManager.getRecentSearchManger().getRecentModelList().contains(alphaCellModel)) { |
||||
this.modelList.add(alphaCellModel); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
} catch (JSONException e) { |
||||
FRLogger.getLogger().error(e.getMessage()); |
||||
} |
||||
if (modelList.size() > 0) { |
||||
modelList.add(0, new MoreModel(Inter.getLocText("FR-Designer_AlphaFine_Conclude"), false)); |
||||
} |
||||
return modelList; |
||||
} |
||||
|
||||
@Override |
||||
public SearchResult getMoreSearchResult() { |
||||
return new SearchResult(); |
||||
} |
||||
|
||||
} |
@ -1,12 +0,0 @@
|
||||
package com.fr.design.mainframe.alphafine.searchManager; |
||||
|
||||
import com.fr.design.mainframe.alphafine.model.SearchResult; |
||||
|
||||
/** |
||||
* Created by XiaXiang on 2017/3/27. |
||||
*/ |
||||
public interface AlphaFineSearchProcessor { |
||||
SearchResult showLessSearchResult(String searchText); |
||||
|
||||
SearchResult showMoreSearchResult(); |
||||
} |
@ -1,89 +0,0 @@
|
||||
package com.fr.design.mainframe.alphafine.searchManager; |
||||
|
||||
import com.fr.design.mainframe.alphafine.AlphaFineHelper; |
||||
import com.fr.design.mainframe.alphafine.cell.cellModel.MoreModel; |
||||
import com.fr.design.mainframe.alphafine.model.SearchResult; |
||||
import com.fr.general.Inter; |
||||
|
||||
import java.io.*; |
||||
|
||||
/** |
||||
* Created by XiaXiang on 2017/3/28. |
||||
*/ |
||||
public class AlphaSearchManager implements AlphaFineSearchProcessor { |
||||
private static AlphaSearchManager searchManager; |
||||
private static PluginSearchManager pluginSearchManager; |
||||
private static DocumentSearchManager documentSearchManager; |
||||
private static FileSearchManager fileSearchManager; |
||||
private static ActionSearchManager actionSearchManager; |
||||
private static ConcludeSearchManager concludeSearchManager; |
||||
private static LatestSearchManager latestSearchManager; |
||||
|
||||
public synchronized static AlphaSearchManager getSearchManager() { |
||||
init(); |
||||
return searchManager; |
||||
|
||||
} |
||||
|
||||
private synchronized static void init() { |
||||
if (searchManager == null) { |
||||
searchManager = new AlphaSearchManager(); |
||||
pluginSearchManager = PluginSearchManager.getPluginSearchManager(); |
||||
documentSearchManager = DocumentSearchManager.getDocumentSearchManager(); |
||||
fileSearchManager = FileSearchManager.getFileSearchManager(); |
||||
actionSearchManager = ActionSearchManager.getActionSearchManager(); |
||||
concludeSearchManager = ConcludeSearchManager.getConcludeSearchManager(); |
||||
latestSearchManager = LatestSearchManager.getLatestSearchManager(); |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public synchronized SearchResult showLessSearchResult(String searchText) { |
||||
SearchResult latestModelList = latestSearchManager.showLessSearchResult(searchText); |
||||
SearchResult concludeModelList = concludeSearchManager.showLessSearchResult(searchText); |
||||
SearchResult actionModelList = actionSearchManager.showLessSearchResult(searchText); |
||||
SearchResult fileModelList = fileSearchManager.showLessSearchResult(searchText); |
||||
SearchResult documentModelList = documentSearchManager.showLessSearchResult(searchText); |
||||
SearchResult pluginModelList = pluginSearchManager.showLessSearchResult(searchText); |
||||
latestModelList.addAll(concludeModelList); |
||||
latestModelList.addAll(actionModelList); |
||||
latestModelList.addAll(fileModelList); |
||||
latestModelList.addAll(documentModelList); |
||||
latestModelList.addAll(pluginModelList); |
||||
return latestModelList; |
||||
} |
||||
|
||||
public SearchResult showDefaultSearchResult() { |
||||
SearchResult searchResult = new SearchResult(); |
||||
searchResult.add(new MoreModel(Inter.getLocText("FR-Designer_AlphaFine_Latest"))); |
||||
searchResult.add(new MoreModel(Inter.getLocText("FR-Designer_AlphaFine_Conclude"))); |
||||
searchResult.add(new MoreModel(Inter.getLocText("FR-Designer_Set"))); |
||||
searchResult.add(new MoreModel(Inter.getLocText("FR-Designer_Templates"))); |
||||
searchResult.add(new MoreModel(Inter.getLocText("FR-Designer_COMMUNITY_HELP"))); |
||||
searchResult.add(new MoreModel(Inter.getLocText("FR-Designer-Plugin_Addon"))); |
||||
return searchResult; |
||||
} |
||||
|
||||
@Override |
||||
public SearchResult showMoreSearchResult() { |
||||
return null; |
||||
} |
||||
|
||||
public SearchResult getLatestSearchResult() { |
||||
ObjectInputStream is; |
||||
SearchResult searchResult; |
||||
try { |
||||
is = new ObjectInputStream(new FileInputStream(AlphaFineHelper.getInfoFile())); |
||||
searchResult = (SearchResult) is.readObject(); |
||||
|
||||
} catch (IOException e) { |
||||
searchResult = new SearchResult(); |
||||
} catch (ClassNotFoundException e) { |
||||
searchResult = new SearchResult(); |
||||
|
||||
} |
||||
return searchResult; |
||||
|
||||
} |
||||
|
||||
} |
@ -1,33 +0,0 @@
|
||||
package com.fr.design.mainframe.alphafine.searchManager; |
||||
|
||||
import com.fr.design.mainframe.alphafine.cell.cellModel.MoreModel; |
||||
import com.fr.design.mainframe.alphafine.model.SearchResult; |
||||
import com.fr.general.Inter; |
||||
|
||||
/** |
||||
* Created by XiaXiang on 2017/3/31. |
||||
*/ |
||||
public class ConcludeSearchManager implements AlphaFineSearchProcessor { |
||||
private static ConcludeSearchManager concludeSearchManager = null; |
||||
private SearchResult modelList; |
||||
|
||||
public synchronized static ConcludeSearchManager getConcludeSearchManager() { |
||||
if (concludeSearchManager == null) { |
||||
concludeSearchManager = new ConcludeSearchManager(); |
||||
} |
||||
return concludeSearchManager; |
||||
} |
||||
@Override |
||||
public synchronized SearchResult showLessSearchResult(String searchText) { |
||||
//todo: 猜您喜欢逻辑需要重新设计
|
||||
this.modelList = new SearchResult(); |
||||
modelList.add(new MoreModel(Inter.getLocText("FR-Designer_AlphaFine_Conclude"), false)); |
||||
return modelList; |
||||
} |
||||
|
||||
@Override |
||||
public SearchResult showMoreSearchResult() { |
||||
return null; |
||||
} |
||||
|
||||
} |
@ -1,91 +0,0 @@
|
||||
package com.fr.design.mainframe.alphafine.searchManager; |
||||
|
||||
import com.fr.design.DesignerEnvManager; |
||||
import com.fr.design.mainframe.alphafine.AlphaFineConstants; |
||||
import com.fr.design.mainframe.alphafine.CellType; |
||||
import com.fr.design.mainframe.alphafine.cell.cellModel.DocumentModel; |
||||
import com.fr.design.mainframe.alphafine.cell.cellModel.MoreModel; |
||||
import com.fr.design.mainframe.alphafine.model.SearchResult; |
||||
import com.fr.general.FRLogger; |
||||
import com.fr.general.Inter; |
||||
import com.fr.general.http.HttpClient; |
||||
import com.fr.json.JSONArray; |
||||
import com.fr.json.JSONException; |
||||
import com.fr.json.JSONObject; |
||||
|
||||
import java.security.AlgorithmConstraints; |
||||
|
||||
/** |
||||
* Created by XiaXiang on 2017/3/27. |
||||
*/ |
||||
public class DocumentSearchManager implements AlphaFineSearchProcessor { |
||||
private static DocumentSearchManager documentSearchManager = null; |
||||
private SearchResult lessModelList; |
||||
private SearchResult moreModelList; |
||||
|
||||
public synchronized static DocumentSearchManager getDocumentSearchManager() { |
||||
if (documentSearchManager == null) { |
||||
documentSearchManager = new DocumentSearchManager(); |
||||
|
||||
} |
||||
return documentSearchManager; |
||||
} |
||||
|
||||
@Override |
||||
public synchronized SearchResult showLessSearchResult(String searchText) { |
||||
this.lessModelList = new SearchResult(); |
||||
this.moreModelList = new SearchResult(); |
||||
if (DesignerEnvManager.getEnvManager().getAlphafineConfigManager().isContainDocument()) { |
||||
String result; |
||||
String url = AlphaFineConstants.DOCUMENT_SEARCH_URL + searchText + "-1"; |
||||
HttpClient httpClient = new HttpClient(url); |
||||
httpClient.setTimeout(5000); |
||||
httpClient.asGet(); |
||||
result = httpClient.getResponseText(); |
||||
try { |
||||
JSONObject jsonObject = new JSONObject(result); |
||||
JSONArray jsonArray = null; |
||||
if (jsonObject.get("docdata") != null) { |
||||
jsonArray = (JSONArray) jsonObject.get("docdata"); |
||||
} |
||||
if (jsonArray.length() > 0) { |
||||
if (jsonArray.length() > AlphaFineConstants.SHOW_SIZE) { |
||||
lessModelList.add(new MoreModel(Inter.getLocText("FR-Designer_COMMUNITY_HELP"), Inter.getLocText("FR-Designer_AlphaFine_ShowAll"),true, CellType.DOCUMENT)); |
||||
} else { |
||||
lessModelList.add(new MoreModel(Inter.getLocText("FR-Designer_COMMUNITY_HELP"), CellType.DOCUMENT)); |
||||
} |
||||
} |
||||
|
||||
final int length = Math.min(AlphaFineConstants.SHOW_SIZE, jsonArray.length()); |
||||
for (int i = 0; i < length; i++) { |
||||
DocumentModel cellModel = getDocumentModel(jsonArray, i); |
||||
this.lessModelList.add(cellModel); |
||||
} |
||||
for (int i = length; i < jsonArray.length(); i++) { |
||||
DocumentModel cellModel = getDocumentModel(jsonArray, i); |
||||
this.moreModelList.add(cellModel); |
||||
} |
||||
|
||||
} catch (JSONException e) { |
||||
FRLogger.getLogger().error(e.getMessage()); |
||||
return lessModelList; |
||||
} |
||||
|
||||
} |
||||
return lessModelList; |
||||
} |
||||
|
||||
private DocumentModel getDocumentModel(JSONArray jsonArray, int i) throws JSONException { |
||||
JSONObject object = jsonArray.getJSONObject(i); |
||||
String name = (String) object.get("title"); |
||||
String content = ((String) object.get("summary")); |
||||
String documentUrl = AlphaFineConstants.DOCUMENT_DOC_URL + object.get("did") + ".html"; |
||||
return new DocumentModel(name, content, documentUrl); |
||||
} |
||||
|
||||
@Override |
||||
public SearchResult showMoreSearchResult() { |
||||
return moreModelList; |
||||
} |
||||
|
||||
} |
@ -1,55 +0,0 @@
|
||||
package com.fr.design.mainframe.alphafine.searchManager; |
||||
|
||||
import com.fr.design.mainframe.alphafine.cell.cellModel.MoreModel; |
||||
import com.fr.design.mainframe.alphafine.model.SearchResult; |
||||
import com.fr.general.Inter; |
||||
|
||||
/** |
||||
* Created by XiaXiang on 2017/3/31. |
||||
*/ |
||||
public class LatestSearchManager implements AlphaFineSearchProcessor { |
||||
private static LatestSearchManager latestSearchManager = null; |
||||
private SearchResult modelList; |
||||
private SearchResult latestModelList; |
||||
|
||||
public synchronized static LatestSearchManager getLatestSearchManager() { |
||||
if (latestSearchManager == null) { |
||||
latestSearchManager = new LatestSearchManager(); |
||||
} |
||||
return latestSearchManager; |
||||
} |
||||
@Override |
||||
public synchronized SearchResult showLessSearchResult(String searchText) { |
||||
this.modelList = new SearchResult(); |
||||
modelList.add(new MoreModel(Inter.getLocText("FR-Designer_AlphaFine_Latest"), false)); |
||||
//todo: 本地常用逻辑需要重新设计
|
||||
// if (getLatestModelList() != null && getLatestModelList().size() > 0) {
|
||||
// modelList.addAll(getLatestModelList());
|
||||
// }
|
||||
return modelList; |
||||
} |
||||
|
||||
@Override |
||||
public SearchResult showMoreSearchResult() { |
||||
return null; |
||||
} |
||||
|
||||
public SearchResult getModelList() { |
||||
return modelList; |
||||
} |
||||
|
||||
public void setModelList(SearchResult modelList) { |
||||
this.modelList = modelList; |
||||
} |
||||
|
||||
public SearchResult getLatestModelList() { |
||||
if(this.latestModelList != null && this.latestModelList.size() > 0) { |
||||
return this.latestModelList; |
||||
} |
||||
return AlphaSearchManager.getSearchManager().getLatestSearchResult(); |
||||
} |
||||
|
||||
public void setLatestModelList(SearchResult latestModelList) { |
||||
this.latestModelList = latestModelList; |
||||
} |
||||
} |
@ -1,105 +0,0 @@
|
||||
package com.fr.design.mainframe.alphafine.searchManager; |
||||
|
||||
import com.fr.design.DesignerEnvManager; |
||||
import com.fr.design.mainframe.alphafine.AlphaFineConstants; |
||||
import com.fr.design.mainframe.alphafine.CellType; |
||||
import com.fr.design.mainframe.alphafine.cell.cellModel.PluginModel; |
||||
import com.fr.design.mainframe.alphafine.cell.cellModel.MoreModel; |
||||
import com.fr.design.mainframe.alphafine.model.SearchResult; |
||||
import com.fr.general.ComparatorUtils; |
||||
import com.fr.general.FRLogger; |
||||
import com.fr.general.Inter; |
||||
import com.fr.general.http.HttpClient; |
||||
import com.fr.json.JSONArray; |
||||
import com.fr.json.JSONException; |
||||
import com.fr.json.JSONObject; |
||||
|
||||
import java.net.URLEncoder; |
||||
|
||||
/** |
||||
* Created by XiaXiang on 2017/3/27. |
||||
*/ |
||||
public class PluginSearchManager implements AlphaFineSearchProcessor { |
||||
private static PluginSearchManager pluginSearchManager = null; |
||||
private SearchResult lessModelList; |
||||
private SearchResult moreModelList; |
||||
|
||||
public synchronized static PluginSearchManager getPluginSearchManager() { |
||||
if (pluginSearchManager == null) { |
||||
pluginSearchManager = new PluginSearchManager(); |
||||
} |
||||
return pluginSearchManager; |
||||
|
||||
} |
||||
|
||||
@Override |
||||
public synchronized SearchResult showLessSearchResult(String searchText) { |
||||
|
||||
this.lessModelList = new SearchResult(); |
||||
this.moreModelList = new SearchResult(); |
||||
if (DesignerEnvManager.getEnvManager().getAlphafineConfigManager().isContainPlugin()) { |
||||
String result; |
||||
try { |
||||
String encodedKey = URLEncoder.encode(searchText, "UTF-8"); |
||||
String url = AlphaFineConstants.PLUGIN_SEARCH_URL + "?keyword=" + encodedKey; |
||||
HttpClient httpClient = new HttpClient(url); |
||||
httpClient.setTimeout(5000); |
||||
httpClient.asGet(); |
||||
result = httpClient.getResponseText(); |
||||
JSONObject jsonObject = new JSONObject(result); |
||||
JSONArray jsonArray = null; |
||||
if (jsonObject.get("result") != null) { |
||||
jsonArray = (JSONArray) jsonObject.get("result"); |
||||
} |
||||
if (jsonArray.length() > 0) { |
||||
if (jsonArray.length() > AlphaFineConstants.SHOW_SIZE) { |
||||
lessModelList.add(new MoreModel(Inter.getLocText("FR-Designer-Plugin_Addon"), Inter.getLocText("FR-Designer_AlphaFine_ShowAll"),true, CellType.PLUGIN)); |
||||
} else { |
||||
lessModelList.add(new MoreModel(Inter.getLocText("FR-Designer-Plugin_Addon"), CellType.PLUGIN)); |
||||
} |
||||
} |
||||
|
||||
int length = Math.min(5, jsonArray.length()); |
||||
for (int i = 0; i < length; i++) { |
||||
PluginModel cellModel = getPluginModel(jsonArray, i); |
||||
this.lessModelList.add(cellModel); |
||||
} |
||||
for (int i = length; i < jsonArray.length(); i++) { |
||||
PluginModel cellModel = getPluginModel(jsonArray, i); |
||||
this.moreModelList.add(cellModel); |
||||
} |
||||
} catch (Exception e) { |
||||
FRLogger.getLogger().error(e.getMessage()); |
||||
return lessModelList; |
||||
} |
||||
} |
||||
return this.lessModelList; |
||||
} |
||||
|
||||
private PluginModel getPluginModel(JSONArray jsonArray, int i) throws JSONException { |
||||
JSONObject object = jsonArray.getJSONObject(i); |
||||
String name = (String) object.get("name"); |
||||
String content = ((String) object.get("description")); |
||||
String pluginUrl = AlphaFineConstants.REUSE_IMAGE_URL + object.get("id"); |
||||
String imageUrl = ((String) object.get("pic")); |
||||
String version = null; |
||||
String jartime = null; |
||||
CellType type = CellType.REUSE; |
||||
String link = (String) object.get("link"); |
||||
if (ComparatorUtils.equals(link, "plugin")) { |
||||
version = (String) object.get("version"); |
||||
jartime = (String) object.get("jartime"); |
||||
type = CellType.PLUGIN; |
||||
pluginUrl = AlphaFineConstants.PLUGIN_IMAGE_URL + object.get("id"); |
||||
} |
||||
int price = (int) object.get("price"); |
||||
return new PluginModel(name, content, pluginUrl, imageUrl, version, jartime, type, price); |
||||
} |
||||
|
||||
@Override |
||||
public SearchResult showMoreSearchResult() { |
||||
return this.moreModelList; |
||||
} |
||||
|
||||
|
||||
} |
Loading…
Reference in new issue