感謝google,感謝"webwork2.2.2的富文本編輯器的不完美解決方法"一文,感謝李李。當(dāng)然,最應(yīng)該感謝的是開(kāi)源(刨源代碼刨出來(lái)的)。
1、解決/webwork/*的路徑問(wèn)題
解決辦法見(jiàn)“http://www.tkk7.com/mmwy/archive/2006/08/18/64234.html”
BTW:也可以象“不完美解決方法”一文中描述的一樣,設(shè)webwork.serve.static=false,將static/下的東西拷至/webwork目錄下。
2、重寫(xiě)(繼承)DefaultRichtexteditorConnector類,解決無(wú)法在windows平臺(tái)上創(chuàng)建目錄的問(wèn)題
?1
public
?
class
?RichtexteditorConnector?
extends
?DefaultRichtexteditorConnector?
{
?2
??
/**?*/
/**
?3
???*?解決無(wú)法在windows平臺(tái)上創(chuàng)建目錄的問(wèn)題
?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,解決上傳路徑自定義問(wèn)題(actualServerPath參數(shù),默認(rèn)的使用DefaultRichtexteditorConnector類中protected String _actualServerPath = "/com/opensymphony/webwork/static/richtexteditor/data/";的定義),解決獲取上傳文件url路徑問(wèn)題(默認(rèn)的使用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端口的問(wèn)題
順著源碼一直跟進(jìn),首先是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
????}
再跟進(jìn)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
因此,解決這個(gè)問(wèn)題的方法很簡(jiǎn)單,只要在webwork.properties中設(shè)webwork.url.http.port = 8080即可。
5、語(yǔ)言問(wèn)題
RichTextEditor標(biāo)記autoDetectLanguage默認(rèn)值為true,在中文環(huán)境下使用/editor/lang/zh.js,顯示繁體中文字符,而簡(jiǎn)體中文應(yīng)該使用zh-cn.js,因此,應(yīng)設(shè)置defaultLanguage="zh-cn"。
1
????????????
<
@ww
.richtexteditor
2
????????????????theme
="simple"
3
????????????????defaultLanguage
="zh-cn"
4
????????????????width
="750"
5
????????????????height
="500"
6
????????????????name
="description4"
?
/>
?
?