0001: /**
0002: * $Id: MAJspMailAppHelper.java,v 1.20 2005/09/21 10:49:04 dg154973 Exp $
0003: * Copyright 2002 Sun Microsystems, Inc. All
0004: * rights reserved. Use of this product is subject
0005: * to license terms. Federal Acquisitions:
0006: * Commercial Software -- Government Users
0007: * Subject to Standard License Terms and
0008: * Conditions.
0009: *
0010: * Sun, Sun Microsystems, the Sun logo, and iPlanet
0011: * are trademarks or registered trademarks of Sun Microsystems,
0012: * Inc. in the United States and other countries.
0013: */package com.sun.portal.wireless.providers.mail;
0014:
0015: import java.net.URL;
0016: import java.net.URLEncoder;
0017: import java.net.MalformedURLException;
0018: import java.util.Properties;
0019: import java.util.Hashtable;
0020: import java.util.Enumeration;
0021: import java.util.Map;
0022: import java.util.HashMap;
0023: import java.util.HashSet;
0024: import java.util.Set;
0025: import java.util.Iterator;
0026: import java.util.Vector;
0027: import java.util.ResourceBundle;
0028: import java.util.logging.Level;
0029: import java.util.logging.LogRecord;
0030: import java.util.logging.Logger;
0031:
0032: import javax.servlet.http.HttpServletRequest;
0033: import javax.servlet.http.HttpServletResponse;
0034: import javax.mail.*;
0035:
0036: import com.iplanet.sso.*;
0037: import com.iplanet.am.sdk.AMStoreConnection;
0038: import com.iplanet.am.sdk.AMUser;
0039:
0040: import com.sun.ssoadapter.SSOAdapter;
0041: import com.sun.ssoadapter.SSOAdapterSession;
0042: import com.sun.ssoadapter.config.*;
0043: import com.sun.portal.log.common.PortalLogger;
0044: import com.sun.portal.providers.mail.MailApplicationHelper;
0045: import com.sun.portal.providers.mail.MailProvider;
0046: import com.sun.portal.providers.context.ProviderContext;
0047: import com.sun.portal.providers.context.ProviderContextException;
0048: import com.sun.portal.providers.ProviderEditUtility;
0049: import com.sun.portal.providers.ProviderException;
0050: import com.sun.portal.providers.InvalidEditFormDataException;
0051:
0052: import com.sun.portal.wireless.taglibs.dispatcher.*;
0053: import com.sun.mobile.util.*;
0054: import com.sun.portal.wireless.util.*;
0055: import com.sun.portal.wireless.providers.util.ProviderUtility;
0056:
0057: /**
0058: * This class implements the MailApplicationHelper
0059: * <p>This MailApplicationHelper implementation consumes the following
0060: * Configuration properties:
0061: * <ul>
0062: * </ul>
0063: *
0064: * @version 1.0
0065: *
0066: */
0067:
0068: public class MAJspMailAppHelper implements MailApplicationHelper {
0069:
0070: public MailProvider provider = null;
0071: public SSOAdapter ssoAdapter = null;
0072: public SSOToken ssoToken = null;
0073: public Properties adapterProperties = null;
0074: private ConfigurationFactory appConfigFactory = null;
0075: private ConfigurationFactory ssoConfigFactory = null;
0076: private PSClientAwareContextFactory saalContextFactory = null;
0077: private Map serviceMap = new HashMap();
0078: private ClientAwareUserContext saalContext = null;
0079: private Configuration appConfig = null;
0080: private MailViews mailViewsHandler = null;
0081:
0082: private String editContainer = null;
0083: private String container = null;
0084: private String editPopSelected = null;
0085: private ResourceBundle bundle = null;
0086: protected String appName = "";
0087:
0088: private static Logger logger = PortalLogger
0089: .getLogger(MAJspMailAppHelper.class);
0090:
0091: private static final int PREDEFINED_REPLIES_LENGTH = 9;
0092:
0093: /**
0094: * Initialize MAMailAppHelper.
0095: *
0096: * @param ssoAdapter SSOAdapter object
0097: */
0098: public void init(MailProvider provider, SSOAdapter ssoAdapter) {
0099: this .provider = provider;
0100: this .ssoAdapter = ssoAdapter;
0101: try {
0102: this .ssoToken = ssoAdapter.getSSOToken();
0103: } catch (Exception e) {
0104: }
0105: this .adapterProperties = ssoAdapter.getProperties();
0106: appConfigFactory = ConfigurationFactory.getInstance(
0107: AppConfigConstants.MAIL_APP_SERVICE_NAME,
0108: AppConfigConstants.MAIL_APP_ATTR_CONFIGURATIONS_NAME,
0109: AppConfigConstants.MAIL_APP_ATTR_TEMPLATES_NAME);
0110: ssoConfigFactory = ConfigurationFactory.getInstance(
0111: SSOAdapterPrivate.SSO_SERVICE_NAME,
0112: SSOAdapterPrivate.SSO_ATTR_CONFIGURATIONS_NAME,
0113: SSOAdapterPrivate.SSO_ATTR_TEMPLATES_NAME);
0114: serviceMap.put("serviceName",
0115: AppConfigConstants.MAIL_APP_SERVICE_NAME);
0116: bundle = ResourceBundle.getBundle("MAJspMailAppHelper",
0117: provider.getProviderContext().getLocale());
0118:
0119: }
0120:
0121: /**
0122: * Construct state that is required to process prefs editing requests...
0123: */
0124: private void prefsReqInit(HttpServletRequest req) throws Exception {
0125: if (editContainer == null) {
0126: editContainer = req.getParameter("provider");
0127: }
0128:
0129: if (container == null) {
0130: container = req.getParameter("containerName");
0131: }
0132:
0133: if (appConfig == null) {
0134:
0135: //
0136: // Verify user has been assigned to the proper service...
0137: //
0138: AMStoreConnection amConn = new AMStoreConnection(ssoToken);
0139: AMUser amUser = amConn.getUser(ssoToken.getPrincipal()
0140: .toString());
0141: Set assignedServices = amUser.getAssignedServices();
0142: Iterator svcIter = assignedServices.iterator();
0143: boolean found = false;
0144: while (svcIter.hasNext()) {
0145: String svcName = (String) svcIter.next();
0146: if (svcName
0147: .equalsIgnoreCase(AppConfigConstants.MAIL_APP_SERVICE_NAME)) {
0148: found = true;
0149: break;
0150: }
0151: }
0152: if (!found) {
0153: throw new Exception(
0154: AppConfigConstants.MAIL_APP_SERVICE_NAME
0155: + " service not assigned to user");
0156: }
0157:
0158: //
0159: // Load/init app prefs...
0160: //
0161: String configName = ssoAdapter.getName();
0162: String nameSuffix = "_" + provider.getName();
0163: int i = configName.indexOf(nameSuffix);
0164: if (i < 0) {
0165: i = configName.length();
0166: configName = configName + nameSuffix;
0167: }
0168:
0169: appConfig = appConfigFactory.readConfiguration(configName,
0170: true, new SSOAdapterSession(req));
0171:
0172: if (appConfig == null) {
0173: //
0174: // If not defined, try getting Dynamic version using naming
0175: // convention established by Comm Channels...
0176: //
0177: appConfig = appConfigFactory.readConfiguration(
0178: configName.substring(0, i), true,
0179: new SSOAdapterSession(req));
0180: if (appConfig != null) {
0181: appConfig.setConfigurationName(configName);
0182: }
0183: if (appConfig == null) {
0184: appConfig = new Configuration();
0185: appConfig.setConfigurationName(configName);
0186: appConfig
0187: .setConfigurationDescription(AppConfigConstants.MAIL_APP_TEMPLATE_NAME);
0188: }
0189: }
0190:
0191: }
0192:
0193: saalContextFactory = PSClientAwareContextFactory.getInstance();
0194: saalContext = saalContextFactory
0195: .getClientAwareUserContext(new SSOAdapterSession(req));
0196:
0197: try {
0198: if (mailViewsHandler == null) {
0199: mailViewsHandler = new MailViews();
0200: mailViewsHandler.init(provider, container,
0201: editContainer, this , req);
0202: }
0203: } catch (Exception e) {
0204: mailViewsHandler = null;
0205: logger.log(Level.INFO, "PSMA_CSPWPM0032", e);
0206: }
0207: }
0208:
0209: /**
0210: * Returns a client URL, if supported by the service.
0211: */
0212: public String getStartURL(MailProvider mprov,
0213: HttpServletRequest request) {
0214: return getApplicationURL(mprov, request);
0215: }
0216:
0217: private String getApplicationURL(MailProvider mprov,
0218: HttpServletRequest request) {
0219:
0220: String appURL = null;
0221: SSOToken token;
0222:
0223: try {
0224: SSOTokenManager tokenManager = SSOTokenManager
0225: .getInstance();
0226: token = tokenManager.createSSOToken(request);
0227:
0228: appURL = "/jsp/default/launchMail.jsp"
0229: + "?mi="
0230: + ContentUtils.rfc2396Escape("", ssoAdapter
0231: .getName());
0232:
0233: Compressor compressor = Compressor.getCompressor(token);
0234:
0235: appURL = request.getContextPath()
0236: + compressor.compressURL(appURL);
0237:
0238: appURL = token.encodeURL(appURL);
0239:
0240: } catch (Exception e) {
0241: return null;
0242: }
0243:
0244: return appURL;
0245: }
0246:
0247: public String getMessageURL(MailProvider mprov,
0248: HttpServletRequest request, Message message) {
0249: return null;
0250: }
0251:
0252: public StringBuffer getAppPrefsEdit(MailProvider mprov,
0253: HttpServletRequest req, HttpServletResponse res) {
0254: StringBuffer edit = null;
0255:
0256: try {
0257: prefsReqInit(req);
0258: } catch (Exception e) {
0259: return null;
0260: }
0261:
0262: String viewMode = req.getParameter("viewmode");
0263: if (viewMode != null) {
0264: try {
0265: edit = mailViewsHandler.getEdit(req, res);
0266: } catch (Exception e) {
0267: logger.log(Level.INFO, "", e);
0268: }
0269: } else {
0270: String page = req.getParameter("page");
0271: if (page == null) {
0272: edit = getAppPrefsMainEdit(mprov, req);
0273: } else if (page.endsWith("PopConfig")) {
0274: edit = getAppPrefsPopEdit(mprov, req, page);
0275: }
0276: }
0277:
0278: return (edit);
0279: }
0280:
0281: private StringBuffer getAppPrefsMainEdit(MailProvider mprov,
0282: HttpServletRequest req) {
0283: StringBuffer popOptions = new StringBuffer();
0284: StringBuffer viewOptions = new StringBuffer();
0285: ProviderContext pc = mprov.getProviderContext();
0286:
0287: Hashtable tagTable = new Hashtable();
0288: Hashtable mailValuePairs = new Hashtable();
0289:
0290: try {
0291:
0292: //
0293: // Grab POP collection values...
0294: //
0295: Enumeration configEnum = ssoConfigFactory
0296: .getConfigurationNames(new SSOAdapterSession(req));
0297:
0298: if (configEnum != null) {
0299: Configuration configProps;
0300: while (configEnum.hasMoreElements()) {
0301: String configName = (String) configEnum
0302: .nextElement();
0303: mailValuePairs.clear();
0304: //Put theme attrs
0305: try {
0306: ProviderUtility.setDefaultPresentation(provider
0307: .getName(), provider
0308: .getProviderContext(), mailValuePairs);
0309: } catch (ProviderContextException pce) {
0310: logger.log(Level.INFO, "", pce);
0311: }
0312:
0313: mailValuePairs.put("configName", configName);
0314: try {
0315: configProps = ssoConfigFactory
0316: .readConfiguration(configName, true,
0317: new SSOAdapterSession(req));
0318: if (configProps.getProperty("protocol").equals(
0319: "pop3")
0320: && configProps
0321: .getConfigurationDescription()
0322: .equals(
0323: AppConfigConstants.POP_COLLECTIONS_TEMPLATE_NAME)) {
0324: popOptions.append(mprov.getTemplate(
0325: "ma-edit-config-options.template",
0326: mailValuePairs));
0327: }
0328: } catch (Exception ee) {
0329: }
0330: }
0331: tagTable.put("popConfigs", popOptions);
0332: }
0333:
0334: //
0335: // Grab signature value...
0336: //
0337: String signature = getSAALStringAttribute(req,
0338: "sunMobileAppMailSignature");
0339: if (signature != null) {
0340: tagTable.put("signature", signature);
0341: }
0342:
0343: //
0344: // Grab pre-defined replies...
0345: //
0346: Set predefinedMsgs = getSAALAttribute(req,
0347: "sunMobileAppMailPredefinedReplies");
0348: int size = predefinedMsgs.size();
0349: int i = 0;
0350: for (Iterator j = predefinedMsgs.iterator(); j.hasNext();) {
0351: String predefinedMsgValuePair = (String) j.next();
0352: if (predefinedMsgValuePair.indexOf('=') != -1) {
0353: String key = predefinedMsgValuePair.substring(0,
0354: predefinedMsgValuePair.indexOf('='));
0355: String value = predefinedMsgValuePair
0356: .substring(predefinedMsgValuePair
0357: .indexOf('=') + 1);
0358: tagTable.put(key, value);
0359: } else {
0360: String key = "preset" + (i + 1);
0361: tagTable.put(key, "");
0362: }
0363: i++;
0364: }
0365:
0366: if (size < PREDEFINED_REPLIES_LENGTH) {
0367: for (i = size; i <= PREDEFINED_REPLIES_LENGTH; i++) {
0368: String key = "preset" + i;
0369: tagTable.put(key, "");
0370: }
0371: }
0372:
0373: //
0374: // Grab sent folder copy flag...
0375: //
0376: boolean sentFolderCopy = false;
0377: String sentFolderCopyString = getAppConfigString(req,
0378: "sentFolderCopy");
0379: if (sentFolderCopyString != null) {
0380: sentFolderCopy = Boolean.valueOf(sentFolderCopyString)
0381: .booleanValue();
0382: }
0383: if (sentFolderCopy) {
0384: tagTable.put("sentFolderCopyChecked", "CHECKED");
0385: tagTable.put("sentFolderCopy", "true");
0386: } else {
0387: tagTable.put("sentFolderCopyChecked", "");
0388: tagTable.put("sentFolderCopy", "false");
0389: }
0390:
0391: //
0392: // Grab fromAddress...
0393: //
0394: String fromAddress = getAppConfigString(req, "fromAddress");
0395: if (fromAddress != null) {
0396: tagTable.put("fromAddress", fromAddress);
0397: }
0398:
0399: //
0400: // Set appPrefs value in hidden field...
0401: //
0402: tagTable.put("isAppHandler", this .getName());
0403:
0404: //Put theme attrs
0405: try {
0406: ProviderUtility.setDefaultPresentation(provider
0407: .getName(), provider.getProviderContext(),
0408: tagTable);
0409: } catch (ProviderContextException pce) {
0410: logger.log(Level.INFO, "", pce);
0411: }
0412:
0413: return (mprov.getTemplate("ma-edit.template", tagTable));
0414:
0415: } catch (Exception e) {
0416: logger.log(Level.INFO, "", e);
0417: return null;
0418: }
0419: }
0420:
0421: private StringBuffer getAppPrefsPopEdit(MailProvider mprov,
0422: HttpServletRequest request, String page) {
0423: StringBuffer edit = null;
0424: Hashtable mailValuePairs = new Hashtable();
0425: ProviderContext pc = mprov.getProviderContext();
0426:
0427: // Get Pop Configuration Attributes
0428: Configuration ssoConfigProps = null;
0429:
0430: try {
0431: mailValuePairs.clear();
0432: mailValuePairs.put("isAppHandler", this .getName());
0433: //Put theme attrs
0434: try {
0435: ProviderUtility.setDefaultPresentation(provider
0436: .getName(), provider.getProviderContext(),
0437: mailValuePairs);
0438: } catch (ProviderContextException pce) {
0439: logger.log(Level.INFO, "", pce);
0440: }
0441:
0442: if (page.equals("AddPopConfig")) {
0443: mailValuePairs.put("process", "AddPop");
0444: mailValuePairs.put("port", "110");
0445:
0446: edit = mprov.getTemplate("ma-edit-pop-config.template",
0447: mailValuePairs);
0448: } else { // page.equals("EditPopConfig")
0449: mailValuePairs.put("process", "EditPop");
0450: String configName = request.getParameter("selection");
0451: try {
0452: ssoConfigProps = ssoConfigFactory
0453: .readConfiguration(configName, true,
0454: new SSOAdapterSession(request));
0455: } catch (Exception e) {
0456: logger.log(Level.INFO, "", e);
0457: return null;
0458: }
0459:
0460: // Remember the selection
0461: editPopSelected = configName;
0462: if (editPopSelected.indexOf('+') != -1) {
0463: editPopSelected = java.net.URLDecoder
0464: .decode(editPopSelected); //encode
0465: }
0466:
0467: mailValuePairs.put("configName", configName);
0468:
0469: setTagtable(mailValuePairs, "host", ssoConfigProps,
0470: "host");
0471: setTagtable(mailValuePairs, "port", ssoConfigProps,
0472: "port");
0473: setTagtable(mailValuePairs, "uid", ssoConfigProps,
0474: "uid");
0475: /**
0476: * Mail User Password:
0477: * password is special case: don't actually put real pw value in
0478: * form. instead insert a string of *'s of the same length to
0479: * give the user the impression that their pw is there.
0480: */
0481: setTagtable(mailValuePairs, "password", ssoConfigProps,
0482: "password");
0483:
0484: boolean popDelete = false;
0485: String popDeleteString = ssoConfigProps
0486: .getProperty("popDelete");
0487: if (popDeleteString != null) {
0488: popDelete = Boolean.valueOf(popDeleteString)
0489: .booleanValue();
0490: }
0491: if (popDelete) {
0492: mailValuePairs.put("popDeleteChecked", "CHECKED");
0493: mailValuePairs.put("popDelete", "true");
0494: } else {
0495: mailValuePairs.put("popDeleteChecked", "");
0496: mailValuePairs.put("popDelete", "false");
0497: }
0498: //setTagtable(mailValuePairs, "popDelete", ssoConfigProps, "popDelete");
0499:
0500: //Put theme attrs
0501: try {
0502: ProviderUtility.setDefaultPresentation(provider
0503: .getName(), provider.getProviderContext(),
0504: mailValuePairs);
0505: } catch (ProviderContextException pce) {
0506: logger.log(Level.INFO, "", pce);
0507: }
0508:
0509: edit = mprov.getTemplate("ma-edit-pop-config.template",
0510: mailValuePairs);
0511:
0512: }
0513: } catch (Exception e) {
0514: logger.log(Level.INFO, "", e);
0515: return null;
0516: }
0517:
0518: return (edit);
0519: }
0520:
0521: public URL processAppPrefsEdit(MailProvider mprov,
0522: HttpServletRequest req, HttpServletResponse res) {
0523: URL finishURL = null;
0524: try {
0525:
0526: URL url = null;
0527: String desktopURL = mprov.getProviderContext()
0528: .getDesktopURL(req);
0529: desktopURL += "?action=edit";
0530: desktopURL += "&provider="
0531: + URLEncoder.encode(editContainer);
0532: desktopURL += "&targetprovider=" + mprov.getName();
0533: desktopURL += "&containerName="
0534: + URLEncoder.encode(container);
0535: finishURL = new URL(desktopURL);
0536: desktopURL += "&appPref="
0537: + URLEncoder.encode(this .getName());
0538:
0539: String process = req.getParameter("process");
0540:
0541: try {
0542: String viewMode = req.getParameter("viewmode");
0543: if (viewMode != null) {
0544: try {
0545: url = mailViewsHandler.processEdit(req, res);
0546: } catch (Exception e) {
0547: logger.log(Level.INFO, "", e);
0548: }
0549: return url;
0550: }
0551: if (process != null) {
0552: if ((process.equals("AddPop"))
0553: || (process.equals("EditPop"))) {
0554: url = processAppPrefsPopEdit(mprov, req, res);
0555: }
0556:
0557: if (url != null) {
0558: return url;
0559: }
0560: }
0561: if (req.getParameter("OpenRules") != null) {
0562: //
0563: // Redirect to edit rules...
0564: //
0565: desktopURL += "&viewmode=Rules";
0566: url = new URL(desktopURL);
0567: } else if (req.getParameter("OpenViews") != null) {
0568: //
0569: // Redirect to edit views...
0570: //
0571: desktopURL += "&viewmode=Views";
0572: url = new URL(desktopURL);
0573: } else if (req.getParameter("OpenDevice") != null) {
0574: //
0575: // Redirect to edit views...
0576: //
0577: desktopURL += "&viewmode=Device";
0578: url = new URL(desktopURL);
0579: } else if (req.getParameter("OpenAddPop") != null) {
0580: //
0581: // Redirect to get edit for pop ADD...
0582: //
0583: desktopURL += "&page=AddPopConfig";
0584: url = new URL(desktopURL);
0585: } else if (req.getParameter("OpenEditPop") != null) {
0586: if (req.getParameter("popConfigs") != null) {
0587: //
0588: // Redirect to get edit for pop EDIT...
0589: //
0590: String popConfig = req
0591: .getParameter("popConfigs");
0592: desktopURL += "&page=EditPopConfig&selection="
0593: + mprov.getProviderContext()
0594: .encodeURLParameter(popConfig);
0595: } else {
0596: //
0597: // If config not spec'd, redirect to get edit for pop ADD...
0598: //
0599: desktopURL += "&page=AddPopConfig";
0600: }
0601: url = new URL(desktopURL);
0602: } else if (req.getParameter("DeletePop") != null) {
0603: url = processAppPrefsPopEdit(mprov, req, res);
0604: } else {
0605: url = processAppPrefsMainEdit(mprov, req, res);
0606: }
0607:
0608: } catch (InvalidEditFormDataException ie) {
0609: //throw ie;
0610: } catch (Exception e) {
0611: logger.log(Level.INFO, "", e);
0612: return finishURL;
0613: }
0614:
0615: if (url == null) {
0616: url = finishURL;
0617: }
0618: return (url);
0619:
0620: //} catch (InvalidEditFormDataException ie) {
0621: //throw ie;
0622: } catch (Exception e) {
0623: logger.log(Level.INFO, "", e);
0624: return finishURL;
0625: }
0626: }
0627:
0628: private URL processAppPrefsMainEdit(MailProvider mprov,
0629: HttpServletRequest req, HttpServletResponse res) {
0630: try {
0631: //
0632: // Process signature...
0633: //
0634: setSAALStringAttribute(req, "sunMobileAppMailSignature",
0635: req.getParameter("signature"));
0636:
0637: //
0638: // Process pre-defined replies...
0639: //
0640: Vector predefinedReplies = new Vector();
0641: for (int i = 1; i <= PREDEFINED_REPLIES_LENGTH; i++) {
0642: String reply = req.getParameter("preset" + i);
0643: predefinedReplies.add("preset" + i + "=" + reply);
0644: }
0645: HashSet predefinedRepliesSet = new HashSet(
0646: predefinedReplies);
0647: setSAALAttribute(req, "sunMobileAppMailPredefinedReplies",
0648: predefinedRepliesSet);
0649:
0650: //
0651: // Process sent folder copy flag...
0652: //
0653: String sentFolderCopy = req.getParameter("sentFolderCopy");
0654: if (sentFolderCopy != null) {
0655: appConfig.setProperty("sentFolderCopy", "true");
0656: } else {
0657: appConfig.setProperty("sentFolderCopy", "false");
0658: }
0659:
0660: //
0661: // Process from address...
0662: //
0663: String fromAddress = req.getParameter("fromAddress");
0664: if (fromAddress != null) {
0665: appConfig.setProperty("fromAddress", fromAddress);
0666: }
0667:
0668: appConfigFactory.writeConfiguration(appConfig,
0669: new SSOAdapterSession(req));
0670:
0671: } catch (Exception e) {
0672: logger.log(Level.INFO, "", e);
0673: return null;
0674: }
0675: return null;
0676: }
0677:
0678: private URL processAppPrefsPopEdit(MailProvider mprov,
0679: HttpServletRequest req, HttpServletResponse res)
0680: throws ProviderException {
0681: String process = req.getParameter("process");
0682:
0683: if (process != null) { // AddPop or EditPop
0684: String configName = req.getParameter("configName");
0685: // return URL to edit page with error message
0686: if (configName == null || configName.length() == 0) {
0687: return (getAppPrefsEditReturnURL(mprov, req, bundle
0688: .getString("MAJspMailAppHelper-noconfigname")));
0689: //throw new InvalidEditFormDataException(bundle.getString("MAJspMailAppHelper-noconfigname"));
0690: }
0691:
0692: String host = req.getParameter("host");
0693: if (host == null || host.length() == 0) {
0694: return (getAppPrefsEditReturnURL(mprov, req, bundle
0695: .getString("MAJspMailAppHelper-nohost")));
0696: //throw new InvalidEditFormDataException(bundle.getString("MAJspMailAppHelper-nohost"));
0697: }
0698:
0699: String portString = req.getParameter("port");
0700: if (portString != null && portString.length() != 0) {
0701: try {
0702: int i = Integer.parseInt(portString);
0703: } catch (Exception e) {
0704: String errMsg = bundle
0705: .getString("MAJspMailAppHelper-invalidPortNum");
0706: return (getAppPrefsEditReturnURL(mprov, req, errMsg));
0707: }
0708: }
0709:
0710: Configuration props;
0711: try {
0712: props = ssoConfigFactory.readConfiguration(configName,
0713: true, new SSOAdapterSession(req));
0714: } catch (Exception e) {
0715: //throw new ProviderException(e.toString());
0716: //TODO: ??? Waiting for Configuration.readConfiguration fix...
0717: //return null;
0718: props = null;
0719: }
0720: if (props == null) { // Edit Work around for SSO API
0721: props = new Configuration();
0722: props.setConfigurationName(configName);
0723: // TODO: hardcoding this is wrong...
0724: props
0725: .setConfigurationDescription(AppConfigConstants.POP_COLLECTIONS_TEMPLATE_NAME);
0726: }
0727:
0728: props.setProperty("protocol", "pop3");
0729: setSSOProperty(props, "host", "host", req);
0730: setSSOProperty(props, "port", "port", req);
0731: setSSOProperty(props, "uid", "uid", req);
0732: setSSOProperty(props, "password", "password", req);
0733: //setSSOProperty(props, "popDelete", "popDelete", req);
0734: if (req.getParameter("popDelete") != null) {
0735: props.setProperty("popDelete", "true");
0736: } else {
0737: props.setProperty("popDelete", "false");
0738: }
0739:
0740: if (process.equals("AddPop")) {
0741: try {
0742: ssoConfigFactory.writeConfiguration(props,
0743: new SSOAdapterSession(req));
0744: } catch (Exception e) {
0745:
0746: if (logger.isLoggable(Level.INFO)) {
0747: LogRecord rec = new LogRecord(Level.INFO,
0748: "PSMA_CSPWPM0031");
0749: String[] param = { configName };
0750: rec.setParameters(param);
0751: rec.setThrown(e);
0752: rec.setLoggerName(logger.getName());
0753: logger.log(rec);
0754: }
0755: // return URL to edit page with error message
0756: String errMsg = bundle
0757: .getString("MAJspMailAppHelper-addpopfail");
0758: return (getAppPrefsEditReturnURL(mprov, req, errMsg));
0759: }
0760: } else { // (process.equals("EditPop")
0761: try {
0762: if (configName.equals(editPopSelected)) { //no config. name change
0763: ssoConfigFactory.writeConfiguration(props,
0764: new SSOAdapterSession(req));
0765: } else { //config name changed
0766: ssoConfigFactory.writeConfiguration(props,
0767: new SSOAdapterSession(req));
0768: ssoConfigFactory.removeConfiguration(
0769: editPopSelected, new SSOAdapterSession(
0770: req));
0771: }
0772: } catch (Exception e) {
0773: if (logger.isLoggable(Level.INFO)) {
0774: LogRecord rec = new LogRecord(Level.INFO,
0775: "PSMA_CSPWPM0030");
0776: String[] param = { configName };
0777: rec.setParameters(param);
0778: rec.setThrown(e);
0779: rec.setLoggerName(logger.getName());
0780: logger.log(rec);
0781: }
0782:
0783: // return URL to edit page with error message
0784: String errMsg = bundle
0785: .getString("MAJspMailAppHelper-editpopfail");
0786: return (getAppPrefsEditReturnURL(mprov, req, errMsg));
0787: }
0788: }
0789: } else { // (req.getParameter("DeletePop") != null)
0790: String selection = req.getParameter("popConfigs");
0791: try {
0792: if (selection != null) {
0793: ssoConfigFactory.removeConfiguration(selection,
0794: new SSOAdapterSession(req));
0795: }
0796: } catch (Exception e) {
0797: if (logger.isLoggable(Level.INFO)) {
0798: LogRecord rec = new LogRecord(Level.INFO,
0799: "PSMA_CSPWPM0029");
0800: String[] param = { selection };
0801: rec.setParameters(param);
0802: rec.setThrown(e);
0803: rec.setLoggerName(logger.getName());
0804: logger.log(rec);
0805:
0806: }
0807:
0808: // return URL to edit page with error message
0809: String errMsg = bundle
0810: .getString("MAJspMailAppHelper-deletepopfail");
0811: return (getAppPrefsEditReturnURL(mprov, req, errMsg));
0812: }
0813: }
0814:
0815: return (getAppPrefsEditReturnURL(mprov, req));
0816: }
0817:
0818: private String getSAALStringAttribute(HttpServletRequest req,
0819: String name) {
0820: try {
0821: return saalContext.getStringAttribute(serviceMap, name);
0822: } catch (Exception e) {
0823: return null;
0824: }
0825: }
0826:
0827: private void setSAALStringAttribute(HttpServletRequest req,
0828: String name, String value) throws Exception {
0829: saalContext.setStringAttribute(serviceMap, name, value);
0830: }
0831:
0832: private Set getSAALAttribute(HttpServletRequest req, String name) {
0833: try {
0834: return saalContext.getAttribute(serviceMap, name);
0835: } catch (Exception e) {
0836: return null;
0837: }
0838: }
0839:
0840: private void setSAALAttribute(HttpServletRequest req, String name,
0841: Set value) throws Exception {
0842: saalContext.setAttribute(serviceMap, name, value);
0843: }
0844:
0845: private String getAppConfigString(HttpServletRequest req,
0846: String name) {
0847: if (appConfig == null) {
0848: try {
0849: appConfig = appConfigFactory.readConfiguration(
0850: ssoAdapter.getName(), true,
0851: new SSOAdapterSession(req));
0852: if (appConfig == null) {
0853: appConfig = new Configuration();
0854: appConfig
0855: .setConfigurationName(ssoAdapter.getName());
0856: appConfig
0857: .setConfigurationDescription(AppConfigConstants.MAIL_APP_TEMPLATE_NAME);
0858: }
0859: } catch (Exception e) {
0860: return null;
0861: }
0862: }
0863: return appConfig.getProperty(name);
0864: }
0865:
0866: /**
0867: * Set tags in a Hashtable from SSO attibute
0868: */
0869: private void setTagtable(Hashtable table, String tag,
0870: Configuration configProps, String prop) {
0871: String value = configProps.getProperty(prop);
0872:
0873: if (value != null) {
0874: table.put(tag, value);
0875: }
0876: }
0877:
0878: /**
0879: * Set properties for SSO attibute
0880: */
0881: private void setSSOProperty(Configuration configProps, String prop,
0882: String param, HttpServletRequest request) {
0883: String value = request.getParameter(param);
0884:
0885: if (value != null) {
0886: configProps.setProperty(prop, value);
0887: } else {
0888: configProps.getHashMap().remove(prop);
0889: }
0890: }
0891:
0892: /**
0893: * Return URL to main edit page
0894: */
0895: private URL getEditReturnURL(MailProvider mprov,
0896: HttpServletRequest request) {
0897: String desktopURL = mprov.getProviderContext().getDesktopURL(
0898: request);
0899: desktopURL += "?action=edit";
0900: desktopURL += "&provider=" + URLEncoder.encode(editContainer);
0901: desktopURL += "&targetprovider=" + mprov.getName();
0902: desktopURL += "&containerName=" + URLEncoder.encode(container);
0903:
0904: URL url = null;
0905: try {
0906: url = new URL(desktopURL);
0907: } catch (MalformedURLException e) {
0908: logger.log(Level.INFO, "", e);
0909: }
0910: return (url);
0911: }
0912:
0913: /**
0914: * Return URL to main edit page
0915: */
0916: private URL getAppPrefsEditReturnURL(MailProvider mprov,
0917: HttpServletRequest request) {
0918: String desktopURL = mprov.getProviderContext().getDesktopURL(
0919: request);
0920: desktopURL += "?action=edit";
0921: desktopURL += "&provider=" + URLEncoder.encode(editContainer);
0922: desktopURL += "&targetprovider=" + mprov.getName();
0923: desktopURL += "&containerName=" + URLEncoder.encode(container);
0924: desktopURL += "&appPref=" + URLEncoder.encode(this .getName());
0925:
0926: URL url = null;
0927: try {
0928: url = new URL(desktopURL);
0929: } catch (MalformedURLException e) {
0930: logger.log(Level.INFO, "", e);
0931: }
0932: return (url);
0933: }
0934:
0935: /**
0936: * Return URL to main edit page with error message
0937: */
0938: private URL getEditReturnURL(MailProvider mprov,
0939: HttpServletRequest request, String errMsg) {
0940: String desktopURL = mprov.getProviderContext().getDesktopURL(
0941: request);
0942: desktopURL += "?action=edit";
0943: desktopURL += "&provider=" + URLEncoder.encode(editContainer);
0944: desktopURL += "&targetprovider=" + mprov.getName();
0945: desktopURL += "&containerName=" + URLEncoder.encode(container);
0946: desktopURL += "&error=" + errMsg;
0947:
0948: URL url = null;
0949: try {
0950: url = new URL(desktopURL);
0951: } catch (MalformedURLException e) {
0952: //mprov.getProviderContext().debugError("MailProvider.getEditReturnURL(): ", e);
0953: }
0954: return (url);
0955: }
0956:
0957: /**
0958: * Return URL to main edit page with error message
0959: */
0960: private URL getAppPrefsEditReturnURL(MailProvider mprov,
0961: HttpServletRequest request, String errMsg) {
0962: String desktopURL = mprov.getProviderContext().getDesktopURL(
0963: request);
0964: desktopURL += "?action=edit";
0965: desktopURL += "&provider=" + URLEncoder.encode(editContainer);
0966: desktopURL += "&targetprovider=" + mprov.getName();
0967: desktopURL += "&containerName=" + URLEncoder.encode(container);
0968: desktopURL += "&appPref=" + URLEncoder.encode(this .getName());
0969: desktopURL += "&error=" + errMsg;
0970:
0971: URL url = null;
0972: try {
0973: url = new URL(desktopURL);
0974: } catch (MalformedURLException e) {
0975: //mprov.getProviderContext().debugError("MailProvider.getEditReturnURL(): ", e);
0976: }
0977: return (url);
0978: }
0979:
0980: /**
0981: * Returns a HTML link containing encoding specific for the app helper
0982: */
0983:
0984: public String getAppHelperEditLink(HttpServletRequest req,
0985: ProviderContext pc) {
0986:
0987: try {
0988: prefsReqInit(req);
0989: } catch (Exception e) {
0990: return "";
0991: }
0992:
0993: Hashtable tagTable = new Hashtable();
0994: StringBuffer link = new StringBuffer();
0995: try {
0996: link.append(pc.getDesktopURL(req));
0997: } catch (Exception e) {
0998: return "";
0999: }
1000: link.append("?action=edit&provider=");
1001: link.append(ProviderEditUtility.getRequestParameter("provider",
1002: req));
1003: link.append("&targetprovider=" + provider.getName());
1004: link.append("&containerName=");
1005: link.append(ProviderEditUtility.getRequestParameter(
1006: "containerName", req));
1007: link.append("&appPref=" + this .getName());
1008:
1009: tagTable.put("editLink", link.toString());
1010:
1011: String content = null;
1012:
1013: //Put theme attrs
1014: try {
1015: ProviderUtility.setDefaultPresentation(provider.getName(),
1016: provider.getProviderContext(), tagTable);
1017: } catch (ProviderContextException pce) {
1018: logger.log(Level.INFO, "", pce);
1019: }
1020:
1021: try {
1022: String fontTag = pc.getStringProperty(provider.getName(),
1023: "fontFace1", "Sans-serif");
1024: tagTable.put("iwtDesktop-fontFace1", fontTag);
1025: content = pc.getTemplate(provider.getName(),
1026: "ma-edit-link.template", tagTable).toString();
1027: if (logger.isLoggable(Level.FINEST)) {
1028: String[] param = { "content", content.toString() };
1029: logger.log(Level.FINEST, "PSMA_CSPWPM0001", param);
1030: }
1031:
1032: } catch (Exception e) {
1033: logger.log(Level.INFO, "PSMA_CSPWPM0028", e);
1034: content = "";
1035: }
1036:
1037: logger.log(Level.FINEST, "PSMA_CSPWPM0027", content.toString());
1038:
1039: return content;
1040: }
1041:
1042: /**
1043: * Sets the App Helpers name
1044: */
1045: public void setName(String name) {
1046: this .appName = name;
1047: }
1048:
1049: /**
1050: * Gets the App Helpers name
1051: */
1052: public String getName() {
1053: return this.appName;
1054: }
1055:
1056: }
|