Merge remote-tracking branch 'remotes/origin/develop' into feature/java-matrix-formats

# Conflicts:
#	.gitmodules
#	CHANGELOG.md
This commit is contained in:
Aleksandr Fedorov
2023-09-14 12:37:01 +03:00
16 changed files with 224 additions and 91 deletions

4
.gitmodules vendored
View File

@ -50,3 +50,7 @@
path = web/documentserver-example/java/src/main/resources/assets/document-formats
url = https://github.com/ONLYOFFICE/document-formats
branch = master
[submodule "web/documentserver-example/java-spring/src/main/resources/assets/document-formats"]
path = web/documentserver-example/java-spring/src/main/resources/assets/document-formats
url = https://github.com/ONLYOFFICE/document-formats
branch = master

View File

@ -7,9 +7,13 @@
- nodejs: submitForm
- nodejs: key in referenceData
- nodejs: change reference source
- java-spring: using a repo with a list of formats
- java: using a repo with a list of formats
- php: using a repo with a list of formats
- nodejs: using a repo with a list of formats
- java: using a repo with a list of formats
- python: using a repo with a list of formats
- ruby: using a repo with a list of formats
- nodejs: delete file without reloading the page
- nodejs: getting history by a separate request
- csharp-mvc: getting history by a separate request

View File

@ -191,7 +191,8 @@ public class FileController {
throw new IOException("Could not update a file"); // if the file cannot be updated, an error occurs
}
fullFileName = fileUtility.getFileNameWithoutExtension(fileNamePath) + fileExtension; // get full file name
fullFileName = fileUtility.getFileNameWithoutExtension(fileNamePath)
+ "." + fileExtension; // get full file name
return createUserMetadata(uid, fullFileName); // create user metadata and return it
} catch (Exception e) {
@ -511,7 +512,7 @@ public class FileController {
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", body.getDirectUrl() ? documentManager.getDownloadUrl(fileName, false) : null);
data.put("referenceData", referenceData);
@ -596,7 +597,7 @@ public class FileController {
bumpedChangesFileWriter.close();
String sourceExtension = fileUtility.getFileExtension(body.getFileName());
String previousBasename = "prev" + sourceExtension;
String previousBasename = "prev." + sourceExtension;
Path bumpedFile = Paths.get(bumpedVersionStringDirectory, previousBasename);
Files.move(sourcePathFile, bumpedFile);

View File

@ -120,7 +120,7 @@ public class DefaultCallbackManager implements CallbackManager {
String newFileName = fileName;
String curExt = fileUtility.getFileExtension(fileName); // get current file extension
String downloadExt = "." + body.getFiletype(); // get an extension of the downloaded file
String downloadExt = body.getFiletype(); // get an extension of the downloaded file
// todo: Refactoring
// convert downloaded file to the file with the current extension if these extensions aren't equal
@ -132,14 +132,14 @@ public class DefaultCallbackManager implements CallbackManager {
null).getUri(); // convert a file and get URL to a new file
if (newFileUri.isEmpty()) {
newFileName = documentManager
.getCorrectName(fileUtility.getFileNameWithoutExtension(fileName)
.getCorrectName(fileUtility.getFileNameWithoutExtension(fileName) + "."
+ downloadExt); // get the correct file name if it already exists
} else {
downloadUri = newFileUri;
}
} catch (Exception e) {
newFileName = documentManager
.getCorrectName(fileUtility.getFileNameWithoutExtension(fileName) + downloadExt);
.getCorrectName(fileUtility.getFileNameWithoutExtension(fileName) + "." + downloadExt);
}
}
@ -163,7 +163,7 @@ public class DefaultCallbackManager implements CallbackManager {
storageMutator.createDirectory(ver); // create the file version directory
lastVersion.toFile().renameTo(new File(versionDir + File.separator + "prev" + curExt));
lastVersion.toFile().renameTo(new File(versionDir + File.separator + "prev." + curExt));
saveFile(byteArrayFile, toSave); // save document file
@ -269,7 +269,7 @@ public class DefaultCallbackManager implements CallbackManager {
String fileName = fileNameParam;
String curExt = fileUtility.getFileExtension(fileName); // get current file extension
String downloadExt = "." + body.getFiletype(); // get an extension of the downloaded file
String downloadExt = body.getFiletype(); // get an extension of the downloaded file
Boolean newFileName = false;
@ -304,10 +304,10 @@ public class DefaultCallbackManager implements CallbackManager {
// get the correct file name if it already exists
fileName = documentManager
.getCorrectName(fileUtility
.getFileNameWithoutExtension(fileName) + "-form" + downloadExt);
.getFileNameWithoutExtension(fileName) + "-form." + downloadExt);
} else {
fileName = documentManager
.getCorrectName(fileUtility.getFileNameWithoutExtension(fileName) + "-form" + curExt);
.getCorrectName(fileUtility.getFileNameWithoutExtension(fileName) + "-form." + curExt);
}
forcesavePath = storagePathBuilder.getFileLocation(fileName); // create forcesave path if it doesn't exist
List<Action> actions = body.getActions();

View File

@ -69,7 +69,7 @@ public class DefaultDocumentManager implements DocumentManager {
// get URL to the created file
public String getCreateUrl(final String fileName, final Boolean sample) {
String fileExt = fileUtility.getFileExtension(fileName).replace(".", "");
String fileExt = fileUtility.getFileExtension(fileName);
String url = storagePathBuilder.getServerUrl(true)
+ "/create?fileExt=" + fileExt + "&sample=" + sample;
return url;
@ -79,13 +79,13 @@ public class DefaultDocumentManager implements DocumentManager {
public String getCorrectName(final String fileName) {
String baseName = fileUtility.getFileNameWithoutExtension(fileName); // get file name without extension
String ext = fileUtility.getFileExtension(fileName); // get file extension
String name = baseName + ext; // create a full file name
String name = baseName + "." + ext; // create a full file name
Path path = Paths.get(storagePathBuilder.getFileLocation(name));
// run through all the files with such a name in the storage directory
for (int i = 1; Files.exists(path); i++) {
name = baseName + " (" + i + ")" + ext; // and add an index to the base name
name = baseName + " (" + i + ")." + ext; // and add an index to the base name
path = Paths.get(storagePathBuilder.getFileLocation(name));
}

View File

@ -103,14 +103,14 @@ public class DefaultHistoryManager implements HistoryManager {
}
dataObj.put("fileType", fileUtility
.getFileExtension(document.getTitle()).replace(".", ""));
.getFileExtension(document.getTitle()));
dataObj.put("key", key);
dataObj.put("url", i == curVer ? document.getUrl()
: documentManager.getHistoryFileUrl(document.getTitle(), i, "prev" + fileUtility
: documentManager.getHistoryFileUrl(document.getTitle(), i, "prev." + fileUtility
.getFileExtension(document.getTitle()), true));
if (!document.getDirectUrl().equals("")) {
dataObj.put("directUrl", i == curVer ? document.getDirectUrl()
: documentManager.getHistoryFileUrl(document.getTitle(), i, "prev" + fileUtility
: documentManager.getHistoryFileUrl(document.getTitle(), i, "prev." + fileUtility
.getFileExtension(document.getTitle()), false));
}
dataObj.put("version", i);

View File

@ -0,0 +1,36 @@
/**
*
* (c) Copyright Ascensio System SIA 2023
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.onlyoffice.integration.documentserver.models;
import java.util.List;
import com.onlyoffice.integration.documentserver.models.enums.DocumentType;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
@Getter
@Setter
@ToString
public class Format {
private String name;
private DocumentType type;
private List<String> actions;
private List<String> convert;
private List<String> mime;
}

View File

@ -18,7 +18,10 @@
package com.onlyoffice.integration.documentserver.util.file;
import com.onlyoffice.integration.documentserver.models.Format;
import com.onlyoffice.integration.documentserver.models.enums.DocumentType;
import com.onlyoffice.integration.documentserver.util.service.FormatService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
@ -26,8 +29,6 @@ import org.springframework.stereotype.Component;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import static com.onlyoffice.integration.documentserver.util.Constants.MAX_FILE_SIZE;
@ -38,55 +39,18 @@ public class DefaultFileUtility implements FileUtility {
@Value("${filesize-max}")
private String filesizeMax;
@Value("${files.docservice.viewed-docs}")
private String docserviceViewedDocs;
@Value("${files.docservice.edited-docs}")
private String docserviceEditedDocs;
@Value("${files.docservice.convert-docs}")
private String docserviceConvertDocs;
@Value("${files.docservice.fillforms-docs}")
private String docserviceFillDocs;
// document extensions
private List<String> extsDocument = Arrays.asList(
".doc", ".docx", ".docm",
".dot", ".dotx", ".dotm",
".odt", ".fodt", ".ott", ".rtf", ".txt",
".html", ".htm", ".mht", ".xml",
".pdf", ".djvu", ".fb2", ".epub", ".xps", ".oform");
// spreadsheet extensions
private List<String> extsSpreadsheet = Arrays.asList(
".xls", ".xlsx", ".xlsm", ".xlsb",
".xlt", ".xltx", ".xltm",
".ods", ".fods", ".ots", ".csv");
// presentation extensions
private List<String> extsPresentation = Arrays.asList(
".pps", ".ppsx", ".ppsm",
".ppt", ".pptx", ".pptm",
".pot", ".potx", ".potm",
".odp", ".fodp", ".otp");
@Autowired
private FormatService formatService;
// get the document type
public DocumentType getDocumentType(final String fileName) {
String ext = getFileExtension(fileName).toLowerCase(); // get file extension from its name
// word type for document extensions
if (extsDocument.contains(ext)) {
return DocumentType.word;
}
// cell type for spreadsheet extensions
if (extsSpreadsheet.contains(ext)) {
return DocumentType.cell;
}
// slide type for presentation extensions
if (extsPresentation.contains(ext)) {
return DocumentType.slide;
List<Format> formats = formatService.getFormats();
for (Format format : formats) {
if (format.getName().equals(ext)) {
return format.getType();
}
}
// default file type is word
@ -121,7 +85,7 @@ public class DefaultFileUtility implements FileUtility {
if (fileName == null) {
return null;
}
String fileExt = fileName.substring(fileName.lastIndexOf("."));
String fileExt = fileName.substring(fileName.lastIndexOf(".") + 1);
return fileExt.toLowerCase();
}
@ -147,34 +111,27 @@ public class DefaultFileUtility implements FileUtility {
}
public List<String> getFillExts() {
return Arrays.asList(docserviceFillDocs.split("\\|"));
return formatService.fillableExtensions();
}
// get file extensions that can be viewed
public List<String> getViewedExts() {
return Arrays.asList(docserviceViewedDocs.split("\\|"));
return formatService.viewableExtensions();
}
// get file extensions that can be edited
public List<String> getEditedExts() {
return Arrays.asList(docserviceEditedDocs.split("\\|"));
return formatService.editableExtensions();
}
// get file extensions that can be converted
public List<String> getConvertExts() {
return Arrays.asList(docserviceConvertDocs.split("\\|"));
return formatService.autoConvertExtensions();
}
// get all the supported file extensions
public List<String> getFileExts() {
List<String> res = new ArrayList<>();
res.addAll(getViewedExts());
res.addAll(getEditedExts());
res.addAll(getConvertExts());
res.addAll(getFillExts());
return res;
return formatService.allExtensions();
}
// generate the file path from file directory and name
@ -188,10 +145,10 @@ public class DefaultFileUtility implements FileUtility {
fileName = getFileNameWithoutExtension(fullFileName) + "(" + i + ")";
// create a new path for this file with the correct name and extension
path = Paths.get(directory + fileName + fileExtension);
path = Paths.get(directory + fileName + "." + fileExtension);
}
path = Paths.get(directory + fileName + fileExtension);
path = Paths.get(directory + fileName + "." + fileExtension);
return path;
}

View File

@ -0,0 +1,102 @@
/**
*
* (c) Copyright Ascensio System SIA 2023
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.onlyoffice.integration.documentserver.util.service;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.onlyoffice.integration.documentserver.models.Format;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.Resource;
import org.springframework.stereotype.Service;
import java.io.File;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@Service
public class DefaultFormatService implements FormatService {
private List<Format> formats;
@Autowired
public DefaultFormatService(
@Value("classpath:assets/document-formats/onlyoffice-docs-formats.json") final Resource resourceFile,
final ObjectMapper objectMapper
) {
try {
File targetFile = resourceFile.getFile();
this.formats = objectMapper.readValue(targetFile, new TypeReference<List<Format>>() { });
} catch (Exception e) {
throw new RuntimeException(e);
}
}
public List<Format> getFormats() {
return this.formats;
}
public List<Format> getFormatsByAction(final String action) {
return this
.formats
.stream()
.filter(format -> format.getActions().contains(action))
.collect(Collectors.toList());
}
public List<String> allExtensions() {
return this
.formats
.stream()
.map(format -> format.getName())
.collect(Collectors.toList());
}
public List<String> fillableExtensions() {
return this
.getFormatsByAction("fill")
.stream()
.map(format -> format.getName())
.collect(Collectors.toList());
}
public List<String> viewableExtensions() {
return this
.getFormatsByAction("view")
.stream()
.map(format -> format.getName())
.collect(Collectors.toList());
}
public List<String> editableExtensions() {
return Stream
.of(this.getFormatsByAction("edit"), this.getFormatsByAction("lossy-edit"))
.flatMap(x -> x.stream())
.map(format -> format.getName())
.collect(Collectors.toList());
}
public List<String> autoConvertExtensions() {
return this
.getFormatsByAction("auto-convert")
.stream()
.map(format -> format.getName())
.collect(Collectors.toList());
}
}

View File

@ -146,8 +146,8 @@ public class DefaultServiceConverter implements ServiceConverter {
Convert body = new Convert();
body.setLang(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.setFilePass(filePass);

View File

@ -0,0 +1,33 @@
/**
*
* (c) Copyright Ascensio System SIA 2023
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.onlyoffice.integration.documentserver.util.service;
import com.onlyoffice.integration.documentserver.models.Format;
import java.util.List;
public interface FormatService {
List<Format> getFormats();
List<Format> getFormatsByAction(String action);
List<String> allExtensions();
List<String> fillableExtensions();
List<String> viewableExtensions();
List<String> editableExtensions();
List<String> autoConvertExtensions();
}

View File

@ -77,7 +77,6 @@ public class DefaultEditorConfigConfigurer implements EditorConfigConfigurer<Def
(JavaType) new TypeToken<HashMap<String, Object>>() { }.getType()));
}
String fileName = wrapper.getFileName(); // set the fileName parameter from the editorConfig wrapper
String fileExt = fileUtility.getFileExtension(fileName);
boolean userIsAnon = wrapper.getUser()
.getName().equals("Anonymous"); // check if the user from the editorConfig wrapper is anonymous or not

View File

@ -8,10 +8,6 @@ filesize-max=5242880
files.storage=
files.storage.folder=documents
files.docservice.fillforms-docs=.docx|.oform
files.docservice.viewed-docs=.djvu|.oxps|.pdf|.xps
files.docservice.edited-docs=.csv|.docm|.docx|.docxf|.dotm|.dotx|.epub|.fb2|.html|.odp|.ods|.odt|.otp|.ots|.ott|.potm|.potx|.ppsm|.ppsx|.pptm|.pptx|.rtf|.txt|.xlsm|.xlsx|.xltm|.xltx
files.docservice.convert-docs=.doc|.dot|.dps|.dpt|.epub|.et|.ett|.fb2|.fodp|.fods|.fodt|.htm|.html|.mht|.mhtml|.odp|.ods|.odt|.otp|.ots|.ott|.pot|.pps|.ppt|.rtf|.stw|.sxc|.sxi|.sxw|.wps|.wpt|.xls|.xlsb|.xlt|.xml
files.docservice.timeout=120000
files.docservice.history.postfix=-hist

View File

@ -25,9 +25,9 @@ var FillExtList;
if (typeof jQuery !== "undefined") {
jQuery.post('/config',
function(data) {
FillExtList = data.FillExtList;
ConverExtList = data.ConverExtList;
EditedExtList = data.EditedExtList;
FillExtList = data.FillExtList.split(',');
ConverExtList = data.ConverExtList.split(',');
EditedExtList = data.EditedExtList.split(',');
UrlConverter = data.UrlConverter;
UrlEditor = data.UrlEditor;
});

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) === -1) {
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) !== -1 || FillExtList.includes(posExt) !== -1) {
jq("#beginEdit").removeClass("disable");
}
};