loy
3 years ago
6 changed files with 24 additions and 125 deletions
@ -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. |
||||
* |
||||
* <p>用于设计器的cptx的一些工具类 |
||||
* <p> |
||||
*/ |
||||
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); |
||||
} |
||||
} |
Loading…
Reference in new issue