本文主要是介绍超强大的图文混排编辑器 Struts2+FCKeditor-2.3 下载即可部署使用,完整Demo,有不懂的可以留言。,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
原文:超强大的图文混排编辑器 Struts2+FCKeditor-2.3 下载即可部署使用,完整Demo,有不懂的可以留言。
源代码下载:http://www.zuidaima.com/share/1550463380982784.htm
超强大的图文混排编辑器 Struts2+FCKeditor-2.3 下载即可部署使用,完整Demo,有不懂的可以留言。 1.文本编辑器分为:Basic,Default var editor = new FCKeditor("content","800","400","Default",""); 2.更换皮肤 找到/EditWebTest/WebRoot/fckeditor/fckconfig.js 找到45行的FCKConfig.SkinPath = FCKConfig.BasePath + 'skins/default/' ; 修改default单词即可,皮肤自带有三种,第一种为default,office2003,silver
package com.zuidaima.edit.util;import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;import net.fckeditor.handlers.CommandHandler;
import net.fckeditor.handlers.ConnectorHandler;
import net.fckeditor.handlers.ExtensionsHandler;
import net.fckeditor.handlers.RequestCycleHandler;
import net.fckeditor.handlers.ResourceTypeHandler;
import net.fckeditor.response.UploadResponse;
import net.fckeditor.response.XmlResponse;
import net.fckeditor.tool.Utils;
import net.fckeditor.tool.UtilsFile;
import net.fckeditor.tool.UtilsResponse;import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.apache.commons.io.FilenameUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
*@author www.zuidaima.com
**/public class MyConnectorServlet extends HttpServlet {private static final long serialVersionUID = 0xb05049436ea5f077L;private static final Logger logger = LoggerFactory.getLogger(MyConnectorServlet.class);public MyConnectorServlet() {}public void init() throws ServletException, IllegalArgumentException {String s = getServletContext().getRealPath(ConnectorHandler.getDefaultUserFilesPath());File file = new File(s);UtilsFile.checkDirAndCreate(file);logger.info("MyConnectorServlet successfully initialized!");}public void doGet(HttpServletRequest httpservletrequest,HttpServletResponse httpservletresponse) throws ServletException,IOException {logger.debug("Entering MyConnectorServlet#doGet");httpservletresponse.setCharacterEncoding("UTF-8");httpservletresponse.setContentType("application/xml; charset=UTF-8");httpservletresponse.setHeader("Cache-Control", "no-cache");PrintWriter printwriter = httpservletresponse.getWriter();String s = httpservletrequest.getParameter("Command");String s1 = httpservletrequest.getParameter("Type");String s2 = httpservletrequest.getParameter("CurrentFolder");logger.debug("Parameter Command: {}", s);logger.debug("Parameter Type: {}", s1);logger.debug("Parameter CurrentFolder: {}", s2);XmlResponse xmlresponse;if (!RequestCycleHandler.isEnabledForFileBrowsing(httpservletrequest))xmlresponse = new XmlResponse(1,"The current user isn't authorized for file browsing!");else if (!CommandHandler.isValidForGet(s))xmlresponse = new XmlResponse(1, "Invalid command specified");else if (s1 != null && !ResourceTypeHandler.isValid(s1))xmlresponse = new XmlResponse(1, "Invalid resource type specified");else if (!UtilsFile.isValidPath(s2)) {xmlresponse = new XmlResponse(1, "Invalid current folder specified");} else {CommandHandler commandhandler = CommandHandler.getCommand(s);ResourceTypeHandler resourcetypehandler = ResourceTypeHandler.getDefaultResourceType(s1);String s3 = UtilsFile.constructServerSidePath(httpservletrequest,resourcetypehandler);// s3=s3+"/"+getDate(3);//浏览时浏览最顶层目录String s4 = getServletContext().getRealPath(s3);File file = new File(s4);UtilsFile.checkDirAndCreate(file);File file1 = new File(file, s2);if (!file1.exists()) {xmlresponse = new XmlResponse(102);} else {xmlresponse = new XmlResponse(commandhandler,resourcetypehandler, s2,UtilsResponse.constructResponseUrl(httpservletrequest,resourcetypehandler, s2, true,ConnectorHandler.isFullUrl()));if (commandhandler.equals(CommandHandler.GET_FOLDERS))xmlresponse.setFolders(file1);else if (commandhandler.equals(CommandHandler.GET_FOLDERS_AND_FILES))xmlresponse.setFoldersAndFiles(file1);else if (commandhandler.equals(CommandHandler.CREATE_FOLDER)) {String s5 = UtilsFile.sanitizeFolderName(httpservletrequest.getParameter("NewFolderName"));logger.debug("Parameter NewFolderName: {}", s5);File file2 = new File(file1, s5);byte byte0 = 110;if (file2.exists())byte0 = 101;elsetry {byte0 = ((byte) (file2.mkdir() ? 0 : 102));} catch (SecurityException securityexception) {byte0 = 103;}xmlresponse.setError(byte0);}}}printwriter.print(xmlresponse);printwriter.flush();printwriter.close();logger.debug("Exiting MyConnectorServlet#doGet");}@SuppressWarnings("unchecked")public void doPost(HttpServletRequest httpservletrequest,HttpServletResponse httpservletresponse) throws ServletException,IOException {logger.debug("Entering Connector#doPost");httpservletresponse.setCharacterEncoding("UTF-8");httpservletresponse.setContentType("text/html; charset=UTF-8");httpservletresponse.setHeader("Cache-Control", "no-cache");PrintWriter printwriter = httpservletresponse.getWriter();String s = httpservletrequest.getParameter("Command");String s1 = httpservletrequest.getParameter("Type");String s2 = httpservletrequest.getParameter("CurrentFolder");logger.debug("Parameter Command: {}", s);logger.debug("Parameter Type: {}", s1);logger.debug("Parameter CurrentFolder: {}", s2);if (Utils.isEmpty(s) && Utils.isEmpty(s2)) {s = "QuickUpload";s2 = "/";}UploadResponse uploadresponse;if (!RequestCycleHandler.isEnabledForFileUpload(httpservletrequest))uploadresponse = new UploadResponse(new Object[] {Integer.valueOf(203), null, null,"The current user isn't authorized for file upload!" });else if (!CommandHandler.isValidForPost(s))uploadresponse = new UploadResponse(new Object[] { Integer.valueOf(1), null, null,"Invalid command specified" });else if (s1 != null && !ResourceTypeHandler.isValid(s1))uploadresponse = new UploadResponse(new Object[] {Integer.valueOf(1), null, null,"Invalid resource type specified" });else if (!UtilsFile.isValidPath(s2)) {uploadresponse = UploadResponse.UR_INVALID_CURRENT_FOLDER;} else {ResourceTypeHandler resourcetypehandler = ResourceTypeHandler.getDefaultResourceType(s1);String s3 = UtilsFile.constructServerSidePath(httpservletrequest,resourcetypehandler);s3 = s3 + "/" + getDate(3);String s4 = getServletContext().getRealPath(s3);File file = new File(s4);UtilsFile.checkDirAndCreate(file);File file1 = new File(file, s2);if (!file1.exists()) {uploadresponse = UploadResponse.UR_INVALID_CURRENT_FOLDER;} else {String s5 = null;DiskFileItemFactory diskfileitemfactory = new DiskFileItemFactory();ServletFileUpload servletfileupload = new ServletFileUpload(diskfileitemfactory);servletfileupload.setHeaderEncoding("UTF-8");try {List list = servletfileupload.parseRequest(httpservletrequest);FileItem fileitem = (FileItem) list.get(0);String s6 = UtilsFile.sanitizeFileName(fileitem.getName());String s7 = FilenameUtils.getName(s6);String s8 = getDate(0);String s9 = FilenameUtils.getExtension(s7);s7 = s8.concat(".").concat(s9.toLowerCase());if (!ExtensionsHandler.isAllowed(resourcetypehandler, s9)) {uploadresponse = new UploadResponse(new Object[] { Integer.valueOf(202) });} else {File file2 = new File(file1, s7);for (int i = 1; file2.exists(); i++) {s5 = s8.concat("_").concat(String.valueOf(i)).concat(".").concat(s9.toLowerCase());file2 = new File(file1, s5);}if (Utils.isEmpty(s5)) {s2 = s2 + getDate(3) + "/";uploadresponse = new UploadResponse(new Object[] {Integer.valueOf(0),UtilsResponse.constructResponseUrl(httpservletrequest,resourcetypehandler, s2, true,ConnectorHandler.isFullUrl()).concat(s7) });String aa = UtilsResponse.constructResponseUrl(httpservletrequest, resourcetypehandler,s2, true, ConnectorHandler.isFullUrl()).concat(s7);} else {uploadresponse = new UploadResponse(new Object[] {Integer.valueOf(201),UtilsResponse.constructResponseUrl(httpservletrequest,resourcetypehandler, s2, true,ConnectorHandler.isFullUrl()).concat(s5), s5 });}if (resourcetypehandler.equals(ResourceTypeHandler.IMAGE)&& ConnectorHandler.isSecureImageUploads()) {if (UtilsFile.isImage(fileitem.getInputStream())) {fileitem.write(file2);} else {fileitem.delete();uploadresponse = new UploadResponse(new Object[] { Integer.valueOf(202) });}} else {fileitem.write(file2);}}} catch (Exception exception) {uploadresponse = new UploadResponse(new Object[] { Integer.valueOf(203) });}}}printwriter.print(uploadresponse);printwriter.flush();printwriter.close();logger.debug("Exiting Connector#doPost");}public static final String getDate(int i) {String as[] = { "yyyyMMddHHmmssSSS", "yyyyMMddHHmmss", "yyMMddHHmmss","yyyyMMdd", "yyyy-MM-dd", "HHmmssSSS", "HHmmss" };SimpleDateFormat simpledateformat = null;try {simpledateformat = new SimpleDateFormat(as[i]);} catch (Exception exception) {exception.printStackTrace();System.out.print(exception.toString());return exception.toString();}return simpledateformat.format(new Date());}}
这篇关于超强大的图文混排编辑器 Struts2+FCKeditor-2.3 下载即可部署使用,完整Demo,有不懂的可以留言。的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!