01: /*
02: * Copyright 2001 Sun Microsystems, Inc. All rights reserved.
03: * PROPRIETARY/CONFIDENTIAL. Use of this product is subject to license terms.
04: */
05: package com.sun.portal.rproxy.rewriter;
06:
07: import com.sun.portal.rewriter.AbsoluteJSFunctionSpec;
08: import com.sun.portal.rewriter.JSFunctionSpec;
09: import com.sun.portal.rewriter.util.Resource;
10: import com.sun.portal.rewriter.util.StringHelper;
11: import com.sun.portal.rewriter.util.uri.PageSpec;
12: import com.sun.portal.rproxy.rewriter.util.uri.SRAPGatewayURI;
13:
14: public class SRAPJSFunctionSpec extends AbsoluteJSFunctionSpec {
15: public static final String INSERT_GATEWAY_URI_PATTERN = "$INSERT_GATEWAY_URI$";
16:
17: private static final String SRAP_EXPRESSION_FUNCTION_DEFINITION = Resource
18: .read(
19: SRAPRewriterModule.RESOURCE_CONVERT_EXPRESSTION_FUNCTION_LOCATION,
20: SRAPJSFunctionSpec.class).trim();
21:
22: private static final String SRAP_SYSTEM_FUNCTION_DEFINITION = Resource
23: .read(
24: SRAPRewriterModule.RESOURCE_CONVERT_SYSTEM_FUNCTION_LOCATION)
25: .trim();
26:
27: private final SRAPGatewayURI gatewayURI;
28:
29: public SRAPJSFunctionSpec(final SRAPGatewayURI aGatewayURI) {
30: super (SRAP_EXPRESSION_FUNCTION_DEFINITION,
31: SRAP_SYSTEM_FUNCTION_DEFINITION);
32: gatewayURI = aGatewayURI;
33: }// constructor()
34:
35: protected String makeExpressionFunction(final PageSpec aPageSpec,
36: final String aDefinition) {
37: return putGatewayURI(super .makeExpressionFunction(aPageSpec,
38: aDefinition));
39: }// makeExpressionFunction()
40:
41: protected String makeSystemFunction(final PageSpec aPageSpec,
42: final String aDefinition) {
43: return putGatewayURI(super .makeSystemFunction(aPageSpec,
44: aDefinition));
45: }// makeSystemFunction()
46:
47: protected String putGatewayURI(String lFunc) {
48: lFunc = StringHelper.searchAndReplace(lFunc,
49: INSERT_GATEWAY_URI_PATTERN, gatewayURI
50: .toReverseProxyForm());
51: return lFunc;
52: }// putGatewayURI()
53:
54: public static void main(String[] args) throws Exception {
55: final PageSpec testURISpec = new PageSpec(
56: "http://rajanagendra.sun.com/Base/Raja/raja.html?name=raja");
57:
58: final JSFunctionSpec jsFunctionSpec = new SRAPJSFunctionSpec(
59: new SRAPGatewayURI("https://gateway.sun.com"));
60:
61: System.out.println("Value of JS_CONVERT_FUNCTION\n"
62: + jsFunctionSpec
63: .getExpressionFunctionDefination(testURISpec));
64: System.out.println("Value of JS_CONVERT_WINDOW_PATH : \n"
65: + jsFunctionSpec
66: .getSystemFunctionDefination(testURISpec));
67: }// main()
68:
69: }// SRAPJSFunctionSpec
|