Merge branch 'develop' into feature/jwtHistoryFiles

This commit is contained in:
Andrey
2021-12-22 17:13:10 +03:00
committed by GitHub
81 changed files with 469 additions and 225 deletions

View File

@ -0,0 +1,9 @@
FROM maven:3.6.1-jdk-8-alpine AS MVN_BLDR
COPY pom.xml /tmp/
COPY src /tmp/src/
WORKDIR /tmp/
RUN mvn package
FROM tomcat:alpine
RUN rm -fr /usr/local/tomcat/webapps/ROOT
COPY --from=MVN_BLDR /tmp/target/*.war $CATALINA_HOME/webapps/ROOT.war

View File

@ -16,13 +16,14 @@ See the detailed guide to learn how to [install Document Server for Windows](htt
Download the [Java example](https://api.onlyoffice.com/editors/demopreview) from our site.
To connect the editors to your website, specify the path to the editors installation in the *\src\main\resources\settings.properties* file:
To connect the editors to your website, specify the path to the editors installation and the path to the storage folder in the *\src\main\resources\settings.properties* file:
```
storage-folder = app_data
files.docservice.url.site=https://documentserver/
```
where the **documentserver** is the name of the server with the ONLYOFFICE Document Server installed.
where the **documentserver** is the name of the server with the ONLYOFFICE Document Server installed and the **storage-folder** is the path where files will be created and stored. You can set an absolute path. For example, *D:\\\\folder*. Please note that on Windows OS the double backslash must be used as a separator.
If you want to experiment with the editor configuration, modify the [parameters](https://api.onlyoffice.com/editors/advanced) in the *\src\main\webapp\editor.jsp* file.
@ -167,13 +168,17 @@ See the detailed guide to learn how to [install Document Server for Linux](https
nano src/main/resources/settings.properties
```
Edit the following line:
Edit the following lines:
```
storage-folder = app_data
files.docservice.url.site=https://documentserver/
```
where the **documentserver** is the name of the server with the ONLYOFFICE Document Server installed.
where the **documentserver** is the name of the server with the ONLYOFFICE Document Server installed and the **storage-folder** is the path where files will be created and stored. Please note that you must have read and write permissions to the folder. If you do not have them, please use the next command:
```
sudo chmod -R ugo+rw /{path}
```
5. Install **Maven**:
@ -242,13 +247,14 @@ Make sure that the Document Server has access to the server with the example ins
nano src/main/resources/settings.properties
```
2. Edit the following line:
2. Edit the following lines:
```
storage-folder = app_data
files.docservice.url.site=https://documentserver/
```
where the **documentserver** is the name of the server with the ONLYOFFICE Document Server installed.
where the **documentserver** is the name of the server with the ONLYOFFICE Document Server installed and the **storage-folder** is the path where files will be created and stored.
3. Run the next command in the Java example directory:

View File

@ -1,7 +1,9 @@
version: '3'
services:
build:
image: maven:3.6
volumes:
- .:/java
command: mvn -f /java package
java-intg-ex:
build:
context: ./
dockerfile: Dockerfile
ports:
- 8080:8080

View File

@ -72,7 +72,7 @@ public class EditorServlet extends HttpServlet
// create file model (get all the necessary parameters from cookies)
FileModel file = new FileModel(fileName, cm.getCookie("ulang"), request.getParameter("actionLink"), user);
// change type parameter if needed
file.changeType(request.getParameter("mode"), request.getParameter("type"), user);
file.changeType(request.getParameter("mode"), request.getParameter("type"), user, fileName);
// an image that will be inserted into the document
Map<String, Object> dataInsertImage = new HashMap<>();

View File

@ -481,8 +481,9 @@ public class IndexServlet extends HttpServlet
try {
String fileName = FileUtility.GetFileName(request.getParameter("fileName"));
String userAddress = request.getParameter("userAddress");
String isEmbedded = request.getParameter("dmode");
if (DocumentManager.TokenEnabled()) {
if (DocumentManager.TokenEnabled() && isEmbedded == null) {
String DocumentJwtHeader = ConfigManager.GetProperty("files.docservice.header");

View File

@ -20,16 +20,14 @@ package entities;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import helpers.DocumentManager;
import helpers.FileUtility;
import helpers.ServiceConverter;
import helpers.Users;
import helpers.*;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import java.io.File;
import java.io.FileInputStream;
import java.text.SimpleDateFormat;
import java.util.*;
public class FileModel
@ -54,7 +52,6 @@ public class FileModel
document = new Document();
document.title = fileName;
document.url = DocumentManager.GetDownloadUrl(fileName); // get file url
document.urlUser = DocumentManager.GetFileUri(fileName, false);
document.fileType = FileUtility.GetFileExtension(fileName).replace(".", ""); // get file extension from the file name
// generate document key
document.key = ServiceConverter.GenerateRevisionId(DocumentManager.CurUserHostAddress(null) + "/" + fileName + "/" + Long.toString(new File(DocumentManager.StoragePath(fileName, null)).lastModified()));
@ -94,11 +91,11 @@ public class FileModel
// write the absolute URL to the file location
editorConfig.customization.goback.url = DocumentManager.GetServerUrl(false) + "/IndexServlet";
changeType(mode, type, user);
changeType(mode, type, user, fileName);
}
// change the document type
public void changeType(String _mode, String _type, User user)
public void changeType(String _mode, String _type, User user, String fileName)
{
if (_mode != null) mode = _mode;
if (_type != null) type = _type;
@ -119,12 +116,12 @@ public class FileModel
// set document permissions
document.permissions = new Permissions(mode, type, canEdit, user);
if (type.equals("embedded")) InitDesktop(); // set parameters for the embedded document
if (type.equals("embedded")) InitDesktop(fileName); // set parameters for the embedded document
}
public void InitDesktop()
public void InitDesktop(String fileName)
{
editorConfig.InitDesktop(document.urlUser);
editorConfig.InitDesktop(DocumentManager.GetDownloadUrl(fileName) + "&dmode=emb");
}
// generate document token
@ -201,7 +198,12 @@ 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
dataObj.put("changesUrl", DocumentManager.GetPathUri(DocumentManager.VersionDir(histDir, i - 1) + File.separator + "diff.zip"));
String storagePath = ConfigManager.GetProperty("storage-folder");
String changesUrl = DocumentManager.GetPathUri(DocumentManager.VersionDir(histDir, i - 1) + File.separator + "diff.zip");
if (new File(storagePath).isAbsolute()) {
changesUrl = DocumentManager.GetDownloadUrl((DocumentManager.VersionDir(histDir, i - 1) + File.separator + "diff.zip").replace(storagePath, ""));
}
dataObj.put("changesUrl", changesUrl);
}
if (DocumentManager.TokenEnabled())
@ -248,7 +250,6 @@ public class FileModel
{
public String title;
public String url;
public String urlUser;
public String fileType;
public String key;
public Info info;
@ -290,7 +291,14 @@ public class FileModel
// the Favorite icon state
public class Info
{
public String owner = "Me";
public Boolean favorite;
public String uploaded = getDate();
private String getDate() {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("EEE MMM dd yyyy", Locale.US);
return simpleDateFormat.format(new Date());
}
}
// the editor config parameters
public class EditorConfig

View File

@ -130,7 +130,20 @@ public class DocumentManager
String hostAddress = CurUserHostAddress(userAddress); // get current user host address
String serverPath = request.getSession().getServletContext().getRealPath(""); // get the server url
String storagePath = ConfigManager.GetProperty("storage-folder"); // get the storage directory
String directory = serverPath + storagePath + File.separator + hostAddress + File.separator;
File f = new File(storagePath);
if (f.isAbsolute()) {
if (!f.exists()) {
if (Files.isWritable(Paths.get(storagePath.substring(0, storagePath.lastIndexOf(File.separator))))) {
f.mkdirs();
} else {
throw new SecurityException("No write permission to path: " + f.toPath());
}
} else if (f.exists() && f.isFile()) {
throw new SecurityException("The path to the file is specified instead of the folder");
}
}
String directory = !f.isAbsolute() ? serverPath + storagePath + File.separator + hostAddress + File.separator : storagePath + File.separator;
File file = new File(directory);
@ -337,13 +350,20 @@ public class DocumentManager
{
String serverPath = GetServerUrl(forDocumentServer);
String storagePath = ConfigManager.GetProperty("storage-folder");
File f = new File(storagePath);
String hostAddress = CurUserHostAddress(null);
String filePath = serverPath + "/" + storagePath + "/" + hostAddress + "/" + URLEncoder.encode(fileName, java.nio.charset.StandardCharsets.UTF_8.toString()).replace("+", "%20");
if (f.isAbsolute() && f.isFile()) {
filePath = GetDownloadUrl(fileName);
if (!Files.isWritable(f.toPath())) {
throw new SecurityException("No write permission to path: " + f.toPath());
}
}
return filePath;
}
catch (UnsupportedEncodingException e)
catch (Exception e)
{
return "";
}

View File

@ -64,7 +64,7 @@ public class Users {
private static List<User> users = new ArrayList<User>() {{
add(new User("uid-1", "John Smith", "smith@example.com",
null, null, new CommentGroups(),
"", null, new CommentGroups(),
null, new ArrayList<String>(), descr_user_1, true));
add(new User("uid-2", "Mark Pottato", "pottato@example.com",
"group-2", Arrays.asList("group-2", ""), new CommentGroups(null, Arrays.asList("group-2", ""), Arrays.asList("group-2")),
@ -73,7 +73,7 @@ public class Users {
"group-3", Arrays.asList("group-2"), new CommentGroups(Arrays.asList("group-3", "group-2"), Arrays.asList("group-2"), new ArrayList<String>()),
false, Arrays.asList("copy", "download", "print"), descr_user_3, false));
add(new User("uid-0", null, null,
null, null, new CommentGroups(),
"", null, new CommentGroups(),
null, new ArrayList<String>(), descr_user_0, false));
}};

View File

@ -1,4 +1,4 @@
version=1.0.0
version=1.1.0
filesize-max=5242880
storage-folder=app_data

View File

@ -86,10 +86,6 @@
}
@media (max-width: 1008px) {
#portal-info {
width: 65vw;
}
.left-panel {
margin-left: 0;
}
@ -299,6 +295,9 @@
.tableRow td:first-child {
max-width: 17%;
}
#portal-info {
max-width: 60vw;
}
}
.downloadContentCellShift:after {

View File

@ -22,6 +22,7 @@ html {
}
body {
display: inline-table;
background: #FFFFFF;
color: #333333;
font-family: Open Sans;
@ -71,6 +72,7 @@ header img {
}
.main{
display: table;
height: calc(100% - 112px);
min-height: 536px;
}
@ -97,6 +99,10 @@ header img {
width: 896px;
}
#portal-info {
max-width: 65vw;
}
.portal-name {
color: #FF6F3D;
font-size: 24px;

View File

@ -139,7 +139,7 @@
<% DocumentManager.Init(request, response); %>
<% File[] files = DocumentManager.GetStoredFiles(null); %>
<div class="main-panel">
<div id="portal-info" style="display: <%= files.length > 0 ? "none" : "block" %>">
<div id="portal-info" style="display: <%= files.length > 0 ? "none" : "table-cell" %>">
<span class="portal-name">ONLYOFFICE Document Editors Welcome!</span>
<span class="portal-descr">
Get started with a demo-sample of ONLYOFFICE Document Editors, the first html5-based editors.
@ -180,7 +180,7 @@
Boolean canEdit = DocumentManager.GetEditedExts().contains(FileUtility.GetFileExtension(files[i].getName()));
String version=" ["+DocumentManager.GetFileVersion(DocumentManager.HistoryDir(DocumentManager.StoragePath(files[i].getName(), null)))+"]";
%>
<tr class="tableRow" title="<%= files[i].getName() %> [<%= version %>]">
<tr class="tableRow" title="<%= files[i].getName() %><%= version %>">
<td class="contentCells">
<a class="stored-edit <%= docType %>" href="EditorServlet?fileName=<%= URLEncoder.encode(files[i].getName(), "UTF-8") %>" target="_blank">
<span><%= files[i].getName() %></span>
@ -215,9 +215,6 @@
</a>
</td>
<% } %>
<% if (!docType.equals("cell") && !docType.equals("word")) { %>
<td class="contentCells contentCells-icon contentCellsEmpty"></td>
<% } %>
<% if (docType.equals("word")) { %>
<td class="contentCells contentCells-icon">
<a href="EditorServlet?fileName=<%= URLEncoder.encode(files[i].getName(), "UTF-8") %>&type=desktop&mode=blockcontent" target="_blank">