001: /*
002: * Copyright 2001 Sun Microsystems, Inc. All rights reserved.
003: * PROPRIETARY/CONFIDENTIAL. Use of this product is subject to license terms.
004: */
005: package com.sun.portal.desktop.context;
006:
007: import java.util.Set;
008: import java.util.HashMap;
009: import java.util.Map;
010: import java.util.Locale;
011: import java.util.logging.Logger;
012: import java.util.logging.Level;
013:
014: import javax.servlet.http.HttpServletRequest;
015:
016: import com.iplanet.services.cdm.Client;
017: import com.iplanet.services.cdm.ClientException;
018:
019: import com.iplanet.am.util.AMClientDetector;
020:
021: import com.sun.portal.desktop.encode.EncoderClassNames;
022:
023: import com.sun.portal.desktop.ROC;
024: import com.sun.portal.log.common.PortalLogger;
025:
026: class DSAMEClientContext implements ClientContext {
027: protected AMClientDetector cd = null;
028:
029: private static final String CLIENT_OBJECT = "clientObject.";
030:
031: private static final String DSAME_KEY_COOKIE_SUPPORT = "cookieSupport";
032: private static final String DSAME_COOKIE_SUPPORT_TRUE = "true";
033: private static final String DSAME_COOKIE_SUPPORT_FALSE = "false";
034:
035: private static Map AUTHLESS_STATES = null;
036: private static DesktopAppContext dac = null;
037:
038: static {
039: AUTHLESS_STATES = new HashMap();
040: AUTHLESS_STATES.put("none", new Short(AUTHLESS_STATE_NONE));
041: AUTHLESS_STATES.put("server", new Short(AUTHLESS_STATE_SERVER));
042: AUTHLESS_STATES.put("client", new Short(AUTHLESS_STATE_CLIENT));
043:
044: dac = DesktopAppContextThreadLocalizer.get();
045: }
046:
047: // Create a logger for this class
048: private static Logger debugLogger = PortalLogger
049: .getLogger(DSAMEClientContext.class);
050:
051: public DSAMEClientContext() {
052: // nothing
053: }
054:
055: public void init() {
056: cd = new AMClientDetector();
057: }
058:
059: private Client getClient(String clientType) {
060: String clientObjectKey = CLIENT_OBJECT + clientType;
061: Client client = (Client) ROC.getObject(clientObjectKey);
062:
063: if (client == null) {
064: try {
065: client = Client.getInstance(clientType);
066: } catch (ClientException c) {
067: throw new ContextError(
068: "DSAMEDPContext.init(): can not get client instance",
069: c);
070: }
071: ROC.setObject(clientObjectKey, client);
072: }
073:
074: return client;
075: }
076:
077: public String getContentType(String clientType) {
078: return getClientTypeProperty(clientType, "contentType");
079: }
080:
081: public String getClientPath(String clientType) {
082: return getClientTypeProperty(clientType, "filePath");
083: }
084:
085: public String getClientType(HttpServletRequest req) {
086: return cd.getClientType(req);
087: }
088:
089: public String getDefaultClientType() {
090: Client cli = Client.getDefaultInstance();
091: return cli.getClientType();
092: }
093:
094: public String getClientTypeProperty(String clientType, String key) {
095:
096: Client client = getClient(clientType);
097: return client.getProperty(key);
098: }
099:
100: public Set getClientTypeProperties(String clientType, String key) {
101:
102: Client client = getClient(clientType);
103: Set properties = client.getProperties(key);
104:
105: return properties;
106: }
107:
108: public String getCharset(String clientType, Locale locale) {
109:
110: Client client = getClient(clientType);
111: return client.getCharset(locale);
112: }
113:
114: public short getCookieSupport(String clientType) {
115: Client client = getClient(clientType);
116: String cookieSupport = client
117: .getProperty(DSAME_KEY_COOKIE_SUPPORT);
118: short retval = COOKIE_SUPPORT_DETECT;
119:
120: debugLogger.log(Level.FINE, "PSDT_CSPDC0003", cookieSupport);
121:
122: //
123: // support for cookieDetect
124: //
125: if (cookieSupport != null) {
126: if (cookieSupport
127: .equalsIgnoreCase(DSAME_COOKIE_SUPPORT_TRUE)) {
128: retval = COOKIE_SUPPORT_TRUE;
129: } else if (cookieSupport
130: .equalsIgnoreCase(DSAME_COOKIE_SUPPORT_FALSE)) {
131: retval = COOKIE_SUPPORT_FALSE;
132: } else {
133: retval = COOKIE_SUPPORT_DETECT;
134: }
135: }
136: return retval;
137: }
138:
139: private short getDefaultAuthlessState(String clientType) {
140: boolean genericHTML = false;
141:
142: String property = getClientTypeProperty(clientType,
143: "genericHTML");
144: if (property != null) {
145: genericHTML = property.equals("true");
146: } else if (clientType.equals("genericHTML")) {
147: genericHTML = true;
148: }
149:
150: //
151: // only "html" devices default to having authless state.
152: // non-html devices default to having no authless state.
153: //
154:
155: if (genericHTML) {
156: return AUTHLESS_STATE_CLIENT;
157: } else {
158: return AUTHLESS_STATE_NONE;
159: }
160: }
161:
162: public short getAuthlessState(String clientType) {
163: Client client = getClient(clientType);
164: String authlessState = client.getProperty("authlessState");
165: if (authlessState == null || authlessState.length() == 0) {
166: return getDefaultAuthlessState(clientType);
167: }
168:
169: Short as = (Short) AUTHLESS_STATES.get(authlessState);
170: if (as == null) {
171: return getDefaultAuthlessState(clientType);
172: }
173:
174: return as.shortValue();
175: }
176:
177: public String getEncoderClassName(String clientType) {
178: Client client = getClient(clientType);
179: String cn = client.getProperty("encoderClassName");
180:
181: if (cn != null && cn.length() != 0) {
182: return cn;
183: } else {
184: //
185: // html is the default, if no encoding type
186: // is defined
187: //
188: return EncoderClassNames.ENCODER_DEFAULT;
189: }
190: }
191: }
|