From 2c984af4d4ebcd859f1d6dbcb742a3c97495f0ad Mon Sep 17 00:00:00 2001 From: rinoux Date: Sat, 24 Feb 2018 15:50:23 +0800 Subject: [PATCH] =?UTF-8?q?DEC-156=20=E8=B5=84=E6=BA=90=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E8=B0=83=E7=94=A8=E6=8E=A5=E5=8F=A3=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/fr/design/module/DesignerModule.java | 3 +- .../com/fr/design/file/TemplateTreePane.java | 10 ++- .../DesignerFrameFileDealerPane.java | 10 ++- designer_base/src/com/fr/env/RemoteEnv.java | 80 +++++++++---------- 4 files changed, 54 insertions(+), 49 deletions(-) diff --git a/designer/src/com/fr/design/module/DesignerModule.java b/designer/src/com/fr/design/module/DesignerModule.java index 1ec15dabb..cdb19d7e3 100644 --- a/designer/src/com/fr/design/module/DesignerModule.java +++ b/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; diff --git a/designer_base/src/com/fr/design/file/TemplateTreePane.java b/designer_base/src/com/fr/design/file/TemplateTreePane.java index 3c690a5c6..112280b94 100644 --- a/designer_base/src/com/fr/design/file/TemplateTreePane.java +++ b/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()); diff --git a/designer_base/src/com/fr/design/mainframe/DesignerFrameFileDealerPane.java b/designer_base/src/com/fr/design/mainframe/DesignerFrameFileDealerPane.java index 6b3606ff9..bcb848ec1 100644 --- a/designer_base/src/com/fr/design/mainframe/DesignerFrameFileDealerPane.java +++ b/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(); diff --git a/designer_base/src/com/fr/env/RemoteEnv.java b/designer_base/src/com/fr/env/RemoteEnv.java index 65733b1df..acaea0f41 100644 --- a/designer_base/src/com/fr/env/RemoteEnv.java +++ b/designer_base/src/com/fr/env/RemoteEnv.java @@ -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 fileArray = new ArrayList<>(); + ArrayList fileArray = new ArrayList<>(); try { HashMap para = new HashMap(); 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 para = new HashMap(); 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 files = ResourceIOUtils.listWithFullPath(cacheDir, new Filter() { + @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