首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

Fckeditor 2.6.5 中文有关问题和fckeditor-java-2.5-bin 文件下传路径动态生成

2012-10-30 
Fckeditor 2.6.5 中文问题和fckeditor-java-2.5-bin 文件上传路径动态生成Fckeditor 2.6.5 中文问题和fcke

Fckeditor 2.6.5 中文问题和fckeditor-java-2.5-bin 文件上传路径动态生成

Fckeditor 2.6.5 中文问题和fckeditor-java-2.5-bin 文件上传路径动态生成

1.解决中文问题

??? 目前fckeditor的java版核心jar包最新为:fckeditor-java-core-2.5.jar
但是该包对中文文件的上传支持不好,包括了中文文件和中文目录乱码的bug,和中文文件(图片)引用回显等乱码问题,因为fckeditor编码格式为utf-8,修改支持纯中文需要改的地方太多了,不是很方便。
??? 所以我的解决办法是,把上传的中文文件重名成时间字符串的文件名,ewebeditor 就是才用这种做法的。

??? 因此查看了了fckeditor-java-2.5-bin 的源码,修改了一下几处:

/** * @author feicer * modify doGet * start *///String newFolderNameStr = request//.getParameter("NewFolderName");//logger.debug("Parameter NewFolderName: {}",//newFolderNameStr);String newFolderNameStr = request.getParameter("NewFolderName");String tempStr = new String(newFolderNameStr.getBytes("iso8859-1"), "utf-8");newFolderNameStr = tempStr;logger.debug("Parameter NewFolderName: {}",newFolderNameStr); /** * @author feicer * end */



找到doPost方法的以下代码,并修改(注释掉的为原代码):

/** * @author feicer * modify doPost * start *///String fileName = FilenameUtils.getName(uplFile.getName());//logger.debug("Parameter NewFile: {}", fileName);String fileName = FilenameUtils.getName(uplFile.getName());String fileExt = fileName.substring(fileName.lastIndexOf("."));Calendar cad = Calendar.getInstance();fileName = String.valueOf(cad.get(Calendar.YEAR))+ String.valueOf(cad.get(Calendar.MONTH))+ String.valueOf(cad.get(Calendar.DAY_OF_MONTH))+ String.valueOf(cad.get(Calendar.HOUR_OF_DAY))+ String.valueOf(cad.get(Calendar.MINUTE))+ String.valueOf(cad.get(Calendar.SECOND));fileName = fileName + fileExt;logger.debug("Parameter NewFile: {}", fileName); /** * @author feicer * end */



这样就可以解决中文问题了。

2.下面解决动态更改上传文件路径问题

你先可以查看

# base URL path for the userfilesconnector.userFilesPath = /userfiles



动态的问题,就要看fck的加载原理了,
fckeditor是在net.fckeditor.handlers包中的PropertiesLoader类来读取

private static final String DEFAULT_FILENAME = "default.properties";private static final String LOCAL_PROPERTIES = "/fckeditor.properties";


其中的属性的,有fckeditor.properties,就用这个的,没有就用default的。
在PropertiesLoader中声明了一个static的properties,这是个静态的属性,而且提供了setProperty方法

我们需要做的,就是在fckeditor加载之前,动态改变fckeditor的加载属性的值。
在jsp页面
我们以用户名为例创建文件夹

?

<?xml version="1.0" encoding="UTF-8" ?><%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8" import="net.fckeditor.*" %><%@ taglib uri="http://java.fckeditor.net" prefix="FCK" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>FCKeditor - JSP Sample</title><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><meta name="robots" content="noindex, nofollow" /><link href="../sample.css" rel="stylesheet" type="text/css" /><link rel="shortcut icon" href="../fckeditor.gif"type="image/x-icon" /><script type="text/javascript">function FCKeditor_OnComplete(editorInstance) {window.status = editorInstance.Description;}</script></head><%FCKeditor fckEditor = new FCKeditor(request, "EditorDefault");%><body><h1>FCKeditor - JSP - Sample 1</h1><p>This sample displays a normal HTML form with an FCKeditor withfull features enabled.</p><p>Basic FCKeditor information:</p><ul><li><FCK:check command="CompatibleBrowser" /></li><li><FCK:check command="GetResources" /></li><li><FCK:check command="FileUpload" /></li><li><FCK:check command="CreateFolder" /></li></ul><hr /><form action="sampleposteddata.jsp" method="post" target="_blank"><%String username="aaaa";//此处可以获取用户名PropertiesLoader.setProperty("connector.userFilesPath","/user"+username);fckEditor.setValue("This is some <strong>sample text</strong>. You are using <a href="http://www.fckeditor.net">FCKeditor</a>.");out.println(fckEditor);%><br /><input type="submit" value="Submit" /></form></body></html>

?

?这样,就可以动态创建useraaaa这个文件夹了。


我把修改过的 fckeditor-java-core-2.5.jar上传上来,大家测试一下吧。。。

?

热点排行