001: /**
002: * $Id: UWCABApplicationHelper.java,v 1.8 2005/09/21 10:40:19 dg154973 Exp $
003: * Copyright 2004 Sun Microsystems, Inc. All rights reserved. Use of this
004: * product is subject to license terms. Federal Acquisitions: Commercial
005: * Software -- Government Users Subject to Standard License Terms and
006: * Conditions. Sun, Sun Microsystems, the Sun logo, and iPlanet are trademarks
007: * or registered trademarks of Sun Microsystems, Inc. in the United States and
008: * other countries.
009: */package com.sun.portal.providers.ab;
010:
011: import java.io.BufferedReader;
012: import java.io.InputStreamReader;
013: import java.io.IOException;
014: import java.io.UnsupportedEncodingException;
015: import java.net.MalformedURLException;
016: import java.net.HttpURLConnection;
017: import java.net.URL;
018: import java.net.URLEncoder;
019: import java.util.Date;
020: import java.util.Enumeration;
021: import java.util.Properties;
022: import java.util.Hashtable;
023: import java.util.List;
024: import java.util.Map;
025: import java.util.Map.Entry;
026: import java.util.Set;
027: import java.util.StringTokenizer;
028: import java.util.Iterator;
029: import java.util.ResourceBundle;
030: import java.util.logging.Logger;
031: import java.util.logging.Level;
032: import javax.servlet.http.HttpServletRequest;
033: import javax.servlet.http.HttpServletResponse;
034: import com.sun.ssoadapter.SSOAdapter;
035: import com.sun.ssoadapter.SSOAdapterException;
036: import com.sun.ssoadapter.SSOAdapterFactory;
037: import com.sun.portal.providers.ProviderEditUtility;
038: import com.sun.portal.providers.context.ProviderContext;
039: import com.sun.portal.providers.context.ProviderContextException;
040: import com.sun.portal.providers.ProviderException;
041: import com.sun.portal.providers.Provider;
042: import com.sun.portal.providers.ProfileProviderAdapter;
043: import com.sun.portal.providers.ApplicationHelper;
044: import com.sun.portal.log.common.PortalLogger;
045: import com.iplanet.sso.SSOToken;
046: import com.iplanet.sso.SSOException;
047:
048: /**
049: * Application helper for the the UWC's AB functionailty
050: *
051: *@author byork
052: *@created March 21, 2003
053: */
054: public class UWCABApplicationHelper extends ApplicationHelper implements
055: AddressBookApplicationHelper {
056: ProviderContext pc = null;
057: Properties ssoProps = null;
058: protected String appName = "";
059: public AddressBookProvider provider = null;
060: public SSOAdapter ssoAdapter = null;
061: public String charset = null;
062:
063: // Create a logger for this class
064: private static Logger debugLogger = PortalLogger
065: .getLogger(UWCABApplicationHelper.class);
066:
067: /**
068: * Initialize AddressBookApplicationHelper.
069: *
070: * @param provider AddressBook
071: * @param ssoAdapter Used to identify the SSOAdapter
072: */
073: public void init(AddressBookProvider provider, SSOAdapter ssoAdapter)
074: throws Exception {
075: super .init((ProfileProviderAdapter) provider, ssoAdapter);
076: if (provider != null) {
077: pc = provider.getProviderContext();
078: this .provider = provider;
079: }
080: if (ssoAdapter != null) {
081: ssoProps = ssoAdapter.getProperties();
082: this .ssoAdapter = ssoAdapter;
083: }
084: SSOToken token = ssoAdapter.getSSOToken();
085: charset = token.getProperty("CharSet");
086: debugLogger.log(Level.FINER, "PSAC_CSPPA0027", charset);
087: }
088:
089: /**
090: * Returns the Application Start URL. Since the UWC relies on IS SSO for its
091: * own functionality we can safely assume IS will handle all SSO tasks and
092: * we just need to return the start URL.
093: *
094: * http://<hostname>:<port>/<contexturi>/?gotoUri=/abclient/AddressBook
095: *
096: * @param provider AddressBookProvider
097: * @param request HttpServletRequest
098: * @return url to access application
099: */
100: public String getStartURL(AddressBookProvider provider,
101: HttpServletRequest request) {
102: StringBuffer clientURL = new StringBuffer();
103: String abURL = "/?gotoUri=/abclient/AddressBook";
104: String host = ssoProps.getProperty("host");
105: String port = ssoProps.getProperty("clientPort", "80");
106: String uwcContext = ssoProps.getProperty("uwcContext");
107: String protocol = ssoProps
108: .getProperty("clientProtocol", "http");
109: clientURL.append(protocol + "://" + host + ":" + port);
110: if (uwcContext == null) {
111: debugLogger.fine("PSAC_CSPPA0062");
112: uwcContext = "/";
113: }
114: if (uwcContext != null) {
115: if (uwcContext.substring(0).equals("/"))
116: clientURL.append(uwcContext);
117: else
118: clientURL.append("/" + uwcContext);
119: }
120: clientURL.append(abURL);
121: return clientURL.toString();
122: }
123:
124: /**
125: * Returns the contents of the AddressBookProviders edit page
126: */
127: public StringBuffer getAppPrefsEdit(AddressBookProvider aprov,
128: HttpServletRequest req, HttpServletResponse res) {
129: setEditContainer(aprov.editContainer);
130: setContainerName(aprov.containerName);
131: setTargetProvider(aprov.targetProvider);
132: return super .getAppPrefsEdit((Provider) aprov, req, res);
133: }
134:
135: /**
136: * Processes values returned from the AddressBookProvider edit page
137: */
138: public URL processAppPrefsEdit(AddressBookProvider aprov,
139: HttpServletRequest req, HttpServletResponse res)
140: throws ProviderException {
141: setEditContainer(aprov.editContainer);
142: setTargetProvider(aprov.targetProvider);
143: setContainerName(aprov.containerName);
144: return super .processAppPrefsEdit((Provider) aprov, req, res);
145: }
146:
147: /**
148: * Implementation of abstract ApplicationHelper method
149: *
150: *@param req servlet request
151: *@return The String representing an URL to get to the edit page for DP
152: * properties
153: */
154:
155: public String getAppHelperEditLink(HttpServletRequest req,
156: ProviderContext pc) {
157:
158: Hashtable tagTable = new Hashtable();
159: StringBuffer link = new StringBuffer();
160: try {
161: link.append(pc.getDesktopURL(req));
162: } catch (Exception e) {
163: return "";
164: }
165: link.append("?action=edit&provider=" + provider.editContainer);
166: link.append("&targetprovider=" + provider.targetProvider);
167: link.append("&containerName=" + provider.containerName);
168: link.append("&appPref=" + this .getName());
169:
170: tagTable.put("editLink", link.toString());
171: String content = null;
172:
173: try {
174: String fontTag = pc.getStringProperty(provider.getName(),
175: "fontFace1", "Sans-serif");
176: tagTable.put("iwtDesktop-fontFace1", fontTag);
177: content = pc.getTemplate(provider.getName(),
178: "edit-link.template", tagTable).toString();
179: debugLogger.log(Level.FINER, "PSAC_CSPPA0041", content
180: .toString());
181: } catch (Exception e) {
182: debugLogger.log(Level.INFO, "PSAC_CSPPA0042", e);
183: content = "";
184: }
185:
186: debugLogger.log(Level.FINER, "PSAC_CSPPA0043", content
187: .toString());
188:
189: return content;
190: }
191:
192: }
|