diff --git a/designer-base/src/main/java/com/fr/nx/app/designer/cptx/io/DesignReadWritableProvider.java b/designer-base/src/main/java/com/fr/nx/app/designer/cptx/io/DesignReadWritableProvider.java index 0896e66e96..cfb7c44955 100644 --- a/designer-base/src/main/java/com/fr/nx/app/designer/cptx/io/DesignReadWritableProvider.java +++ b/designer-base/src/main/java/com/fr/nx/app/designer/cptx/io/DesignReadWritableProvider.java @@ -2,14 +2,9 @@ package com.fr.nx.app.designer.cptx.io; import com.fr.common.annotations.Negative; import com.fr.file.FILE; -import com.fr.nx.app.designer.utils.DesignerCptxFileUtils; -import com.fr.nx.cptx.io.handle.impl.AbstractCptxIOProvider; -import com.fr.nx.cptx.pack.util.CompiledReportInputStream; +import com.fr.nx.cptx.io.handle.impl.CompileToPathCptxIOProvider; import com.fr.nx.cptx.pack.util.CompiledReportOutputStream; - -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; +import com.fr.nx.cptx.utils.CptxFileUtils; /** * 用于设计器保存编译后的结果并缓存可web预览模版 @@ -20,41 +15,21 @@ import java.io.OutputStream; * @Description: 用于cptx写操作的Provider */ @Negative(until = "2020-05-10") -public class DesignReadWritableProvider extends AbstractCptxIOProvider { +public class DesignReadWritableProvider extends CompileToPathCptxIOProvider { /** * 原文件 */ private final FILE file; - /** - * 编译文件夹 - */ - private final String compileDir; - - private CompiledReportOutputStream outputStream; public DesignReadWritableProvider(FILE file) { + super(CptxFileUtils.getFormatPath(file.getPath())); this.file = file; - this.compileDir = DesignerCptxFileUtils.generateCompileDir(file); } - @Override - public InputStream open() throws Exception { - if (outputStream == null) { - throw new IOException("can not read cptx template before compile"); - } - return new CompiledReportInputStream(outputStream.toByteArray()); - } - /** - * 对于写操作,用到的只有这个方法,以流形式来操作 - * - * @return 保存的目标输出流 - * @throws Exception e - */ @Override - public OutputStream createTemp() throws Exception { - outputStream = new CompiledReportOutputStream(file.asOutputStream(), compileDir); - return outputStream; + public CompiledReportOutputStream outputOpen() throws Exception { + return new CompiledReportOutputStream(file.asOutputStream(), getCompilePath()); } } diff --git a/designer-base/src/main/java/com/fr/nx/app/designer/toolbar/TemplateTransformer.java b/designer-base/src/main/java/com/fr/nx/app/designer/toolbar/TemplateTransformer.java index 6294fa4d88..42490fe7d5 100644 --- a/designer-base/src/main/java/com/fr/nx/app/designer/toolbar/TemplateTransformer.java +++ b/designer-base/src/main/java/com/fr/nx/app/designer/toolbar/TemplateTransformer.java @@ -136,12 +136,12 @@ public enum TemplateTransformer { @NotNull public static TransformResultInfo compileCPTX(WorkBook workbook, FILE file) { //对于非工作目录的cptx,修改无需执行编译 - if(!(file instanceof FileNodeFILE)){ + if (!(file instanceof FileNodeFILE)) { try { OutputStream outputStream = file.asOutputStream(); workbook.export(outputStream); return TransformResultInfo.generateResult(TransformResult.SUCCESS).saved(true); - }catch (Exception e){ + } catch (Exception e) { FineLoggerFactory.getLogger().error(e.getMessage(), e); return TransformResultInfo.generateResult(TransformResult.FAILED).saved(false); } @@ -206,9 +206,8 @@ public enum TemplateTransformer { // 读取可 web 预览模版并缓存 try { // todo 是否考虑异步 - String timestampedPath = CptxFileUtils.getTimestampedPath(file.getPath()); CptxTemplate previewCptxTemplate = CptxIOManager.open(cptx).getTemplate(); - CptxTemplatePool.getInstance().addCptxTemplate(timestampedPath, previewCptxTemplate); + CptxTemplatePool.getInstance().addCptxTemplate(CptxFileUtils.getFormatPath(file.getPath()), previewCptxTemplate); } catch (Exception e) { FineLoggerFactory.getLogger().error(e.getMessage(), e); } diff --git a/designer-base/src/main/java/com/fr/nx/app/designer/utils/DesignerCptxFileUtils.java b/designer-base/src/main/java/com/fr/nx/app/designer/utils/DesignerCptxFileUtils.java deleted file mode 100644 index a51e047688..0000000000 --- a/designer-base/src/main/java/com/fr/nx/app/designer/utils/DesignerCptxFileUtils.java +++ /dev/null @@ -1,79 +0,0 @@ -package com.fr.nx.app.designer.utils; - -import com.fr.file.FILE; -import com.fr.general.CommonIOUtils; -import com.fr.log.FineLoggerFactory; -import com.fr.main.impl.WorkBook; -import com.fr.nx.marshal.impl.xml.DefaultXMLObjectUnmarshaler; -import com.fr.nx.marshal.util.MarshalUtil; -import com.fr.nx.cptx.entry.metadata.CptxMetadata; -import com.fr.nx.cptx.io.handle.impl.OriginCptProvider; -import com.fr.nx.cptx.marshal.util.CptxMarshalUtil; -import com.fr.nx.cptx.utils.CptxFileUtils; -import com.fr.stable.EncodeConstants; -import com.fr.stable.StableUtils; -import com.fr.stable.xml.XMLableReader; -import com.fr.workspace.WorkContext; - -import java.io.ByteArrayOutputStream; -import java.io.InputStream; -import java.io.InputStreamReader; - -/** - * Created by loy on 2021/1/18. - * - *
用于设计器的cptx的一些工具类 - *
- */
-public class DesignerCptxFileUtils {
-
- /**
- * 根据file来获取cptx中的cpt
- * @param file
- * @return
- */
- public static WorkBook getWorkBook(final FILE file){
- try (InputStream input = file.asInputStream();
- ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
- CommonIOUtils.copyBinaryTo(input, outputStream);
- OriginCptProvider provider = new OriginCptProvider(outputStream.toByteArray());
- return CptxFileUtils.getWorkBook(provider);
- } catch (Exception e) {
- FineLoggerFactory.getLogger().error(e.getMessage(), e);
- }
- return null;
- }
-
- /**
- * 获取模板的元数据
- * @param file
- * @return
- */
- public static CptxMetadata getMetadata(FILE file){
- try {
- String metadataPath = StableUtils.pathJoin(generateCompileDir(file), CptxMarshalUtil.NAME_METADATA);
- if(!WorkContext.getWorkResource().exist(metadataPath)){
- return null;
- }
- InputStream metadataInput = WorkContext.getWorkResource().openStream(metadataPath);
- XMLableReader reader = XMLableReader.createXMLableReader(
- new InputStreamReader(metadataInput, EncodeConstants.ENCODING_UTF_8));
- CptxMetadata metadata = (CptxMetadata) new DefaultXMLObjectUnmarshaler().unmarshal(
- MarshalUtil.createMarshalableExtra(CptxMetadata.class), reader);
- return metadata;
- } catch (Exception e) {
- FineLoggerFactory.getLogger().error(e.getMessage(), e);
- }
- return null;
- }
-
- /**
- * 根据文件获取编译后的文件夹绝对路径,比如原文件位于reportlets/test/merge.cptx,转化后为evn://assets/engine/test/merge文件夹
- * @param file
- * @return
- */
- public static String generateCompileDir(FILE file){
- String filePath = file.getPath();
- return CptxFileUtils.generateCompileDir(filePath);
- }
-}
diff --git a/designer-realize/src/main/java/com/fr/nx/app/designer/CptxApp.java b/designer-realize/src/main/java/com/fr/nx/app/designer/CptxApp.java
index 9186a67346..f76be4d89f 100644
--- a/designer-realize/src/main/java/com/fr/nx/app/designer/CptxApp.java
+++ b/designer-realize/src/main/java/com/fr/nx/app/designer/CptxApp.java
@@ -5,7 +5,7 @@ import com.fr.design.mainframe.AbstractAppProvider;
import com.fr.design.mainframe.JTemplate;
import com.fr.file.FILE;
import com.fr.main.impl.WorkBook;
-import com.fr.nx.app.designer.utils.DesignerCptxFileUtils;
+import com.fr.nx.cptx.utils.CptxFileUtils;
/**
* 支持设计器打开cptx文件
@@ -35,7 +35,7 @@ public class CptxApp extends AbstractAppProvider