`
hanting99
  • 浏览: 4243 次
  • 来自: ...
社区版块
存档分类
最新评论

java FCKeditor 2.4 修改

    博客分类:
  • java
阅读更多
公司要把一些新闻每天备份。想找个FCKeditor能把上传图片按日期分目录。没找到。自己动手改了一下。

java FCKeditor2.4 的上传在 net.fckeditor.connector下的  ConnectorServle类中。用XJad把类反编译了。

修改成下面代码:


package net.fckeditor.connector;

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;

public class ConnectorServlet extends HttpServlet
{

	private static final long serialVersionUID = 0xb05049436ea5f077L;
	private static final Logger logger = LoggerFactory.getLogger(ConnectorServlet.class);

	public ConnectorServlet()
	{
	}

	public void init()
		throws ServletException, IllegalArgumentException
	{
		String s = getServletContext().getRealPath(ConnectorHandler.getDefaultUserFilesPath());
		File file = new File(s);
		UtilsFile.checkDirAndCreate(file);
		logger.info("ConnectorServlet successfully initialized!");
	}

	public void doGet(HttpServletRequest httpservletrequest, HttpServletResponse httpservletresponse)
		throws ServletException, IOException
	{
		logger.debug("Entering ConnectorServlet#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;
					else
						try
						{
							byte0 = ((byte)(file2.mkdir() ? 0 : 102));
						}
						catch (SecurityException securityexception)
						{
							byte0 = 103;
						}
					xmlresponse.setError(byte0);
				}
			}
		}
		printwriter.print(xmlresponse);
		printwriter.flush();
		printwriter.close();
		logger.debug("Exiting ConnectorServlet#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());
	}

}


修改后上传的图片目录是/当天日期/当前时间.jpg  了. 不会出现中文乱码了。
在www.pjwqh.cn基础上修改的。感谢下作者。
分享到:
评论
3 楼 hanting99 2009-06-26  
如果要修修后的留邮箱我传给你
2 楼 limao1358 2009-06-24  
不用XJad把类反编译的啊.这些都是开源项目,所以都有源代码的,你去下载就可以了.
1 楼 cuiran 2009-06-14  
你好,我也用你这种方法但出现了一个问题:
if (!RequestCycleHandler.isEnabledForFileUpload(request))
ur = new UploadResponse(UploadResponse.SC_SECURITY_ERROR, null, null,
        Messages.NOT_AUTHORIZED_FOR_UPLOAD);
else if (!CommandHandler.isValidForPost(commandStr))
ur = new UploadResponse(UploadResponse.SC_ERROR, null, null, Messages.INVALID_COMMAND);
else if (typeStr != null && !ResourceTypeHandler.isValid(typeStr))
ur = new UploadResponse(UploadResponse.SC_ERROR, null, null, Messages.INVALID_TYPE);
else if (!UtilsFile.isValidPath(currentFolderStr))
ur = UploadResponse.UR_INVALID_CURRENT_FOLDER;


问题是UploadResponse没有定义那些方法。出现个红叉。帮我解答下。谢谢。

相关推荐

    fckeditor-java-2.4源码

    《深入解析FCKeditor 2.4 Java源码》 FCKeditor是一款历史悠久且功能强大的网页文本编辑器,尤其在Web开发领域广受好评。它提供了丰富的文本编辑功能,允许用户在网页上进行类似Word的文本编辑操作。本文将重点探讨...

    jsp已配置好的fckeditor 2.4

    在JSP(JavaServer Pages)环境中,FCKeditor 2.4版本是一个常见且实用的选择。本篇文章将详细介绍如何在JSP项目中配置并使用FCKeditor 2.4,以及涉及到的相关技术点。 **一、FCKeditor简介** FCKeditor 2.4是一款...

    fckeditor-java-2.4

    "Fckeditor-java-2.4" 是一款基于Java的开源Web文本编辑器,它为开发者提供了一个在网页上创建和编辑富文本内容的解决方案。这款编辑器功能强大,易用性好,广泛应用于各种Web应用程序中,如内容管理系统、论坛、...

    FCKeditor2.4基本文件

    **FCKeditor2.4基本文件详解** FCKeditor是一款著名的开源富文本编辑器,它在Web开发领域中被广泛使用,特别是在Java环境下。标题中的"FCKeditor2.4基本文件"指的是该编辑器的2.4版本的核心组件,这些组件构成了在...

    fckeditor-java-2.4-src.rar源码

    《深入解析FCKeditor Java 2.4源码》 FCKeditor是一款广泛使用的开源文本编辑器,尤其在Web开发领域,它以其丰富的功能、良好的兼容性和易用性深受开发者喜爱。本文将针对"Fckeditor-java-2.4-src.rar"源代码进行...

    fckeditor for java 2.4 修改版

    前段时间在fck的官网上溜达的时候发现了 fckEditor for java 2.4X 的版本,没想到for java的也有新的版本出来了,用了那么老长时间的for java2.3 ,呵呵 于是就下来体验了一下,确实不错,而且fck2.6的版本,对文件的上传...

    FCKEditor2.6和fckeditor-java2.4的使用.doc

    ### FCKEditor 2.6 和 fckeditor-java 2.4 使用详解 #### 一、简介 FCKEditor是一款功能强大的在线富文本编辑器,它能够帮助开发者在Web应用程序中集成高级文本编辑功能。FCKEditor 2.6 版本与 fckeditor-java 2.4...

    FCKeditor for java2.4 远程保存图片 java版

    FCKeditor for java2.4 远程保存图片 java版 功能介绍: 在FCKeditor中复制网页内容时,其中的图片仍然保存在源站点上,当远程服务器路径做出更改或者关闭,本地图片将无法打开。给网友造成不好的印象,使用本功能...

    FckEditor for java 2.4的JSP 配置方法详解

    **FCKEditor for Java 2.4 JSP配置方法详解** FCKEditor是一款非常流行的开源富文本编辑器,它提供了丰富的HTML编辑功能,使得用户在Web应用中可以方便地进行文本格式化、图像上传等操作。本文将详细介绍如何在Java...

    JSP版FCKeditor附最新Java开发包v2.4

    5. **自定义配置**: 根据项目需求,可以修改FCKeditor的配置文件,例如禁用某些功能,更改默认样式,或者设置上传文件的路径等。 FCKeditor v2.4虽然相比最新的版本有些过时,但它稳定且功能齐全,对于许多旧项目...

    Fckeditor_java_v2.4(修正上传文件中文编码问题)

    FCKEditor_for java_v2.4官方修改版,可以直接在Myeclipse环境中导入使用,做了文件、图片、Flash上传时中文编码的修改。同时,做了一些必要的瘦身,添加了常用的中文字体。

    RemoteUpload Plugin for FCKEditor 2.6 java 版(2.4)

    "RemoteUpload Plugin for FCKEditor 2.6 java 版(2.4)" 这个标题指的是一个专门为FCKEditor 2.6版本开发的远程上传插件,该插件的Java实现版本是2.4。FCKEditor是一款开源的富文本编辑器,广泛用于网页内容编辑,而...

    FCKEditor for java

    2. **配置Web应用**:将FCKeditor_2.6.3.zip 和 fckeditor-java-2.4-bin.zip 文件解压至项目中相应的目录。 3. **配置Servlets**:在项目的`web.xml`文件中添加对`SimpleUploaderServlet`和`ConnectorServlet`的配置...

    FCKeditor.Java 源码下载

    在下载的"FCKeditor.Java"压缩包中,文件名"fckeditor-java-2.4"很可能包含了FCKeditor的Java版本源码。这通常会包含以下几个部分: 1. **源码目录**:源代码通常分布在几个不同的目录下,包括核心编辑器组件、Java...

    FCKeditor_2.6.3.zip jsp编辑器

    同时,该压缩包还包含了"fckeditor-java-2.4-bin.zip",这是FCKeditor的Java版本二进制库,使得在Java环境中集成编辑器变得更加便捷。 FCKeditor 2.6.3是一个功能强大的WYSIWYG(所见即所得)编辑器,它提供了诸如...

    fckeditor-java-demo-2.4.1.rar_DEMO_fckeditor_fckeditor demo_fcke

    FCKeditor的可定制性强,可以根据项目需求进行各种自定义,如修改编辑器样式、增加自定义按钮、调整工具栏布局等。此外,还可以利用FCKeditor提供的API实现更复杂的功能,如实现与服务器端的数据同步、实时预览等。 ...

    FCKeditor2.6.3完整包下载(全)

    3. **fckeditor-java-2.4-bin.zip**:这是FCKeditor的Java SDK,包含了Java版的FCKeditor库和相关示例代码。如果你正在开发Java Web应用,并打算集成FCKeditor,这个包会非常有用。它提供了与Java服务器端交互的方法...

    FCKeditor源代码。。。。

    在提供的压缩包`fckeditor-java-2.4`中,我们可以找到FCKeditor的Java版本。这个版本通常用于与Java服务器端进行交互,例如处理文件上传。了解其Java API和如何在Java应用中嵌入和使用FCKeditor同样重要。 总之,...

    fckeditor文本编辑 实现了上传大小控制 中文名问题 格式控制等

    在`fckeditor-java-2.4`中,提供了与FCKeditor交互的Java API,用于在服务器端处理编辑器提交的内容。例如,你可以使用`FCKeditorProcessor`类来获取和处理编辑器的HTML内容: ```java FCKeditorProcessor ...

Global site tag (gtag.js) - Google Analytics