001: /*
002: * GatewayListIntranetInfo.java
003: *
004: * Created on May 16, 2003, 1:57 PM
005: */
006:
007: package com.sun.portal.util;
008:
009: import java.util.HashMap;
010: import java.util.List;
011: import java.util.logging.Logger;
012:
013: import com.sun.portal.log.common.PortalLogger;
014: import com.sun.portal.rproxy.server.GatewayContext;
015: import com.sun.portal.rproxy.server.GatewayContextFactory;
016:
017: /**
018: *
019: * @author mm132998
020: * @version
021: */
022: public class GatewayListIntranetInfo implements IntranetInfo {
023:
024: private static final char PIPE = '|';
025:
026: private static final char SPACE = ' ';
027:
028: private static final char DOT = '.';
029:
030: private static final String STAR_DOT_STRING = "*.";
031:
032: private static final String STAR_STRING = "*";
033:
034: private final HashMap proxyMap = new HashMap();
035:
036: private String defaultDomain;
037:
038: private String defaultSubDomainAndDomain;
039:
040: private static Logger logger = PortalLogger
041: .getLogger(GatewayListIntranetInfo.class);
042:
043: private void initDefaultDomainSubDomain() {
044:
045: GatewayContext gatewayContext = GatewayContextFactory
046: .getGatewayContext();
047:
048: String defaultDomainSubDomain = gatewayContext
049: .getDefaultDomainAndSubDomain(); // GatewayProfile.getString(DEFAULT_DOMAIN_AND_SUBDOMAINS,"").toLowerCase();
050:
051: String[] splitEntry = StringHelper.split(
052: defaultDomainSubDomain, PIPE);
053:
054: if (splitEntry.length == 0) {
055: defaultDomain = "";
056: defaultSubDomainAndDomain = "";
057: // logger.severe("The default sub-domain / domain not specified in
058: // gateway profile!");
059: logger.severe("PSSR_CSPU016");
060: } else if (splitEntry.length == 1) {
061: defaultDomain = DOT + splitEntry[0];
062: defaultSubDomainAndDomain = defaultDomain;
063: } else {
064: defaultDomain = DOT + splitEntry[0];
065: defaultSubDomainAndDomain = DOT + splitEntry[1]
066: + defaultDomain;
067: }
068: }
069:
070: private void populateProxyList(String entry) {
071: String[] splitEntry = StringHelper.split(entry, PIPE);
072: if (splitEntry.length == 0) {
073: return;
074: }
075:
076: String[] domainEntry = StringHelper.split(splitEntry[0], SPACE);
077: String domainName = (domainEntry.length > 0) ? domainEntry[0]
078: .toLowerCase() : null;
079:
080: String domainProxy = (domainEntry.length > 1) ? domainEntry[1]
081: : null;
082:
083: if (proxyMap.get(domainName) == null) {
084: proxyMap.put(domainName, domainProxy);
085: }
086:
087: for (int i = 1; i < splitEntry.length; i++) {
088: String[] temp = StringHelper.split(splitEntry[i], SPACE);
089: if (temp.length == 0) {
090: continue;
091: }
092:
093: String subDomainName = temp[0].toLowerCase();
094:
095: if (proxyMap.get(subDomainName) == null) {
096: String subDomainProxy = (temp.length > 1) ? temp[1]
097: : (subDomainName.equals(STAR_STRING) ? null
098: : domainProxy);
099:
100: proxyMap.put(subDomainName + DOT + domainName,
101: subDomainProxy);
102: }
103: }
104: }
105:
106: private String getFQDNEntry(String host) {
107: String entry = getMapEntry(host);
108: if (entry != null) {
109: return entry;
110: }
111:
112: int index = host.indexOf(DOT);
113: String newHost = null;
114: if (index == -1) {
115: newHost = host + defaultSubDomainAndDomain;
116: }/*
117: * else if (index == host.lastIndexOf(DOT)) { newHost = host +
118: * defaultDomain; }
119: */
120:
121: return (newHost == null) ? null : getMapEntry(newHost);
122:
123: }
124:
125: private String getMapEntry(String host) {
126:
127: int index = 0;
128: do {
129: if (proxyMap.containsKey((host))) {
130: return host;
131: }
132:
133: index = host.indexOf(DOT);
134: host = host.substring(index + 1);
135:
136: String starHost = STAR_DOT_STRING + host;
137: if (proxyMap.containsKey(starHost)) {
138: return starHost;
139: }
140:
141: } while (index != -1);
142:
143: return null;
144: }
145:
146: public String getWebProxy(String protocol, String host) {
147: String entry = getFQDNEntry(host);
148:
149: return (entry == null) ? (String) proxyMap.get(STAR_STRING)
150: : (String) proxyMap.get(entry);
151: }
152:
153: public boolean containHost(String host) {
154: String entry = getFQDNEntry(host);
155: return (entry != null);
156: }
157:
158: /** Creates new GatewayListIntranetInfo */
159: public GatewayListIntranetInfo() {
160:
161: GatewayContext gatewayContext = GatewayContextFactory
162: .getGatewayContext();
163: List domainsAndSubDomainsList = gatewayContext
164: .getDomainsAndSubDomainsList();
165:
166: for (int i = 0; i < domainsAndSubDomainsList.size(); i++) {
167: populateProxyList(domainsAndSubDomainsList.get(i)
168: .toString());
169: }
170: initDefaultDomainSubDomain();
171: }
172: }
|