net.kindeditor.servlet.FileManagerServlet Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of filemanager Show documentation
Show all versions of filemanager Show documentation
KindEditor(http://kindeditor.org/) is a lightweight, Open Source(LGPL), cross browser, web based WYSIWYG HTML editor.
kind-file-manager is the upload manager and file manager for kindeditor,
it use Servlet 3.0 technology, and can be deployed as a single web fragment jar.
The newest version!
package net.kindeditor.servlet;
import static net.kindeditor.util.Constants.*;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Properties;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import net.kindeditor.bean.FileManagerContext;
import net.kindeditor.util.ConstraintChecker;
import com.fasterxml.jackson.databind.ObjectMapper;
/**
* Process directory or file request from kind editor.
* @author luyanfei
*
*/
public class FileManagerServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
@Override
protected void service(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
final ServletContext context = request.getServletContext();
Properties config = (Properties) context.getAttribute(SC_KIND_CONFIG);
String rootPath = config.getProperty(UPLOAD_ROOT);
String rootUrl = config.getProperty(DEST_URL_PREFIX);
response.setContentType("application/json; charset=UTF-8");
PrintWriter out = response.getWriter();
String subdir = request.getParameter("dir");
String path = request.getParameter("path");
//排序形式,name or size or type
String order = request.getParameter("order");
ConstraintChecker checker = (ConstraintChecker)context.getAttribute(SC_CONSTRAINT_CHECKER);
checker.checkSubDirectory(rootPath, subdir);
FileManagerContext fmc = new FileManagerContext(rootPath, rootUrl, path);
fmc.sortFileList(order);
ObjectMapper mapper = (ObjectMapper)context.getAttribute(SC_OBJECT_MAPPER);
out.println(mapper.writeValueAsString(fmc));
}
}