java: changed getFileExtension return without dot

This commit is contained in:
Aleksandr Fedorov
2023-09-13 11:27:06 +03:00
parent 5e2f812fee
commit 5a63bd47c1
8 changed files with 27 additions and 27 deletions

View File

@ -635,7 +635,7 @@ public class IndexServlet extends HttpServlet {
String newfilename = (String) body.get("newfilename");
String dockey = (String) body.get("dockey");
String origExt = "." + (String) body.get("ext");
String origExt = (String) body.get("ext");
String curExt = newfilename;
if (newfilename.indexOf(".") != -1) {
@ -643,7 +643,7 @@ public class IndexServlet extends HttpServlet {
}
if (origExt.compareTo(curExt) != 0) {
newfilename += origExt;
newfilename += "." + origExt;
}
HashMap<String, String> meta = new HashMap<>();
@ -724,7 +724,7 @@ public class IndexServlet extends HttpServlet {
referenceData.put("fileKey", gson.toJson(fileKey));
HashMap<String, Object> data = new HashMap<>();
data.put("fileType", FileUtility.getFileExtension(fileName).replace(".", ""));
data.put("fileType", FileUtility.getFileExtension(fileName));
data.put("url", DocumentManager.getDownloadUrl(fileName, true));
data.put("directUrl", directUrl ? DocumentManager.getDownloadUrl(fileName, false) : null);
data.put("referenceData", referenceData);
@ -805,7 +805,7 @@ public class IndexServlet extends HttpServlet {
bumpedChangesFileWriter.close();
String sourceExtension = FileUtility.getFileExtension(sourceBasename);
String previousBasename = "prev" + sourceExtension;
String previousBasename = "prev." + sourceExtension;
Path bumpedFile = Paths.get(bumpedVersionStringDirectory, previousBasename);
Files.move(sourcePathFile, bumpedFile);
@ -947,16 +947,16 @@ public class IndexServlet extends HttpServlet {
key = DocumentManager.readFileToEnd(new File(verDir + File.separator + "key.txt"));
}
dataObj.put("fileType", FileUtility.getFileExtension(fileName).substring(1));
dataObj.put("fileType", FileUtility.getFileExtension(fileName));
dataObj.put("key", key);
dataObj.put("url", i == curVer
? DocumentManager.getDownloadUrl(fileName, true)
: DocumentManager.getDownloadHistoryUrl(fileName, i, "prev" + FileUtility
: DocumentManager.getDownloadHistoryUrl(fileName, i, "prev." + FileUtility
.getFileExtension(fileName), true));
if (directUrl.equals("true")) {
dataObj.put("directUrl", i == curVer
? DocumentManager.getDownloadUrl(fileName, false)
: DocumentManager.getDownloadHistoryUrl(fileName, i, "prev" + FileUtility
: DocumentManager.getDownloadHistoryUrl(fileName, i, "prev." + FileUtility
.getFileExtension(fileName), false));
}

View File

@ -63,7 +63,7 @@ public class FileModel {
document.setDirectUrl(isEnableDirectUrl ? DocumentManager.getDownloadUrl(fileName, false) : "");
// get file extension from the file name
document.setFileType(FileUtility.getFileExtension(fileName).replace(".", ""));
document.setFileType(FileUtility.getFileExtension(fileName));
// generate document key
document.setKey(ServiceConverter
.generateRevisionId(DocumentManager

View File

@ -248,12 +248,12 @@ public final class DocumentManager {
public static String getCorrectName(final String fileName, final String userAddress) {
String baseName = FileUtility.getFileNameWithoutExtension(fileName);
String ext = FileUtility.getFileExtension(fileName);
String name = baseName + ext;
String name = baseName + "." + ext;
File file = new File(storagePath(name, userAddress));
for (int i = 1; file.exists(); i++) { // run through all the files with such a name in the storage directory
name = baseName + " (" + i + ")" + ext; // and add an index to the base name
name = baseName + " (" + i + ")." + ext; // and add an index to the base name
file = new File(storagePath(name, userAddress));
}

View File

@ -75,7 +75,7 @@ public final class FileUtility {
if (fileName == null) {
return null;
}
String fileExt = fileName.substring(fileName.lastIndexOf("."));
String fileExt = fileName.substring(fileName.lastIndexOf(".") + 1);
return fileExt.toLowerCase();
}

View File

@ -158,8 +158,8 @@ public final class ServiceConverter {
ConvertBody body = new ConvertBody();
body.setRegion(lang);
body.setUrl(documentUri);
body.setOutputtype(toExtension.replace(".", ""));
body.setFiletype(fromExt.replace(".", ""));
body.setOutputtype(toExtension);
body.setFiletype(fromExt);
body.setTitle(title);
body.setKey(documentRevId);
body.setPassword(filePass);

View File

@ -150,7 +150,7 @@ public final class TrackManager {
String newFileName = fileName;
String curExt = FileUtility.getFileExtension(fileName); // get current file extension
String downloadExt = "." + (String) body.get("filetype"); // get the extension of the downloaded file
String downloadExt = (String) body.get("filetype"); // get the extension of the downloaded file
// convert downloaded file to the file with the current extension if these extensions aren't equal
if (!curExt.equals(downloadExt)) {
@ -164,13 +164,13 @@ public final class TrackManager {
// get the correct file name if it already exists
newFileName = DocumentManager
.getCorrectName(FileUtility
.getFileNameWithoutExtension(fileName) + downloadExt, userAddress);
.getFileNameWithoutExtension(fileName) + "." + downloadExt, userAddress);
} else {
downloadUri = newFileUri;
}
} catch (Exception e) {
newFileName = DocumentManager.getCorrectName(FileUtility
.getFileNameWithoutExtension(fileName) + downloadExt, userAddress);
.getFileNameWithoutExtension(fileName) + "." + downloadExt, userAddress);
}
}
@ -193,7 +193,7 @@ public final class TrackManager {
}
// get the path to the previous file version and rename the last file version with it
lastVersion.renameTo(new File(versionDir + File.separator + "prev" + curExt));
lastVersion.renameTo(new File(versionDir + File.separator + "prev." + curExt));
saveFile(byteArrayFile, toSave); // save document file
@ -236,7 +236,7 @@ public final class TrackManager {
String downloadUri = (String) body.get("url");
String curExt = FileUtility.getFileExtension(fileName); // get current file extension
String downloadExt = "." + (String) body.get("filetype"); // get the extension of the downloaded file
String downloadExt = (String) body.get("filetype"); // get the extension of the downloaded file
Boolean newFileName = false;
@ -265,10 +265,10 @@ public final class TrackManager {
// new file
if (newFileName) {
fileName = DocumentManager.getCorrectName(FileUtility.getFileNameWithoutExtension(fileName)
+ "-form" + downloadExt, userAddress); // get the correct file name if it already exists
+ "-form." + downloadExt, userAddress); // get the correct file name if it already exists
} else {
fileName = DocumentManager.getCorrectName(FileUtility.getFileNameWithoutExtension(fileName)
+ "-form" + curExt, userAddress);
+ "-form." + curExt, userAddress);
}
forcesavePath = DocumentManager.storagePath(fileName, userAddress);
} else {

View File

@ -367,9 +367,9 @@
<script type="text/javascript" src="scripts/jscript.js"></script>
<script language="javascript" type="text/javascript">
var FillExtList = "<%= String.join(",", DocumentManager.getFillExts()) %>";
var ConverExtList = "<%= String.join(",", DocumentManager.getConvertExts()) %>";
var EditedExtList = "<%= String.join(",", DocumentManager.getEditedExts()) %>";
var FillExtList = "<%= String.join(",", DocumentManager.getFillExts()) %>".split(",");
var ConverExtList = "<%= String.join(",", DocumentManager.getConvertExts()) %>".split(",");
var EditedExtList = "<%= String.join(",", DocumentManager.getEditedExts()) %>".split(",");
var UrlConverter = "IndexServlet?type=convert";
var UrlEditor = "EditorServlet";

View File

@ -100,10 +100,10 @@ if (typeof jQuery !== "undefined") {
jq("#filePass").val("");
var fileName = jq("#hiddenFileName").val();
var posExt = fileName.lastIndexOf(".");
var posExt = fileName.lastIndexOf(".") + 1;
posExt = 0 <= posExt ? fileName.substring(posExt).trim().toLowerCase() : "";
if (ConverExtList.indexOf(posExt) === -1) {
if (!ConverExtList.includes(posExt)) {
jq("#step2").addClass("done").removeClass("current");
loadScripts();
return;
@ -177,10 +177,10 @@ if (typeof jQuery !== "undefined") {
jq("#beginView, #beginEmbedded").removeClass("disable");
var fileName = jq("#hiddenFileName").val();
var posExt = fileName.lastIndexOf(".");
var posExt = fileName.lastIndexOf(".") + 1;
posExt = 0 <= posExt ? fileName.substring(posExt).trim().toLowerCase() : "";
if (EditedExtList.indexOf(posExt) !== -1 || FillExtList.indexOf(posExt) !== -1) {
if (EditedExtList.includes(posExt) || FillExtList.includes(posExt)) {
jq("#beginEdit").removeClass("disable");
}
};