Browse Source

DEC-156 资源文件调用接口调整

master
rinoux 6 years ago
parent
commit
2c984af4d4
  1. 3
      designer/src/com/fr/design/module/DesignerModule.java
  2. 10
      designer_base/src/com/fr/design/file/TemplateTreePane.java
  3. 10
      designer_base/src/com/fr/design/mainframe/DesignerFrameFileDealerPane.java
  4. 80
      designer_base/src/com/fr/env/RemoteEnv.java

3
designer/src/com/fr/design/module/DesignerModule.java

@ -53,6 +53,7 @@ import com.fr.general.ModuleContext;
import com.fr.general.xml.GeneralXMLTools;
import com.fr.io.importer.Excel2007ReportImporter;
import com.fr.io.importer.ExcelReportImporter;
import com.fr.io.utils.ResourceIOUtils;
import com.fr.main.impl.WorkBook;
import com.fr.quickeditor.cellquick.CellBiasTextPainterEditor;
import com.fr.quickeditor.cellquick.CellDSColumnEditor;
@ -348,7 +349,7 @@ public class DesignerModule extends DesignModule {
namestyle.clear();
String checkStr = StringUtils.EMPTY;
try {
checkStr = IOUtils.inputStream2String(file.asInputStream());
checkStr = ResourceIOUtils.inputStream2String(file.asInputStream());
tpl.readStream(file.asInputStream());
} catch (Exception exp) {
String errorMessage = StringUtils.EMPTY;

10
designer_base/src/com/fr/design/file/TemplateTreePane.java

@ -26,7 +26,11 @@ import com.sun.jna.platform.FileUtils;
import javax.swing.*;
import javax.swing.tree.DefaultMutableTreeNode;
import java.awt.*;
import java.awt.event.*;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
@ -139,7 +143,7 @@ public class TemplateTreePane extends JPanel implements FileOperations {
public void openContainerFolder() {
FileNode fn = TemplateTreePane.this.reportletsTree.getSelectedFileNode();
LocalEnv localEnv = (LocalEnv) FRContext.getCurrentEnv();
String filePath = StableUtils.pathJoin(new String[]{localEnv.path, fn.getEnvPath()});
String filePath = StableUtils.pathJoin(localEnv.path, fn.getEnvPath());
filePath = filePath.substring(0, filePath.lastIndexOf(CoreConstants.SEPARATOR));
try {
Desktop.getDesktop().open(new File(filePath));
@ -315,6 +319,8 @@ public class TemplateTreePane extends JPanel implements FileOperations {
if (fileUtils.hasTrash()) {
try {
fileUtils.moveToTrash(new File[]{new File(StableUtils.pathJoin(nodeFile.getEnvPath(), nodeFile.getPath()))});
//todo 走下这个流程,否则集群下其它节点无法同步删除
//DEC-156 资源文件调用接口调整FRContext.getCurrentEnv().deleteFile(nodeFile.getPath());
} catch (IOException e) {
FRLogger.getLogger().info(e.getMessage());
FRContext.getCurrentEnv().deleteFile(nodeFile.getPath());

10
designer_base/src/com/fr/design/mainframe/DesignerFrameFileDealerPane.java

@ -28,6 +28,7 @@ import com.fr.file.FileNodeFILE;
import com.fr.file.filetree.FileNode;
import com.fr.general.ComparatorUtils;
import com.fr.general.Inter;
import com.fr.io.utils.ResourceIOUtils;
import com.fr.stable.CoreConstants;
import com.fr.stable.StableUtils;
import com.fr.stable.project.ProjectConstants;
@ -382,8 +383,8 @@ public class DesignerFrameFileDealerPane extends JPanel implements FileToolbarSt
return;
}
final FileNodeFILE nodeFile = new FileNodeFILE(new FileNode(StableUtils.pathJoin(new String[]{ProjectConstants.REPORTLETS_NAME, reportPath}), false));
final String path = StableUtils.pathJoin(new String[]{nodeFile.getEnvPath(), nodeFile.getPath()});
final FileNodeFILE nodeFile = new FileNodeFILE(new FileNode(StableUtils.pathJoin(ProjectConstants.REPORTLETS_NAME, reportPath), false));
final String path = nodeFile.getPath();
oldName = nodeFile.getName();
suffix = oldName.substring(oldName.lastIndexOf(CoreConstants.DOT), oldName.length());
oldName = oldName.replaceAll(suffix, "");
@ -476,8 +477,9 @@ public class DesignerFrameFileDealerPane extends JPanel implements FileToolbarSt
String newPath = path.replace(nodeFile.getName(), userInput + suffix);
renameTemplateInMemory(nodeFile, userInput + suffix, oldName + suffix);
DesignerEnvManager.getEnvManager().replaceRecentOpenedFilePath(oldPath, newPath.replaceAll("/", "\\\\"));
File newFile = new File(newPath);
new File(path).renameTo(newFile);
//模版重命名
ResourceIOUtils.renameTo(path, newPath);
selectedOperation.refresh();
DesignerContext.getDesignerFrame().setTitle();
jd.dispose();

80
designer_base/src/com/fr/env/RemoteEnv.java vendored

@ -31,6 +31,7 @@ import com.fr.file.DatasourceManagerProvider;
import com.fr.file.filetree.FileNode;
import com.fr.general.*;
import com.fr.general.http.HttpClient;
import com.fr.io.utils.ResourceIOUtils;
import com.fr.json.JSONArray;
import com.fr.json.JSONException;
import com.fr.json.JSONObject;
@ -39,6 +40,7 @@ import com.fr.regist.License;
import com.fr.share.ShareConstants;
import com.fr.stable.ArrayUtils;
import com.fr.stable.EncodeConstants;
import com.fr.stable.Filter;
import com.fr.stable.JavaCompileInfo;
import com.fr.stable.ProductConstants;
import com.fr.stable.StableUtils;
@ -1481,16 +1483,11 @@ public class RemoteEnv extends AbstractEnv {
* @param path 制定路径,是基于报表目录下resource文件夹路径
* @return 读到的文件
*/
public File[] readPathSvgFiles(String path) {
String cataloguePath = StableUtils.pathJoin(new String[]{CacheManager.getProviderInstance().getCacheDirectory().getPath(), SvgProvider.SERVER, path});
public String[] readPathSvgFiles(String path) {
String cataloguePath = StableUtils.pathJoin(CacheManager.getProviderInstance().getCacheDirectory().getPath(), SvgProvider.SERVER, path);
//检查缓存文件保存的目录下serversvgs文件夹是否存在 ,先用来暂存服务器读过来的svg文件
File catalogue = new File(cataloguePath);
if (!catalogue.exists()) {
catalogue.mkdirs();
}
ArrayList<File> fileArray = new ArrayList<>();
ArrayList<String> fileArray = new ArrayList<>();
try {
HashMap<String, String> para = new HashMap<String, String>();
para.put("op", "fr_remote_design");
@ -1506,17 +1503,17 @@ public class RemoteEnv extends AbstractEnv {
JSONObject jsonObject = (JSONObject) ja.get(i);
String svgFileName = (String) jsonObject.get("svgfileName");
String svgfileContent = (String) jsonObject.get("svgfileContent");
File file = new File(StableUtils.pathJoin(new String[]{cataloguePath, svgFileName}));
String file = StableUtils.pathJoin(cataloguePath, svgFileName);
InputStream in = new ByteArrayInputStream(svgfileContent.getBytes(EncodeConstants.ENCODING_UTF_8));
FileOutputStream out = new FileOutputStream(file);
IOUtils.copyBinaryTo(in, out);
ResourceIOUtils.write(file, in);
fileArray.add(file);
}
} catch (Exception e) {
FRContext.getLogger().error(e.getMessage());
}
return fileArray.toArray(new File[fileArray.size()]);
return fileArray.toArray(new String[fileArray.size()]);
}
@ -2098,14 +2095,12 @@ public class RemoteEnv extends AbstractEnv {
public void pluginServiceStart(String serviceID){
}
@Override
public File[] loadREUFile() throws Exception {
File target = new File(CacheManager.getProviderInstance().getCacheDirectory(),
ShareConstants.DIR_SHARE_CACHE);
StableUtils.deleteFile(target);
StableUtils.mkdirs(target);
File cacheDir = null;
File zip = null;
OutputStream out = null;
public String[] loadREUFile() throws Exception {
ResourceIOUtils.delete(StableUtils.pathJoin(
CacheManager.getProviderInstance().getCacheDirectory().getAbsolutePath(),
ShareConstants.DIR_SHARE_CACHE));
String zipFilePath = null;
try {
HashMap<String, String> para = new HashMap<String, String>();
para.put("op", "fr_remote_design");
@ -2114,34 +2109,35 @@ public class RemoteEnv extends AbstractEnv {
para.put("currentUsername", this.getUser());
HttpClient client = createHttpMethod(para);
InputStream input = client.getResponseStream();//拿到服务端传过来的整个共享文件夹的压缩文件的文件流
zip = new File(StableUtils.pathJoin(CacheManager.getProviderInstance().getCacheDirectory().getAbsolutePath()), "share.zip");
cacheDir = new File(StableUtils.pathJoin(CacheManager.getProviderInstance().getCacheDirectory().getAbsolutePath()), ShareConstants.DIR_SHARE_CACHE);
StableUtils.deleteFile(cacheDir);
StableUtils.mkdirs(cacheDir);
StableUtils.makesureFileExist(zip);
out = new FileOutputStream(zip);
IOUtils.copyBinaryTo(input, out);//放到本地缓存目录下
IOUtils.unzip(zip, cacheDir.getAbsolutePath(), EncodeConstants.ENCODING_GBK);//先解压到临时目录
if (cacheDir.exists() && cacheDir.isDirectory()) {
return cacheDir.listFiles(new FilenameFilter() {
public boolean accept(File file, String s) {
return s.endsWith("reu");
}
});
}
//拿到服务端传过来的整个共享文件夹的压缩文件的文件流
InputStream input = client.getResponseStream();
zipFilePath = StableUtils.pathJoin(CacheManager.getProviderInstance().getCacheDirectory().getAbsolutePath(), "share.zip");
String cacheDir = StableUtils.pathJoin(CacheManager.getProviderInstance().getCacheDirectory().getAbsolutePath(), ShareConstants.DIR_SHARE_CACHE);
ResourceIOUtils.write(zipFilePath, input);
ResourceIOUtils.unzip(zipFilePath, cacheDir, EncodeConstants.ENCODING_GBK);
List<String> files = ResourceIOUtils.listWithFullPath(cacheDir, new Filter<String>() {
@Override
public boolean accept(String s) {
return s.endsWith(ProjectConstants.REU);
}
});
return files.toArray(new String[files.size()]);
} catch (Exception e) {
FRContext.getLogger().error(e.getMessage());
} finally {
if (out != null) {
out.flush();
out.close();
if (zipFilePath != null) {
ResourceIOUtils.delete(zipFilePath);
}
StableUtils.deleteFile(zip);
}
return new File[0];
return new String[0];
}
@Override

Loading…
Cancel
Save