CKFinderConnectorServlet.java
2.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/**
* Copyright © 2015-2018 ODM All rights reserved.
*/
package com.thinkgem.jeesite.common.web;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.utils.FileUtils;
import com.thinkgem.jeesite.modules.sys.security.SystemAuthorizingRealm.Principal;
import com.thinkgem.jeesite.modules.sys.utils.UserUtils;
import com.ckfinder.connector.ConnectorServlet;
/**
* CKFinderConnectorServlet
* @author ThinkGem
* @version 2014-06-25
*/
public class CKFinderConnectorServlet extends ConnectorServlet {
private static final long serialVersionUID = 1L;
@Override
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
prepareGetResponse(request, response, false);
super.doGet(request, response);
}
@Override
protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
prepareGetResponse(request, response, true);
super.doPost(request, response);
}
private void prepareGetResponse(final HttpServletRequest request,
final HttpServletResponse response, final boolean post) throws ServletException {
Principal principal = (Principal) UserUtils.getPrincipal();
if (principal == null){
return;
}
String command = request.getParameter("command");
String type = request.getParameter("type");
// 初始化时,如果startupPath文件夹不存在,则自动创建startupPath文件夹
if ("Init".equals(command)){
String startupPath = request.getParameter("startupPath");// 当前文件夹可指定为模块名
if (startupPath!=null){
String[] ss = startupPath.split(":");
if (ss.length==2){
String realPath = Global.getUserfilesBaseDir() + Global.USERFILES_BASE_URL
+ principal + "/" + ss[0] + ss[1];
FileUtils.createDirectory(FileUtils.path(realPath));
}
}
}
// 快捷上传,自动创建当前文件夹,并上传到该路径
else if ("QuickUpload".equals(command) && type!=null){
String currentFolder = request.getParameter("currentFolder");// 当前文件夹可指定为模块名
String realPath = Global.getUserfilesBaseDir() + Global.USERFILES_BASE_URL
+ principal + "/" + type + (currentFolder != null ? currentFolder : "");
FileUtils.createDirectory(FileUtils.path(realPath));
}
// System.out.println("------------------------");
// for (Object key : request.getParameterMap().keySet()){
// System.out.println(key + ": " + request.getParameter(key.toString()));
// }
}
}