You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
119 lines
4.0 KiB
119 lines
4.0 KiB
package com.fr.nx.app.designer; |
|
|
|
import com.fr.base.extension.FileExtension; |
|
import com.fr.design.actions.file.export.CSVExportAction; |
|
import com.fr.design.actions.file.export.PDFExportAction; |
|
import com.fr.design.actions.file.export.SVGExportAction; |
|
import com.fr.design.actions.file.export.TextExportAction; |
|
import com.fr.design.actions.file.export.WordExportAction; |
|
import com.fr.design.mainframe.JWorkBook; |
|
import com.fr.design.menu.MenuDef; |
|
import com.fr.design.menu.ShortCut; |
|
import com.fr.file.FILE; |
|
import com.fr.general.ComparatorUtils; |
|
import com.fr.locale.InterProviderFactory; |
|
import com.fr.log.FineLoggerFactory; |
|
import com.fr.main.impl.WorkBook; |
|
import com.fr.nx.app.designer.menu.CalculateAttrAction; |
|
import com.fr.nx.app.designer.toolbar.TemplateTransformer; |
|
import com.fr.nx.app.designer.toolbar.TransformResult; |
|
import com.fr.nx.app.designer.toolbar.TransformResultInfo; |
|
import com.fr.nx.cptx.entry.metadata.CptxMetadata; |
|
import com.fr.nx.cptx.utils.CptxFileUtils; |
|
import com.fr.stable.StringUtils; |
|
import com.fr.stable.project.ProjectConstants; |
|
import com.fr.third.jodd.util.ArraysUtil; |
|
|
|
import java.io.File; |
|
import java.io.FileOutputStream; |
|
import java.io.OutputStream; |
|
import java.nio.file.Paths; |
|
|
|
public class JStreamBook extends JWorkBook { |
|
|
|
|
|
public JStreamBook(WorkBook workBook, FILE file) { |
|
super(workBook, file); |
|
} |
|
|
|
@Override |
|
protected boolean saveFile() { |
|
boolean saved; |
|
TransformResultInfo resultInfo = TemplateTransformer.compileCPTX(getTarget(), getEditingFILE()); |
|
saved = resultInfo.isSaved(); |
|
this.setSaved(saved); |
|
if (saved) { |
|
this.fireJTemplateSaved(); |
|
} |
|
return saved; |
|
} |
|
|
|
@Override |
|
protected boolean saveToNewFile(String oldName) { |
|
String path = this.getEditingFILE().getPath(); |
|
try { |
|
if (!path.startsWith(ProjectConstants.REPORTLETS_NAME)) { |
|
File file = new File(path); |
|
if (file.getParentFile() != null && !file.getParentFile().exists()) { |
|
file.getParentFile().mkdirs(); |
|
} |
|
file.createNewFile(); |
|
OutputStream outputStream = new FileOutputStream(file); |
|
this.getTarget().export(outputStream); |
|
return true; |
|
}else { |
|
TransformResult result; |
|
if (FileExtension.CPT.matchExtension(path)) { |
|
result = TemplateTransformer.TO_CPT.transform(this); |
|
} else { |
|
result = TemplateTransformer.TO_CPTX.transform(this); |
|
} |
|
return ComparatorUtils.equals(TransformResult.SUCCESS, result); |
|
} |
|
} catch (Exception e) { |
|
FineLoggerFactory.getLogger().error(e.getMessage(), e); |
|
} |
|
return false; |
|
} |
|
|
|
|
|
/** |
|
* 保存文件的后缀名 |
|
* |
|
* @return 后缀的字符串 |
|
*/ |
|
@Override |
|
public String suffix() { |
|
return ".cptx"; |
|
} |
|
|
|
@Override |
|
protected void addShortCut(MenuDef exportMenuDef, MenuDef excelExportMenuDef) { |
|
exportMenuDef.addShortCut(excelExportMenuDef, new PDFExportAction(this), new WordExportAction(this), new SVGExportAction(this), |
|
new CSVExportAction(this), new TextExportAction(this)); |
|
} |
|
|
|
|
|
@Override |
|
public String getPath() { |
|
return getEditingFILE().getPath() + getSuffix(); |
|
} |
|
|
|
public String getTemplateName() { |
|
return getEditingFILE().getName() + getSuffix(); |
|
} |
|
|
|
private String getSuffix() { |
|
String path = this.getEditingFILE().getPath(); |
|
CptxMetadata metadata = Paths.get(path).isAbsolute() ? null : CptxFileUtils.getMetadata(path); |
|
if (metadata != null && metadata.isForceCpt()) { |
|
return InterProviderFactory.getProvider().getLocText("Fine-Plugin_Engine_Compatibility_Mode"); |
|
} |
|
return StringUtils.EMPTY; |
|
} |
|
|
|
@Override |
|
public ShortCut[] shortcut4TemplateMenu() { |
|
return ArraysUtil.insert(super.shortcut4TemplateMenu(), new CalculateAttrAction(this), 5); |
|
} |
|
} |