commit | author | age
|
9bcb19
|
1 |
/* |
I |
2 |
Copyright [2020] [https://www.xiaonuo.vip] |
|
3 |
|
|
4 |
Licensed under the Apache License, Version 2.0 (the "License"); |
|
5 |
you may not use this file except in compliance with the License. |
|
6 |
You may obtain a copy of the License at |
|
7 |
|
|
8 |
http://www.apache.org/licenses/LICENSE-2.0 |
|
9 |
|
|
10 |
Unless required by applicable law or agreed to in writing, software |
|
11 |
distributed under the License is distributed on an "AS IS" BASIS, |
|
12 |
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
13 |
See the License for the specific language governing permissions and |
|
14 |
limitations under the License. |
|
15 |
|
|
16 |
Snowy采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意以下几点: |
|
17 |
|
|
18 |
1.请不要删除和修改根目录下的LICENSE文件。 |
|
19 |
2.请不要删除和修改Snowy源码头部的版权声明。 |
|
20 |
3.请保留源码和相关描述文件的项目出处,作者声明等。 |
|
21 |
4.分发源码时候,请注明软件出处 https://gitee.com/xiaonuobase/snowy-layui |
|
22 |
5.在修改包名,模块名称,项目代码等时,请注明软件出处 https://gitee.com/xiaonuobase/snowy-layui |
|
23 |
6.若您的项目无法满足以上几点,可申请商业授权,获取Snowy商业授权许可,请在官网购买授权,地址为 https://www.xiaonuo.vip |
|
24 |
*/ |
|
25 |
package vip.xiaonuo.sys.modular.file.result; |
|
26 |
|
|
27 |
import cn.hutool.core.io.FileUtil; |
|
28 |
import com.google.gson.Gson; |
|
29 |
import com.google.gson.reflect.TypeToken; |
|
30 |
import lombok.Data; |
|
31 |
import vip.xiaonuo.core.consts.CommonConstant; |
|
32 |
import vip.xiaonuo.core.consts.SymbolConstant; |
|
33 |
import vip.xiaonuo.sys.modular.file.util.OnlineDocumentUtil; |
|
34 |
|
|
35 |
import java.io.File; |
|
36 |
import java.util.HashMap; |
|
37 |
|
|
38 |
/** |
|
39 |
* 在线文件信息结果集 |
|
40 |
* |
|
41 |
* @author yubaoshan |
|
42 |
* @date 2020/6/7 22:15 |
|
43 |
*/ |
|
44 |
@Data |
|
45 |
public class SysOnlineFileInfoResult { |
|
46 |
|
|
47 |
public String fileId; |
|
48 |
public String[] history; |
|
49 |
public String type = "desktop"; |
|
50 |
public String mode = "edit"; |
|
51 |
public String documentType; |
|
52 |
public Document document; |
|
53 |
public EditorConfig editorConfig; |
|
54 |
public String token; |
|
55 |
|
|
56 |
public static class Document { |
|
57 |
public String title; |
|
58 |
public String url; |
|
59 |
public String fileType; |
|
60 |
public String key; |
|
61 |
public Permissions permissions; |
|
62 |
} |
|
63 |
|
|
64 |
public static class Permissions { |
|
65 |
public Boolean comment; |
|
66 |
public Boolean download; |
|
67 |
public Boolean edit; |
|
68 |
public Boolean fillForms; |
|
69 |
public Boolean modifyFilter; |
|
70 |
public Boolean modifyContentControl; |
|
71 |
public Boolean review; |
|
72 |
|
|
73 |
public Permissions(String mode, String type, Boolean canEdit) { |
|
74 |
comment = !mode.equals("view") && !mode.equals("fillForms") && !mode.equals("embedded") && !mode.equals("blockcontent"); |
|
75 |
download = true; |
|
76 |
edit = canEdit && (mode.equals("edit") || mode.equals("filter") || mode.equals("blockcontent")); |
|
77 |
fillForms = !mode.equals("view") && !mode.equals("comment") && !mode.equals("embedded") && !mode.equals("blockcontent"); |
|
78 |
modifyFilter = !mode.equals("filter"); |
|
79 |
modifyContentControl = !mode.equals("blockcontent"); |
|
80 |
review = mode.equals("edit") || mode.equals("review"); |
|
81 |
} |
|
82 |
} |
|
83 |
|
|
84 |
public static class EditorConfig { |
|
85 |
public HashMap<String, Object> actionLink = null; |
|
86 |
public String mode = "edit"; |
|
87 |
public String callbackUrl; |
|
88 |
public String lang = "en"; |
|
89 |
public Integer forcesavetype = 1; |
|
90 |
public User user; |
|
91 |
public Customization customization; |
|
92 |
public Embedded embedded; |
|
93 |
|
|
94 |
public EditorConfig(String actionData) { |
|
95 |
if (actionData != null) { |
|
96 |
Gson gson = new Gson(); |
|
97 |
actionLink = gson.fromJson(actionData, new TypeToken<HashMap<String, Object>>() { }.getType()); |
|
98 |
} |
|
99 |
user = new User(); |
|
100 |
customization = new Customization(); |
|
101 |
} |
|
102 |
|
|
103 |
public void InitDesktop(String url) { |
|
104 |
embedded = new Embedded(); |
|
105 |
embedded.saveUrl = url; |
|
106 |
embedded.embedUrl = url; |
|
107 |
embedded.shareUrl = url; |
|
108 |
embedded.toolbarDocked = "top"; |
|
109 |
} |
|
110 |
|
|
111 |
public static class User { |
|
112 |
public String id = "-1"; |
|
113 |
public String name = CommonConstant.UNKNOWN; |
|
114 |
} |
|
115 |
|
|
116 |
public static class Customization { |
|
117 |
public GoBack goback; |
|
118 |
public Boolean forcesave = true; |
|
119 |
public Customization() |
|
120 |
{ |
|
121 |
goback = new GoBack(); |
|
122 |
} |
|
123 |
|
|
124 |
public class GoBack { |
|
125 |
public String url; |
|
126 |
} |
|
127 |
} |
|
128 |
|
|
129 |
public static class Embedded { |
|
130 |
public String saveUrl; |
|
131 |
public String embedUrl; |
|
132 |
public String shareUrl; |
|
133 |
public String toolbarDocked; |
|
134 |
} |
|
135 |
} |
|
136 |
|
|
137 |
public SysOnlineFileInfoResult(String fileId, String fileOriginName, String userId, String userName) { |
|
138 |
if (fileOriginName == null) fileOriginName = ""; |
|
139 |
fileOriginName = fileOriginName.trim(); |
|
140 |
documentType = OnlineDocumentUtil.getFileType(fileOriginName).toLowerCase(); |
|
141 |
this.fileId = fileId; |
|
142 |
document = new Document(); |
|
143 |
document.title = fileOriginName; |
|
144 |
document.url = OnlineDocumentUtil.getFileUri(fileId, fileOriginName); |
|
145 |
document.fileType = FileUtil.getSuffix(fileOriginName); |
|
146 |
document.key = GenerateRevisionId(fileOriginName + SymbolConstant.PERIOD + new File(OnlineDocumentUtil.getStoragePath(fileId + SymbolConstant.PERIOD + FileUtil.getSuffix(fileOriginName))).lastModified()); |
|
147 |
|
|
148 |
editorConfig = new EditorConfig(null); |
|
149 |
editorConfig.callbackUrl = OnlineDocumentUtil.getCallback(fileId, document.fileType); |
|
150 |
editorConfig.lang = "zh"; |
|
151 |
|
|
152 |
if (userId != null) editorConfig.user.id = userId; |
|
153 |
if (userName != null) editorConfig.user.name = userName; |
|
154 |
|
|
155 |
editorConfig.customization.goback.url = ""; |
|
156 |
|
|
157 |
changeType(mode, type); |
|
158 |
} |
|
159 |
|
|
160 |
public void changeType(String _mode, String _type) { |
|
161 |
if (_mode != null) mode = _mode; |
|
162 |
if (_type != null) type = _type; |
|
163 |
|
|
164 |
Boolean canEdit = OnlineDocumentUtil.getEditedSuffix().contains(SymbolConstant.PERIOD + FileUtil.getSuffix(document.title)); |
|
165 |
|
|
166 |
editorConfig.mode = canEdit && !mode.equals("view") ? "edit" : "view"; |
|
167 |
|
|
168 |
document.permissions = new Permissions(mode, type, canEdit); |
|
169 |
|
|
170 |
if (type.equals("embedded")) InitDesktop(); |
|
171 |
} |
|
172 |
|
|
173 |
public static String GenerateRevisionId(String expectedKey) { |
|
174 |
if (expectedKey.length() > 20) |
|
175 |
expectedKey = Integer.toString(expectedKey.hashCode()); |
|
176 |
|
|
177 |
String key = expectedKey.replace("[^0-9-.a-zA-Z_=]", "_"); |
|
178 |
|
|
179 |
return key.substring(0, Math.min(key.length(), 20)); |
|
180 |
} |
|
181 |
|
|
182 |
public void InitDesktop() { |
|
183 |
editorConfig.InitDesktop(document.url); |
|
184 |
} |
|
185 |
|
|
186 |
|
|
187 |
} |