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.AbstractTranslator;
08: import com.sun.portal.rewriter.JSFunctionSpec;
09: import com.sun.portal.rewriter.util.uri.DecoratedURI;
10: import com.sun.portal.rewriter.util.uri.PageSpec;
11: import com.sun.portal.rproxy.rewriter.util.SRAPConfigManager;
12: import com.sun.portal.rproxy.rewriter.util.uri.SRAPGatewayURI;
13:
14: public class SRAPTranslator extends AbstractTranslator {
15: private JSFunctionSpec srapJSFunctionSpec;
16:
17: private SRAPGatewayURI gatewayURI;
18:
19: public SRAPTranslator(final SRAPGatewayURI aGatewayURI,
20: final PageSpec aPageSpec) {
21: super (aPageSpec);
22: init(aGatewayURI);
23: }// constructor
24:
25: private void init(final SRAPGatewayURI aGatewayURI) {
26: gatewayURI = aGatewayURI;
27: srapJSFunctionSpec = new SRAPJSFunctionSpec(gatewayURI);
28: }// init()
29:
30: public JSFunctionSpec getJSFunctionSpec() {
31: return srapJSFunctionSpec;
32: }// getJSFunctionSpec()
33:
34: public String hook4Translate(final DecoratedURI aAbsoluteURI,
35: final DecoratedURI aTranslatedURI) {
36: if (needs2Translate(aAbsoluteURI) == false ||
37: // RFE:4651214, 4893960, 4892642
38: SRAPConfigManager.isNot2RewriteURI(aAbsoluteURI)) {
39: return aAbsoluteURI.getInputString();
40: }
41:
42: return SRAPTranslatorHelper.prefixGateway(gatewayURI,
43: aTranslatedURI);
44: }// hook4Translate()
45:
46: public SRAPGatewayURI getGatewayURI() {
47: return gatewayURI;
48: }// getGatewayURI()
49:
50: private boolean needs2Translate(final DecoratedURI aAbsoluteURI) {
51: String lLowerCaseProtocol = aAbsoluteURI.getProtocol()
52: .toLowerCase();
53: String lLowerCaseHost = aAbsoluteURI.getHost().toLowerCase();
54:
55: // don't rewrite if the protol is neither http or https or if
56: // it is local host.
57: if ( // Bug No: 4297833
58: !(lLowerCaseProtocol.equals("http") || lLowerCaseProtocol
59: .equals("https"))
60: || lLowerCaseHost.equals("localhost")
61: || lLowerCaseHost.equals("127.0.0.1")) {
62: return false;
63: }
64:
65: // check if the proxy is present or not..
66: if (SRAPConfigManager.isIntranet(lLowerCaseHost) == true) {
67: return true;
68: }
69:
70: /*
71: * irrespective of the domain rules, translate all the src links
72: * (provided the gateway runs in https and src in http - this avoids the
73: * the browser warning message) - Bug No:4496453
74: */
75: if (SRAPConfigManager.isRewriteSRCValue()
76: && getLookAheadInfo().getTagContext().isSRC()
77: && lLowerCaseProtocol.equals("http")
78: && gatewayURI.getProtocol().equalsIgnoreCase("https")) {
79: return true;
80: }
81:
82: return false;
83: }// needs2Translate()
84:
85: }// class SRAPTranslator
|