/*
* Copyright 2001 Sun Microsystems, Inc. All rights reserved.
* PROPRIETARY/CONFIDENTIAL. Use of this product is subject to license terms.
*/
package com.sun.portal.desktop.context;
import java.util.Set;
import java.util.HashMap;
import java.util.Map;
import java.util.Locale;
import java.util.logging.Logger;
import java.util.logging.Level;
import javax.servlet.http.HttpServletRequest;
import com.iplanet.services.cdm.Client;
import com.iplanet.services.cdm.ClientException;
import com.iplanet.am.util.AMClientDetector;
import com.sun.portal.desktop.encode.EncoderClassNames;
import com.sun.portal.desktop.ROC;
import com.sun.portal.log.common.PortalLogger;
class DSAMEClientContext implements ClientContext {
protected AMClientDetector cd = null;
private static final String CLIENT_OBJECT = "clientObject.";
private static final String DSAME_KEY_COOKIE_SUPPORT = "cookieSupport";
private static final String DSAME_COOKIE_SUPPORT_TRUE = "true";
private static final String DSAME_COOKIE_SUPPORT_FALSE = "false";
private static Map AUTHLESS_STATES = null;
private static DesktopAppContext dac = null;
static {
AUTHLESS_STATES = new HashMap();
AUTHLESS_STATES.put("none", new Short(AUTHLESS_STATE_NONE));
AUTHLESS_STATES.put("server", new Short(AUTHLESS_STATE_SERVER));
AUTHLESS_STATES.put("client", new Short(AUTHLESS_STATE_CLIENT));
dac = DesktopAppContextThreadLocalizer.get();
}
// Create a logger for this class
private static Logger debugLogger = PortalLogger.getLogger (DSAMEClientContext.class);
public DSAMEClientContext() {
// nothing
}
public void init() {
cd = new AMClientDetector();
}
private Client getClient(String clientType) {
String clientObjectKey = CLIENT_OBJECT + clientType;
Client client = (Client)ROC.getObject(clientObjectKey);
if (client == null) {
try {
client = Client.getInstance(clientType);
}
catch (ClientException c) {
throw new ContextError("DSAMEDPContext.init(): can not get client instance", c);
}
ROC.setObject(clientObjectKey, client);
}
return client;
}
public String getContentType(String clientType) {
return getClientTypeProperty(clientType, "contentType");
}
public String getClientPath(String clientType) {
return getClientTypeProperty(clientType, "filePath");
}
public String getClientType(HttpServletRequest req) {
return cd.getClientType(req);
}
public String getDefaultClientType() {
Client cli = Client.getDefaultInstance();
return cli.getClientType();
}
public String getClientTypeProperty(String clientType, String key) {
Client client = getClient(clientType);
return client.getProperty(key);
}
public Set getClientTypeProperties(String clientType, String key) {
Client client = getClient(clientType);
Set properties = client.getProperties(key);
return properties;
}
public String getCharset(String clientType, Locale locale) {
Client client = getClient(clientType);
return client.getCharset(locale);
}
public short getCookieSupport(String clientType) {
Client client = getClient(clientType);
String cookieSupport = client.getProperty(DSAME_KEY_COOKIE_SUPPORT);
short retval = COOKIE_SUPPORT_DETECT;
debugLogger.log(Level.FINE, "PSDT_CSPDC0003", cookieSupport);
//
// support for cookieDetect
//
if (cookieSupport != null) {
if (cookieSupport.equalsIgnoreCase(DSAME_COOKIE_SUPPORT_TRUE)) {
retval = COOKIE_SUPPORT_TRUE;
} else if (cookieSupport.equalsIgnoreCase(DSAME_COOKIE_SUPPORT_FALSE)) {
retval = COOKIE_SUPPORT_FALSE;
} else {
retval = COOKIE_SUPPORT_DETECT;
}
}
return retval;
}
private short getDefaultAuthlessState(String clientType) {
boolean genericHTML = false;
String property = getClientTypeProperty(clientType, "genericHTML");
if (property != null) {
genericHTML = property.equals("true");
} else if (clientType.equals("genericHTML")) {
genericHTML = true;
}
//
// only "html" devices default to having authless state.
// non-html devices default to having no authless state.
//
if (genericHTML) {
return AUTHLESS_STATE_CLIENT;
} else {
return AUTHLESS_STATE_NONE;
}
}
public short getAuthlessState(String clientType) {
Client client = getClient(clientType);
String authlessState = client.getProperty("authlessState");
if (authlessState == null || authlessState.length() == 0) {
return getDefaultAuthlessState(clientType);
}
Short as = (Short)AUTHLESS_STATES.get(authlessState);
if (as == null) {
return getDefaultAuthlessState(clientType);
}
return as.shortValue();
}
public String getEncoderClassName(String clientType) {
Client client = getClient(clientType);
String cn = client.getProperty("encoderClassName");
if (cn != null && cn.length() != 0) {
return cn;
} else {
//
// html is the default, if no encoding type
// is defined
//
return EncoderClassNames.ENCODER_DEFAULT;
}
}
}
|