001: package com.sun.portal.providers;
002:
003: import java.io.*;
004: import java.util.*;
005: import java.util.logging.Level;
006: import java.util.logging.Logger;
007: import java.net.*;
008: import com.sun.ssoadapter.SSOAdapter;
009: import com.sun.ssoadapter.SSOAdapterException;
010: import com.sun.ssoadapter.SSOAdapterFactory;
011: import com.sun.portal.providers.ProviderEditUtility;
012: import com.iplanet.sso.SSOToken;
013: import com.iplanet.sso.SSOException;
014: import com.sun.portal.providers.context.ProviderContext;
015: import com.sun.portal.providers.context.ProviderContextException;
016: import com.sun.portal.providers.ProviderException;
017: import com.sun.portal.providers.ProfileProviderAdapter;
018: import com.sun.portal.providers.Provider;
019: import com.sun.ssoadapter.SSOAdapterLogger;
020:
021: import javax.servlet.http.HttpServletRequest;
022: import javax.servlet.http.HttpServletResponse;
023:
024: /**
025: * This class is a base class from which all of the application helpers inherit
026: * from. This is to cut down on code duplication.
027: *
028: *@author Bill York
029: *@created August 23, 2004
030: */
031: public abstract class ApplicationHelper {
032:
033: public Provider provider = null;
034: public SSOAdapter ssoAdapter = null;
035: public Properties adapterProperties = null;
036: public String appName = null;
037: public ProviderContext pc = null;
038: public String editContainer = null;
039: public String targetProvider = null;
040: public String containerName = null;
041:
042: private static Logger logger = SSOAdapterLogger
043: .getLogger(ApplicationHelper.class);
044:
045: /**
046: * Initialize ApplicationHelper. Set adapterProperties with ssoAdapter
047: * properties
048: *
049: *@param provider AddressBookProvider
050: *@param ssoAdapter SSOAdapter
051: *@exception Exception Description of the Exception
052: */
053: public void init(ProfileProviderAdapter provider,
054: SSOAdapter ssoAdapter) throws Exception {
055: this .provider = (Provider) provider;
056: this .ssoAdapter = ssoAdapter;
057: this .pc = provider.getProviderContext();
058:
059: if (ssoAdapter != null) {
060: this .adapterProperties = ssoAdapter.getProperties();
061: }
062: }
063:
064: public void setEditContainer(String container) {
065: if (logger.isLoggable(Level.FINEST)) {
066: String[] param = { "value", container };
067: logger.log(Level.FINEST, "PSSA_CSPP0001", param);
068: }
069:
070: this .editContainer = container;
071: }
072:
073: public void setContainerName(String container) {
074: if (logger.isLoggable(Level.FINEST)) {
075: String[] param = { "value", container };
076: logger.log(Level.FINEST, "PSSA_CSPP0001", param);
077: }
078:
079: this .containerName = container;
080: }
081:
082: public void setTargetProvider(String provider) {
083: if (logger.isLoggable(Level.FINEST)) {
084: String[] param = { "value", provider };
085: logger.log(Level.FINEST, "PSSA_CSPP0001", param);
086: }
087:
088: this .targetProvider = provider;
089: }
090:
091: /**
092: * Sets the App Helpers name
093: *
094: *@param name The new name value
095: */
096: public void setName(String name) {
097: this .appName = name;
098: }
099:
100: /**
101: * Gets the App Helpers name
102: *
103: *@return The name value
104: */
105: public String getName() {
106: return this .appName;
107: }
108:
109: /**
110: * Returns the contents of the AddressBookProviders edit page
111: *
112: *@param prov Description of the Parameter
113: *@param req Description of the Parameter
114: *@param res Description of the Parameter
115: *@return The appPrefsEdit value
116: */
117: public StringBuffer getAppPrefsEdit(Provider prov,
118: HttpServletRequest req, HttpServletResponse res) {
119: StringBuffer content = new StringBuffer();
120: Hashtable tagTable = new Hashtable();
121: Map dpEditMap = null;
122: String fontTag = "";
123:
124: // get the list of edit attributes to display
125: try {
126: List pflist = pc.getClientAndLocalePropertiesFilters();
127: dpEditMap = pc.getCollectionProperty(prov.getName(),
128: "dpEditAttributes", pflist);
129: fontTag = pc.getStringProperty(prov.getName(), "fontFace1",
130: "Sans-serif");
131: tagTable.put("iwtDesktop-fontFace1", fontTag);
132: tagTable.put("isAppHandler", this .getName());
133: ProviderEditUtility.setDefaultPresentation(prov.getName(),
134: pc, tagTable);
135: } catch (ProviderContextException pce) {
136: logger.log(Level.WARNING, "PSSA_CSPP0006", pce);
137: }
138:
139: if (dpEditMap != null) {
140: try {
141: content.append(pc.getTemplate(provider.getName(),
142: "edit-start.template", tagTable));
143: } catch (ProviderContextException pce) {
144: logger.log(Level.WARNING, "PSSA_CSPP0006", pce);
145: }
146: Set entries = dpEditMap.entrySet();
147: Iterator iter = entries.iterator();
148: while (iter.hasNext()) {
149: // get values from DP
150: Map.Entry entry = (Map.Entry) iter.next();
151: String key = (String) entry.getKey();
152: String value = (String) entry.getValue();
153: StringTokenizer tok = new StringTokenizer(value, "|");
154: while (tok.hasMoreElements()) {
155: String type = tok.nextToken();
156: String header = tok.nextToken();
157: content.append(ProviderEditUtility
158: .createEditContent(type, header, key, prov
159: .getName(), pc, true));
160: }
161: }
162:
163: try {
164: content.append(pc.getTemplate(provider.getName(),
165: "edit-end.template", tagTable));
166: } catch (ProviderContextException pce) {
167: logger.log(Level.INFO, "PSSA_CSPP0006", pce);
168: }
169: }
170: return content;
171: }
172:
173: /**
174: * Processes values returned from the MailPprovider edit page
175: *
176: *@param prov Instance of Address Book Provider
177: *@param request Description of the Parameter
178: *@param response Description of the Parameter
179: *@return Description of the Return Value
180: *@exception ProviderException Description of the Exception
181: */
182: public URL processAppPrefsEdit(Provider prov,
183: HttpServletRequest request, HttpServletResponse response)
184: throws ProviderException {
185: URL url = null;
186: Properties props = null;
187: Map dpEditMap = null;
188: StringBuffer returnURL = new StringBuffer();
189: List pflist = null;
190:
191: try {
192: url = getAppHelperProcessURL(request, prov);
193: pflist = pc.getClientAndLocalePropertiesFilters();
194: dpEditMap = pc.getCollectionProperty(prov.getName(),
195: "dpEditAttributes", pflist);
196: } catch (ProviderContextException pce) {
197: throw new ProviderException(
198: "ApplicationHelper.processAppPrefsEdit():\n", pce);
199: }
200:
201: if (dpEditMap != null) {
202: Set entries = dpEditMap.entrySet();
203: Iterator iter = entries.iterator();
204: while (iter.hasNext()) {
205: // get values from DP
206: Map.Entry entry = (Map.Entry) iter.next();
207: String key = (String) entry.getKey();
208: String value = (String) entry.getValue();
209: StringTokenizer tok = new StringTokenizer(value, "|");
210: String type = tok.nextToken();
211: try {
212: if (logger.isLoggable(Level.FINEST)) {
213: String[] param = { "key", key };
214: logger
215: .log(Level.FINEST, "PSSA_CSPP0001",
216: param);
217: }
218: if ((type.equals("string"))
219: || (type.equals("select"))
220: || (type.equals("password"))) {
221: String reqString = ProviderEditUtility
222: .getRequestParameter(key, request);
223: if (!reqString.equals("")) {
224: if (pc.existsStringProperty(prov.getName(),
225: key, pflist)) {
226: pc.setStringProperty(prov.getName(),
227: key, reqString, pflist);
228: } else if (pc.existsStringProperty(prov
229: .getName(), key)) {
230: pc.setStringProperty(prov.getName(),
231: key, reqString);
232: } else {
233: if (logger.isLoggable(Level.WARNING)) {
234: String[] param = { key };
235: logger.log(Level.WARNING,
236: "PSSA_CSPP0002", param);
237: }
238: }
239: }
240: } else if (type.equals("int")) {
241: String reqNumber = ProviderEditUtility
242: .getRequestParameter(key, request);
243: if (!reqNumber.equals("")) {
244: //pc.setIntegerProperty(prov.getName(), key, Integer.parseInt(reqNumber));
245: if (pc.existsIntegerProperty(
246: prov.getName(), key, pflist)) {
247: pc.setIntegerProperty(prov.getName(),
248: key, Integer
249: .parseInt(reqNumber),
250: pflist);
251: } else if (pc.existsIntegerProperty(prov
252: .getName(), key)) {
253: pc.setIntegerProperty(prov.getName(),
254: key, Integer
255: .parseInt(reqNumber));
256: } else {
257: if (logger.isLoggable(Level.WARNING)) {
258: String[] param = { key };
259: logger.log(Level.WARNING,
260: "PSSA_CSPP0002", param);
261: }
262: }
263: }
264: } else if (type.equals("check")) {
265: String reqBool = ProviderEditUtility
266: .getRequestParameter(key, request);
267: Boolean bool = null;
268: if (reqBool.equals("")) {
269: bool = new Boolean("false");
270: } else {
271: bool = new Boolean("true");
272: }
273: //pc.setBooleanProperty(prov.getName(), key, bool.booleanValue());
274: if (pc.existsBooleanProperty(prov.getName(),
275: key, pflist)) {
276: pc.setBooleanProperty(prov.getName(), key,
277: bool.booleanValue(), pflist);
278: } else if (pc.existsBooleanProperty(prov
279: .getName(), key)) {
280: pc.setBooleanProperty(prov.getName(), key,
281: bool.booleanValue());
282: } else {
283: if (logger.isLoggable(Level.WARNING)) {
284: String[] param = { key };
285: logger.log(Level.WARNING,
286: "PSSA_CSPP0002", param);
287: }
288: }
289: }
290: } catch (ProviderContextException pce) {
291: throw new ProviderException(
292: "ApplicationHelper.processAppPrefsEdit():\n",
293: pce);
294: }
295:
296: }
297: }
298:
299: if (logger.isLoggable(Level.WARNING)) {
300: String[] param = { "return url", url.toString() };
301: logger.log(Level.WARNING, "PSSA_CSPP0001", param);
302: }
303: return url;
304: }
305:
306: /**
307: * Gets the appHelperProcessURL attribute of the ProviderHelper object
308: *
309: *@param req Description of the Parameter
310: *@param prov Description of the Parameter
311: *@return The appHelperProcessURL value
312: */
313: protected URL getAppHelperProcessURL(HttpServletRequest req,
314: Provider prov) {
315:
316: StringBuffer link = new StringBuffer();
317: URL returnURL = null;
318: try {
319: link.append(pc.getDesktopURL(req));
320: } catch (Exception e) {
321: return null;
322: }
323:
324: String providerName = provider.getName();
325: if (logger.isLoggable(Level.FINEST)) {
326: String[] param = { "link", link.toString() };
327: logger.log(Level.FINEST, "PSSA_CSPP0001", param);
328: param[0] = "editContainer";
329: param[1] = editContainer;
330: logger.log(Level.FINEST, "PSSA_CSPP0001", param);
331: param[0] = "isEmptyReturns";
332: param[1] = "" + ProviderEditUtility.isEmpty(editContainer);
333: logger.log(Level.FINEST, "PSSA_CSPP0001", param);
334:
335: param[0] = "targetProvider";
336: param[1] = targetProvider;
337: logger.log(Level.FINEST, "PSSA_CSPP0001", param);
338: param[0] = "isEmptyReturns";
339: param[1] = "" + ProviderEditUtility.isEmpty(targetProvider);
340: logger.log(Level.FINEST, "PSSA_CSPP0001", param);
341:
342: param[0] = "containerName";
343: param[1] = containerName;
344: logger.log(Level.FINEST, "PSSA_CSPP0001", param);
345: param[0] = "isEmptyReturns";
346: param[1] = "" + ProviderEditUtility.isEmpty(targetProvider);
347: logger.log(Level.FINEST, "PSSA_CSPP0001", param);
348:
349: }
350:
351: if (((ProviderEditUtility.isEmpty(editContainer))
352: || (ProviderEditUtility.isEmpty(targetProvider)) || (ProviderEditUtility
353: .isEmpty(containerName)))) {
354: logger.info("PSSA_CSPP0004");
355: try {
356: returnURL = new URL(link.toString());
357: } catch (Exception e) {
358: logger.log(Level.WARNING, "PSSA_CSPP0004", e);
359: return null;
360: }
361: } else {
362: link.append("?action=edit&provider=" + editContainer);
363: link.append("&targetprovider=" + targetProvider);
364: link.append("&containerName=" + containerName);
365: try {
366: returnURL = new URL(link.toString());
367: if (logger.isLoggable(Level.FINEST)) {
368: String[] param = { "returnURL",
369: returnURL.toString() };
370: logger.log(Level.FINEST, "PSSA_CSPP0001", param);
371: }
372: } catch (Exception e) {
373: logger.log(Level.INFO, "PSSA_CSPP0003", e);
374: return null;
375: }
376: }
377: return returnURL;
378: }
379:
380: /**
381: * Returns a HTML link containing encoding specific for the app helper
382: */
383:
384: public abstract String getAppHelperEditLink(HttpServletRequest req,
385: ProviderContext pc);
386:
387: }
|