Browse Source

Merge pull request #780 in DESIGN/design from ~YAOH.WU/design:release/10.0 to release/10.0

* commit '052f9357e2b688099f530baf7026d2040e3df094':
  REPORT-14624 Rename 方式导出
bugfix/10.0
yaoh.wu 6 years ago
parent
commit
bfff8eefdf
  1. 15
      designer-base/src/main/java/com/fr/design/actions/file/export/AbstractExportAction.java
  2. 93
      designer-base/src/main/java/com/fr/file/AbstractFILE.java
  3. 2
      designer-base/src/main/java/com/fr/file/FileFILE.java
  4. 102
      designer-base/src/main/java/com/fr/file/RenameExportFILE.java
  5. 34
      designer-base/src/main/java/com/fr/file/StashedFILE.java

15
designer-base/src/main/java/com/fr/design/actions/file/export/AbstractExportAction.java

@ -1,7 +1,7 @@
package com.fr.design.actions.file.export;
import com.fr.base.vcs.DesignerMode;
import com.fr.design.actions.JTemplateAction;
import com.fr.design.base.mode.DesignModeContext;
import com.fr.design.gui.iprogressbar.FRProgressBar;
import com.fr.design.i18n.Toolkit;
import com.fr.design.mainframe.DesignerContext;
@ -9,6 +9,7 @@ import com.fr.design.mainframe.JTemplate;
import com.fr.exception.RemoteDesignPermissionDeniedException;
import com.fr.file.FILE;
import com.fr.file.FILEChooserPane;
import com.fr.file.RenameExportFILE;
import com.fr.file.filter.ChooseFileFilter;
import com.fr.io.exporter.DesignExportType;
import com.fr.io.exporter.ExporterKey;
@ -92,12 +93,17 @@ public abstract class AbstractExportAction<E extends JTemplate<?, ?>> extends JT
int saveValue = fileChooserPane.showSaveDialog(DesignerContext.getDesignerFrame(), "." + this.getDefaultExtension());
if (saveValue == FILEChooserPane.JOPTIONPANE_OK_OPTION || saveValue == FILEChooserPane.OK_OPTION) {
FILE target = fileChooserPane.getSelectedFILE();
//rename 方式导出
target = RenameExportFILE.create(target);
try {
target.mkfile();
} catch (Exception exp) {
FineLoggerFactory.getLogger().error("Error In Make New File", exp);
}
FineLoggerFactory.getLogger().info("\"" + target.getName() + "\"" + Toolkit.i18nText("Fine-Design_Report_Prepare_Export") + "!");
FineLoggerFactory.getLogger().info(
"\"" + RenameExportFILE.recoverFileName(target.getName()) + "\"" +
Toolkit.i18nText("Fine-Design_Report_Prepare_Export") + "!"
);
progressbar = new FRProgressBar(
createExportWork(getSource(), target, para),
@ -124,7 +130,7 @@ public abstract class AbstractExportAction<E extends JTemplate<?, ?>> extends JT
private boolean processNotSaved() {
//当前编辑的模板
E e = getEditingComponent();
if (!e.isALLSaved() && !DesignerMode.isVcsMode()) {
if (!e.isALLSaved() && !DesignModeContext.isVcsMode()) {
e.stopEditing();
int returnVal = JOptionPane.showConfirmDialog(
DesignerContext.getDesignerFrame(),
@ -149,7 +155,7 @@ public abstract class AbstractExportAction<E extends JTemplate<?, ?>> extends JT
private SwingWorker createExportWork(final FILE source, final FILE target, final Map<String, Object> parameterMap) {
final String path = source.getPath();
final String name = target.getName();
final String name = RenameExportFILE.recoverFileName(target.getName());
return new SwingWorker<Void, Void>() {
@ -162,7 +168,6 @@ public abstract class AbstractExportAction<E extends JTemplate<?, ?>> extends JT
dealExporter(outputStream, path, parameterMap);
this.setProgress(80);
outputStream.flush();
outputStream.close();
this.setProgress(100);
FineLoggerFactory.getLogger().info("\"" + name + "\"" + Toolkit.i18nText("Fine-Design_Report_Finish_Export") + "!");

93
designer-base/src/main/java/com/fr/file/AbstractFILE.java

@ -0,0 +1,93 @@
package com.fr.file;
import javax.swing.Icon;
import java.io.InputStream;
import java.io.OutputStream;
public abstract class AbstractFILE implements FILE {
@Override
public String prefix() {
throw new UnsupportedOperationException();
}
@Override
public boolean isDirectory() {
throw new UnsupportedOperationException();
}
@Override
public String getName() {
throw new UnsupportedOperationException();
}
@Override
public Icon getIcon() {
throw new UnsupportedOperationException();
}
@Override
public String getPath() {
throw new UnsupportedOperationException();
}
@Override
public void setPath(String path) {
throw new UnsupportedOperationException();
}
@Override
public FILE getParent() {
throw new UnsupportedOperationException();
}
@Override
public FILE[] listFiles() {
throw new UnsupportedOperationException();
}
@Override
public boolean createFolder(String name) {
throw new UnsupportedOperationException();
}
@Override
public boolean mkfile() throws Exception {
throw new UnsupportedOperationException();
}
@Override
public boolean exists() {
throw new UnsupportedOperationException();
}
@Override
public void closeTemplate() throws Exception {
throw new UnsupportedOperationException();
}
@Override
public InputStream asInputStream() throws Exception {
throw new UnsupportedOperationException();
}
@Override
public OutputStream asOutputStream() throws Exception {
throw new UnsupportedOperationException();
}
@Override
public String getEnvFullName() {
throw new UnsupportedOperationException();
}
@Override
public boolean isMemFile() {
throw new UnsupportedOperationException();
}
@Override
public boolean isEnvFile() {
throw new UnsupportedOperationException();
}
}

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

@ -201,7 +201,7 @@ public class FileFILE implements FILE {
OutputStream out;
try {
StableUtils.makesureFileExist(file);
out = new FileOutputStream(file, true);
out = new FileOutputStream(file, false);
} catch (Exception e) {
throw SessionLocalManager.createLogPackedException(e);
}

102
designer-base/src/main/java/com/fr/file/RenameExportFILE.java

@ -0,0 +1,102 @@
package com.fr.file;
import com.fr.stable.StableUtils;
import com.fr.stable.StringUtils;
import com.fr.third.org.apache.commons.io.FileUtils;
import com.fr.web.session.SessionLocalManager;
import javax.swing.Icon;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
public class RenameExportFILE extends AbstractFILE {
private static final String EXPORT_SUFFIX = ".FRExportTmp";
private FILE file;
private RenameExportFILE(FILE file) {
this.file = new FileFILE(new File(file.getPath() + EXPORT_SUFFIX));
}
public static RenameExportFILE create(FILE file) {
return new RenameExportFILE(file);
}
public static String recoverFileName(String fileName) {
if (StringUtils.isEmpty(fileName) || !fileName.endsWith(EXPORT_SUFFIX)) {
return fileName;
}
return fileName.substring(0, fileName.lastIndexOf(EXPORT_SUFFIX));
}
@Override
public String prefix() {
return file.prefix();
}
@Override
public boolean isDirectory() {
return false;
}
@Override
public String getName() {
return file.getName();
}
@Override
public Icon getIcon() {
return null;
}
@Override
public String getPath() {
return file.getPath();
}
@Override
public FILE getParent() {
return file.getParent();
}
@Override
public boolean mkfile() throws Exception {
return file.mkfile();
}
@Override
public boolean exists() {
return file.exists();
}
@Override
public OutputStream asOutputStream() throws Exception {
final File localeFile = new File(file.getPath());
OutputStream out;
try {
StableUtils.makesureFileExist(localeFile);
out = new FileOutputStream(localeFile, false) {
@Override
public void close() throws IOException {
super.close();
String path = file.getPath();
if (localeFile.exists()) {
FileUtils.copyFile(localeFile, new File(recoverFileName(path)));
if (localeFile.getPath().endsWith(EXPORT_SUFFIX)) {
FileUtils.forceDelete(localeFile);
}
}
}
};
} catch (Exception e) {
throw SessionLocalManager.createLogPackedException(e);
}
return out;
}
}

34
designer-base/src/main/java/com/fr/file/StashedFILE.java

@ -1,15 +1,13 @@
package com.fr.file;
import javax.swing.Icon;
import javax.transaction.NotSupportedException;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.io.OutputStream;
/**
* 切换环境用于暂存的文件类型
*/
public class StashedFILE implements FILE {
public class StashedFILE extends AbstractFILE {
private FILE file;
private byte[] content;
@ -44,31 +42,6 @@ public class StashedFILE implements FILE {
return file.getPath();
}
@Override
public void setPath(String path) {
throw new UnsupportedOperationException();
}
@Override
public FILE getParent() {
throw new UnsupportedOperationException();
}
@Override
public FILE[] listFiles() {
throw new UnsupportedOperationException();
}
@Override
public boolean createFolder(String name) {
throw new UnsupportedOperationException();
}
@Override
public boolean mkfile() throws Exception {
throw new UnsupportedOperationException();
}
@Override
public boolean exists() {
return false;
@ -84,11 +57,6 @@ public class StashedFILE implements FILE {
return new ByteArrayInputStream(content);
}
@Override
public OutputStream asOutputStream() throws Exception {
throw new NotSupportedException();
}
@Override
public String getEnvFullName() {
return file.getEnvFullName();

Loading…
Cancel
Save