From 75c6837e3571c45c28a9fefa69a9ad9921818135 Mon Sep 17 00:00:00 2001 From: "alex.sung" Date: Tue, 21 Aug 2018 23:54:36 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=84=E8=8C=83=E5=9B=BD=E9=99=85=E5=8C=96?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E5=8F=8A=E5=9B=BD=E9=99=85=E5=8C=96=E5=AE=9A?= =?UTF-8?q?=E4=B9=89=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../alphafine/AlphaFineConfigManager.java | 21 +-- .../help/alphafine/AlphaFineConfigPane.java | 26 +-- .../alphafine/AlphaFineConstants.java | 21 ++- .../alphafine/cell/model/BottomModel.java | 7 +- .../alphafine/cell/model/RobotModel.java | 8 +- .../cell/render/ContentCellRender.java | 20 +-- .../alphafine/component/AlphaFineDialog.java | 160 +++++++++--------- .../component/AlphaFineTextField.java | 6 - .../alphafine/preview/ContainsCirclePane.java | 2 +- .../manager/impl/ActionSearchManager.java | 3 +- .../manager/impl/ComplementAdviceManager.java | 23 +-- .../manager/impl/DocumentSearchManager.java | 20 +-- .../manager/impl/FileSearchManager.java | 2 +- .../search/manager/impl/HotIssuesManager.java | 70 ++++---- .../manager/impl/PluginSearchManager.java | 23 +-- .../manager/impl/RecentSearchManager.java | 3 - .../manager/impl/RecommendSearchManager.java | 30 ++-- .../manager/impl/SegmentationManager.java | 13 +- .../manager/impl/SimilarSearchManeger.java | 28 ++- 19 files changed, 243 insertions(+), 243 deletions(-) diff --git a/designer-base/src/main/java/com/fr/design/actions/help/alphafine/AlphaFineConfigManager.java b/designer-base/src/main/java/com/fr/design/actions/help/alphafine/AlphaFineConfigManager.java index 11bc0fb34c..d62f44a4bc 100644 --- a/designer-base/src/main/java/com/fr/design/actions/help/alphafine/AlphaFineConfigManager.java +++ b/designer-base/src/main/java/com/fr/design/actions/help/alphafine/AlphaFineConfigManager.java @@ -58,11 +58,11 @@ public class AlphaFineConfigManager implements XMLable { /** * 分词搜索 */ - private boolean isNeedSegmentationCheckbox = true; + private boolean needSegmentationCheckbox = true; /** * 智能客服 */ - private boolean isNeedIntelligentCustomerService = true; + private boolean needIntelligentCustomerService = true; /** * 快捷键 */ @@ -102,8 +102,8 @@ public class AlphaFineConfigManager implements XMLable { this.setContainAction(reader.getAttrAsBoolean("isContainAction", true)); this.setContainTemplate(reader.getAttrAsBoolean("isContainTemplate", true)); this.setContainFileContent(reader.getAttrAsBoolean("isContainFileContent", false)); - this.setNeedSegmentationCheckbox(reader.getAttrAsBoolean("isNeedSegmentationCheckbox", true)); - this.setNeedIntelligentCustomerService(reader.getAttrAsBoolean("isNeedIntelligentCustomerService", true)); + this.setNeedSegmentationCheckbox(reader.getAttrAsBoolean("needSegmentationCheckbox", true)); + this.setNeedIntelligentCustomerService(reader.getAttrAsBoolean("needIntelligentCustomerService", true)); this.setShortcuts(reader.getAttrAsString("shortcuts", getDefaultShortCuts())); this.setNeedRemind(reader.getAttrAsBoolean("isNeedRemind", true)); this.setOperateCount(reader.getAttrAsInt("operateCount", 0)); @@ -126,8 +126,8 @@ public class AlphaFineConfigManager implements XMLable { .attr("isContainFileContent", this.isContainFileContent()) .attr("isNeedRemind", this.isNeedRemind()) .attr("operateCount", this.getOperateCount()) - .attr("isNeedSegmentationCheckbox", this.isNeedSegmentationCheckbox()) - .attr("isNeedIntelligentCustomerService", this.isNeedIntelligentCustomerService()); + .attr("needSegmentationCheckbox", this.isNeedSegmentationCheckbox()) + .attr("needIntelligentCustomerService", this.isNeedIntelligentCustomerService()); writer.end(); } @@ -240,20 +240,21 @@ public class AlphaFineConfigManager implements XMLable { } public boolean isNeedSegmentationCheckbox() { - return isNeedSegmentationCheckbox; + return needSegmentationCheckbox; } public void setNeedSegmentationCheckbox(boolean needSegmentationCheckbox) { - isNeedSegmentationCheckbox = needSegmentationCheckbox; + this.needSegmentationCheckbox = needSegmentationCheckbox; } public boolean isNeedIntelligentCustomerService() { - return isNeedIntelligentCustomerService; + return needIntelligentCustomerService; } public void setNeedIntelligentCustomerService(boolean needIntelligentCustomerService) { - isNeedIntelligentCustomerService = needIntelligentCustomerService; + this.needIntelligentCustomerService = needIntelligentCustomerService; } + public int getOperateCount() { return operateCount; } diff --git a/designer-base/src/main/java/com/fr/design/actions/help/alphafine/AlphaFineConfigPane.java b/designer-base/src/main/java/com/fr/design/actions/help/alphafine/AlphaFineConfigPane.java index 1520a7e1dd..6f93631bc0 100644 --- a/designer-base/src/main/java/com/fr/design/actions/help/alphafine/AlphaFineConfigPane.java +++ b/designer-base/src/main/java/com/fr/design/actions/help/alphafine/AlphaFineConfigPane.java @@ -55,7 +55,7 @@ public class AlphaFineConfigPane extends BasicPane { private static final double COLUMN_GAP = 180; private static final double ROW_GAP = 25; private KeyStroke shortCutKeyStore = null; - private UICheckBox isEnabledCheckbox, isSearchOnlineCheckbox, isNeedSegmentationCheckbox, isNeedIntelligentCustomerService, isContainRecommendCheckbox, isContainActionCheckbox, isContainDocumentCheckbox, isContainTemplateCheckbox, isContainPluginCheckbox, isContainFileContentCheckbox; + private UICheckBox isEnabledCheckbox, isSearchOnlineCheckbox, needSegmentationCheckbox, needIntelligentCustomerService, isContainRecommendCheckbox, isContainActionCheckbox, isContainDocumentCheckbox, isContainTemplateCheckbox, isContainPluginCheckbox, isContainFileContentCheckbox; private UITextField shortcutsField; public AlphaFineConfigPane() { @@ -77,14 +77,14 @@ public class AlphaFineConfigPane extends BasicPane { Component[][] components = new Component[][]{ new Component[]{isContainRecommendCheckbox, isContainActionCheckbox, isContainDocumentCheckbox}, new Component[]{isContainTemplateCheckbox, isContainPluginCheckbox, isContainFileContentCheckbox}, - new Component[]{isNeedIntelligentCustomerService, null, null} + new Component[]{needIntelligentCustomerService, null, null} }; return components; } private Component[][] initOnlineComponents() { Component[][] components = new Component[][]{ - new Component[]{isSearchOnlineCheckbox, isNeedSegmentationCheckbox, null} + new Component[]{isSearchOnlineCheckbox, needSegmentationCheckbox, null} }; return components; } @@ -101,7 +101,7 @@ public class AlphaFineConfigPane extends BasicPane { isContainDocumentCheckbox = new UICheckBox(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Community_Help")); isContainTemplateCheckbox = new UICheckBox(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Templates")); isContainFileContentCheckbox = new UICheckBox(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Templates_Content")); - isNeedIntelligentCustomerService = new UICheckBox(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_AlphaFine_Intelligent_Customer_Service")); + needIntelligentCustomerService = new UICheckBox(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_AlphaFine_Intelligent_Customer_Service")); JPanel searchConfigPane = TableLayoutHelper.createTableLayoutPane(initSearchRangeComponents(), rowSize, columnSize); northPane.add(searchConfigPane); contentPane.add(northPane); @@ -148,7 +148,7 @@ public class AlphaFineConfigPane extends BasicPane { private void createOnlinePane(JPanel contentPane) { JPanel northPane = FRGUIPaneFactory.createTitledBorderPane(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_AlphaFine_Search_Type")); isSearchOnlineCheckbox = new UICheckBox(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_AlphaFine_Enable_Internet_Search")); - isNeedSegmentationCheckbox = new UICheckBox(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_AlphaFine_Enable_Segmentation")); + needSegmentationCheckbox = new UICheckBox(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_AlphaFine_Enable_Segmentation")); isSearchOnlineCheckbox.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { @@ -156,16 +156,16 @@ public class AlphaFineConfigPane extends BasicPane { isContainRecommendCheckbox.setEnabled(false); isContainPluginCheckbox.setEnabled(false); isContainDocumentCheckbox.setEnabled(false); - isNeedIntelligentCustomerService.setEnabled(false); + needIntelligentCustomerService.setEnabled(false); isContainRecommendCheckbox.setSelected(false); isContainPluginCheckbox.setSelected(false); isContainDocumentCheckbox.setSelected(false); - isNeedIntelligentCustomerService.setSelected(false); + needIntelligentCustomerService.setSelected(false); } else { isContainRecommendCheckbox.setEnabled(true); isContainPluginCheckbox.setEnabled(true); isContainDocumentCheckbox.setEnabled(true); - isNeedIntelligentCustomerService.setEnabled(true); + needIntelligentCustomerService.setEnabled(true); } } }); @@ -203,9 +203,9 @@ public class AlphaFineConfigPane extends BasicPane { this.isContainRecommendCheckbox.setEnabled(alphaFineConfigManager.isSearchOnLine()); this.shortcutsField.setText(getDisplayShortCut(alphaFineConfigManager.getShortcuts())); - this.isNeedSegmentationCheckbox.setSelected(alphaFineConfigManager.isNeedSegmentationCheckbox()); - this.isNeedIntelligentCustomerService.setSelected(alphaFineConfigManager.isNeedIntelligentCustomerService() && alphaFineConfigManager.isSearchOnLine()); - this.isNeedIntelligentCustomerService.setEnabled(alphaFineConfigManager.isSearchOnLine()); + this.needSegmentationCheckbox.setSelected(alphaFineConfigManager.isNeedSegmentationCheckbox()); + this.needIntelligentCustomerService.setSelected(alphaFineConfigManager.isNeedIntelligentCustomerService() && alphaFineConfigManager.isSearchOnLine()); + this.needIntelligentCustomerService.setEnabled(alphaFineConfigManager.isSearchOnLine()); shortCutKeyStore = convert2KeyStroke(alphaFineConfigManager.getShortcuts()); } @@ -220,8 +220,8 @@ public class AlphaFineConfigPane extends BasicPane { alphaFineConfigManager.setSearchOnLine(this.isSearchOnlineCheckbox.isSelected()); alphaFineConfigManager.setContainTemplate(this.isContainTemplateCheckbox.isSelected()); alphaFineConfigManager.setContainFileContent(this.isContainFileContentCheckbox.isSelected()); - alphaFineConfigManager.setNeedSegmentationCheckbox(this.isNeedSegmentationCheckbox.isSelected()); - alphaFineConfigManager.setNeedIntelligentCustomerService(this.isNeedIntelligentCustomerService.isSelected()); + alphaFineConfigManager.setNeedSegmentationCheckbox(this.needSegmentationCheckbox.isSelected()); + alphaFineConfigManager.setNeedIntelligentCustomerService(this.needIntelligentCustomerService.isSelected()); alphaFineConfigManager.setShortcuts(shortCutKeyStore != null ? shortCutKeyStore.toString().replace(TYPE, DISPLAY_TYPE) : this.shortcutsField.getText()); designerEnvManager.setAlphaFineConfigManager(alphaFineConfigManager); try { diff --git a/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/AlphaFineConstants.java b/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/AlphaFineConstants.java index cf7f04e0ae..410796f269 100644 --- a/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/AlphaFineConstants.java +++ b/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/AlphaFineConstants.java @@ -1,7 +1,6 @@ package com.fr.design.mainframe.alphafine; import com.fr.general.CloudCenter; - import java.awt.Color; import java.awt.Dimension; import java.awt.Font; @@ -69,6 +68,8 @@ public class AlphaFineConstants { public static final Color RED = new Color(0xf46c4c); + public static final String HIGH_LIGHT_COLOR = "rgb(51,148,240)"; + public static final Font SMALL_FONT = new Font("Song_TypeFace", 0, 10); public static final Font MEDIUM_FONT = new Font("Song_TypeFace", 0, 12); @@ -81,6 +82,8 @@ public class AlphaFineConstants { public static final String IMAGE_URL = "/com/fr/design/mainframe/alphafine/images/"; + public static final String ALPHA_HOT_IMAGE_NAME = "alphafine_hot"; + public static final String PLUGIN_SEARCH_URL = CloudCenter.getInstance().acquireUrlByKind("plugin.searchAPI"); public static final String PLUGIN_URL = CloudCenter.getInstance().acquireUrlByKind("af.pluginInfo"); @@ -100,13 +103,23 @@ public class AlphaFineConstants { public static final String SEARCH_API = CloudCenter.getInstance().acquireUrlByKind("af.cloud_search"); + public static final String SPECIAL_CHARACTER_REGEX = "[`~!@#$%^&*()+=|{}':;',\\[\\].<>/?~!@#¥%……&*()——+|{}【】';:”“’。,、?]"; + + public static final String BOTTOM_REGEX_FIRST = "
([\\s\\S]*?)class=\"jiaoyes\">YES
"; + + public static final String BOTTOM_REGEX_SECOND = "
"; + public static final String ALPHA_ROBOT_SEARCH_TOKEN = "K8dl0Np6l0gs"; - public static final String SIMILAR_SEARCH_URL_PREFIX = "http://robot.finereport.com/openapi/like.php?action=search&"; + public static final String SIMILAR_SEARCH_URL_PREFIX = CloudCenter.getInstance().acquireUrlByKind("af.similar_search"); + + public static final String COMPLEMENT_ADVICE_SEARCH_URL_PREFIX = CloudCenter.getInstance().acquireUrlByKind("af.advice_search"); + + public static final String ALPHA_HOT_SEARCH = CloudCenter.getInstance().acquireUrlByKind("af.hot_search"); - public static final String COMPLEMENT_ADVICE_SEARCH_URL_PREFIX = "http://robot.finereport.com/openapi/getkw.php?"; + public static final String ALPHA_GO_TO_FORUM = CloudCenter.getInstance().acquireUrlByKind("af.go_fourm"); - public static final String ALPHA_HOT_SEARCH = "http://robot.finereport.com/openapi/hot.php"; + public static final String ALPHA_GO_TO_WEB = CloudCenter.getInstance().acquireUrlByKind("af.go_web"); } diff --git a/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/cell/model/BottomModel.java b/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/cell/model/BottomModel.java index 76528685eb..50dc169bfe 100644 --- a/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/cell/model/BottomModel.java +++ b/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/cell/model/BottomModel.java @@ -1,5 +1,6 @@ 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.json.JSONException; import com.fr.json.JSONObject; @@ -31,12 +32,12 @@ public class BottomModel extends AlphaCellModel { @Override public JSONObject ModelToJson() throws JSONException { - return null; + return JSONObject.EMPTY; } @Override public String getStoreInformation() { - return null; + return ""; } @Override @@ -47,7 +48,7 @@ public class BottomModel extends AlphaCellModel { @Override public void doAction() { try { - Desktop.getDesktop().browse(new URI("http://bbs.fanruan.com/post_newthread_ajax.php?action=newthread&fid=39")); + Desktop.getDesktop().browse(new URI(AlphaFineConstants.ALPHA_GO_TO_FORUM)); } catch (IOException e) { FineLoggerFactory.getLogger().error(e.getMessage()); } catch (URISyntaxException e) { diff --git a/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/cell/model/RobotModel.java b/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/cell/model/RobotModel.java index 99ccab4bd0..85e0cfa84b 100644 --- a/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/cell/model/RobotModel.java +++ b/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/cell/model/RobotModel.java @@ -24,14 +24,14 @@ public class RobotModel extends AlphaCellModel { private String content; //热门问题列表的list不需要渲染图标,所以这里需要区分一下 - private boolean isHotItemModel = false; + private boolean hotItemModel = false; public boolean isHotItemModel() { - return isHotItemModel; + return hotItemModel; } public void setHotItemModel(boolean hotItemModel) { - isHotItemModel = hotItemModel; + this.hotItemModel = hotItemModel; } public String getTitle() { @@ -45,7 +45,7 @@ public class RobotModel extends AlphaCellModel { public static String getContent(String titleStr) { String result; String token = DigestUtils.md5Hex(AlphaFineConstants.ALPHA_ROBOT_SEARCH_TOKEN + titleStr); - String url = "http://robot.finereport.com/openapi/reply.php?action=search&msg=" + titleStr + "&token=" + token; + String url = AlphaFineConstants.ALPHA_GO_TO_WEB + titleStr + "&token=" + token; HttpClient httpClient = new HttpClient(url); httpClient.asGet(); result = httpClient.getResponseText(); diff --git a/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/cell/render/ContentCellRender.java b/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/cell/render/ContentCellRender.java index 367de258c5..cd9affb30c 100644 --- a/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/cell/render/ContentCellRender.java +++ b/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/cell/render/ContentCellRender.java @@ -57,18 +57,18 @@ public class ContentCellRender implements ListCellRenderer { String iconUrl = SELECTED_PATH + model.getType().getTypeValue() + SUFFIX; panel.setBackground(AlphaFineConstants.BLUE); titleLabel.setForeground(Color.WHITE); - if(value instanceof RobotModel && ((RobotModel) value).isHotItemModel()){ + if (value instanceof RobotModel && ((RobotModel) value).isHotItemModel()) { titleLabel.setIcon(null); - }else{ + } else { titleLabel.setIcon(IconLoader.getIcon(iconUrl)); } } else { titleLabel.setText(dealWithModelName(model.getName(), segmentationResult)); String iconUrl = CELL_PATH + model.getType().getTypeValue() + SUFFIX; - if(value instanceof RobotModel && ((RobotModel) value).isHotItemModel()){ + if (value instanceof RobotModel && ((RobotModel) value).isHotItemModel()) { titleLabel.setIcon(null); - }else{ + } else { titleLabel.setIcon(IconLoader.getIcon(iconUrl)); } } @@ -104,14 +104,14 @@ public class ContentCellRender implements ListCellRenderer { * @param strings * @return */ - public String dealWithModelName(String modelName, String strings[]) { + public String dealWithModelName(String modelName, String[] strings) { if (strings == null) { return modelName; } for (int i = 0; i < strings.length; i++) { String primaryStr = getReplacedString(modelName, strings[i]); - modelName = modelName.replaceAll("(?i)" + strings[i], "|" + strings[i] + "|"); - if(!StringUtils.isEmpty(primaryStr)){ + modelName = modelName.replaceAll("(?i)" + strings[i], "|" + strings[i] + "|"); + if (StringUtils.isNotEmpty(primaryStr)) { modelName = modelName.replaceAll(strings[i], primaryStr); } } @@ -121,10 +121,10 @@ public class ContentCellRender implements ListCellRenderer { private String getReplacedString(String modelName, String string) { int index = modelName.toLowerCase().indexOf(string.toLowerCase()); - if(index == -1){ - return null; + if (index == -1) { + return ""; } - return modelName.substring(index, index+string.length()); + return modelName.substring(index, index + string.length()); } } diff --git a/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/component/AlphaFineDialog.java b/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/component/AlphaFineDialog.java index af7cf2d265..d9f06137c9 100644 --- a/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/component/AlphaFineDialog.java +++ b/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/component/AlphaFineDialog.java @@ -11,11 +11,29 @@ import com.fr.design.gui.ilable.UILabel; import com.fr.design.mainframe.alphafine.AlphaFineConstants; import com.fr.design.mainframe.alphafine.AlphaFineHelper; import com.fr.design.mainframe.alphafine.cell.CellModelHelper; -import com.fr.design.mainframe.alphafine.cell.model.*; +import com.fr.design.mainframe.alphafine.cell.model.RobotModel; +import com.fr.design.mainframe.alphafine.cell.model.BottomModel; +import com.fr.design.mainframe.alphafine.cell.model.AlphaCellModel; +import com.fr.design.mainframe.alphafine.cell.model.FileModel; +import com.fr.design.mainframe.alphafine.cell.model.MoreModel; +import com.fr.design.mainframe.alphafine.cell.model.PluginModel; import com.fr.design.mainframe.alphafine.cell.render.ContentCellRender; import com.fr.design.mainframe.alphafine.model.SearchResult; -import com.fr.design.mainframe.alphafine.preview.*; -import com.fr.design.mainframe.alphafine.search.manager.impl.*; +import com.fr.design.mainframe.alphafine.preview.DocumentPreviewPane; +import com.fr.design.mainframe.alphafine.preview.FilePreviewPane; +import com.fr.design.mainframe.alphafine.preview.NoResultPane; +import com.fr.design.mainframe.alphafine.preview.PluginPreviewPane; +import com.fr.design.mainframe.alphafine.preview.RobotPreviewPane; +import com.fr.design.mainframe.alphafine.preview.ContainsCirclePane; +import com.fr.design.mainframe.alphafine.search.manager.impl.ActionSearchManager; +import com.fr.design.mainframe.alphafine.search.manager.impl.DocumentSearchManager; +import com.fr.design.mainframe.alphafine.search.manager.impl.FileSearchManager; +import com.fr.design.mainframe.alphafine.search.manager.impl.HotIssuesManager; +import com.fr.design.mainframe.alphafine.search.manager.impl.PluginSearchManager; +import com.fr.design.mainframe.alphafine.search.manager.impl.RecentSearchManager; +import com.fr.design.mainframe.alphafine.search.manager.impl.RecommendSearchManager; +import com.fr.design.mainframe.alphafine.search.manager.impl.SegmentationManager; +import com.fr.design.mainframe.alphafine.search.manager.impl.SimilarSearchManeger; import com.fr.design.mainframe.errorinfo.ErrorInfoUploader; import com.fr.design.mainframe.templateinfo.TemplateInfoCollector; import com.fr.form.main.Form; @@ -33,11 +51,38 @@ import com.fr.stable.StringUtils; import com.fr.stable.project.ProjectConstants; import javax.imageio.ImageIO; -import javax.swing.*; +import javax.swing.BorderFactory; +import javax.swing.DefaultListModel; +import javax.swing.ImageIcon; +import javax.swing.JLabel; +import javax.swing.JList; +import javax.swing.JPanel; +import javax.swing.JTextField; +import javax.swing.KeyStroke; +import javax.swing.SwingUtilities; +import javax.swing.SwingWorker; +import javax.swing.Timer; import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; -import java.awt.*; -import java.awt.event.*; +import java.awt.AWTEvent; +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.Dimension; +import java.awt.Frame; +import java.awt.Graphics; +import java.awt.GridLayout; +import java.awt.Image; +import java.awt.Point; +import java.awt.Rectangle; +import java.awt.Toolkit; +import java.awt.Window; +import java.awt.event.AWTEventListener; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.KeyAdapter; +import java.awt.event.KeyEvent; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; import java.awt.image.BufferedImage; import java.io.IOException; import java.net.URL; @@ -68,6 +113,7 @@ public class AlphaFineDialog extends UIDialog { private static final String SIMILAR_MARK = "k:robot "; private static final String PLACE_HOLDER = com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_AlphaFine"); private static final int MAX_SHOW_SIZE = 12; + private static final int TIMER_DELAY = 300; private AlphaFineTextField searchTextField; private UIButton closeButton; @@ -91,8 +137,8 @@ public class AlphaFineDialog extends UIDialog { private JPanel backPane; SearchResult modeList = null; private static String beforeSearchStr = ""; - private static boolean isAlreadySearch = false; - private static boolean isAlreadyInitHot = false; + private static boolean alreadySearch = false; + private static boolean alreadyInitHot = false; public AlphaFineDialog(Frame parent, boolean forceOpen) { super(parent); @@ -248,17 +294,6 @@ public class AlphaFineDialog extends UIDialog { win.setLocation((screenSize.width - winSize.width) / 2, (screenSize.height - winSize.height) / AlphaFineConstants.SHOW_SIZE); } -// TODO: 2017/5/8 xiaxiang: 窗体圆角setShape()有毛边,重写paint方法可以解决毛边问题,但带来了别的问题,处理比较麻烦,暂用setShape(); -// public void paint(Graphics g){ -// Graphics2D g2 = (Graphics2D) g.create(); -// RenderingHints qualityHints = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); -// qualityHints.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); -// g2.setRenderingHints(qualityHints); -// g2.setPaint(Color.WHITE); -// g2.fillRoundRect(0, 0, getWidth(), getHeight(), 15, 15); -// g2.dispose(); -// } - /** * 执行搜索 * @@ -669,12 +704,14 @@ public class AlphaFineDialog extends UIDialog { @Override protected String doInBackground() { String content = RobotModel.getContent((selectedValue).getName()); - //去掉小帆底部的信息 - String regex1 = "
([\\s\\S]*?)class=\"jiaoyes\">YES
"; - String regex2 = "
"; - content = content.replaceAll(regex1, "") - .replaceAll(regex2, ""); - return content; + if(StringUtils.isNotEmpty(content)){ + //去掉小帆底部的信息 + content = content.replaceAll(AlphaFineConstants.BOTTOM_REGEX_FIRST, "") + .replaceAll(AlphaFineConstants.BOTTOM_REGEX_SECOND, ""); + return content; + }else{ + return ""; + } } @Override @@ -684,9 +721,9 @@ public class AlphaFineDialog extends UIDialog { try { rightSearchResultPane.add(new RobotPreviewPane((selectedValue).getName(), get())); } catch (InterruptedException e) { - e.printStackTrace(); + FineLoggerFactory.getLogger().error("get hot item content error: " + e.getMessage()); } catch (ExecutionException e) { - e.printStackTrace(); + FineLoggerFactory.getLogger().error("get hot item content execution error: " + e.getMessage()); } validate(); repaint(); @@ -762,11 +799,11 @@ public class AlphaFineDialog extends UIDialog { } }); - Timer timer = new Timer(300, new ActionListener() { + Timer timer = new Timer(TIMER_DELAY, new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - if (!isAlreadyInitHot && searchTextField.getText().length() == 0) { - isAlreadyInitHot = true; + if (!alreadyInitHot && StringUtils.isEmpty(searchTextField.getText())) { + alreadyInitHot = true; removeSearchResult(); refreshContainer(); if (DesignerEnvManager.getEnvManager().getAlphaFineConfigManager().isNeedIntelligentCustomerService()) { @@ -779,8 +816,8 @@ public class AlphaFineDialog extends UIDialog { } refreshContainer(); return; - } else if (beforeSearchStr.equals(searchTextField.getText()) && beforeSearchStr.length() != 0) { - if (isAlreadySearch) { + } else if (beforeSearchStr.equals(searchTextField.getText()) && StringUtils.isNotEmpty(beforeSearchStr)) { + if (alreadySearch) { return; } else { removeHotPane(); @@ -796,21 +833,21 @@ public class AlphaFineDialog extends UIDialog { segmentationResult = SegmentationManager.getInstance().startSegmentation(searchTextField.getText().toLowerCase()); } } else { - if(StringUtils.isEmpty(getRealSearchText(searchTextField.getText().toLowerCase()))){ + if(StringUtils.isEmpty(getRealSearchText(searchTextField.getText()))){ segmentationResult = null; }else{ - segmentationResult = new String[]{getRealSearchText(searchTextField.getText().toLowerCase())}; + segmentationResult = new String[]{getRealSearchText(searchTextField.getText())}; } } doSearch(searchTextField.getText().toLowerCase()); - isAlreadySearch = true; + alreadySearch = true; } } else { beforeSearchStr = searchTextField.getText(); - isAlreadySearch = false; + alreadySearch = false; } if (beforeSearchStr.equals(searchTextField.getText()) && beforeSearchStr.length() != 0) { - isAlreadyInitHot = false; + alreadyInitHot = false; } } @@ -822,8 +859,8 @@ public class AlphaFineDialog extends UIDialog { * 去除特殊字符,空格等 */ private String getRealSearchText(String searchText){ - String regEx = "[`~!@#$%^&*()+=|{}':;',\\[\\].<>/?~!@#¥%……&*()——+|{}【】';:”“’。,、?]"; - Pattern p = Pattern.compile(regEx); + searchText = searchText.toLowerCase(); + Pattern p = Pattern.compile(AlphaFineConstants.SPECIAL_CHARACTER_REGEX); Matcher m = p.matcher(searchText); searchText = m.replaceAll("").trim().replaceAll(" ", ""); if (searchText.length() == 0) { @@ -1301,7 +1338,8 @@ public class AlphaFineDialog extends UIDialog { jLabel.setFont(AlphaFineConstants.SMALL_FONT); jLabel.setForeground(AlphaFineConstants.DARK_GRAY); backPane.add(jLabel, BorderLayout.CENTER); - jLabel.addMouseListener(new MouseListener() { + + jLabel.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { if (searchResultPane != null) { @@ -1318,26 +1356,6 @@ public class AlphaFineDialog extends UIDialog { } refreshContainer(); } - - @Override - public void mousePressed(MouseEvent e) { - - } - - @Override - public void mouseReleased(MouseEvent e) { - - } - - @Override - public void mouseEntered(MouseEvent e) { - - } - - @Override - public void mouseExited(MouseEvent e) { - - } }); } @@ -1379,7 +1397,7 @@ public class AlphaFineDialog extends UIDialog { final UILabel subTitle = new UILabel(str[i]); subTitle.setForeground(AlphaFineConstants.DARK_GRAY); subTitle.setFont(AlphaFineConstants.MEDIUM_FONT_ANOTHER); - subTitle.addMouseListener(new MouseListener() { + subTitle.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { segmentationResult = null; @@ -1393,26 +1411,6 @@ public class AlphaFineDialog extends UIDialog { modeList = HotIssuesManager.getInstance().getTitleSearchResult(subTitle.getText()); showIssuesList(); } - - @Override - public void mousePressed(MouseEvent e) { - - } - - @Override - public void mouseReleased(MouseEvent e) { - - } - - @Override - public void mouseEntered(MouseEvent e) { - - } - - @Override - public void mouseExited(MouseEvent e) { - - } }); bottomPanel.add(subTitle); } diff --git a/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/component/AlphaFineTextField.java b/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/component/AlphaFineTextField.java index 006c0b7b8d..ba4d279fbc 100644 --- a/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/component/AlphaFineTextField.java +++ b/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/component/AlphaFineTextField.java @@ -26,12 +26,6 @@ public class AlphaFineTextField extends UITextField { this.placeHolder = null; } - - @Override - public String getText() { - return super.getText(); - } - @Override public void paintComponent(Graphics g) { super.paintComponent(g); diff --git a/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/preview/ContainsCirclePane.java b/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/preview/ContainsCirclePane.java index e320c723a2..15076d5754 100644 --- a/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/preview/ContainsCirclePane.java +++ b/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/preview/ContainsCirclePane.java @@ -15,7 +15,7 @@ import java.awt.Graphics; public class ContainsCirclePane extends JPanel { public ContainsCirclePane(int pngIndex) { - UILabel iconLabel = new UILabel(IconLoader.getIcon(AlphaFineConstants.IMAGE_URL + "alphafine_hot" + pngIndex + ".png")); + UILabel iconLabel = new UILabel(IconLoader.getIcon(AlphaFineConstants.IMAGE_URL + AlphaFineConstants.ALPHA_HOT_IMAGE_NAME + pngIndex + ".png")); iconLabel.setPreferredSize(AlphaFineConstants.HOT_ICON_LABEL_SIZE); iconLabel.setOpaque(true); iconLabel.setBackground(Color.WHITE); diff --git a/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/ActionSearchManager.java b/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/ActionSearchManager.java index 6335be5615..a8d6d2b946 100644 --- a/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/ActionSearchManager.java +++ b/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/ActionSearchManager.java @@ -15,6 +15,7 @@ import com.fr.general.ComparatorUtils; import com.fr.json.JSONObject; import com.fr.stable.StringUtils; +import com.fr.third.org.apache.commons.lang3.ArrayUtils; import java.util.List; @@ -61,7 +62,7 @@ public class ActionSearchManager implements AlphaFineSearchProvider { filterModelList = new SearchResult(); lessModelList = new SearchResult(); moreModelList = new SearchResult(); - if (searchText.length == 0) { + if (ArrayUtils.isEmpty(searchText)) { lessModelList.add(new MoreModel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Set"))); return lessModelList; } diff --git a/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/ComplementAdviceManager.java b/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/ComplementAdviceManager.java index c548a1b47c..1e141b3d43 100644 --- a/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/ComplementAdviceManager.java +++ b/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/ComplementAdviceManager.java @@ -5,7 +5,7 @@ import com.fr.design.mainframe.alphafine.AlphaFineConstants; import com.fr.design.mainframe.alphafine.AlphaFineHelper; import com.fr.design.mainframe.alphafine.cell.model.RobotModel; import com.fr.design.mainframe.alphafine.model.SearchResult; -import com.fr.general.http.HttpClient; +import com.fr.general.http.HttpToolbox; import com.fr.json.JSONArray; import com.fr.json.JSONException; import com.fr.json.JSONObject; @@ -14,15 +14,17 @@ import com.fr.log.FineLoggerFactory; import com.fr.stable.StringUtils; import org.apache.commons.codec.digest.DigestUtils; +import java.io.IOException; +//import com.fr.third.org.apache.commons.codec.digest.DigestUtils; + + /** * @author alex.sung created on 2018/7/23. */ public class ComplementAdviceManager { - public static int count = 0; - private static ComplementAdviceManager instance; - private SearchResult allModelList; + private volatile SearchResult allModelList; public static ComplementAdviceManager getInstance() { if (instance == null) { @@ -40,19 +42,16 @@ public class ComplementAdviceManager { * @param searchText * @return */ - public synchronized SearchResult getAllSearchResult(String[] searchText) { + public SearchResult getAllSearchResult(String[] searchText) { allModelList = new SearchResult(); if (DesignerEnvManager.getEnvManager().getAlphaFineConfigManager().isNeedIntelligentCustomerService()) { SearchResult searchResult = new SearchResult(); for (int j = 0; j < searchText.length; j++) { - String result; String token = DigestUtils.md5Hex(AlphaFineConstants.ALPHA_ROBOT_SEARCH_TOKEN + searchText[j]); String url = AlphaFineConstants.COMPLEMENT_ADVICE_SEARCH_URL_PREFIX + "msg=" + searchText[j] + "&token=" + token; - HttpClient httpClient = new HttpClient(url); - httpClient.asGet(); - result = httpClient.getResponseText(); - AlphaFineHelper.checkCancel(); try { + String result = HttpToolbox.get(url); + AlphaFineHelper.checkCancel(); Object json = new JSONTokener(result).nextValue(); if (json instanceof JSONArray) { JSONArray jsonArray = new JSONArray(result); @@ -61,7 +60,7 @@ public class ComplementAdviceManager { JSONObject jsonObject = jsonArray.optJSONObject(i); String temp = jsonObject.optString("keywords"); - if (!StringUtils.isEmpty(temp)) { + if (StringUtils.isNotEmpty(temp)) { RobotModel robotModel = new RobotModel(temp, null); if (!AlphaFineHelper.getFilterResult().contains(robotModel) && !allModelList.contains(robotModel)) { allModelList.add(robotModel); @@ -71,6 +70,8 @@ public class ComplementAdviceManager { } } catch (JSONException e) { FineLoggerFactory.getLogger().error("complement advice search error: " + e.getMessage()); + }catch (IOException e1) { + FineLoggerFactory.getLogger().error("complement advice get result error: " + e1.getMessage()); } } if (searchResult.isEmpty()) { diff --git a/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/DocumentSearchManager.java b/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/DocumentSearchManager.java index cad89640e4..74ae8df280 100644 --- a/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/DocumentSearchManager.java +++ b/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/DocumentSearchManager.java @@ -8,12 +8,14 @@ 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.design.mainframe.alphafine.search.manager.fun.AlphaFineSearchProvider; - -import com.fr.general.http.HttpClient; +import com.fr.general.http.HttpToolbox; import com.fr.json.JSONArray; import com.fr.json.JSONException; import com.fr.json.JSONObject; import com.fr.log.FineLoggerFactory; +import com.fr.third.org.apache.commons.lang3.ArrayUtils; + +import java.io.IOException; /** * Created by XiaXiang on 2017/3/27. @@ -52,23 +54,17 @@ public class DocumentSearchManager implements AlphaFineSearchProvider { public synchronized SearchResult getLessSearchResult(String[] searchText) { lessModelList = new SearchResult(); moreModelList = new SearchResult(); - if (searchText.length == 0) { + if (ArrayUtils.isEmpty(searchText)) { lessModelList.add(new MoreModel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Community_Help"))); return lessModelList; } if (DesignerEnvManager.getEnvManager().getAlphaFineConfigManager().isContainDocument()) { SearchResult searchResult = new SearchResult(); for (int j = 0; j < searchText.length; j++) { - String result; String url = AlphaFineConstants.DOCUMENT_SEARCH_URL + searchText[j] + "-1"; - HttpClient httpClient = new HttpClient(url); - httpClient.asGet(); - if (!httpClient.isServerAlive()) { - return getNoConnectList(); - } - result = httpClient.getResponseText(); - AlphaFineHelper.checkCancel(); try { + String result = HttpToolbox.get(url); + AlphaFineHelper.checkCancel(); JSONObject jsonObject = new JSONObject(result); JSONArray jsonArray = jsonObject.optJSONArray("docdata"); if (jsonArray != null) { @@ -83,6 +79,8 @@ public class DocumentSearchManager implements AlphaFineSearchProvider { } } catch (JSONException e) { FineLoggerFactory.getLogger().error("document search error: " + e.getMessage()); + } catch (IOException e) { + FineLoggerFactory.getLogger().error("document search get result error: " + e.getMessage()); } } lessModelList.clear(); diff --git a/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/FileSearchManager.java b/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/FileSearchManager.java index 107cbb8648..dfe0ca53bb 100644 --- a/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/FileSearchManager.java +++ b/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/FileSearchManager.java @@ -69,7 +69,7 @@ public class FileSearchManager implements AlphaFineSearchProvider { for (int j = 0; j < searchText.length; j++) { this.searchText = dealWithSearchText(searchText[j]); if (StringUtils.isBlank(this.searchText) || ComparatorUtils.equals(this.searchText, DS_NAME)) { - lessModelList.add(new MoreModel(com.fr.design.i18n.Toolkit.i18nText("FR-Designer_Templates"))); + lessModelList.add(new MoreModel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Templates"))); return lessModelList; } AlphaFineHelper.checkCancel(); diff --git a/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/HotIssuesManager.java b/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/HotIssuesManager.java index 1ec5625462..bb65d98be0 100644 --- a/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/HotIssuesManager.java +++ b/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/HotIssuesManager.java @@ -5,14 +5,14 @@ import com.fr.design.mainframe.alphafine.AlphaFineHelper; import com.fr.design.mainframe.alphafine.cell.model.MoreModel; import com.fr.design.mainframe.alphafine.cell.model.RobotModel; import com.fr.design.mainframe.alphafine.model.SearchResult; -import com.fr.general.Inter; -import com.fr.general.http.HttpClient; +import com.fr.general.http.HttpToolbox; import com.fr.json.JSONArray; import com.fr.json.JSONException; import com.fr.json.JSONObject; +import com.fr.json.JSONUtils; import com.fr.log.FineLoggerFactory; import com.fr.stable.StringUtils; - +import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; @@ -27,14 +27,15 @@ public class HotIssuesManager { private static HotIssuesManager instance; private static final int HOT_ITEM_NUM = 6; private static final int HOT_SUB_ITEM_NUM = 4; + private static final String HOT_ITEM = "item"; + private static final String HOT_ITEM_DATA = "itemData"; + private static final String HOT_ITEM_TEXT = "text"; + private static final String HOT_TYPE = "type"; + private static final String HOT_DATA = "data"; - public static HotIssuesManager getInstance() { + public static synchronized HotIssuesManager getInstance() { if (instance == null) { - synchronized (HotIssuesManager.class) { - if (instance == null) { - instance = new HotIssuesManager(); - } - } + instance = new HotIssuesManager(); } return instance; } @@ -44,14 +45,14 @@ public class HotIssuesManager { /** * 将子标题下的数据塞入modeList - * @param getStr + * @param subTitle * @return */ - public SearchResult getTitleSearchResult(String getStr) { + public SearchResult getTitleSearchResult(String subTitle) { SearchResult modeList = new SearchResult(); - modeList.add(0, new MoreModel(com.fr.design.i18n.Toolkit.i18nText((getStr)))); + modeList.add(0, new MoreModel(com.fr.design.i18n.Toolkit.i18nText((subTitle)))); - List issueList = map.get(getStr); + List issueList = map.get(subTitle); for (int i = 0; i < issueList.size(); i++) { RobotModel robotModel = new RobotModel(issueList.get(i), null); robotModel.setHotItemModel(true); @@ -65,24 +66,22 @@ public class HotIssuesManager { * @return */ public String[][] getHotIssues() { - String result; - HttpClient httpClient = new HttpClient(AlphaFineConstants.ALPHA_HOT_SEARCH); - httpClient.asGet(); - if (!httpClient.isServerAlive()) { - return null; - } - result = httpClient.getResponseText(); - AlphaFineHelper.checkCancel(); + try { - JSONArray jsonArray = new JSONArray(result); - for (int i = 0; i < HOT_ITEM_NUM; i++) { - AlphaFineHelper.checkCancel(); - JSONObject jsonObject = jsonArray.optJSONObject(i); - data[i] = getTitleStrings(jsonObject); + String result = HttpToolbox.get(AlphaFineConstants.ALPHA_HOT_SEARCH); + AlphaFineHelper.checkCancel(); + JSONArray jsonArray = (JSONArray)JSONUtils.jsonDecode(result); + if(jsonArray != null){ + for (int i = 0; i < HOT_ITEM_NUM; i++) { + AlphaFineHelper.checkCancel(); + JSONObject jsonObject = jsonArray.optJSONObject(i); + data[i] = getTitleStrings(jsonObject); + } } - } catch (JSONException e) { FineLoggerFactory.getLogger().error("hotissues search error: " + e.getMessage()); + } catch (IOException e) { + FineLoggerFactory.getLogger().error("hotissues search get result error: " + e.getMessage()); } return data; } @@ -93,16 +92,16 @@ public class HotIssuesManager { * @return */ private String[] getTitleStrings(JSONObject jsonObject) { - String[] temp = getSubTitleFromCloud(jsonObject.optJSONObject("data")); + String[] temp = getSubTitleFromCloud(jsonObject.optJSONObject(HOT_DATA)); String[] temp1 = new String[1]; - temp1[0] = jsonObject.optString("type"); + temp1[0] = jsonObject.optString(HOT_TYPE); int strLen1 = temp.length; int strLen2 = temp1.length; temp1 = Arrays.copyOf(temp1, strLen2 + strLen1); System.arraycopy(temp, 0, temp1, strLen2, strLen1); - getIssueStrings(jsonObject.optJSONObject("data")); + getIssueStrings(jsonObject.optJSONObject(HOT_DATA)); return temp1; } @@ -112,21 +111,20 @@ public class HotIssuesManager { * @param data * @return */ - private String[] getIssueStrings(JSONObject data) { + private void getIssueStrings(JSONObject data) { try { for (int j = 0; j < HOT_SUB_ITEM_NUM; j++) { - String temp = data.getString("item" + (j + 1)); - JSONArray jsonArray = data.getJSONArray("itemData" + (j + 1)); + String temp = data.getString(HOT_ITEM + (j + 1)); + JSONArray jsonArray = data.getJSONArray(HOT_ITEM_DATA + (j + 1)); List tempList = new ArrayList<>(); for (int i = 0; i < jsonArray.length(); i++) { - tempList.add(jsonArray.optJSONObject(i).optString("text")); + tempList.add(jsonArray.optJSONObject(i).optString(HOT_ITEM_TEXT)); } map.put(temp, tempList); } } catch (JSONException e) { } - return null; } /** @@ -139,7 +137,7 @@ public class HotIssuesManager { for (int i = 0; i < HOT_SUB_ITEM_NUM; i++) { String temp = null; try { - temp = data.getString("item" + (i + 1)); + temp = data.getString(HOT_ITEM + (i + 1)); } catch (JSONException e) { } if (!StringUtils.isEmpty(temp)) { diff --git a/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/PluginSearchManager.java b/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/PluginSearchManager.java index c59b93c02f..e54d9d67c4 100644 --- a/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/PluginSearchManager.java +++ b/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/PluginSearchManager.java @@ -9,15 +9,17 @@ import com.fr.design.mainframe.alphafine.cell.model.PluginModel; import com.fr.design.mainframe.alphafine.model.SearchResult; import com.fr.design.mainframe.alphafine.search.manager.fun.AlphaFineSearchProvider; import com.fr.general.ComparatorUtils; - -import com.fr.general.http.HttpClient; +import com.fr.general.http.HttpToolbox; import com.fr.json.JSONArray; import com.fr.json.JSONException; import com.fr.json.JSONObject; import com.fr.log.FineLoggerFactory; import com.fr.plugin.basic.version.Version; import com.fr.plugin.basic.version.VersionIntervalFactory; +import com.fr.stable.EncodeConstants; +import com.fr.third.org.apache.commons.lang3.ArrayUtils; +import java.io.IOException; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; @@ -95,25 +97,22 @@ public class PluginSearchManager implements AlphaFineSearchProvider { @Override public synchronized SearchResult getLessSearchResult(String[] searchText) { + if (ArrayUtils.isEmpty(searchText)) { + return new SearchResult(); + } this.lessModelList = new SearchResult(); this.moreModelList = new SearchResult(); - if (searchText.length == 0) { + if (ArrayUtils.isEmpty(searchText)) { lessModelList.add(new MoreModel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Plugin_Addon"))); return lessModelList; } SearchResult searchResult = new SearchResult(); if (DesignerEnvManager.getEnvManager().getAlphaFineConfigManager().isContainPlugin()) { for (int j = 0; j < searchText.length; j++) { - String result; try { - String encodedKey = URLEncoder.encode(searchText[j], "UTF-8"); + String encodedKey = URLEncoder.encode(searchText[j], EncodeConstants.ENCODING_UTF_8); String url = AlphaFineConstants.PLUGIN_SEARCH_URL + "?keyword=" + encodedKey; - HttpClient httpClient = new HttpClient(url); - httpClient.asGet(); - if (!httpClient.isServerAlive()) { - return getNoConnectList(); - } - result = httpClient.getResponseText(); + String result = HttpToolbox.get(url); AlphaFineHelper.checkCancel(); JSONObject jsonObject = new JSONObject(result); JSONArray jsonArray = jsonObject.optJSONArray("result"); @@ -130,6 +129,8 @@ public class PluginSearchManager implements AlphaFineSearchProvider { FineLoggerFactory.getLogger().error("plugin search json error :" + e.getMessage()); } catch (UnsupportedEncodingException e) { FineLoggerFactory.getLogger().error("plugin search encode error :" + e.getMessage()); + } catch (IOException e) { + FineLoggerFactory.getLogger().error("plugin search get result error :" + e.getMessage()); } } if (searchResult.isEmpty()) { diff --git a/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/RecentSearchManager.java b/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/RecentSearchManager.java index b9c8e69623..2b24c84c19 100644 --- a/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/RecentSearchManager.java +++ b/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/RecentSearchManager.java @@ -138,9 +138,6 @@ public class RecentSearchManager implements AlphaFineSearchProvider { initWriter(); Document doc = new Document(); doc.add(new StringField("searchKey", searchKey, Field.Store.YES)); - if(cellModel == null){ - System.out.println("null"); - } doc.add(new StringField("cellModel", cellModel.ModelToJson().toString(), Field.Store.YES)); doc.add(new LongField("time", System.currentTimeMillis(), Field.Store.YES)); writeDoc(doc); diff --git a/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/RecommendSearchManager.java b/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/RecommendSearchManager.java index d75f1552d2..e3a87d6f0a 100644 --- a/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/RecommendSearchManager.java +++ b/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/RecommendSearchManager.java @@ -10,8 +10,7 @@ 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.design.mainframe.alphafine.search.manager.fun.AlphaFineSearchProvider; - -import com.fr.general.http.HttpClient; +import com.fr.general.http.HttpToolbox; import com.fr.json.JSONArray; import com.fr.json.JSONException; import com.fr.json.JSONObject; @@ -19,7 +18,9 @@ import com.fr.json.JSONTokener; import com.fr.log.FineLoggerFactory; import com.fr.stable.CodeUtils; import com.fr.stable.StringUtils; +import com.fr.third.org.apache.commons.lang3.ArrayUtils; +import java.io.IOException; import java.util.Iterator; import java.util.List; @@ -48,21 +49,18 @@ public class RecommendSearchManager implements AlphaFineSearchProvider { @Override public synchronized SearchResult getLessSearchResult(String[] searchText) { + if (ArrayUtils.isEmpty(searchText)) { + return new SearchResult(); + } + this.modelList = new SearchResult(); this.recommendModelList = new SearchResult(); if (DesignerEnvManager.getEnvManager().getAlphaFineConfigManager().isContainRecommend()) { for (int j = 0; j < searchText.length; j++) { - String result; searchText[j] = searchText[j].replaceAll(StringUtils.BLANK, StringUtils.EMPTY); - HttpClient httpClient = new HttpClient(AlphaFineConstants.SEARCH_API + CodeUtils.cjkEncode(searchText[j])); - httpClient.asGet(); - if (!httpClient.isServerAlive()) { - return getNoConnectList(); - } - httpClient.setTimeout(3000); - result = httpClient.getResponseText(); - AlphaFineHelper.checkCancel(); try { + String result = HttpToolbox.get(AlphaFineConstants.SEARCH_API + CodeUtils.cjkEncode(searchText[j])); + AlphaFineHelper.checkCancel(); Object json = new JSONTokener(result).nextValue(); if (json instanceof JSONObject) { JSONObject jsonObject = new JSONObject(result); @@ -82,6 +80,8 @@ public class RecommendSearchManager implements AlphaFineSearchProvider { } } catch (JSONException e) { FineLoggerFactory.getLogger().error("recommend search error! :" + e.getMessage()); + } catch (IOException e) { + FineLoggerFactory.getLogger().error("recommend search get result error! :" + e.getMessage()); } } @@ -136,17 +136,17 @@ public class RecommendSearchManager implements AlphaFineSearchProvider { modelList.addAll(complementAdviceModelList); } } - }else{ - if(complementAdviceModelList.size() > 0) { + } else { + if (complementAdviceModelList.size() > 0) { if (complementAdviceModelList.size() > AlphaFineConstants.SHOW_SIZE) { modelList.add(0, new MoreModel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_AlphaFine_Recommend"), com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_AlphaFine_ShowAll"), true, CellType.RECOMMEND)); modelList.addAll(complementAdviceModelList.subList(0, AlphaFineConstants.SHOW_SIZE)); moreModelList.addAll(complementAdviceModelList.subList(AlphaFineConstants.SHOW_SIZE, complementAdviceModelList.size())); - }else{ + } else { modelList.add(0, new MoreModel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_AlphaFine_Recommend"), false)); modelList.addAll(complementAdviceModelList); } - }else{ + } else { return modelList; } } diff --git a/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/SegmentationManager.java b/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/SegmentationManager.java index ff1d68b954..aed356a22e 100644 --- a/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/SegmentationManager.java +++ b/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/SegmentationManager.java @@ -1,5 +1,6 @@ package com.fr.design.mainframe.alphafine.search.manager.impl; +import com.fr.design.mainframe.alphafine.AlphaFineConstants; import com.fr.stable.StringUtils; import com.fr.third.ibm.icu.text.BreakIterator; @@ -15,13 +16,12 @@ public class SegmentationManager { private static SegmentationManager segmentationManager = null; private static final int MAX_CHINESE_CHARACTERS_NUM = 4; - public static SegmentationManager getInstance() { + public static synchronized SegmentationManager getInstance() { if (segmentationManager == null) { segmentationManager = new SegmentationManager(); return segmentationManager; - } else { - return segmentationManager; } + return segmentationManager; } /** @@ -52,14 +52,13 @@ public class SegmentationManager { * @return */ public String[] startSegmentation(String searchText) { - String regEx = "[`~!@#$%^&*()+=|{}':;',\\[\\].<>/?~!@#¥%……&*()——+|{}【】';:”“’。,、?]"; - Pattern p = Pattern.compile(regEx); + Pattern p = Pattern.compile(AlphaFineConstants.SPECIAL_CHARACTER_REGEX); Matcher m = p.matcher(searchText); searchText = m.replaceAll("").trim().replaceAll(" ", ""); - if (searchText.length() == 0) { + if (StringUtils.isEmpty(searchText)) { return null; } - if(!isNeedSegmentation(searchText)){ + if (!isNeedSegmentation(searchText)) { return new String[]{searchText}; } List result = new ArrayList<>(); diff --git a/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/SimilarSearchManeger.java b/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/SimilarSearchManeger.java index 2a09182a0a..48d527ae27 100644 --- a/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/SimilarSearchManeger.java +++ b/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/SimilarSearchManeger.java @@ -8,7 +8,7 @@ import com.fr.design.mainframe.alphafine.cell.model.MoreModel; import com.fr.design.mainframe.alphafine.cell.model.RobotModel; import com.fr.design.mainframe.alphafine.model.SearchResult; import com.fr.design.mainframe.alphafine.search.manager.fun.AlphaFineSearchProvider; -import com.fr.general.http.HttpClient; +import com.fr.general.http.HttpToolbox; import com.fr.json.JSONArray; import com.fr.json.JSONException; import com.fr.json.JSONObject; @@ -16,39 +16,35 @@ import com.fr.json.JSONTokener; import com.fr.log.FineLoggerFactory; import org.apache.commons.codec.digest.DigestUtils; +import java.io.IOException; +//import com.fr.third.org.apache.commons.codec.digest.DigestUtils; + /** * Created by alex.sung on 2018/8/3. */ public class SimilarSearchManeger implements AlphaFineSearchProvider { private static SimilarSearchManeger instance; - private SearchResult lessModelList; - private SearchResult moreModelList = new SearchResult(); + private volatile SearchResult lessModelList; + private volatile SearchResult moreModelList = new SearchResult(); - public static SimilarSearchManeger getInstance() { + public static synchronized SimilarSearchManeger getInstance() { if (instance == null) { - synchronized (SimilarSearchManeger.class) { - if (instance == null) { - instance = new SimilarSearchManeger(); - } - } + instance = new SimilarSearchManeger(); } return instance; } @Override - public synchronized SearchResult getLessSearchResult(String[] searchText) { + public SearchResult getLessSearchResult(String[] searchText) { lessModelList = new SearchResult(); if (DesignerEnvManager.getEnvManager().getAlphaFineConfigManager().isNeedIntelligentCustomerService()) { SearchResult allModelList = new SearchResult(); for (int j = 0; j < searchText.length; j++) { - String result; String token = DigestUtils.md5Hex(AlphaFineConstants.ALPHA_ROBOT_SEARCH_TOKEN + searchText[j]); String url = AlphaFineConstants.SIMILAR_SEARCH_URL_PREFIX + "msg=" + searchText[j] + "&token=" + token; - HttpClient httpClient = new HttpClient(url); - httpClient.asGet(); - result = httpClient.getResponseText(); - AlphaFineHelper.checkCancel(); try { + String result = HttpToolbox.get(url); + AlphaFineHelper.checkCancel(); Object json = new JSONTokener(result).nextValue(); if (json instanceof JSONArray) { JSONArray jsonArray = new JSONArray(result); @@ -65,6 +61,8 @@ public class SimilarSearchManeger implements AlphaFineSearchProvider { } } catch (JSONException e) { FineLoggerFactory.getLogger().error("similar search error: " + e.getMessage()); + } catch (IOException e) { + FineLoggerFactory.getLogger().error("similar search get result error: " + e.getMessage()); } } moreModelList.clear();