效果图
kindeditor包下类
UploadAccessory.java
/* */ package com.scrh.web.com.elkan.kindeditor;
/* */
/* */ import java.io.File;
/* */ import java.io.IOException;
/* */ import java.io.PrintStream;
/* */ import java.io.PrintWriter;
/* */ import java.text.SimpleDateFormat;
/* */ import java.util.Arrays;
/* */ import java.util.Date;
/* */ import java.util.Iterator;
/* */ import java.util.List;
/* */ import java.util.Random;
/* */ import javax.servlet.ServletContext;
/* */ import javax.servlet.ServletException;
/* */ import javax.servlet.http.HttpServlet;
/* */ import javax.servlet.http.HttpServletRequest;
/* */ import javax.servlet.http.HttpServletResponse;
/* */ import javax.servlet.http.HttpSession;
/* */ import org.apache.commons.fileupload.FileItem;
/* */ import org.apache.commons.fileupload.FileItemFactory;
/* */ import org.apache.commons.fileupload.disk.DiskFileItemFactory;
/* */ import org.apache.commons.fileupload.servlet.ServletFileUpload;
/* */
/* */ public class UploadAccessory extends HttpServlet
/* */ {
/* */ private static final long serialVersionUID = 1L;
/* 28 */ protected long MAX_SIZE = 1000000L;
/* */
/* 30 */ protected String[] FILETYPES = { "doc", "xls", "ppt", "pdf", "txt", "rar", "zip" };
/* */
/* 32 */ protected String UPLOAD_PATH = "";
/* */
/* 34 */ protected String id = "";
/* */
/* 36 */ protected String attachTitle = "";
/* */
/* 38 */ protected boolean isFlag = false;
/* */
/* 40 */ protected String tempTitle = "";
/* */
/* */ public void doGet(HttpServletRequest request, HttpServletResponse response)
/* */ throws ServletException, IOException
/* */ {
/* 45 */ doPost(request, response);
/* */ }
/* */
/* */ public void doPost(HttpServletRequest request, HttpServletResponse response)
/* */ throws ServletException, IOException
/* */ {
/* 52 */ response.setContentType("text/html; charset=UTF-8");
/* 53 */ PrintWriter out = response.getWriter();
/* 54 */ String savePath = getInitParameter("UPLOAD_PATH");
/* 55 */ if ((savePath == null) || (savePath.isEmpty())) {
/* 56 */ out.println(alertMsg("你还没设置上传文件保存的目录路径!"));
/* 57 */ return;
/* */ }
/* */
/* 60 */ if (getInitParameter("MAX_SIZE") != null) {
/* 61 */ this.MAX_SIZE = Integer.parseInt(getInitParameter("MAX_SIZE"));
/* */ }
/* */
/* 64 */ if (getInitParameter("FILETYPES") != null) {
/* 65 */ this.FILETYPES = toArray(getInitParameter("FILETYPES"));
/* */ }
/* */
/* 68 */ String uploadPath = request.getSession().getServletContext().getRealPath("/") + savePath;
/* */
/* 71 */ String saveUrl = request.getContextPath() + "/" + savePath;
/* */
/* 73 */ if (!ServletFileUpload.isMultipartContent(request)) {
/* 74 */ out.println(alertMsg("请选择要上传的文件。"));
/* 75 */ return;
/* */ }
/* */
/* 78 */ File uploadDir = new File(uploadPath);
/* 79 */ if (!uploadDir.isDirectory()) {
/* 80 */ out.println(alertMsg("上传目录不存在。"));
/* 81 */ return;
/* */ }
/* */
/* 84 */ if (!uploadDir.canWrite()) {
/* 85 */ out.println(alertMsg("当前角色对上传目录没有写权限。"));
/* 86 */ return;
/* */ }
/* */
/* 89 */ FileItemFactory factory = new DiskFileItemFactory();
/* 90 */ ServletFileUpload upload = new ServletFileUpload(factory);
/* 91 */ upload.setHeaderEncoding("UTF-8");
/* 92 */ String temp = null;
/* 93 */ String ext = null;
/* */ try {
/* 95 */ List items = upload.parseRequest(request);
/* 96 */ Iterator itr = items.iterator();
/* 97 */ while (itr.hasNext()) {
/* 98 */ FileItem item = (FileItem)itr.next();
/* 99 */ String fileName = item.getName();
/* 100 */ temp = item.getName();
/* 101 */ if ((temp != null) && (!this.isFlag)) {
/* 102 */ temp = temp.substring(temp.lastIndexOf("\\") + 1);
/* 103 */ this.tempTitle = temp;
/* 104 */ this.isFlag = true;
/* */ }
/* */
/* 107 */ if (item.getFieldName().equals("id")) {
/* 108 */ this.id = item.getString();
/* */ }
/* */
/* 111 */ if (item.getFieldName().equals("attachTitle")) {
/* 112 */ this.attachTitle = item.getString();
/* 113 */ if (this.attachTitle != null) {
/* 114 */ this.attachTitle = new String(this.attachTitle.getBytes("ISO8859-1"), "UTF-8");
/* */ }
/* */ }
/* 117 */ if (item.isFormField())
/* */ continue;
/* 119 */ if (item.getSize() > this.MAX_SIZE) {
/* 120 */ out.println(alertMsg("上传文件大小超过限制。"));
/* 121 */ return;
/* */ }
/* */
/* 124 */ String fileExt = fileName.substring(fileName.lastIndexOf(".") + 1).toLowerCase();
/* 125 */ if (!Arrays.asList(this.FILETYPES).contains(fileExt)) {
/* 126 */ out.println(alertMsg("上传文件扩展名是不允许的扩展名。"));
/* 127 */ return;
/* */ }
/* */
/* 130 */ SimpleDateFormat folderNameFormat = new SimpleDateFormat("yyyyMMdd");
/* 131 */ String realPath = uploadPath + folderNameFormat.format(new Date());
/* 132 */ File folder = new File(realPath);
/* 133 */ boolean flag = folder.exists();
/* */
/* 135 */ if (!flag) {
/* 136 */ flag = folder.mkdir();
/* */ }
/* */
/* 139 */ if (flag) {
/* 140 */ SimpleDateFormat fileNameFormat = new SimpleDateFormat("yyyyMMddHHmmss");
/* 141 */ String newFileName = fileNameFormat.format(new Date()) + "_" + new Random().nextInt(1000) + "." + fileExt;
/* 142 */ File uploadedFile = new File(realPath, newFileName);
/* 143 */ item.write(uploadedFile);
/* 144 */ saveUrl = saveUrl + folderNameFormat.format(new Date()) + "/" + newFileName;
/* 145 */ ext = fileExt;
/* */ } else {
/* 147 */ System.out.println(" 文件夹创建失败,请确认磁盘没有写保护并且空件足够");
/* */ }
/* */
/* */ }
/* */
/* 153 */ if ((this.attachTitle == null) || (this.attachTitle.isEmpty())) {
/* 154 */ this.attachTitle = this.tempTitle;
/* */ }
/* */
/* 157 */ out.println(insertAttach(this.id, saveUrl, this.attachTitle, ext));
/* */ }
/* */ catch (Exception e) {
/* 160 */ e.printStackTrace();
/* */ } finally {
/* 162 */ out.flush();
/* 163 */ out.close();
/* 164 */ this.isFlag = false;
/* */ }
/* */ }
/* */
/* */ public String alertMsg(String message)
/* */ {
/* 170 */ StringBuilder sb = new StringBuilder("");
/* 171 */ sb.append("
UploadImage.java
/* */ package com.scrh.web.com.elkan.kindeditor;
/* */
/* */ import com.scrh.web.com.elkan.utils.ImageUtil;
/* */ import java.io.File;
/* */ import java.io.IOException;
/* */ import java.io.PrintStream;
/* */ import java.io.PrintWriter;
/* */ import java.text.SimpleDateFormat;
/* */ import java.util.Arrays;
/* */ import java.util.Date;
/* */ import java.util.Iterator;
/* */ import java.util.List;
/* */ import java.util.Random;
/* */ import javax.servlet.ServletContext;
/* */ import javax.servlet.ServletException;
/* */ import javax.servlet.http.HttpServlet;
/* */ import javax.servlet.http.HttpServletRequest;
/* */ import javax.servlet.http.HttpServletResponse;
/* */ import javax.servlet.http.HttpSession;
/* */ import org.apache.commons.fileupload.FileItem;
/* */ import org.apache.commons.fileupload.FileItemFactory;
/* */ import org.apache.commons.fileupload.FileUploadException;
/* */ import org.apache.commons.fileupload.disk.DiskFileItemFactory;
/* */ import org.apache.commons.fileupload.servlet.ServletFileUpload;
/* */
/* */ public class UploadImage extends HttpServlet
/* */ {
/* */ private static final long serialVersionUID = 5121794650920770832L;
/* 37 */ protected int MAX_WIDTH = -1;
/* */
/* 39 */ protected int MAX_HEIGHT = -1;
/* */
/* 41 */ protected long MAX_SIZE = 1000000L;
/* */
/* 43 */ protected String[] IMAGETYPES = { "gif", "jpg", "jpeg", "png", "bmp" };
/* */
/* 45 */ protected String UPLOAD_PATH = "";
/* */
/* 48 */ protected String id = "";
/* */
/* 50 */ protected String imgTitle = "";
/* */
/* 52 */ protected int imgWidth = -1;
/* */
/* 54 */ protected int imgHeight = -1;
/* */
/* 56 */ protected String imgBorder = "";
/* */
/* 58 */ protected String resizeImg = "";
/* */
/* 60 */ protected boolean isFlag = false;
/* */
/* 62 */ protected String tempTitle = "";
/* */
/* */ protected void doGet(HttpServletRequest request, HttpServletResponse response)
/* */ throws ServletException, IOException
/* */ {
/* 68 */ response.setContentType("text/html; charset=UTF-8");
/* 69 */ PrintWriter out = response.getWriter();
/* 70 */ String savePath = getInitParameter("UPLOAD_PATH");
/* 71 */ if ((savePath == null) || (savePath.isEmpty())) {
/* 72 */ out.println(alertMsg("你还没设置上传图片保存的目录路径!"));
/* 73 */ return;
/* */ }
/* */
/* 76 */ if (getInitParameter("MAX_SIZE") != null) {
/* 77 */ this.MAX_SIZE = Integer.parseInt(getInitParameter("MAX_SIZE"));
/* */ }
/* */
/* 80 */ if (getInitParameter("IMAGETYPES") != null) {
/* 81 */ this.IMAGETYPES = toArray(getInitParameter("IMAGETYPES"));
/* */ }
/* */
/* 84 */ String uploadPath = request.getSession().getServletContext().getRealPath("/") + savePath;
/* */
/* 87 */ String saveUrl = request.getContextPath() + "/" + savePath;
/* */
/* 90 */ if (!ServletFileUpload.isMultipartContent(request)) {
/* 91 */ out.println(alertMsg("请选择你要上传的图片!"));
/* 92 */ return;
/* */ }
/* */
/* 96 */ File uploadDir = new File(uploadPath);
/* 97 */ if (!uploadDir.isDirectory()) {
/* 98 */ out.println(alertMsg("上传图片保存的目录不存在。"));
/* 99 */ return;
/* */ }
/* */
/* 103 */ if (!uploadDir.canWrite()) {
/* 104 */ out.println(alertMsg("上传图片保存的目录没有写权限。"));
/* 105 */ return;
/* */ }
/* */
/* 109 */ FileItemFactory factory = new DiskFileItemFactory();
/* 110 */ ServletFileUpload upload = new ServletFileUpload(factory);
/* 111 */ upload.setHeaderEncoding("UTF-8");
/* 112 */ List items = null;
/* 113 */ String temp = null;
/* */ try {
/* 115 */ items = upload.parseRequest(request);
/* 116 */ Iterator itr = items.iterator();
/* 117 */ while (itr.hasNext())
/* */ {
/* 119 */ FileItem item = (FileItem)itr.next();
/* */
/* 121 */ String fileName = item.getName();
/* 122 */ temp = item.getName();
/* 123 */ if ((temp != null) && (!this.isFlag)) {
/* 124 */ temp = temp.substring(temp.lastIndexOf("\\") + 1);
/* 125 */ this.tempTitle = temp;
/* 126 */ this.isFlag = true;
/* */ }
/* */
/* 129 */ if (item.getFieldName().equals("id")) {
/* 130 */ this.id = item.getString();
/* */ }
/* */
/* 134 */ if (item.getFieldName().equals("imgTitle")) {
/* 135 */ this.imgTitle = item.getString();
/* 136 */ if (this.imgTitle != null) {
/* 137 */ this.imgTitle = new String(this.imgTitle.getBytes("ISO8859-1"), "UTF-8");
/* */ }
/* */ }
/* */
/* 141 */ if (item.getFieldName().equals("imgWidth")) {
/* 142 */ String imgWidth = item.getString();
/* 143 */ if ((imgWidth != null) && (!imgWidth.isEmpty())) {
/* 144 */ this.imgWidth = Integer.parseInt(imgWidth);
/* */ }
/* */ }
/* */
/* 148 */ if (item.getFieldName().equals("imgHeight")) {
/* 149 */ String imgHeight = item.getString();
/* 150 */ if ((imgHeight != null) && (!imgHeight.isEmpty())) {
/* 151 */ this.imgHeight = Integer.parseInt(imgHeight);
/* */ }
/* */ }
/* */
/* 155 */ if (item.getFieldName().equals("imgBorder")) {
/* 156 */ this.imgBorder = item.getString();
/* */ }
/* */
/* 159 */ long fileSize = item.getSize();
/* 160 */ if (item.isFormField())
/* */ continue;
/* 162 */ if (fileSize > this.MAX_SIZE) {
/* 163 */ out.println(alertMsg("上传文件大小超过限制。"));
/* 164 */ return;
/* */ }
/* */
/* 168 */ String fileExt = fileName.substring(fileName.lastIndexOf(".") + 1).toLowerCase();
/* 169 */ if (!Arrays.asList(this.IMAGETYPES).contains(fileExt)) {
/* 170 */ out.println(alertMsg("上传图片扩展名是不允许的扩展名。"));
/* 171 */ return;
/* */ }
/* */
/* 174 */ SimpleDateFormat folderNameFormat = new SimpleDateFormat("yyyyMMdd");
/* 175 */ String realPath = uploadPath + folderNameFormat.format(new Date());
/* 176 */ File folder = new File(realPath);
/* 177 */ boolean flag = folder.exists();
/* */
/* 179 */ if (!flag) {
/* 180 */ flag = folder.mkdir();
/* */ }
/* */
/* 183 */ if (flag) {
/* 184 */ SimpleDateFormat fileNameFormat = new SimpleDateFormat("yyyyMMddHHmmss");
/* 185 */ String newFileName = fileNameFormat.format(new Date()) + "_" + new Random().nextInt(1000) + "." + fileExt;
/* 186 */ File uploadedFile = new File(realPath, newFileName);
/* 187 */ item.write(uploadedFile);
/* 188 */ this.resizeImg = uploadedFile.getPath();
/* 189 */ this.resizeImg = this.resizeImg.replaceAll("\\\\", "/");
/* 190 */ saveUrl = saveUrl + folderNameFormat.format(new Date()) + "/" + newFileName;
/* */ } else {
/* 192 */ System.out.println(" 文件夹创建失败,请确认磁盘没有写保护并且空件足够");
/* */ }
/* */
/* */ }
/* */
/* 198 */ String max_width = getInitParameter("MAX_WIDTH");
/* 199 */ String max_height = getInitParameter("MAX_HEIGHT");
/* 200 */ if ((max_width != null) && (!max_width.isEmpty())) {
/* 201 */ this.MAX_WIDTH = Integer.parseInt(max_width);
/* */ }
/* 203 */ if ((max_height != null) && (!max_height.isEmpty())) {
/* 204 */ this.MAX_HEIGHT = Integer.parseInt(max_height);
/* */ }
/* */
/* 207 */ if ((this.imgTitle == null) || (this.imgTitle.isEmpty())) {
/* 208 */ this.imgTitle = this.tempTitle;
/* */ }
/* */
/* 212 */ if ((this.MAX_WIDTH != -1) || (this.MAX_HEIGHT != -1))
/* */ {
/* 214 */ ImageUtil.resizeImg(this.resizeImg, this.resizeImg, this.MAX_WIDTH, this.MAX_HEIGHT);
/* */
/* 216 */ if (this.imgWidth > ImageUtil.ImgWidth) {
/* 217 */ this.imgWidth = ImageUtil.ImgWidth;
/* */ }
/* */
/* 220 */ if (this.imgHeight > ImageUtil.ImgHeight) {
/* 221 */ this.imgHeight = ImageUtil.ImgHeight;
/* */ }
/* */
/* 225 */ out.println(insertEditor(this.id, saveUrl, this.imgTitle, this.imgWidth, this.imgHeight, this.imgBorder));
/* */ }
/* */ else {
/* 228 */ out.println(insertEditor(this.id, saveUrl, this.imgTitle, this.imgWidth, this.imgHeight, this.imgBorder));
/* */ }
/* */ }
/* */ catch (FileUploadException e) {
/* 232 */ e.printStackTrace();
/* */ } catch (Exception e) {
/* 234 */ e.printStackTrace();
/* */ } finally {
/* 236 */ out.flush();
/* 237 */ out.close();
/* 238 */ this.isFlag = false;
/* */ }
/* */ }
/* */
/* */ protected void doPost(HttpServletRequest request, HttpServletResponse response)
/* */ throws ServletException, IOException
/* */ {
/* 246 */ doGet(request, response);
/* */ }
/* */
/* */ public String alertMsg(String message)
/* */ {
/* 257 */ StringBuffer sb = new StringBuffer("{\"error\":\"1\",\"message\":\"");
/* 258 */ sb.append(message).append("\"}");
/* 259 */ return sb.toString();
/* */ }
/* */
/* */ public String insertEditor(String id, String saveUrl, String imgTitle, int imgWidth, int imgHeight, String imgBorder)
/* */ {
/* 281 */ StringBuffer sb = new StringBuffer("");
/* 287 */ return sb.toString();
/* */ }
/* */
/* */ public String[] toArray(String filesType)
/* */ {
/* 299 */ if (filesType == null) {
/* 300 */ return null;
/* */ }
/* */
/* 303 */ String[] types = filesType.split(",");
/* 304 */ String[] allowTypes = new String[types.length];
/* 305 */ int i = 0;
/* 306 */ for (String type : types) {
/* 307 */ allowTypes[i] = type;
/* 308 */ i++;
/* */ }
/* */
/* 311 */ return allowTypes;
/* */ }
/* */ }
/* Location: C:\Users\yanglei\Desktop\新建文件夹\kindeditorservlet\
* Qualified Name: com.elkan.kindeditor.upload.UploadImage
* JD-Core Version: 0.6.0
*/
UploadImageManager.java
/* */ package com.scrh.web.com.elkan.kindeditor;
/* */
/* */ import java.io.File;
/* */ import java.io.IOException;
/* */ import java.io.PrintWriter;
/* */ import java.text.SimpleDateFormat;
/* */ import java.util.ArrayList;
/* */ import java.util.Arrays;
/* */ import java.util.Collections;
/* */ import java.util.Comparator;
/* */ import java.util.Hashtable;
/* */ import java.util.List;
/* */ import javax.servlet.ServletContext;
/* */ import javax.servlet.ServletException;
/* */ import javax.servlet.http.HttpServlet;
/* */ import javax.servlet.http.HttpServletRequest;
/* */ import javax.servlet.http.HttpServletResponse;
/* */ import javax.servlet.http.HttpSession;
/* */
/* */ public class UploadImageManager extends HttpServlet
/* */ {
/* */ private static final long serialVersionUID = -8359652838938248988L;
/* 23 */ protected String[] FILETYPES = { "gif", "jpg", "jpeg", "png", "bmp" };
/* */
/* 25 */ protected String UPLOAD_PATH = "";
/* */
/* */ public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
/* */ {
/* 29 */ response.setContentType("text/html; charset=UTF-8");
/* 30 */ PrintWriter out = response.getWriter();
/* 31 */ String savePath = getInitParameter("UPLOAD_PATH");
/* 32 */ if ((savePath == null) || (savePath.isEmpty())) {
/* 33 */ out.println(alertMsg("你还没设置读取上传图片保存的目录路径!"));
/* 34 */ return;
/* */ }
/* */
/* 37 */ String rootPath = request.getSession().getServletContext().getRealPath("/") + savePath;
/* */
/* 39 */ String rootUrl = request.getContextPath() + "/" + savePath;
/* */
/* 41 */ String path = request.getParameter("path") != null ? request.getParameter("path") : "";
/* 42 */ String currentPath = rootPath + path;
/* 43 */ String currentUrl = rootUrl + path;
/* 44 */ String currentDirPath = path;
/* 45 */ String moveupDirPath = "";
/* */
/* 47 */ if (!"".equals(path)) {
/* 48 */ String str = currentDirPath.substring(0, currentDirPath.length() - 1);
/* 49 */ moveupDirPath = str.lastIndexOf("/") >= 0 ? str.substring(0, str.lastIndexOf("/") + 1) : "";
/* */ }
/* */
/* 53 */ String order = request.getParameter("order") != null ? request.getParameter("order").toLowerCase() : "name";
/* */
/* 56 */ if (path.indexOf("..") >= 0) {
/* 57 */ out.println(alertMsg("不允许使用移动到上一级目录"));
/* 58 */ return;
/* */ }
/* */
/* 62 */ if ((!"".equals(path)) && (!path.endsWith("/"))) {
/* 63 */ out.println("Parameter is not valid.");
/* 64 */ return;
/* */ }
/* */
/* 67 */ File currentPathFile = new File(currentPath);
/* 68 */ if (!currentPathFile.isDirectory()) {
/* 69 */ out.println("Directory does not exist.");
/* 70 */ return;
/* */ }
/* */
/* 74 */ List fileList = new ArrayList();
/* 75 */ if (currentPathFile.listFiles() != null) {
/* 76 */ for (File file : currentPathFile.listFiles()) {
/* 77 */ Hashtable hash = new Hashtable();
/* 78 */ String fileName = file.getName();
/* 79 */ if (file.isDirectory()) {
/* 80 */ hash.put("is_dir", Boolean.valueOf(true));
/* 81 */ hash.put("has_file", Boolean.valueOf(file.listFiles() != null));
/* 82 */ hash.put("filesize", Long.valueOf(0L));
/* 83 */ hash.put("is_photo", Boolean.valueOf(false));
/* 84 */ hash.put("filetype", "");
/* 85 */ } else if (file.isFile()) {
/* 86 */ String fileExt = fileName.substring(fileName.lastIndexOf(".") + 1).toLowerCase();
/* 87 */ hash.put("is_dir", Boolean.valueOf(false));
/* 88 */ hash.put("has_file", Boolean.valueOf(false));
/* 89 */ hash.put("filesize", Long.valueOf(file.length()));
/* 90 */ hash.put("is_photo", Boolean.valueOf(Arrays.asList(this.FILETYPES).contains(fileExt)));
/* 91 */ hash.put("filetype", fileExt);
/* */ }
/* 93 */ hash.put("filename", fileName);
/* 94 */ hash.put("datetime", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(Long.valueOf(file.lastModified())));
/* 95 */ fileList.add(hash);
/* */ }
/* */ }
/* */
/* 99 */ if ("size".equals(order))
/* 100 */ Collections.sort(fileList, new SizeComparator());
/* 101 */ else if ("type".equals(order))
/* 102 */ Collections.sort(fileList, new TypeComparator());
/* */ else {
/* 104 */ Collections.sort(fileList, new NameComparator());
/* */ }
/* */
/* 107 */ out.println(toJSONString(currentUrl, currentDirPath, moveupDirPath, fileList));
/* */
/* 109 */ out.flush();
/* 110 */ out.close();
/* */ }
/* */
/* */ public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
/* */ {
/* 115 */ doGet(request, response);
/* */ }
/* */
/* */ public String alertMsg(String message)
/* */ {
/* 126 */ StringBuffer sb = new StringBuffer("");
/* 129 */ return sb.toString();
/* */ }
/* */
/* */ public String toJSONString(String currentUrl, String currentDirPath, String moveupDirPath, List
/* 133 */ StringBuilder sb = new StringBuilder("{\"current_url\":\"");
/* 134 */ sb.append(currentUrl).append("\",").append("\"current_dir_path\":\"");
/* 135 */ sb.append(currentDirPath).append("\",\"moveup_dir_path\":\"").append(moveupDirPath).append("\",");
/* 136 */ sb.append("\"file_list\":[");
/* 137 */ int i = 0;
/* 138 */ sb.append("{");
/* 139 */ for (Hashtable he : fileList) {
/* 140 */ if (i != fileList.size() - 1) {
/* 141 */ sb.append("\"filename\":\"").append(he.get("filename")).append("\",");
/* 142 */ sb.append("\"filesize\":").append(he.get("filesize")).append(",");
/* 143 */ sb.append("\"filetype\":\"").append(he.get("filetype")).append("\",");
/* 144 */ sb.append("\"has_file\":").append(he.get("has_file")).append(",");
/* 145 */ sb.append("\"is_dir\":").append(he.get("is_dir")).append(",");
/* 146 */ sb.append("\"is_photo\":").append(he.get("is_photo")).append(",");
/* 147 */ sb.append("\"datetime\":\"").append(he.get("datetime")).append("\"");
/* 148 */ sb.append("},{");
/* */ } else {
/* 150 */ sb.append("\"filename\":\"").append(he.get("filename")).append("\",");
/* 151 */ sb.append("\"filesize\":").append(he.get("filesize")).append(",");
/* 152 */ sb.append("\"filetype\":\"").append(he.get("filetype")).append("\",");
/* 153 */ sb.append("\"has_file\":").append(he.get("has_file")).append(",");
/* 154 */ sb.append("\"is_dir\":").append(he.get("is_dir")).append(",");
/* 155 */ sb.append("\"is_photo\":").append(he.get("is_photo")).append(",");
/* 156 */ sb.append("\"datetime\":\"").append(he.get("datetime")).append("\"");
/* 157 */ sb.append("}");
/* */ }
/* 159 */ i++;
/* */ }
/* 161 */ i = 0;
/* 162 */ sb.append("],\"total_count\":").append(fileList.size()).append("}");
/* 163 */ return sb.toString();
/* */ }
/* */ public class NameComparator implements Comparator
utils包
ImageUtil.java
/* */ package com.scrh.web.com.elkan.utils;
/* */
/* */ import com.sun.image.codec.jpeg.JPEGCodec;
/* */ import com.sun.image.codec.jpeg.JPEGImageEncoder;
/* */ import java.awt.Graphics;
/* */ import java.awt.Image;
/* */ import java.awt.image.BufferedImage;
/* */ import java.io.File;
/* */ import java.io.FileOutputStream;
/* */ import java.io.IOException;
/* */ import javax.imageio.ImageIO;
/* */
/* */ public class ImageUtil
/* */ {
/* 21 */ public static int ImgWidth = -1;
/* */
/* 23 */ public static int ImgHeight = -1;
/* */
/* */ static {
/* 26 */ System.setProperty("jmagick.systemclassloader", "no");
/* */ }
/* */
/* */ public static void resizeImg(String imgsrc, String imgdist, int widthdist, int heightdist)
/* */ {
/* */ try
/* */ {
/* 44 */ File srcfile = new File(imgsrc);
/* 45 */ if (!srcfile.exists()) {
/* 46 */ return;
/* */ }
/* 48 */ Image src = ImageIO.read(srcfile);
/* 49 */ ImgWidth = src.getWidth(null);
/* 50 */ ImgHeight = src.getHeight(null);
/* 51 */ if (ImgWidth < widthdist)
/* 52 */ widthdist = ImgWidth;
/* */ else {
/* 54 */ ImgWidth = widthdist;
/* */ }
/* 56 */ if (ImgHeight < heightdist)
/* 57 */ heightdist = ImgHeight;
/* */ else {
/* 59 */ ImgHeight = heightdist;
/* */ }
/* 61 */ BufferedImage tag = new BufferedImage(widthdist, heightdist, 1);
/* */
/* 63 */ tag.getGraphics().drawImage(src.getScaledInstance(widthdist, heightdist, 4), 0, 0, null);
/* 64 */ FileOutputStream out = new FileOutputStream(imgdist);
/* 65 */ JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
/* 66 */ encoder.encode(tag);
/* 67 */ out.close();
/* */ } catch (IOException ex) {
/* 69 */ ex.printStackTrace();
/* */ }
/* */ }
/* */ }
/* Location: C:\Users\yanglei\Desktop\新建文件夹\kindeditorservlet\
* Qualified Name: com.elkan.utils.ImageUtil
* JD-Core Version: 0.6.0
*/
web.xml
editor.jsp富文本输入文件
<%@page contentType="text/html" language="java" pageEncoding="UTF-8"%>
<%@ include file="/comm.jsp"%>
editor.jsp富文本再输入文件
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%
request.setCharacterEncoding("UTF-8");
String htmlData = request.getParameter("content1") != null ? request.getParameter("content1") : "";
%>
<%@ include file="/comm.jsp"%>
<%=htmlData%>
<%!
private String htmlspecialchars(String str) {
str = str.replaceAll("&", "&");
str = str.replaceAll("<", "<");
str = str.replaceAll(">", ">");
str = str.replaceAll("\"", """);
return str;
}
%>