Sun Java System Portal Server Secure Remote Access 7.2 管理指南

函数参数

值需重写的函数参数分为以下 4 类:

一般语法

<Function name="functionName " paramPatterns="y,y," [type="URL|EXPRESSION|DHTML|DJS" source="*"]/>

其中

name 是 JavaScript 函数的名称(强制项)

paramPatterns 指定需要重写的参数(强制项)

y y 的位置指示需要重写的参数。例如,在语法中,第一个参数需要重写,但不能重写第二个参数

type 指定该参数所需值的类型(可选项,默认值是 EXPRESSION 类型)

source 是页的源 URI(可选项,默认值是 *,指在任何页中)

URL 参数

函数将该参数视为一个字符串并且该字符串可以作为 URL 对待。

本节分为下列各小部分:

URL 参数语法

<Function name="functionName" paramPatterns="y,," type="URL" [source="*"]/>

其中

name 是具有 URL 类型参数的函数的名称(强制项)

paramPatterns 指定需要重写的参数(强制项)

y y 的位置指示需要重写的参数。例如,在语法中,第一个参数需要重写,但不能重写第二个参数

type 是函数的类型(强制项,其值必须是 URL)

source 是具有该函数调用的页的 URL(可选项,默认值是 *,指在任何 URL 中)

URL 参数示例

假定页的基 URL 为:

http://abc.sesta.com/test/rewriter/test1/jscript/test2/page.html

页内容

<script language="JavaScript">
<!--
function test(one,two,three){
alert(one + "##" + two + "##" +three);
}
test("/test.html","../test.html","123");
window.open("/index.html","gen",width=500,height=500);
//-->
</SCRIPT>

规则

<Function name="URL" name="test" paramPatterns="y,y,"/>
<Function name="URL" name="window.open" paramPatterns="y,,,"/>

输出

<SCRIPT language="JavaScript">
<!--
function test(one,two,three) {
alert(one + "##" + two + "##" +three);
}
test("gateway-URL/http://abc.sesta.com/test.html","
gateway-URL/http://abc.sesta.com/test/rewriter/
test1/jscript/test.html","123");window.open("gateway-URL/
http://abc.sesta.com/index.html","gen",width=500,height=500);
//-->
</SCRIPT>

描述

第一项规则指定需要重写名为 test 的函数中的前两个参数。因此会重写 test 函数的前两个参数。第二项规则指定需要重写 window.open 函数的第一个参数。会在 window.open 函数中的 URL 前面加上网关 URL 以及包含函数参数的页的基 URL。

EXPRESSION 参数

这些参数接受表达式值,表达式计算结果为 URL。

本节分为下列各小部分:

EXPRESSION 参数语法

<Function name="functionName" paramPatterns="y" [type="EXPRESSION" source="*"]/>

其中

name 是函数的名称(强制项)

paramPatterns 指定需要重写的参数(强制项)

y y 的位置指示需要重写的函数参数。在上述语法中,只会重写第一个参数

type 指定 EXPRESSION 值(可选项)

source 是其中调用了该函数的页的 URI

EXPRESSION 参数示例

假定页的基 URL 为:

http://abc.sesta.com/dir1/dir2/page.html

页内容

<script language="JavaScript">
<!--
function jstest2(){
return ".html";
}
function jstest1(one){
return one;
}
var dir="/images/test"
var test1=jstest1(dir+"/test"+jstest2());
document.write("<a HREF="+test1+">TEST</a>");
alert(test1);
//-->
</SCRIPT>

规则

<Function type="EXPRESSION" name="jstest1" paramPatterns="y"/>
或
<Function name="jstest1" paramPatterns="y"/>

输出

<script language="JavaScript">
<!--
function jstest2(){
return ".html";
}
function jstest1(one){
return one;
}
var dir="/images/test"
var test1=jstest1(psSRAPRewriter_convert_expression(dir+"/test"+jstest2()));
document.write("<a HREF="+test1+">TEST</a>");
alert(test1);
//-->
</SCRIPT>

描述

此规则将 jstest1 函数的第一个参数视为 EXPRESSION 函数参数,以此来指定需要重写该参数。在示例页内容中,第一个参数是一个表达式,只会在运行时对其进行求值。重写器会在该表达式前加上 psSRAPRewriter_convert_expression 函数。此表达式要进行求值,并且 psSRAPRewriter_convert_expression 函数会在运行时重写输出结果。


注 –

在上述示例中,不需要在 JavaScript 变量规则中包含 test1jstest1 的函数规则会负责执行重写工作。


DHTML 参数

值为 HTML 的函数参数

本机 JavaScript 方法(如可动态生成 HTML 页的 document.write())归属于这一类别。

本节分为下列各小部分:

DHTML 参数语法

<Function name="functionName" paramPatterns="y" type="DHTML" [source="*"]/>

其中

name 是函数的名称

paramPatterns 指定需要重写的参数(强制项)

y y 的位置指示需要重写的函数参数。在上述语法中,只会重写第一个参数

DHTML 参数示例

假定页的基 URL 为:

http://xyz.siroe.com/test/rewriter/test1/jscript/JSFUNC/page.html

页内容

<script>
<!--
document.write(\q<a href="/index.html">write</a><BR>\q)
document.writeln(\q<a href="index.html">writeln</a><BR>\q)
document.write("http://abc.sesta.com/index.html<BR>")
document.writeln("http://abc.sesta.com/index.html<BR>")
//-->
</SCRIPT>

规则

<Function name="DHTML" name="document.write" paramPatterns="y"/>
<Function name="DHTML" name="document.writeln" paramPatterns="y"/>
<Attribute name="href"/>

输出

<SCRIPT>
<!--
document.write(\q<a href="gateway-URL/
http://xyz.siroe.com/index.html">write</a><BR>\q)
document.writeln(\q<a href="gateway-URL/
http://xyz.siroe.com/test/rewriter/test1/
jscript/JSFUNC/index.html">writeln</a><BR>\q)
document.write("http://abc.sesta.com/index.html<BR>")
document.writeln("http://abc.sesta.com/index.html<BR>")
//-->
</SCRIPT>

描述

第一项规则指定需要重写函数 document.write 中的第一个参数。第二项规则指定需要重写函数 document.writeln 中的第一个参数。第三项规则是一项简单的 HTML 规则,它指定需要重写名为 href 的所有属性。在示例中,DHTML 参数规则将会确定函数中需要重写的参数。然后会应用 HTML 属性规则来实际重写已确定的参数。

DJS 参数

值为 JavaScript 的函数参数。

本节分为下列各小部分:

DJS 参数语法

<Function name="functionName" paramPatterns="y" type="DJS" [source="*"]/>

其中

name 是含有一个参数 DJS 的函数的名称(强制项)

paramPatterns 指定上述函数中的哪个参数是 DJS(强制项)

y y 的位置指示需要重写的函数参数。在上述语法中,只会重写第一个参数

type 为 DJS(强制项)

source 是页的 URI(可选项,默认值为 *,指任何 URI)

DJS 参数示例

假定页的基 URL 为:

http://abc.sesta.com/page.html

页内容

<script>
menu.addItem(new NavBarMenuItem("All Available Information","JavaScript:top.location=\qhttp://abc.sesta.com\q"));
</script>

规则

<Function name="DJS" name="NavBarMenuItem" paramPatterns=",y"/>
<Variable name="URL">top.location</Variable>

输出

<script>
menu.addItem(new NavBarMenuItem("All Available Information",
"JavaScript:top.location=\qgateway-URL/
http://abc.sesta.com\q"));
</script>

描述

第一项规则指定需要重写函数 NavBarMenuItem 中的第二个包含 JavaScript 的参数。在 JavaScript 中,变量 top.location 也需要重写。该变量是使用第二项规则来重写的。