FCKeditor在Java项目中应用

转载:http://noname.iteye.com/blog/28194

 

这是来到新公司头儿给我的第一个活儿,网上一搜资料挺多,整理如下
        FCKeditor 2.3.1 是功能完善的可视化编辑器,文件上传管理部分功能已经支持asp,php,aspx...等等,唯独尚未支持jsp,幸运的是Simone Chiaretta制作了Java 的整合文件FCKeditor.Java。
1. 下载最新版的FCKeditor
        http://www.fckeditor.net/download/
        目前最新版是:FCKeditor_2.3.2(我用的是2.3.1)和 FCKeditor.Java
(FCKeditor-2.3)
2. 简介
        解压FCKeditor 2.3.1.zip后得到如下目录结构:
FCKeditor_2.3.1
---editor
    ---_source (有的资料说要删除此文件夹,删除将会出现很多初始化js错误)
    ---css(样式)
    ---dialog(editor所有的网页对话框都在这里了)
    ---filemanager(文件上传管理部分)
        ---browser(存放用于浏览选择上传到服务器的文件,创建文件夹的浏览器)
        ---defult
               ---connectors(asp、php 、aspx等实现文件浏览、创建文件夹的文件。java项目中用 connectorservlet.Java实现,所以可以删除下面所有文件)
        ---upload(asp、php、aspx等实现文件上传时的文件,java项目中用  servlet实现上传,所以可以删除下面所有文件)
    ---images(editor使用到的图片)
    ---js
    ---lang (存放用于支持多语言的js文件)
    ---plugins(扩展插件)
    ---skins(editor皮肤,2.3.1版有default、office 2003和silvers三种)
fckconfig.js
     fckeditor.js
     fckstyles.xml
     fcktemplates.xml
     ….其余文件删掉即可
解压FCKeditor 2.3.zip后得到如下目录结构:
FCKeditor_2.3
---docs
    ---api(api文档,介绍了类的功能和配置方法)
---src(java源文件)
---web
    ---_samples
    ---web-inf
         ---lib(存放FCKeditor-2.3.jar 和Apache文件上传开源项目commons-fileupload.jar)
        Web.xml
Build.xml
Readme.txt
    
3. demo
我的开发环境是eclipse3.1和Myeclipse4.1,jdk1.5,resin-pro-3.0.18
    3.1 建立一个webproject,命名为FCKeditor
    3.2 将FCKeditor_2.3.1下的editor文件夹和fckeditor.js,fckconfig.js,fckstyles.xml,fcktemplates.xml拷贝到FCKeditor/webroot下。
    3.3 FCKeditor.java 2.3解压后,把其中的web目录下的WEB-INF目录和copy到FCKeditor/webroot下(里面有commons- fileupload.jar, FCKeditor-2.3.jar,web.xml等几个文件), 再把其中的src目录下的FCKeditor.tld文件copy到FCKeditor/webroot/WEB-INF/下,_samples文件夹拷 贝到FCKeditor/webroot/下。
    3.4 修改web.xml和FCKeditor/webroot/editor/fckconfig.js:
<web-app>
        <display-name>FCKeditor Test Application</display-name>

        <servlet>
                <servlet-name>Connector</servlet-name>
                <servlet-class>com.fredck.FCKeditor.connector.ConnectorServlet</servlet-class>
                <init-param>
                        <param-name>baseDir</param-name>
将在FCKeditor/editor/下创建Image和Flash文件夹,用于存放上传文件
                        <param-value>/editor/</param-value>
                </init-param>
                <init-param>
                        <param-name>debug</param-name>
                        <param-value>false</param-value>调试时设为true
                </init-param>
                <load-on-startup>1</load-on-startup>
        </servlet>

        <servlet>
                <servlet-name>SimpleUploader</servlet-name>
                <servlet-class>com.fredck.FCKeditor.uploader.SimpleUploaderServlet</servlet-class>
                <init-param>
                 <param-name>baseDir</param-name>
将在FCKeditor/editor/下创建Image和Flash文件夹,用于存放上传文件
                        <param-value>/editor/</param-value>
                </init-param>
                <init-param>
                        <param-name>debug</param-name>
                        <param-value>true</param-value>调试时设为true
                </init-param>
                <init-param>
                        <param-name>enabled</param-name>
                        <param-value>true</param-value>修改成true
                </init-param>
                <init-param>
                        <param-name>AllowedExtensionsFile</param-name>
                        <param-value></param-value>
                </init-param>
                <init-param>
                        <param-name>DeniedExtensionsFile</param-name>
                        <param-value>php|php3|php5|phtml|asp|aspx|ascx|jsp|cfm|cfc|pl|bat|exe|dll|reg|cgi</param-value>
                </init-param>
                <init-param>
                        <param-name>AllowedExtensionsImage</param-name>
                        <param-value>jpg|gif|jpeg|png|bmp</param-value>
                </init-param>
                <init-param>
                        <param-name>DeniedExtensionsImage</param-name>
                        <param-value></param-value>
                </init-param>
                <init-param>
                        <param-name>AllowedExtensionsFlash</param-name>
                        <param-value>swf|fla</param-value>
                </init-param>
                <init-param>
                        <param-name>DeniedExtensionsFlash</param-name>
                        <param-value></param-value>
                </init-param>
                <load-on-startup>1</load-on-startup>
        </servlet>

        <servlet-mapping>
                <servlet-name>Connector</servlet-name>
和fckconfig.js的ImageBrowserURL等对应
                <url-pattern>/editor/filemanager/browser/default/connectors/jsp/connector</url-pattern>
        </servlet-mapping>

        <servlet-mapping>
                <servlet-name>SimpleUploader</servlet-name>
这里你可以按自己应用具体配置,需要和fckconfig.js的ImageUploadUrl等对应
                <url-pattern>/editor/upload.do</url-pattern>
        </servlet-mapping>

        
        <welcome-file-list>配置欢迎文件
                <welcome-file>_samples/index.jsp</welcome-file>
        </welcome-file-list>
        
        <taglib>
                <taglib-uri>/etag</taglib-uri>配置FCKeditor自定义标签
                <taglib-location>/web-inf/FCKeditor.tld</taglib-location>
        </taglib>

</web-app>
  

        修改 fckconfig.js中:
FCKConfig.DefaultLanguage = 'zh-cn' ; 修改默认语言为简体中文

    把FCKConfig.LinkBrowserURL等的值替换成以下内容:

FCKConfig.LinkBrowserURL = FCKConfig.BasePath + "filemanager/browser/default/browser.html?Connector=connectors/" + _FileBrowserLanguage + "/connector"

FCKConfig.ImageBrowserURL = FCKConfig.BasePath + "filemanager/browser/default/browser.html?Type=Image&Connector=connectors/" + _FileBrowserLanguage + "/connector";

FCKConfig.FlashBrowserURL = FCKConfig.BasePath + "filemanager/browser/default/browser.html?Type=Flash&Connector=connectors/" + _FileBrowserLanguage + "/connector";

FCKConfig.LinkUploadURL = FCKConfig.BasePath + "filemanager/upload/" + _QuickUploadLanguage + "/connector?Type=File";

FCKConfig.ImageUploadURL=FCKConfig.BasePath + "upload.do?Type=Image";

FCKConfig.FlashUploadURL=FCKConfig.BasePath+ "upload.do?Type=Flash";
Connector参数的值完全可以修改,只要和web.xml中配置一致即可
    3.5    有的例子说必须在FCKeditor/webroot/editor/下手工新建Image和Flash两个文件 夹,FCKeditor不会自己创建文件上传的文件夹,否则无法上传文件,将提示无权操作,在java应用下无需自己创 建,ConnectorServlet会在你第一次执行文件浏览时,根据url的type参数,判断baseDir下是否存在以type值为名字的文件 夹,不存在就创建它。

该问题,我遇到了,新建了Flash文件夹以后好了~~~~~~~~~~~

     3.6    在JbossHome\lib\endorsed 下的4个文件是xml解析器,整个endorsed文件夹复制到$JAVA_HOME\jre\lib\下面,其中xalan.jar放在ResinHome\lib\下 你的应用的web-inf\lib下

    3.7    启动resin,发布应用,浏览器键入http://localhost:8080/FCKeditor即看到 sample1页面,选择samplelist中的不同选项感受FCKeditor的功能吧,还不错。(没有使用过eclipse的同学直接将应用 coyp到服务器的deploy目录下就行,tomcat放在webapps下)

             对了,sample02等用自定义标签生成editor的时候得把所有的路径参数删除(用fckconfig.js中得配置即可)或修改成正确得路径!

 

 

4 、在编辑器域内可以使用Tab 键。(1 为是,0 为否)

FCKConfig.TabSpaces = 0 ; 改为FCKConfig.TabSpaces = 1 ;

5 、加上几种我们常用的字体的方法,例如:

修改

FCKConfig.FontNames = 'Arial;Comic Sans MS;Courier New;Tahoma;Times New Roman;Verdana' ;

FCKConfig.FontNames = ' 宋体 ; 黑体 ; 隶书 ; 楷体 _GB2312;Arial;Comic Sans MS;Courier New;Tahoma;Times New Roman;Verdana'

 

6 、编辑器域内默认的显示字体为 12px ,想要修改可以通过修改样式表来达到要求,打开 /editor/css/fck_editorarea.css ,修改 font-size 属性即可。如 font-size: 14px;

你可能感兴趣的:(java,应用服务器,servlet,项目管理,fckeditor)