|
|
@ -1,6 +1,7 @@ |
|
|
|
package com.fr.design.mainframe.alphafine.search.manager.impl; |
|
|
|
package com.fr.design.mainframe.alphafine.search.manager.impl; |
|
|
|
|
|
|
|
|
|
|
|
import com.fr.base.FRContext; |
|
|
|
import com.fr.base.FRContext; |
|
|
|
|
|
|
|
import com.fr.base.extension.FileExtension; |
|
|
|
import com.fr.design.DesignerEnvManager; |
|
|
|
import com.fr.design.DesignerEnvManager; |
|
|
|
import com.fr.design.mainframe.alphafine.AlphaFineConstants; |
|
|
|
import com.fr.design.mainframe.alphafine.AlphaFineConstants; |
|
|
|
import com.fr.design.mainframe.alphafine.AlphaFineHelper; |
|
|
|
import com.fr.design.mainframe.alphafine.AlphaFineHelper; |
|
|
@ -11,21 +12,10 @@ import com.fr.design.mainframe.alphafine.model.SearchResult; |
|
|
|
import com.fr.design.mainframe.alphafine.search.manager.fun.AlphaFineSearchProvider; |
|
|
|
import com.fr.design.mainframe.alphafine.search.manager.fun.AlphaFineSearchProvider; |
|
|
|
import com.fr.file.filetree.FileNode; |
|
|
|
import com.fr.file.filetree.FileNode; |
|
|
|
import com.fr.general.ComparatorUtils; |
|
|
|
import com.fr.general.ComparatorUtils; |
|
|
|
|
|
|
|
|
|
|
|
import com.fr.json.JSONObject; |
|
|
|
import com.fr.json.JSONObject; |
|
|
|
import com.fr.log.FineLoggerFactory; |
|
|
|
|
|
|
|
import com.fr.stable.StableUtils; |
|
|
|
|
|
|
|
import com.fr.stable.StringUtils; |
|
|
|
import com.fr.stable.StringUtils; |
|
|
|
import com.fr.stable.project.ProjectConstants; |
|
|
|
import com.fr.stable.project.ProjectConstants; |
|
|
|
import com.fr.workspace.WorkContext; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.io.BufferedReader; |
|
|
|
|
|
|
|
import java.io.ByteArrayInputStream; |
|
|
|
|
|
|
|
import java.io.File; |
|
|
|
|
|
|
|
import java.io.InputStream; |
|
|
|
|
|
|
|
import java.io.InputStreamReader; |
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Created by XiaXiang on 2017/3/27. |
|
|
|
* Created by XiaXiang on 2017/3/27. |
|
|
@ -40,9 +30,9 @@ public class FileSearchManager implements AlphaFineSearchProvider { |
|
|
|
private SearchResult lessModelList; |
|
|
|
private SearchResult lessModelList; |
|
|
|
private SearchResult moreModelList; |
|
|
|
private SearchResult moreModelList; |
|
|
|
private String searchText; |
|
|
|
private String searchText; |
|
|
|
private List<FileNode> fileNodes = null; |
|
|
|
private FileNode[] fileNodes = null; |
|
|
|
|
|
|
|
|
|
|
|
//停止搜索
|
|
|
|
//停止搜索
|
|
|
|
private boolean stopSearch = false; |
|
|
|
|
|
|
|
//隐藏的搜索功能,可根据特殊的字符标记判断搜索分类
|
|
|
|
//隐藏的搜索功能,可根据特殊的字符标记判断搜索分类
|
|
|
|
private boolean isContainCpt = true; |
|
|
|
private boolean isContainCpt = true; |
|
|
|
private boolean isContainFrm = true; |
|
|
|
private boolean isContainFrm = true; |
|
|
@ -58,9 +48,6 @@ public class FileSearchManager implements AlphaFineSearchProvider { |
|
|
|
return instance; |
|
|
|
return instance; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public synchronized static void init() { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 根据文件路径获取文件模型 |
|
|
|
* 根据文件路径获取文件模型 |
|
|
@ -84,173 +71,66 @@ public class FileSearchManager implements AlphaFineSearchProvider { |
|
|
|
lessModelList.add(new MoreModel(com.fr.design.i18n.Toolkit.i18nText("FR-Designer_Templates"))); |
|
|
|
lessModelList.add(new MoreModel(com.fr.design.i18n.Toolkit.i18nText("FR-Designer_Templates"))); |
|
|
|
return lessModelList; |
|
|
|
return lessModelList; |
|
|
|
} |
|
|
|
} |
|
|
|
fileNodes = new ArrayList<>(); |
|
|
|
|
|
|
|
fileNodes = listTpl(ProjectConstants.REPORTLETS_NAME, true); |
|
|
|
|
|
|
|
AlphaFineHelper.checkCancel(); |
|
|
|
AlphaFineHelper.checkCancel(); |
|
|
|
|
|
|
|
fileNodes = FRContext.getFileNodes().list(ProjectConstants.REPORTLETS_NAME, new FileExtension[]{FileExtension.CPT, FileExtension.FRM}, true); |
|
|
|
isContainCpt = true; |
|
|
|
isContainCpt = true; |
|
|
|
isContainFrm = true; |
|
|
|
isContainFrm = true; |
|
|
|
doSearch(this.searchText, true); |
|
|
|
doSearch(this.searchText); |
|
|
|
if (stopSearch) { |
|
|
|
|
|
|
|
lessModelList.add(0, new MoreModel(com.fr.design.i18n.Toolkit.i18nText("FR-Designer_Templates"), com.fr.design.i18n.Toolkit.i18nText("FR-Designer_AlphaFine_ShowAll"), true, CellType.FILE)); |
|
|
|
|
|
|
|
lessModelList.addAll(filterModelList.subList(0, AlphaFineConstants.SHOW_SIZE)); |
|
|
|
|
|
|
|
stopSearch = false; |
|
|
|
|
|
|
|
return this.lessModelList; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (filterModelList.isEmpty()) { |
|
|
|
if (filterModelList.isEmpty()) { |
|
|
|
return new SearchResult(); |
|
|
|
return new SearchResult(); |
|
|
|
} |
|
|
|
} else if (filterModelList.size() < AlphaFineConstants.SHOW_SIZE + 1) { |
|
|
|
lessModelList.add(0, new MoreModel(com.fr.design.i18n.Toolkit.i18nText("FR-Designer_Templates"), com.fr.design.i18n.Toolkit.i18nText("FR-Designer_AlphaFine_ShowAll"), false, CellType.FILE)); |
|
|
|
lessModelList.add(0, new MoreModel(com.fr.design.i18n.Toolkit.i18nText("FR-Designer_Templates"))); |
|
|
|
lessModelList.addAll(filterModelList); |
|
|
|
lessModelList.addAll(filterModelList); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
lessModelList.add(0, new MoreModel(com.fr.design.i18n.Toolkit.i18nText("FR-Designer_Templates"), com.fr.design.i18n.Toolkit.i18nText("FR-Designer_AlphaFine_ShowAll"), true, CellType.FILE)); |
|
|
|
|
|
|
|
lessModelList.addAll(filterModelList.subList(0, AlphaFineConstants.SHOW_SIZE)); |
|
|
|
|
|
|
|
moreModelList.addAll(filterModelList.subList(AlphaFineConstants.SHOW_SIZE, filterModelList.size())); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
return lessModelList; |
|
|
|
return lessModelList; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public SearchResult getMoreSearchResult(String searchText) { |
|
|
|
public SearchResult getMoreSearchResult(String searchText) { |
|
|
|
if (moreModelList != null && !moreModelList.isEmpty()) { |
|
|
|
|
|
|
|
return moreModelList; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
this.filterModelList = new SearchResult(); |
|
|
|
|
|
|
|
this.moreModelList = new SearchResult(); |
|
|
|
|
|
|
|
AlphaFineHelper.checkCancel(); |
|
|
|
|
|
|
|
isContainCpt = true; |
|
|
|
|
|
|
|
isContainFrm = true; |
|
|
|
|
|
|
|
doSearch(this.searchText, false); |
|
|
|
|
|
|
|
moreModelList.addAll(filterModelList.subList(AlphaFineConstants.SHOW_SIZE, filterModelList.size())); |
|
|
|
|
|
|
|
return moreModelList; |
|
|
|
return moreModelList; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void doSearch(String searchText, boolean needMore) { |
|
|
|
private void doSearch(String searchText) { |
|
|
|
|
|
|
|
if (DesignerEnvManager.getEnvManager().getAlphaFineConfigManager().isContainTemplate()) { |
|
|
|
for (FileNode node : fileNodes) { |
|
|
|
for (FileNode node : fileNodes) { |
|
|
|
boolean isAlreadyContain = false; |
|
|
|
if (node.getName().toLowerCase().contains(searchText)) { |
|
|
|
isAlreadyContain = searchFile(searchText, node, isAlreadyContain, needMore); |
|
|
|
|
|
|
|
if (DesignerEnvManager.getEnvManager().getAlphaFineConfigManager().isContainFileContent() && node.getLock() == null) { |
|
|
|
|
|
|
|
searchFileContent(searchText, node, isAlreadyContain, needMore); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (filterModelList.size() > AlphaFineConstants.SHOW_SIZE && stopSearch) { |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private String dealWithSearchText(String searchText) { |
|
|
|
|
|
|
|
if (searchText.startsWith(FRM_PREFIX)) { |
|
|
|
|
|
|
|
isContainCpt = false; |
|
|
|
|
|
|
|
searchText = searchText.substring(MARK_LENGTH, searchText.length()); |
|
|
|
|
|
|
|
} else if (searchText.startsWith(CPT_PREFIX)) { |
|
|
|
|
|
|
|
isContainFrm = false; |
|
|
|
|
|
|
|
searchText = searchText.substring(MARK_LENGTH, searchText.length()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return searchText; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 搜索文件内容 |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param searchText |
|
|
|
|
|
|
|
* @param node |
|
|
|
|
|
|
|
* @param isAlreadyContain |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
private void searchFileContent(String searchText, FileNode node, boolean isAlreadyContain, boolean needMore) { |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
InputStream inputStream = new ByteArrayInputStream(WorkContext.getWorkResource().readFully(StableUtils.pathJoin(ProjectConstants.REPORTLETS_NAME, node.getEnvPath().substring(ProjectConstants.REPORTLETS_NAME.length() + 1)))); |
|
|
|
|
|
|
|
InputStreamReader isr = new InputStreamReader(inputStream, "UTF-8"); |
|
|
|
|
|
|
|
BufferedReader reader = new BufferedReader(isr); |
|
|
|
|
|
|
|
String line; |
|
|
|
|
|
|
|
int columnNumber; |
|
|
|
|
|
|
|
boolean isFoundInContent = false; |
|
|
|
|
|
|
|
while ((line = reader.readLine()) != null) { |
|
|
|
|
|
|
|
columnNumber = line.toLowerCase().indexOf(searchText); |
|
|
|
|
|
|
|
if (columnNumber != -1) { |
|
|
|
|
|
|
|
isFoundInContent = true; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (isFoundInContent && !isAlreadyContain) { |
|
|
|
|
|
|
|
FileModel model = new FileModel(node.getName(), node.getEnvPath()); |
|
|
|
FileModel model = new FileModel(node.getName(), node.getEnvPath()); |
|
|
|
if (!AlphaFineHelper.getFilterResult().contains(model)) { |
|
|
|
if (!AlphaFineHelper.getFilterResult().contains(model)) { |
|
|
|
AlphaFineHelper.checkCancel(); |
|
|
|
AlphaFineHelper.checkCancel(); |
|
|
|
filterModelList.add(model); |
|
|
|
filterModelList.add(model); |
|
|
|
} |
|
|
|
} |
|
|
|
if (this.filterModelList.size() > AlphaFineConstants.SHOW_SIZE && needMore) { |
|
|
|
|
|
|
|
stopSearch = true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
isr.close(); |
|
|
|
|
|
|
|
reader.close(); |
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
|
|
FineLoggerFactory.getLogger().error("file read error: " + e.getMessage()); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (DesignerEnvManager.getEnvManager().getAlphaFineConfigManager().isContainFileContent()) { |
|
|
|
/** |
|
|
|
FileNode[] fileNodes = FRContext.getFileNodes().filterFiles(searchText, ProjectConstants.REPORTLETS_NAME, new FileExtension[]{FileExtension.CPT, FileExtension.FRM}, true); |
|
|
|
* 搜索模板 |
|
|
|
for (FileNode node : fileNodes) { |
|
|
|
* |
|
|
|
|
|
|
|
* @param searchText |
|
|
|
|
|
|
|
* @param node |
|
|
|
|
|
|
|
* @param isAlreadyContain |
|
|
|
|
|
|
|
* @return |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
private boolean searchFile(String searchText, FileNode node, boolean isAlreadyContain, boolean needMore) { |
|
|
|
|
|
|
|
if (DesignerEnvManager.getEnvManager().getAlphaFineConfigManager().isContainTemplate()) { |
|
|
|
|
|
|
|
if (node.getName().toLowerCase().contains(searchText)) { |
|
|
|
|
|
|
|
FileModel model = new FileModel(node.getName(), node.getEnvPath()); |
|
|
|
FileModel model = new FileModel(node.getName(), node.getEnvPath()); |
|
|
|
if (!AlphaFineHelper.getFilterResult().contains(model)) { |
|
|
|
if (!AlphaFineHelper.getFilterResult().contains(model) && !filterModelList.contains(model)) { |
|
|
|
AlphaFineHelper.checkCancel(); |
|
|
|
AlphaFineHelper.checkCancel(); |
|
|
|
filterModelList.add(model); |
|
|
|
filterModelList.add(model); |
|
|
|
} |
|
|
|
} |
|
|
|
if (filterModelList.size() > AlphaFineConstants.SHOW_SIZE && needMore) { |
|
|
|
|
|
|
|
stopSearch = true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
isAlreadyContain = true; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return isAlreadyContain; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
private String dealWithSearchText(String searchText) { |
|
|
|
* 获取工作目录下所有符合要求的模板 |
|
|
|
if (searchText.startsWith(FRM_PREFIX)) { |
|
|
|
* |
|
|
|
isContainCpt = false; |
|
|
|
* @param rootFilePath |
|
|
|
searchText = searchText.substring(MARK_LENGTH, searchText.length()); |
|
|
|
* @param recurse |
|
|
|
} else if (searchText.startsWith(CPT_PREFIX)) { |
|
|
|
* @return |
|
|
|
isContainFrm = false; |
|
|
|
*/ |
|
|
|
searchText = searchText.substring(MARK_LENGTH, searchText.length()); |
|
|
|
private List<FileNode> listTpl(String rootFilePath, boolean recurse) { |
|
|
|
|
|
|
|
List<FileNode> fileNodeList = new ArrayList<FileNode>(); |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
listAll(rootFilePath, fileNodeList, recurse); |
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
|
|
FRContext.getLogger().error("file search error: " + e.getMessage(), e); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
return fileNodeList; |
|
|
|
return searchText; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 获取当前工作目录下所有模板 |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param rootFilePath |
|
|
|
|
|
|
|
* @param nodeList |
|
|
|
|
|
|
|
* @param recurse |
|
|
|
|
|
|
|
* @throws Exception |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
private void listAll(String rootFilePath, List<FileNode> nodeList, boolean recurse) throws Exception { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
FileNode[] fns = FRContext.getFileNodes().list(rootFilePath); |
|
|
|
|
|
|
|
for (int i = 0; i < fns.length; i++) { |
|
|
|
|
|
|
|
FileNode fileNode = fns[i]; |
|
|
|
|
|
|
|
if (fileNode.isDirectory()) { |
|
|
|
|
|
|
|
if (recurse) { |
|
|
|
|
|
|
|
listAll(rootFilePath + File.separator + fns[i].getName(), nodeList, true); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
nodeList.add(fns[i]); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else if (isContainCpt && fileNode.isFileType("cpt")) { |
|
|
|
|
|
|
|
nodeList.add(fileNode); |
|
|
|
|
|
|
|
} else if (isContainFrm && fileNode.isFileType("frm")) { |
|
|
|
|
|
|
|
nodeList.add(fileNode); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 是否包含cpt |
|
|
|
* 是否包含cpt |
|
|
|