感谢google,感谢"webwork2.2.2的富文本编辑器的不完美解决方法"一文,感谢李李。当然,最应该感谢的是开源(刨源代码刨出来的)。
1、解决/webwork/*的路径问题
解决办法见“http://www.blogjava.net/mmwy/archive/2006/08/18/64234.html”
BTW:也可以象“不完美解决方法”一文中描述的一样,设webwork.serve.static=false,将static/下的东西拷至/webwork目录下。
2、重写(继承)DefaultRichtexteditorConnector类,解决无法在windows平台上创建目录的问题
1
public
class
RichtexteditorConnector
extends
DefaultRichtexteditorConnector
{
2
/** */
/**
3
* 解决无法在windows平台上创建目录的问题
4
* overriding methods
5
* (non-Javadoc)
6
*
@see
com.opensymphony.webwork.components.DefaultRichtexteditorConnector#calculateActualServerPath(java.lang.String, java.lang.String, java.lang.String)
7
*/
8
protected
String calculateActualServerPath(String actualServerPath,
9
String type, String folderPath)
throws
Exception
{
10
String path
=
StringUtils.replaceChars(
"
file:///
"
11
+
servletContext.getRealPath(
"
/
"
+
actualServerPath),
'
\\
'
,
'
/
'
);
12
makeDirIfNotExists(path);
13
path
=
path.endsWith(
"
/
"
)
14
?
path
15
: path
+
"
/
"
;
16
return
path
+
type
+
folderPath;
17
}
18
19
private
ServletContext servletContext;
20
21
public
void
setServletContext(ServletContext servletContext)
{
22
this
.servletContext
=
servletContext;
23
}
24
}
3、配置webwork.xml,解决上传路径自定义问题(actualServerPath参数,默认的使用DefaultRichtexteditorConnector类中protected String _actualServerPath = "/com/opensymphony/webwork/static/richtexteditor/data/";的定义),解决获取上传文件url路径问题(默认的使用AbstractRichtexteditorConnector类中String _serverPath = "/webwork/richtexteditor/data/";的定义)
1
<
package
2
name
="richtexteditor-browse"
3
extends
="webwork-default"
4
namespace
="/webwork/richtexteditor/editor/filemanager/browser/default/connectors/jsp"
>
5
<
action
6
name
="connector"
7
class
="com.mmwy.weblogic_sitemesh.util.RichtexteditorConnector"
8
method
="browse"
>
9
<
result
10
name
="getFolders"
11
type
="richtexteditorGetFolders"
/>
12
<
result
13
name
="getFoldersAndFiles"
14
type
="richtexteditorGetFoldersAndFiles"
/>
15
<
result
16
name
="createFolder"
17
type
="richtexteditorCreateFolder"
/>
18
<
result
19
name
="fileUpload"
20
type
="richtexteditorFileUpload"
/>
21
<
param
name
="actualServerPath"
>
/upload/
</
param
>
22
<
param
name
="serverPath"
>
/upload/
</
param
>
23
</
action
>
24
</
package
>
25
26
<
package
27
name
="richtexteditor-upload"
28
extends
="webwork-default"
29
namespace
="/webwork/richtexteditor/editor/filemanager/upload"
>
30
<
action
31
name
="uploader"
32
class
="com.mmwy.weblogic_sitemesh.util.RichtexteditorConnector"
33
method
="upload"
>
34
<
result
name
="richtexteditorFileUpload"
/>
35
<
param
name
="actualServerPath"
>
/upload/
</
param
>
36
<
param
name
="serverPath"
>
/upload/
</
param
>
37
</
action
>
38
</
package
>
注意:serverPath路径必须有后面的"/"。
4、解决获取上传文件url只能使用80端口的问题
顺着源码一直跟进,首先是DefaultRichtexteditorConnector类:
1
protected
String calculateServerPath(String serverPath, String folderPath, String type)
throws
Exception
{
2
//
return UrlHelper.buildUrl(serverPath, _request, _response, null, _request.getScheme(), true, true, true);
3
return
UrlHelper.buildUrl(serverPath
+
type
+
folderPath, _request, _response,
new
HashMap(), _request.getScheme(),
true
,
true
,
true
);
4
}
再跟进UrlHelper.buildUrl方法
1
public
static
String buildUrl(String action, HttpServletRequest request, HttpServletResponse response, Map params, String scheme,
boolean
includeContext,
boolean
encodeResult,
boolean
forceAddSchemeHostAndPort)
{
2
StringBuffer link
=
new
StringBuffer();
3
4
boolean
changedScheme
=
false
;
5
6
int
httpPort
=
DEFAULT_HTTP_PORT;
7
8
try
{
9
httpPort
=
Integer.parseInt((String) Configuration.get(WebWorkConstants.WEBWORK_URL_HTTP_PORT));
10
}
catch
(Exception ex)
{
11
}
12
13
int
httpsPort
=
DEFAULT_HTTPS_PORT;
14
15
try
{
16
httpsPort
=
Integer.parseInt((String) Configuration.get(WebWorkConstants.WEBWORK_URL_HTTPS_PORT));
17
}
catch
(Exception ex)
{
18
}
19
因此,解决这个问题的方法很简单,只要在webwork.properties中设webwork.url.http.port = 8080即可。
5、语言问题
RichTextEditor标记autoDetectLanguage默认值为true,在中文环境下使用/editor/lang/zh.js,显示繁体中文字符,而简体中文应该使用zh-cn.js,因此,应设置defaultLanguage="zh-cn"。
1
<
@ww
.richtexteditor
2
theme
="simple"
3
defaultLanguage
="zh-cn"
4
width
="750"
5
height
="500"
6
name
="description4"
/>