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 javax.servlet.http.HttpServletRequest;
008:
009: import java.util.Properties;
010: import java.util.Set;
011: import java.util.Locale;
012:
013: import java.io.File;
014: import java.io.IOException;
015: import java.io.FileInputStream;
016: import java.io.FileOutputStream;
017: import com.iplanet.sso.SSOToken;
018:
019: /**
020: * This class implements the DesktopContext interface using Java
021: * properties files.
022: */
023:
024: public class PropertiesServiceContext implements ServiceContext {
025: protected Properties properties = null;
026: protected String filename = null;
027:
028: protected static final String CONTAINERPROVIDERCONTEXTCLASSNAME_KEY = "containerProviderContextClassName";
029: protected static final String PROVIDERMANAGERCONTEXTCLASSNAME_KEY = "providerManagerContextClassName";
030: protected static final String DPCONTEXTCLASSNAME_KEY = "dpContextClassName";
031: protected static final String DPUSERCONTEXTCLASSNAME_KEY = "dpUserContextClassName";
032: protected static final String DEBUGCONTEXTCLASSNAME_KEY = "debugContextClassName";
033: protected static final String SESSIONCONTEXTCLASSNAME_KEY = "sessionContextClassName";
034: protected static final String TEMPLATECONTEXTCLASSNAME_KEY = "templateContextClassName";
035: protected static final String CLIENTCONTEXTCLASSNAME_KEY = "clientContextClassName";
036: protected static final String PROPERTIESCONTEXTCLASSNAME_KEY = "propertiesContextClassName";
037:
038: protected static final String LOCALESTRING_KEY = "localeString";
039: protected static final String NOSESSIONURL_KEY = "noSessionURL";
040: protected static final String SESSIONRETURNURLPARAMNAME_KEY = "sessionReturnURLParamName";
041: protected static final String DESKTOPURL_KEY = "desktopURL";
042: protected static final String LOGOUTURL_KEY = "logoutURL";
043: protected static final String LOGINURL_KEY = "loginURL";
044: protected static final String TYPE_KEY = "type";
045: protected static final String DEFAULTCHANNELNAME_KEY = "defaultChannelName";
046: protected static final String EDITPROVIDERCONTAINERNAME_KEY = "editProviderContainerName";
047: protected static final String TEMPLATEBASEDIR_KEY = "templateBaseDir";
048:
049: protected static final String DEFAULT_FILENAME = "/etc/opt/SUNWportal/service-context.properties";
050:
051: public PropertiesServiceContext() {
052: this (DEFAULT_FILENAME);
053: }
054:
055: public PropertiesServiceContext(String filename) {
056: properties = new Properties();
057: this .filename = filename;
058:
059: FileInputStream fis = null;
060: try {
061: fis = new FileInputStream(new File(filename));
062: properties.load(fis);
063: } catch (IOException ioe) {
064: throw new ContextError("PropertiesContext.getDP(): ", ioe);
065: }
066: }
067:
068: public void init(SSOToken token) {
069: // nothing
070: }
071:
072: public void init(HttpServletRequest req) {
073: // nothing
074: }
075:
076: public void init(HttpServletRequest req, String uid, String pw) {
077: // nothing
078: }
079:
080: public String getLocaleString() {
081: return properties.getProperty(LOCALESTRING_KEY);
082: }
083:
084: public String getDesktopType() {
085: return properties.getProperty(TYPE_KEY);
086: }
087:
088: public String getDefaultChannelName() {
089: return properties.getProperty(DEFAULTCHANNELNAME_KEY);
090: }
091:
092: public String getEditProviderContainerName() {
093: return properties.getProperty(EDITPROVIDERCONTAINERNAME_KEY);
094: }
095:
096: public String getDPContextClassName() {
097: return properties.getProperty(DPCONTEXTCLASSNAME_KEY);
098: }
099:
100: public String getDPUserContextClassName() {
101: return properties.getProperty(DPUSERCONTEXTCLASSNAME_KEY);
102: }
103:
104: public String getContainerProviderContextClassName() {
105: return properties
106: .getProperty(CONTAINERPROVIDERCONTEXTCLASSNAME_KEY);
107: }
108:
109: public String getProviderManagerContextClassName() {
110: return properties
111: .getProperty(PROVIDERMANAGERCONTEXTCLASSNAME_KEY);
112: }
113:
114: public String getPropertiesContextClassName() {
115: return properties.getProperty(PROPERTIESCONTEXTCLASSNAME_KEY);
116: }
117:
118: public String getTemplateContextClassName() {
119: return properties.getProperty(TEMPLATECONTEXTCLASSNAME_KEY);
120: }
121:
122: public String getClientContextClassName() {
123: return properties.getProperty(CLIENTCONTEXTCLASSNAME_KEY);
124: }
125:
126: public String getDesktopServletPath() {
127: return properties.getProperty(DESKTOPURL_KEY);
128: }
129:
130: public String getNoSessionURL() {
131: return properties.getProperty(NOSESSIONURL_KEY);
132: }
133:
134: public String getSessionReturnURLParamName() {
135: return properties.getProperty(SESSIONRETURNURLPARAMNAME_KEY);
136: }
137:
138: public String getLogoutURL() {
139: return properties.getProperty(LOGOUTURL_KEY);
140: }
141:
142: public String getLoginURL() {
143: return properties.getProperty(LOGINURL_KEY);
144: }
145:
146: public String getDebugContextClassName() {
147: return properties.getProperty(DEBUGCONTEXTCLASSNAME_KEY);
148: }
149:
150: public String getSessionContextClassName() {
151: return properties.getProperty(SESSIONCONTEXTCLASSNAME_KEY);
152: }
153:
154: public String getAuthlessSessionContextClassName() {
155: //
156: // not supported in properties impl
157: //
158: return null;
159: }
160:
161: public String getWSRPSessionContextClassName() {
162: //
163: // not supported in properties impl
164: //
165: return null;
166: }
167:
168: public String getStringAttribute(String name) {
169: return properties.getProperty(name);
170: }
171:
172: public String getStringAttribute(String name, Locale locale) {
173: return getStringAttribute(name);
174: }
175:
176: public void setStringAttribute(String name, String val) {
177: properties.setProperty(name, val);
178:
179: FileOutputStream fos = null;
180: try {
181: fos = new FileOutputStream(new File(filename));
182: properties.store(fos, "Last updated at: ");
183: } catch (IOException ioe) {
184: throw new ContextError(
185: "PropertiesContext.storeAttribute()", ioe);
186: }
187: }
188:
189: public Set getRoles() {
190: //not supported in Properties impl
191: return null;
192: }
193: }
|