001: /*
002: *
003: * Copyright 2000 Sun Microsystems, Inc. All rights reserved.
004: * PROPRIETARY/CONFIDENTIAL. Use of this product is subject to license terms.
005: */
006:
007: package com.sun.portal.comm.url;
008:
009: import javax.mail.Address;
010: import javax.mail.Message;
011: import javax.mail.MessagingException;
012:
013: import com.sun.ssoadapter.SSOAdapter;
014:
015: public class ExchangeMailURLBuilder extends URLBuilder implements
016: MailURL {
017:
018: /**
019: * Call prior init functions and set the path to the exchange operation
020: *
021: * @param SSOAdapter ssoadapter used to init everything
022: */
023: public void init(SSOAdapter ssoAdapter) {
024: super .init(ssoAdapter);
025: setPath(adapterProperties.getProperty("exchangeContextPath",
026: "/exchange"));
027: }
028:
029: /**Message
030: * Return URL string for mail client.
031: *
032: * @return String Client start URL
033: */
034: public String getStartURL() {
035: StringBuffer startURL = new StringBuffer(getBaseURL());
036: startURL.append(getPath());
037: String exchangeOperation = adapterProperties
038: .getProperty("exchangeOperation");
039: if (exchangeOperation != null) {
040: startURL.append('/');
041: startURL.append(encode(user));
042: startURL.append('/');
043: startURL.append(encode(exchangeOperation));
044: }
045: return startURL.toString();
046: }
047:
048: /**
049: * Lets invoking classes know if per-message urls are available
050: * in this URLBuilder.
051: *
052: * @return boolean Are message URLs available
053: */
054: public boolean allowsMessageURL() {
055: return true;
056: }
057:
058: /**
059: * Return URL string for specific message to be opened in mail client.
060: * On error return the start URL
061: *
062: * @param javax.mail.Message The message to open
063: * @return String Message URL string
064: */
065: public String getMessageURL(Message message) {
066:
067: StringBuffer result = new StringBuffer(getStartURL());
068: result.append("/");
069: result.append(encode(user));
070: result.append("/");
071: result.append(message.getFolder());
072: result.append("/");
073: try {
074: result.append(encodec(changeSubjectToURL(message
075: .getSubject())));
076: } catch (MessagingException ex) {
077: ex.printStackTrace();
078: }
079: result.append(".EML?Cmd=open");
080: return result.toString();
081: }
082:
083: /**
084: * Lets invoking classes know if composing URLs are available
085: * in this URLBuilder.
086: *
087: * @return boolean Are compisition URLs available
088: */
089: public boolean allowsComposeURL() {
090: return false;
091: }
092:
093: /**
094: * Return URL string to open the client's compose window.
095: *
096: * @param String Subject of the message
097: * @param javax.mail.Address[] Array of to: addresses
098: * @param javax.mail.Address[] Array of cc: addresses
099: * @param javax.mail.Address[] Array of bcc: addresses
100: * @return String Composition URL string
101: */
102: public String getComposeURL(String subject, Address[] to,
103: Address[] cc, Address[] bcc) {
104: return getStartURL();
105: }
106:
107: private String changeSubjectToURL(String subject) {
108: if (subject == null) {
109: return "No Subject";
110: }
111: if (subject.startsWith("Canceled:")) {
112: return subject.substring(9).trim();
113: }
114: return subject.trim();
115: }
116:
117: private static String encodec(String text) {
118: StringBuffer result = new StringBuffer();
119: int i = 0;
120: while (i < text.length()) {
121: char ch = text.charAt(i);
122: if (ch == ' ') {
123: result.append("%20");
124: } else {
125: result.append(ch);
126: }
127: i++;
128: }
129: return result.toString();
130: }
131:
132: }
|