This repository has been archived on 2025-09-14. You can view files and clone it, but cannot push or open issues or pull requests.
Files
k18-ntcs-web-argus-service/src/main/java/com/nis/web/controller/CKFinderConnectorServlet.java
zhangdongxu 13acafd43d 上传代码
2017-12-19 14:55:52 +08:00

76 lines
2.6 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* Copyright &copy; 2012-2014 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
*/
package com.nis.web.controller;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.ckfinder.connector.ConnectorServlet;
import com.nis.util.Constants;
import com.nis.util.FileUtils;
import com.nis.util.StringUtils;
import com.nis.web.security.SystemAuthorizingRealm.Principal;
import com.nis.web.security.UserUtils;
/**
* 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);
response.setContentType("text/html;charset=UTF-8");
super.doGet(request, response);
}
@Override
protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
prepareGetResponse(request, response, true);
response.setContentType("text/html;charset=UTF-8");
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 = StringUtils.getUserfilesBaseDir() + Constants.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 = StringUtils.getUserfilesBaseDir() + Constants.USERFILES_BASE_URL
+ principal + "/" + type + (currentFolder != null ? currentFolder : "");
FileUtils.createDirectory(FileUtils.path(realPath));
}
}
}