Browse Source

REPORT-70481 远程设计切换校验机制优化

优化代码,避免直接修改templateToStashFile方法
feature/x
Yvan 2 years ago
parent
commit
1741b2705b
  1. 2
      designer-base/src/main/java/com/fr/design/file/HistoryTemplateListCache.java
  2. 31
      designer-base/src/main/java/com/fr/design/mainframe/JTemplate.java

2
designer-base/src/main/java/com/fr/design/file/HistoryTemplateListCache.java

@ -431,7 +431,7 @@ public class HistoryTemplateListCache implements CallbackEvent {
FILE file = template.getEditingFILE();
boolean needReload = context == null || needReloadTemplate(context, template);
if (needReload) {
FILE stashFile = template.templateToStashFile4Other();
FILE stashFile = template.templateToStashFile();
if (stashFile != null) {
FineLoggerFactory.getLogger().info("{} is being reloaded", file.getName());
template.refreshResource(stashFile);

31
designer-base/src/main/java/com/fr/design/mainframe/JTemplate.java

@ -447,36 +447,35 @@ public abstract class JTemplate<T extends BaseBook, U extends BaseUndoState<?>>
* @return
*/
public FILE templateToStashFile4Envchange() {
return templateToStashFile(true);
FILE file = this.getEditingFILE();
if (file.isEnvFile() && !isSaved()) {
// 切换工作目录时,存在未保存的环境文件时,将其转化为与环境无关的内存文件,再创建暂存文件
return new StashedFILE(new MemFILE(file.getName()), exportBaseBook2ByteArray(), template.suffix());
} else {
// 其它情况下,直接创建暂存文件
return templateToStashFile();
}
}
/**
* 用于 其它情况 的模板资源暂存
* 例如 插件插件安装/启用
* @return
*/
public FILE templateToStashFile4Other() {
return templateToStashFile(false);
public FILE templateToStashFile() {
FILE file = this.getEditingFILE();
return new StashedFILE(file, exportBaseBook2ByteArray(), template.suffix());
}
private FILE templateToStashFile(boolean envChange) {
FILE file = this.getEditingFILE();
private byte[] exportBaseBook2ByteArray() {
try {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
BaseBook target = this.getTarget();
if (target != null) {
target.export(outputStream);
return envChange && file.isEnvFile() && !isSaved()?
// 切换工作目录时,未保存的环境文件转化为与环境无关的内存文件,再创建暂存文件
new StashedFILE(new MemFILE(file.getName()), outputStream.toByteArray(), template.suffix()) :
// 其它情况下,直接创建暂存文件
new StashedFILE(file, outputStream.toByteArray(), template.suffix());
return outputStream.toByteArray();
}
// 如果 target == null 那么这个模板是被模板内存优化功能处理过的,不用处理
} catch (Exception e) {
FineLoggerFactory.getLogger().error("Export BaseBook to Byte Array Failed");
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
return null;
return new byte[0];
}

Loading…
Cancel
Save