From 77ec1649a5331f71befc4ea20bd5d805120063de Mon Sep 17 00:00:00 2001 From: Andrey Yumatov Date: Mon, 31 Jan 2022 15:00:27 +0300 Subject: [PATCH] Java: fix the code and remove the encoding of the url version --- .../java/src/main/java/entities/FileModel.java | 9 ++------- .../java/src/main/java/helpers/DocumentManager.java | 10 ++++------ 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/web/documentserver-example/java/src/main/java/entities/FileModel.java b/web/documentserver-example/java/src/main/java/entities/FileModel.java index 3c7e1c4f..37963485 100755 --- a/web/documentserver-example/java/src/main/java/entities/FileModel.java +++ b/web/documentserver-example/java/src/main/java/entities/FileModel.java @@ -177,7 +177,7 @@ public class FileModel dataObj.put("fileType", FileUtility.GetFileExtension(document.title).substring(1)); dataObj.put("key", key); - dataObj.put("url", i == curVer ? document.url : DocumentManager.GetDownloadHistoryUrl(document.title, i.toString(), "prev" + FileUtility.GetFileExtension(document.title))); + dataObj.put("url", i == curVer ? document.url : DocumentManager.GetDownloadHistoryUrl(document.title, i, "prev" + FileUtility.GetFileExtension(document.title))); dataObj.put("version", i); if (i > 1) { //check if the version number is greater than 1 @@ -198,13 +198,8 @@ public class FileModel prevInfo.put("url", prev.get("url")); dataObj.put("previous", prevInfo); // write information about previous file version to the data object // write the path to the diff.zip archive with differences in this file version - String storagePath = ConfigManager.GetProperty("storage-folder"); - Integer verdiff = i - 1; - String changesUrl = DocumentManager.GetDownloadHistoryUrl(document.title, verdiff.toString(), "prev" + FileUtility.GetFileExtension(document.title)); - if (new File(storagePath).isAbsolute()) { - changesUrl = DocumentManager.GetDownloadUrl((DocumentManager.VersionDir(histDir, i - 1) + File.separator + "diff.zip").replace(storagePath, "")); - } + String changesUrl = DocumentManager.GetDownloadHistoryUrl(document.title, verdiff, "diff.zip"); dataObj.put("changesUrl", changesUrl); } diff --git a/web/documentserver-example/java/src/main/java/helpers/DocumentManager.java b/web/documentserver-example/java/src/main/java/helpers/DocumentManager.java index 8f91c739..66d54439 100644 --- a/web/documentserver-example/java/src/main/java/helpers/DocumentManager.java +++ b/web/documentserver-example/java/src/main/java/helpers/DocumentManager.java @@ -169,11 +169,9 @@ public class DocumentManager String hostAddress = CurUserHostAddress(userAddress); String serverPath = request.getSession().getServletContext().getRealPath(""); String storagePath = ConfigManager.GetProperty("storage-folder"); - String directory = serverPath + storagePath + File.separator + hostAddress + File.separator; - - if (file == null | file == "") { - file = "prev"+fileName.substring(fileName.lastIndexOf(".")); + if (new File(storagePath).isAbsolute()) { + directory = FilesRootPath(userAddress); } directory = directory + fileName + "-hist" + File.separator + version + File.separator + file; @@ -467,13 +465,13 @@ public class DocumentManager } // get url to download a file to History prev.* - public static String GetDownloadHistoryUrl(String fileName, String version, String file) { + public static String GetDownloadHistoryUrl(String fileName, Integer version, String file) { String serverPath = GetServerUrl(true); String hostAddress = CurUserHostAddress(null); try { String query = "?type=downloadhistory&fileName=" + URLEncoder.encode(fileName, java.nio.charset.StandardCharsets.UTF_8.toString()) + "&userAddress=" + URLEncoder.encode(hostAddress, java.nio.charset.StandardCharsets.UTF_8.toString()); - query = query + "&ver=" + URLEncoder.encode(version, java.nio.charset.StandardCharsets.UTF_8.toString()) + "&file=" + URLEncoder.encode(file, java.nio.charset.StandardCharsets.UTF_8.toString()); + query = query + "&ver=" + version + "&file=" + URLEncoder.encode(file, java.nio.charset.StandardCharsets.UTF_8.toString()); return serverPath + "/IndexServlet" + query; }