0001: /*
0002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
0003: *
0004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
0005: *
0006: * The contents of this file are subject to the terms of either the GNU
0007: * General Public License Version 2 only ("GPL") or the Common
0008: * Development and Distribution License("CDDL") (collectively, the
0009: * "License"). You may not use this file except in compliance with the
0010: * License. You can obtain a copy of the License at
0011: * http://www.netbeans.org/cddl-gplv2.html
0012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
0013: * specific language governing permissions and limitations under the
0014: * License. When distributing the software, include this License Header
0015: * Notice in each file and include the License file at
0016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
0017: * particular file as subject to the "Classpath" exception as provided
0018: * by Sun in the GPL Version 2 section of the License file that
0019: * accompanied this code. If applicable, add the following below the
0020: * License Header, with the fields enclosed by brackets [] replaced by
0021: * your own identifying information:
0022: * "Portions Copyrighted [year] [name of copyright owner]"
0023: *
0024: * Contributor(s):
0025: *
0026: * The Original Software is NetBeans. The Initial Developer of the Original
0027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
0028: * Microsystems, Inc. All Rights Reserved.
0029: *
0030: * If you wish your version of this file to be governed by only the CDDL
0031: * or only the GPL Version 2, indicate your decision by adding
0032: * "[Contributor] elects to include this software in this distribution
0033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
0034: * single choice of license, a recipient has the option to distribute
0035: * your version of this file under either the CDDL, the GPL Version 2 or
0036: * to extend the choice of license to its licensees as provided above.
0037: * However, if you add GPL Version 2 code and therefore, elected the GPL
0038: * Version 2 license, then the option applies only if the new code is
0039: * made subject to such option by the copyright holder.
0040: */
0041: package org.netbeans.modules.collab.provider.im;
0042:
0043: import com.sun.collablet.Account;
0044: import com.sun.collablet.CollabException;
0045: import com.sun.collablet.CollabManager;
0046: import com.sun.collablet.CollabPrincipal;
0047: import com.sun.collablet.CollabSession;
0048: import com.sun.collablet.CollabletFactoryManager;
0049: import com.sun.collablet.ContactGroup;
0050: import com.sun.collablet.Conversation;
0051: import com.sun.collablet.ConversationPrivilege;
0052:
0053: import org.openide.*;
0054: import org.openide.util.*;
0055:
0056: import java.beans.*;
0057:
0058: import java.io.*;
0059:
0060: import java.util.*;
0061:
0062: import org.netbeans.lib.collab.*;
0063:
0064: import org.netbeans.modules.collab.core.Debug;
0065:
0066: /**
0067: *
0068: *
0069: * @author Todd Fast <todd.fast@sun.com>
0070: */
0071: public class IMCollabSession extends Object implements CollabSession,
0072: CollaborationSessionListener, InviteMessageStatusListener,
0073: PresenceServiceListener, PersonalStoreServiceListener,
0074: NotificationServiceListener, ConferenceServiceListener {
0075: ////////////////////////////////////////////////////////////////////////////
0076: // Class fields
0077: ////////////////////////////////////////////////////////////////////////////
0078: ////////////////////////////////////////////////////////////////////////////
0079: // Instance fields
0080: ////////////////////////////////////////////////////////////////////////////
0081: private IMCollabManager manager;
0082: private CollaborationSession session;
0083: private PresenceService presenceService;
0084: private NewsService newsService;
0085: private ConferenceService conferenceService;
0086: private NotificationService messageService;
0087: private PersonalStoreService personalStoreService;
0088: private final Object SESSION_LOCK = new Object();
0089: private Account currentLogin;
0090: private IMCollabPrincipal userPrincipal;
0091: private List conversations = Collections
0092: .synchronizedList(new ArrayList());
0093: private List subscribedConversations = Collections
0094: .synchronizedList(new ArrayList());
0095: private PropertyChangeSupport changeSupport = new PropertyChangeSupport(
0096: this );
0097: private Map principals = new HashMap();
0098: private IMContactList contactList;
0099: private boolean isLoaded = false;
0100: private PrivacyList visibleToAll = null;
0101: private PrivacyList invisibleToAll = null;
0102: private final String INVISIBLE_TO_ALL = NbBundle
0103: .getMessage(IMCollabSession.class,
0104: "LBL_IMCollabSession_InvisibleToAll");
0105: private final String VISIBLE_TO_ALL = NbBundle.getMessage(
0106: IMCollabSession.class, "LBL_IMCollabSession_VisibleToAll");
0107: private ConversationPrivilege[] _tempPrivileges = new ConversationPrivilege[0];
0108: private boolean criticalServerError = false;
0109:
0110: /**
0111: *
0112: *
0113: */
0114: protected IMCollabSession(IMCollabManager manager, Account account) {
0115: super ();
0116: this .manager = manager;
0117: this .currentLogin = account;
0118: }
0119:
0120: /**
0121: *
0122: *
0123: */
0124: public CollabManager getManager() {
0125: return manager;
0126: }
0127:
0128: /**
0129: * Associates this session object with the provider session
0130: *
0131: */
0132: protected void attachSession(CollaborationSession session)
0133: throws CollabException, CollaborationException {
0134: this .session = session;
0135:
0136: // Allocation the personal store session first, so we can properly
0137: // look up our own principal. NOTE: This is highly order dependent
0138: // and must be done before the remaining sessions are allocated
0139: // (particularly the presence session)
0140: userPrincipal = (IMCollabPrincipal) getPrincipal(session
0141: .getPrincipal());
0142: userPrincipal.setDisplayName(getDisplayName());
0143:
0144: personalStoreService = session.getPersonalStoreService();
0145: conferenceService = session.getConferenceService();
0146: presenceService = session.getPresenceService();
0147: newsService = session.getNewsService();
0148:
0149: personalStoreService.initialize(this );
0150: presenceService.initialize(this );
0151: conferenceService.initialize(this );
0152:
0153: String v = (String) personalStoreService.getProfile()
0154: .getProperty("licenseKey", ""); // NOI18N
0155: if (v.trim().length() == 0) {
0156: personalStoreService.getProfile().setProperty("licenseKey",
0157: "NB-50"); // NOI18N
0158: personalStoreService.getProfile().save();
0159: }
0160: String forumManage = personalStoreService.getProfile()
0161: .getProperty("sunIMAllowForumManage", "deny"); // NOI18N
0162:
0163: userPrincipal.setConversationAdminRole(forumManage
0164: .equals("allow") ? true : false);
0165:
0166: // Get the current user's principal
0167: // userPrincipal=(IMCollabPrincipal)getPrincipal(
0168: // StringUtility.removeResource(
0169: // session.getPrincipal().getUID()));
0170: // Create the contact list
0171: contactList = new IMContactList(this );
0172:
0173: // Republish events from the contact list
0174: contactList
0175: .addPropertyChangeListener(new PropertyChangeListener() {
0176: public void propertyChange(PropertyChangeEvent event) {
0177: changeSupport.firePropertyChange(event
0178: .getPropertyName(),
0179: event.getOldValue(), event
0180: .getNewValue());
0181: }
0182: });
0183:
0184: contactList.load();
0185: isLoaded = true;
0186:
0187: loadSubscribedConversations();
0188: setVisibleToAll();
0189:
0190: // Set user online
0191: publishStatus(CollabPrincipal.STATUS_ONLINE, ""); // NOI18N
0192: }
0193:
0194: /**
0195: *
0196: *
0197: */
0198: public CollabPrincipal getUserPrincipal() {
0199: return userPrincipal;
0200: }
0201:
0202: /**
0203: *
0204: *
0205: */
0206: public String getDisplayName() {
0207: return NbBundle.getMessage(IMCollabSession.class,
0208: "LBL_IMCollabSession_DisplayName",
0209: // getUserPrincipal().getDisplayName());
0210: getAccount().getDisplayName());
0211: }
0212:
0213: ////////////////////////////////////////////////////////////////////////////
0214: // Session management methods
0215: ////////////////////////////////////////////////////////////////////////////
0216:
0217: /**
0218: *
0219: *
0220: */
0221: public boolean isValid() {
0222: // TODO: Add additional checks here
0223: return isLoggedIn();
0224: }
0225:
0226: /**
0227: *
0228: *
0229: */
0230: public boolean isLoggedIn() {
0231: return session != null;
0232: }
0233:
0234: /**
0235: *
0236: *
0237: */
0238: public Account getAccount() {
0239: return currentLogin;
0240: }
0241:
0242: /**
0243: *
0244: *
0245: */
0246: public void logout() {
0247: try {
0248: synchronized (SESSION_LOCK) {
0249: if (session != null) {
0250: // Leave all conversations
0251: Conversation[] conversations = getConversations();
0252:
0253: for (int i = 0; i < conversations.length; i++) {
0254: try {
0255: conversations[i].leave();
0256: } catch (Exception e) {
0257: // Ignore
0258: Debug.debugNotify(e);
0259: }
0260: }
0261:
0262: // Set the user offline
0263: try {
0264: if (!skipSend()) {
0265: publishStatus(
0266: CollabPrincipal.STATUS_OFFLINE, ""); // NOI18N
0267: }
0268: } catch (Exception e) {
0269: // Ignore
0270: Debug.debugNotify(e);
0271: }
0272:
0273: // Logout from the conference session
0274: try {
0275: conferenceService = null;
0276: personalStoreService = null;
0277: presenceService = null;
0278: } catch (Exception e) {
0279: // Ignore
0280: Debug.debugNotify(e);
0281: }
0282:
0283: // Logout from the collaboration session
0284: try {
0285: session.logout();
0286: session = null;
0287: } catch (Exception e) {
0288: // Ignore
0289: Debug.debugNotify(e);
0290: }
0291:
0292: Debug.out.println("Logged out successfully");
0293: }
0294: }
0295: } catch (Exception e) {
0296: // Ignore
0297: Debug.debugNotify(e);
0298: }
0299:
0300: // Remove ourselves from the manager
0301: ((IMCollabManager) getManager()).removeSession(this );
0302: }
0303:
0304: ////////////////////////////////////////////////////////////////////////////
0305: // IM session accessors
0306: ////////////////////////////////////////////////////////////////////////////
0307:
0308: /**
0309: *
0310: *
0311: */
0312: public CollaborationSession getCollaborationSession() {
0313: return session;
0314: }
0315:
0316: /**
0317: *
0318: *
0319: */
0320: public PresenceService getPresenceService() {
0321: return presenceService;
0322: }
0323:
0324: /**
0325: *
0326: *
0327: */
0328: public NewsService getNewsService() {
0329: return newsService;
0330: }
0331:
0332: /**
0333: *
0334: *
0335: */
0336: public ConferenceService getConferenceService() {
0337: return conferenceService;
0338: }
0339:
0340: /**
0341: *
0342: *
0343: */
0344: public NotificationService getMessageService() {
0345: return messageService;
0346: }
0347:
0348: /**
0349: *
0350: *
0351: */
0352: public PersonalStoreService getPersonalStoreService() {
0353: return personalStoreService;
0354: }
0355:
0356: /**
0357: *
0358: *
0359: */
0360: protected IMContactList getContactList() {
0361: return contactList;
0362: }
0363:
0364: ////////////////////////////////////////////////////////////////////////////
0365: // Conversation management methods
0366: ////////////////////////////////////////////////////////////////////////////
0367:
0368: /**
0369: *
0370: *
0371: */
0372: public Conversation createConversation() throws CollabException {
0373: try {
0374: // TODO: Assume management access level for now; should this ever
0375: // be anything different?
0376: // IMConversation conversation=new IMConversation(this);
0377: // Conference conference=getConferenceService().setupConference(
0378: // conversation,Conference.MANAGE);
0379: // conversation.attachConference(conference);
0380: IMConversation conversation = new IMConversation(this , true);
0381:
0382: // Track this conversation
0383: addConversation(conversation);
0384:
0385: // Configure the channels for this conversation. We do this
0386: // after add the conversation to out list so that it has a chance
0387: // to fire channel change messages to listeners (not that this
0388: // is expected to be very likely, but it helps maintainability to
0389: // preserve proper semantics).
0390: CollabletFactoryManager.getDefault().configureChannels(
0391: conversation);
0392:
0393: return conversation;
0394: } catch (CollaborationException e) {
0395: CollabException ex = new CollabException(e,
0396: "Could not create new confersation");
0397: throw ex;
0398: }
0399: }
0400:
0401: /**
0402: *
0403: *
0404: */
0405: public Conversation[] getConversations() {
0406: return (Conversation[]) conversations
0407: .toArray(new Conversation[conversations.size()]);
0408: }
0409:
0410: /**
0411: *
0412: *
0413: */
0414: public String[] getSubscribedPublicConversations() {
0415: return (String[]) subscribedConversations
0416: .toArray(new String[subscribedConversations.size()]);
0417: }
0418:
0419: /**
0420: *
0421: *
0422: */
0423: protected void addConversation(Conversation conversation) {
0424: conversations.add(conversation);
0425:
0426: // TODO: Include old/new conversation arrays
0427: changeSupport
0428: .firePropertyChange(PROP_CONVERSATIONS, null, null);
0429: }
0430:
0431: /**
0432: * Note, this method does not leave the conversation; it only removes it
0433: * from the internal list of current conversations.
0434: *
0435: */
0436: protected void removeConversation(Conversation conversation) {
0437: conversations.remove(conversation);
0438:
0439: // TODO: Include old/new conversation arrays
0440: changeSupport
0441: .firePropertyChange(PROP_CONVERSATIONS, null, null);
0442: }
0443:
0444: /**
0445: *
0446: *
0447: */
0448: protected void addSubscribedConversation(String conversationName) {
0449: subscribedConversations.add(conversationName);
0450:
0451: // TODO: Include old/new conversation arrays
0452: changeSupport
0453: .firePropertyChange(PROP_CONVERSATIONS, null, null);
0454: }
0455:
0456: /**
0457: * Note, this method does not leave the conversation; it only removes it
0458: * from the internal list of current conversations.
0459: *
0460: */
0461: protected void removeSubscribedConversation(String conversationName) {
0462: subscribedConversations.remove(conversationName);
0463:
0464: // TODO: Include old/new conversation arrays
0465: changeSupport
0466: .firePropertyChange(PROP_CONVERSATIONS, null, null);
0467: }
0468:
0469: /**
0470: *
0471: *
0472: */
0473: public String[] findPublicConversations(int searchType,
0474: String pattern) {
0475: try {
0476: int type = personalStoreService.SEARCHTYPE_CONTAINS;
0477:
0478: switch (searchType) {
0479: case CollabSession.SEARCHTYPE_CONTAINS:
0480: type = personalStoreService.SEARCHTYPE_CONTAINS;
0481:
0482: break;
0483:
0484: case CollabSession.SEARCHTYPE_ENDSWITH:
0485: type = personalStoreService.SEARCHTYPE_ENDSWITH;
0486:
0487: break;
0488:
0489: case CollabSession.SEARCHTYPE_EQUALS:
0490: type = personalStoreService.SEARCHTYPE_EQUALS;
0491:
0492: break;
0493:
0494: case CollabSession.SEARCHTYPE_STARTSWITH:
0495: type = personalStoreService.SEARCHTYPE_STARTSWITH;
0496: }
0497:
0498: PersonalStoreEntry[] entries = personalStoreService.search(
0499: type, pattern, PersonalStoreEntry.CONFERENCE);
0500:
0501: if (entries == null) {
0502: return null;
0503: }
0504:
0505: // Conference[] conferences=new Conference[entries.length];
0506: // IMConversation[] conversations=new IMConversation[entries.length];
0507: List conversations = new ArrayList();
0508:
0509: String[] ret = new String[entries.length];
0510:
0511: for (int i = 0; i < entries.length; i++) {
0512: // Conference conference = getConferenceService().getPublicConference(entries[i].getEntryId());
0513: ret[i] = entries[i].getEntryId();
0514: }
0515:
0516: return ret;
0517: } catch (CollaborationException ne) {
0518: Debug.debugNotify(ne);
0519:
0520: return null;
0521: }
0522: }
0523:
0524: /**
0525: *
0526: *
0527: */
0528: public String[] getPublicConversations() {
0529: return findPublicConversations(
0530: PersonalStoreService.SEARCHTYPE_EQUALS, "*");
0531: }
0532:
0533: /**
0534: *
0535: *
0536: */
0537: public void loadSubscribedConversations() throws CollabException {
0538: try {
0539: Collection conferences = getPersonalStoreService()
0540: .getEntries(PersonalStoreEntry.CONFERENCE);
0541: Iterator it = new ArrayList(conferences).iterator();
0542:
0543: while (it.hasNext()) {
0544: PersonalConference entry = (PersonalConference) it
0545: .next();
0546: String address = entry.getAddress();
0547: Conference con = getConferenceService()
0548: .getPublicConference(address);
0549:
0550: // if (publicConversationExists(address))
0551: if (con != null) {
0552: // Conference conf = getConferenceService().getPublicConference(address);
0553: addSubscribedConversation(con.getDestination());
0554: } else {
0555: unsubscribePublicConversation(address);
0556: }
0557: }
0558: } catch (CollaborationException e) {
0559: throw new CollabException(e);
0560: }
0561: }
0562:
0563: ////////////////////////////////////////////////////////////////////////////
0564: // Service listener methods
0565: ////////////////////////////////////////////////////////////////////////////
0566:
0567: /**
0568: *
0569: *
0570: */
0571: public void onInvite(Conference conference, InviteMessage message) {
0572: try {
0573: //skip non-invite type messages
0574: // if(!acceptMessage(message))
0575: // {
0576: // return;
0577: // }
0578: //workaround for bug#6269975
0579: //return if not proper invitation message
0580: String inviteMsg = message.getContent();
0581:
0582: if ((inviteMsg != null)
0583: && (inviteMsg.indexOf("<?xml") != -1)) {
0584: return;
0585: }
0586:
0587: // Prompt user to join the conference
0588: boolean join = getManager().getUserInterface()
0589: .acceptConversation(
0590: this ,
0591: getPrincipal(StringUtility
0592: .removeResource(message
0593: .getOriginator())),
0594: conference.getDestination(), inviteMsg);
0595:
0596: // Repond as appropriate
0597: message.rsvp(join);
0598:
0599: if (join) {
0600: // Spawn a new listener for conference events
0601: IMConversation conversation = new IMConversation(this ,
0602: conference);
0603: conference.join(conversation);
0604:
0605: // Add the conference to our internal list
0606: if (subscribedConversations.contains(conference
0607: .getDestination())) {
0608: changeSupport.firePropertyChange(
0609: PROP_PUBLIC_CONVERSATIONS, null,
0610: conversation);
0611: }
0612:
0613: addConversation(conversation);
0614:
0615: // Configure the channels for this conversation. We do this
0616: // after add the conversation to out list so that it has a
0617: // chance to fire channel change messages to listeners (not
0618: // that this is expected to be very likely, but it helps
0619: // maintainability to preserve proper semantics).
0620: CollabletFactoryManager.getDefault().configureChannels(
0621: conversation);
0622:
0623: // Make sure the conversation is showing
0624: getManager().getUserInterface().showConversation(
0625: conversation);
0626: }
0627: } catch (CollabException e) {
0628: // TODO: Need proper error handling
0629: Debug.errorManager.notify(e);
0630: } catch (CollaborationException e) {
0631: // TODO: Need proper error handling
0632: Debug.errorManager.notify(e);
0633: }
0634: }
0635:
0636: /**
0637: *
0638: *
0639: */
0640: public boolean acceptMessage(InviteMessage message)
0641: throws CollabException {
0642: //return true;
0643: // TODO: How do we discriminate chat messages from any other message?
0644: // TODO: Temporary impl
0645: try {
0646: // String messageContent=message.getContent();
0647: // if (messageContent==null || messageContent.trim().length()==0)
0648: // {
0649: // return true;
0650: // }
0651: String channelType = message.getHeader("x-channel");
0652:
0653: if ((channelType != null) && "chat".equals(channelType)) {
0654: return true;
0655: }
0656: } catch (Exception e) {
0657: throw new CollabException(e);
0658: }
0659:
0660: return false;
0661: }
0662:
0663: ////////////////////////////////////////////////////////////////////////////
0664: // Property change methods
0665: ////////////////////////////////////////////////////////////////////////////
0666:
0667: /**
0668: *
0669: *
0670: */
0671: public void addPropertyChangeListener(
0672: PropertyChangeListener listener) {
0673: changeSupport.addPropertyChangeListener(listener);
0674: }
0675:
0676: /**
0677: *
0678: *
0679: */
0680: public void removePropertyChangeListener(
0681: PropertyChangeListener listener) {
0682: changeSupport.removePropertyChangeListener(listener);
0683: }
0684:
0685: ////////////////////////////////////////////////////////////////////////////
0686: // CollaborationSessionListener methods
0687: ////////////////////////////////////////////////////////////////////////////
0688:
0689: /**
0690: *
0691: *
0692: */
0693: public void onError(CollaborationException e) {
0694: if (e != null && e.getMessage() != null
0695: && e.getMessage().indexOf("Server Disconnected") != -1) { //NOI18N
0696: criticalServerError = true;
0697: ((IMCollabManager) getManager()).getReconnect()
0698: .startReconnect(this );
0699:
0700: javax.swing.SwingUtilities.invokeLater(new Runnable() {
0701: public void run() {
0702: logout();
0703: }
0704: });
0705: } else {
0706: e.printStackTrace(); // System.err -> ide.log
0707: Debug.logDebugException("onError called with exception", e,
0708: true);
0709:
0710: // Show a friendly user error
0711: getManager().getUserInterface().notifySessionError(this ,
0712: e.getMessage());
0713: }
0714: }
0715:
0716: /**
0717: *
0718: *
0719: */
0720: public void onRsvp(String destination, boolean accepted) {
0721: onRsvp(destination, null, accepted);
0722: }
0723:
0724: /**
0725: *
0726: *
0727: */
0728: public void onRsvp(String destination, Message message,
0729: boolean accepted) {
0730: try {
0731: if (!accepted) {
0732: String msg = (message == null) ? "" : message
0733: .getContent();
0734: CollabPrincipal principal = getPrincipal(StringUtility
0735: .removeResource(destination));
0736: String decliner = principal.getDisplayName();
0737:
0738: // Notify user
0739: getManager().getUserInterface()
0740: .notifyInvitationDeclined(decliner, msg);
0741:
0742: // Remove the decliner from the invited participant list.
0743: // Note, this is only a 90% solution, since we actually
0744: // don't know which conversation to remove them from. In
0745: // practice, however, it's unlikely we'll have more than
0746: // one conversation on the same client inviting the same user,
0747: // and even if so, the lost of the invited user is not really
0748: // a significant issue.
0749: Conversation[] conversations = getConversations();
0750:
0751: for (int i = 0; i < conversations.length; i++) {
0752: ((IMConversation) conversations[i])
0753: .removeInvitedParticipant(principal);
0754: }
0755: }
0756: } catch (CollaborationException e) {
0757: Debug.debugNotify(e);
0758: } catch (CollabException ce) {
0759: Debug.errorManager.notify(ce);
0760: }
0761: }
0762:
0763: ////////////////////////////////////////////////////////////////////////////
0764: // ContactGroup methods
0765: ////////////////////////////////////////////////////////////////////////////
0766:
0767: /**
0768: *
0769: *
0770: */
0771: public ContactGroup[] getContactGroups() {
0772: return getContactList().getContactGroups();
0773: }
0774:
0775: /**
0776: *
0777: *
0778: */
0779: public ContactGroup getContactGroup(String name) {
0780: return getContactList().getContactGroup(name);
0781: }
0782:
0783: /**
0784: *
0785: *
0786: */
0787: public ContactGroup createContactGroup(String name)
0788: throws CollabException {
0789: ContactGroup group = getContactList().getContactGroup(name);
0790:
0791: if (group != null) {
0792: throw new CollabException("Contact group \"" + name + // NOI18N
0793: "\" already exists"); // NOI18N
0794: }
0795:
0796: group = new IMContactGroup(getContactList(), name);
0797: getContactList().addContactGroup(group);
0798:
0799: return group;
0800: }
0801:
0802: /**
0803: *
0804: *
0805: */
0806: public CollabPrincipal[] findPrincipals(int searchType,
0807: String pattern) throws CollabException {
0808: try {
0809: int type = PersonalStoreService.SEARCHTYPE_CONTAINS;
0810:
0811: switch (searchType) {
0812: case CollabSession.SEARCHTYPE_CONTAINS:
0813: type = PersonalStoreService.SEARCHTYPE_CONTAINS;
0814:
0815: break;
0816:
0817: case CollabSession.SEARCHTYPE_ENDSWITH:
0818: type = PersonalStoreService.SEARCHTYPE_ENDSWITH;
0819:
0820: break;
0821:
0822: case CollabSession.SEARCHTYPE_EQUALS:
0823: type = PersonalStoreService.SEARCHTYPE_EQUALS;
0824:
0825: break;
0826:
0827: case CollabSession.SEARCHTYPE_STARTSWITH:
0828: type = PersonalStoreService.SEARCHTYPE_STARTSWITH;
0829: }
0830:
0831: assert getPersonalStoreService() != null : "personalStoreService is null";
0832:
0833: // Search for principals
0834: CollaborationPrincipal[] principals = getPersonalStoreService()
0835: .searchPrincipals(type, pattern);
0836:
0837: if (principals == null) {
0838: principals = new CollaborationPrincipal[0];
0839: }
0840:
0841: // Canonicalize the principal array
0842: CollabPrincipal[] result = new CollabPrincipal[principals.length];
0843:
0844: for (int i = 0; i < principals.length; i++)
0845: result[i] = getPrincipal(principals[i]);
0846:
0847: return result;
0848: } catch (CollaborationException e) {
0849: throw new CollabException(e,
0850: "Exception during principal search"); // NOI18N
0851: }
0852: }
0853:
0854: // /**
0855: // *
0856: // *
0857: // */
0858: // public void importContactList(File file) {
0859: //// buddyListManager.importContactList(file);
0860: //
0861: // // TAF: We should do this from somewhere else I think
0862: //// changeSupport.firePropertyChange(PROP_CONTACTS,null,null);
0863: // }
0864: ////////////////////////////////////////////////////////////////////////////
0865: // PresenceListener methods
0866: ////////////////////////////////////////////////////////////////////////////
0867:
0868: /**
0869: *
0870: *
0871: */
0872: public void onPresenceNotify(String presentityURL,
0873: String presenceInfo, java.util.Date expires) {
0874: //Debug.out.println("A presence notification was received");
0875: // TODO: implement onPresenceNotify
0876: // TAF: When does this occur?
0877: }
0878:
0879: /**
0880: *
0881: *
0882: */
0883: public void onPresence(Presence presence) {
0884: // if (!isLoaded)
0885: // {
0886: // return;
0887: // }
0888: Object[] tuples = presence.getTuples().toArray();
0889: PresenceTuple tuple = (PresenceTuple) tuples[0];
0890:
0891: String uid = StringUtility.removeResource(tuple.getContact());
0892:
0893: // Ignore presence from ourselves
0894: // if (uid.equals(getUserPrincipal().getIdentifier()))
0895: // return;
0896: // ignore presence from those just deleted from roster list
0897: // try
0898: // {
0899: // PersonalStoreEntry entry = getPersonalStoreService().
0900: // getEntry(PersonalStoreEntry.CONTACT, uid);
0901: // if (entry==null)
0902: // return;
0903: // }
0904: // catch (NullPointerException e)
0905: // {
0906: // Debug.debugNotify(e);
0907: // }
0908: // catch (CollaborationException ce)
0909: // {
0910: // // ignore,
0911: // return;
0912: // }
0913: // Find the principal
0914: try {
0915: CollabPrincipal principal = getPrincipal(uid);
0916:
0917: // Handle user status
0918: String status = tuple.getStatus();
0919: String reason = tuple.getNote();
0920: setPrincipalStatus(principal, status);
0921: } catch (CollabException e) {
0922: // TODO: What should we do here?
0923: Debug.errorManager.notify(e);
0924: }
0925: }
0926:
0927: /**
0928: *
0929: *
0930: */
0931: public void onSubscribeRequest(Presence presence) {
0932: Object[] tuples = presence.getTuples().toArray();
0933: assert (tuples != null) && (tuples.length > 0) : "Presence tuple array was null or empty";
0934:
0935: PresenceTuple tuple = (PresenceTuple) tuples[0];
0936:
0937: try {
0938: /*
0939: String uid=StringUtility.getLocalPartFromAddress(
0940: tuple.getContact());
0941: */
0942: String uid = tuple.getContact();
0943: CollabPrincipal principal = getPrincipal(StringUtility
0944: .removeResource(uid));
0945:
0946: boolean approve = getManager().getUserInterface()
0947: .approvePresenceSubscription(this , principal);
0948:
0949: if (approve) {
0950: getPresenceService().authorize(uid);
0951: } else {
0952: getPresenceService().cancel(uid);
0953: }
0954: } catch (CollaborationException ce) {
0955: Debug.logDebugException("Exception in onSubscribeRequest",
0956: ce, true);
0957: } catch (CollabException e) {
0958: // TODO: Need proper error dialog here
0959: // Debug.errorManager.notify(e);
0960: Debug.logDebugException("Exception in onSubscribeRequest",
0961: e, true);
0962: }
0963: }
0964:
0965: /**
0966: *
0967: *
0968: */
0969: public void onSubscribed(Presence presence) {
0970: getContactList().refreshWatcherGroup();
0971: }
0972:
0973: /**
0974: *
0975: *
0976: */
0977: public boolean onUnsubscribeRequest(Presence presence) {
0978: getContactList().refreshWatcherGroup();
0979:
0980: // TODO: Should we prompt user here?
0981: return true;
0982: }
0983:
0984: /**
0985: * This callback is invoked to indicate unsubscribing is successful
0986: *
0987: */
0988: public void onUnsubscribed(Presence presence) {
0989: Object[] tuples = presence.getTuples().toArray();
0990: assert (tuples != null) && (tuples.length > 0) : "Presence tuple array was null or empty";
0991:
0992: PresenceTuple tuple = (PresenceTuple) tuples[0];
0993: String uid = StringUtility.removeResource(tuple.getContact());
0994: String status = tuple.getStatus();
0995:
0996: try {
0997: CollabPrincipal principal = getPrincipal(uid);
0998: int oldStatus = principal.getStatus();
0999: principal.setStatus(CollabPrincipal.STATUS_UNKNOWN);
1000:
1001: /* If the status is 'pending', it's triggered by subscription denial
1002: * otherwise, it's triggered by current user unsubscribing to contact
1003: * in his roster
1004: */
1005:
1006: // if (principal.getStatus() != CollabPrincipal.STATUS_PENDING)
1007: if (oldStatus != CollabPrincipal.STATUS_PENDING) {
1008: return;
1009: }
1010:
1011: getManager().getUserInterface().notifySubscriptionDenied(
1012: principal);
1013: } catch (CollabException e) {
1014: Debug.errorManager.notify(e);
1015: }
1016: }
1017:
1018: public void onUnsubscribe(Presence p) {
1019: }
1020:
1021: ////////////////////////////////////////////////////////////////////////////
1022: // NotificationServiceListener methods
1023: ////////////////////////////////////////////////////////////////////////////
1024:
1025: /**
1026: *
1027: *
1028: */
1029: public void onMessage(Message message) {
1030: // TODO: Implement onMessage (when does this occur?)
1031: Debug.out.println("Session message: " + message);
1032: }
1033:
1034: ////////////////////////////////////////////////////////////////////////////
1035: // PersonalStoreServiceListener methods
1036: ////////////////////////////////////////////////////////////////////////////
1037:
1038: /**
1039: *
1040: *invoked when an change of event for PersonalStoreEntry happens
1041: */
1042: public void onEvent(PersonalStoreEvent personalStoreEvent) {
1043: // Debug.out.println(" personal store entry changed");
1044: }
1045:
1046: ////////////////////////////////////////////////////////////////////////////
1047: // Principal management methods
1048: ////////////////////////////////////////////////////////////////////////////
1049:
1050: /**
1051: *
1052: *
1053: */
1054: protected CollabPrincipal getPrincipal(
1055: CollaborationPrincipal principal) throws CollabException {
1056: CollabPrincipal result = (CollabPrincipal) principals
1057: .get(principal.getUID());
1058:
1059: if (result != null) {
1060: return result;
1061: }
1062:
1063: result = new IMCollabPrincipal(this , principal);
1064:
1065: // try
1066: // {
1067: // Presence presence = getPresenceService().
1068: // fetchPresence(principal.getUID());
1069: // Object[] tuples=presence.getTuples().toArray();
1070: // assert tuples!=null && tuples.length>0:
1071: // "Presence tuple array was null or empty";
1072: //
1073: // PresenceTuple tuple=(PresenceTuple)tuples[0];
1074: // setPrincipalStatus(result, tuple.getStatus());
1075: // }
1076: // catch (CollaborationException ce)
1077: // {
1078: // throw new CollabException(ce,"Could not obtain status for principal "+ // NOI18N
1079: // "for identifier \""+principal.getUID()+"\""); // NOI18N
1080: // }
1081: addPrincipalToCache(result);
1082:
1083: return result;
1084: }
1085:
1086: /**
1087: *
1088: *
1089: */
1090: public CollabPrincipal getPrincipal(String identifier)
1091: throws CollabException {
1092: try {
1093: synchronized (principals) {
1094: CollabPrincipal element = (CollabPrincipal) principals
1095: .get(identifier);
1096:
1097: if (element != null) {
1098: return element;
1099: }
1100:
1101: // PersonalStoreEntry entry=getPersonalStoreSession().getEntry(
1102: // PersonalStoreEntry.CONTACT,identifier);
1103: // if (entry!=null)
1104: // {
1105: //Debug.out.println("- Found as entry = "+identifier);
1106: // element=new IMCollabPrincipal(this,entry.getPrincipal());
1107: // }
1108: // else
1109: // {
1110: // CollaborationPrincipal[] users = getPersonalStoreService().searchPrincipals(
1111: // PersonalStoreService.SEARCHTYPE_EQUALS, StringUtility.getLocalPartFromAddress(identifier)
1112: // );
1113:
1114: // if ((users != null) && (users.length > 0)) {
1115: // element = new IMCollabPrincipal(this, users[0]);
1116: // }
1117:
1118: if (element == null) {
1119: element = new IMCollabPrincipal(this ,
1120: getCollaborationSession().createPrincipal(
1121: identifier));
1122: }
1123:
1124: // }
1125: // fetch presence and set principal's initial status
1126: // Presence presence = getPresenceService().fetchPresence(identifier);
1127: // Object[] tuples=presence.getTuples().toArray();
1128: // assert tuples!=null && tuples.length>0:
1129: // "Presence tuple array was null or empty";
1130: //
1131: // PresenceTuple tuple=(PresenceTuple)tuples[0];
1132: // setPrincipalStatus(element, tuple.getStatus());
1133: // Debug.out.println(" fetch presence of " + tuple.getContact() + " , status: "
1134: // + tuple.getStatus());
1135: addPrincipalToCache(element);
1136:
1137: return element;
1138: }
1139: } catch (CollaborationException e) {
1140: Debug.logDebugException("Could not obtain principal", e,
1141: true);
1142:
1143: return null;
1144: }
1145: }
1146:
1147: /**
1148: *
1149: *
1150: */
1151: protected void addPrincipalToCache(CollabPrincipal principal) {
1152: if (principal == null) {
1153: return;
1154: }
1155:
1156: principals.put(principal.getIdentifier(), principal);
1157: }
1158:
1159: /**
1160: *
1161: *
1162: */
1163: protected void addPrincipalsToCache(CollabPrincipal[] p) {
1164: if (p == null) {
1165: return;
1166: }
1167:
1168: for (int i = 0; i < p.length; i++)
1169: addPrincipalToCache(p[i]);
1170: }
1171:
1172: /**
1173: *
1174: *
1175: */
1176: protected boolean isPrincipalCached(String identifier) {
1177: return principals.containsKey(identifier);
1178: }
1179:
1180: /**
1181: *
1182: *
1183: */
1184: protected void clearPrincipalCache() {
1185: principals.clear();
1186: }
1187:
1188: /**
1189: *
1190: *
1191: */
1192: public void publishStatus(int status, String reason)
1193: throws CollabException {
1194: if (getUserPrincipal() == null) {
1195: return;
1196: }
1197:
1198: try {
1199: PresenceTuple tuple = new PresenceTuple(getUserPrincipal()
1200: .getIdentifier());
1201:
1202: switch (status) {
1203: case CollabPrincipal.STATUS_ONLINE:
1204: tuple.setStatus(PresenceService.STATUS_OPEN);
1205: getUserPrincipal().setStatus(status);
1206:
1207: break;
1208:
1209: case CollabPrincipal.STATUS_OFFLINE:
1210: tuple.setStatus(PresenceService.STATUS_CLOSED);
1211: getUserPrincipal().setStatus(status);
1212:
1213: break;
1214:
1215: case CollabPrincipal.STATUS_BUSY:
1216: tuple.setStatus(PresenceService.STATUS_BUSY);
1217: getUserPrincipal().setStatus(status);
1218:
1219: break;
1220:
1221: case CollabPrincipal.STATUS_AWAY:
1222: tuple.setStatus(PresenceService.STATUS_AWAY);
1223: getUserPrincipal().setStatus(status);
1224:
1225: break;
1226:
1227: case CollabPrincipal.STATUS_IDLE:
1228: tuple.setStatus(PresenceService.STATUS_IDLE);
1229: getUserPrincipal().setStatus(status);
1230:
1231: break;
1232:
1233: default:
1234: tuple.setStatus(PresenceService.STATUS_OTHER);
1235: getUserPrincipal().setStatus(status);
1236: }
1237:
1238: tuple.addNote(reason);
1239:
1240: Presence presence = new Presence(getUserPrincipal()
1241: .getIdentifier());
1242: presence.addTuple(tuple);
1243: getPresenceService().publish(presence);
1244: } catch (CollaborationException e) {
1245: throw new CollabException(e);
1246: }
1247: }
1248:
1249: /**
1250: *
1251: *
1252: */
1253: protected void setPrincipalStatus(CollabPrincipal principal,
1254: String status) {
1255: if (status.equals(PresenceService.STATUS_OPEN)) {
1256: //Debug.out.println("Presence of "+principal+" is online");
1257: principal.setStatus(CollabPrincipal.STATUS_ONLINE);
1258: } else if (status.equals(PresenceService.STATUS_CLOSED)) {
1259: //Debug.out.println("Presence of "+principal+" is offline");
1260: principal.setStatus(CollabPrincipal.STATUS_OFFLINE);
1261: } else if (status.equals(PresenceService.STATUS_IDLE)) {
1262: //Debug.out.println("Presence of "+principal+" is idle");
1263: principal.setStatus(CollabPrincipal.STATUS_IDLE);
1264: } else if (status.equals(PresenceService.STATUS_AWAY)) {
1265: //Debug.out.println("Presence of "+principal+" is away");
1266: principal.setStatus(CollabPrincipal.STATUS_AWAY);
1267: } else if (status.equals(PresenceService.STATUS_BUSY)) {
1268: //Debug.out.println("Presence of "+principal+" is busy");
1269: principal.setStatus(CollabPrincipal.STATUS_BUSY);
1270: } else if (status.equals(PresenceService.STATUS_CHAT)) {
1271: //Debug.out.println("Presence of "+principal+" is chat");
1272: principal.setStatus(CollabPrincipal.STATUS_CHAT);
1273: }
1274: /*
1275: else
1276: if (status.equals(PresenceService.STATUS_WATCHED))
1277: {
1278: Debug.out.println("Presence of "+principal+" is watched");
1279: principal.setStatus(CollabPrincipal.STATUS_WATCHED);
1280: }
1281: */
1282: else if (status.equals(PresenceService.STATUS_PENDING)) {
1283: //Debug.out.println("Presence of "+principal+" is pending");
1284: principal.setStatus(CollabPrincipal.STATUS_PENDING);
1285: } else {
1286: //Debug.out.println("Presence of "+principal+" is unknown");
1287: principal.setStatus(CollabPrincipal.STATUS_UNKNOWN);
1288: }
1289: }
1290:
1291: public void setInvisibleToAll() throws CollabException {
1292: try {
1293: // PrivacyList invisibleToAll =
1294: // getCollaborationSession().getPrivacyList(privacyListName);
1295: if (invisibleToAll == null) {
1296: invisibleToAll = getCollaborationSession()
1297: .createPrivacyList(INVISIBLE_TO_ALL);
1298:
1299: PrivacyItem item = invisibleToAll.createPrivacyItem(
1300: null, PrivacyItem.DENY);
1301: item.setResource(PrivacyItem.PRESENCE_OUT);
1302: invisibleToAll.addPrivacyItem(item);
1303: getCollaborationSession()
1304: .addPrivacyList(invisibleToAll);
1305: }
1306:
1307: getCollaborationSession().setActivePrivacyListName(
1308: INVISIBLE_TO_ALL);
1309: } catch (CollaborationException e) {
1310: // swallow it - many servers don't support privacy list
1311: // throw new CollabException(e);
1312: }
1313: }
1314:
1315: public void setVisibleToAll() throws CollabException {
1316: try {
1317: // PrivacyList visibleToAll =
1318: // getCollaborationSession().getPrivacyList(privacyListName);
1319: if (visibleToAll == null) {
1320: visibleToAll = getCollaborationSession()
1321: .createPrivacyList(VISIBLE_TO_ALL);
1322:
1323: PrivacyItem item = visibleToAll.createPrivacyItem(null,
1324: PrivacyItem.ALLOW);
1325: item.setResource(PrivacyItem.PRESENCE_OUT);
1326: visibleToAll.addPrivacyItem(item);
1327: getCollaborationSession().addPrivacyList(visibleToAll);
1328: }
1329:
1330: getCollaborationSession().setActivePrivacyListName(
1331: VISIBLE_TO_ALL);
1332: } catch (CollaborationException e) {
1333: // swallow it - many servers don't support privacy list
1334: // throw new CollabException(e);
1335: }
1336: }
1337:
1338: /**
1339: *
1340: *
1341: */
1342: public Conversation createPublicConversation(String name)
1343: throws CollabException {
1344: Iterator it = conversations.iterator();
1345:
1346: while (it.hasNext()) {
1347: Conversation conv = (Conversation) it.next();
1348:
1349: if (conv.getIdentifier().equals(name)) {
1350: return conv;
1351: }
1352: }
1353:
1354: try {
1355: IMConversation conv = new IMConversation(this );
1356:
1357: // Find the conference, this api has a bug, it returns null only on
1358: // the first time when the unauthorized user queries it, so switch to
1359: // use publicConversationExists(name)
1360: // Conference conf=getConferenceService().getPublicConference(name);
1361: // If it doesn't exist, create it
1362: boolean created = false;
1363: Conference conf;
1364:
1365: if (!publicConversationExists(name))// if (conf==null)
1366: {
1367: // Create the conversation
1368: conf = getConferenceService().setupPublicConference(
1369: name, conv, Conference.LISTEN);
1370: created = true;
1371: } else {
1372: conf = getConferenceService().getPublicConference(name);
1373: }
1374:
1375: // Attach the conference to the conversation
1376: conv.attachConference(conf);
1377:
1378: if (created) {
1379: conv.subscribe();
1380: }
1381:
1382: conv.join();
1383: conversations.add(conv);
1384: changeSupport.firePropertyChange(PROP_PUBLIC_CONVERSATIONS,
1385: null, conv);
1386:
1387: return conv;
1388: } catch (CollaborationException e) {
1389: //throw new CollabException(e);
1390: Debug.logDebugException(
1391: "Could not create the public conversation", e,
1392: false);
1393:
1394: return null;
1395: }
1396: }
1397:
1398: /**
1399: *
1400: *
1401: */
1402: public void subscribePublicConversation(String name)
1403: throws CollabException {
1404: try {
1405: if (subscribedConversations.contains(name)) {
1406: return;
1407: }
1408:
1409: PersonalConference pc = (PersonalConference) getPersonalStoreService()
1410: .createEntry(PersonalStoreEntry.CONFERENCE, name);
1411: pc.setAddress(name);
1412: pc.save();
1413: addSubscribedConversation(name);
1414: } catch (CollaborationException ce) {
1415: throw new CollabException(ce, ce.getMessage());
1416: }
1417: }
1418:
1419: /**
1420: *
1421: *
1422: *
1423: */
1424: public void unsubscribePublicConversation(String name)
1425: throws CollabException {
1426: try {
1427: PersonalConference pc = (PersonalConference) getPersonalStoreService()
1428: .getEntry(PersonalStoreEntry.CONFERENCE, name);
1429:
1430: if (pc != null) {
1431: ((PersonalStoreEntry) pc).remove();
1432: }
1433:
1434: //setValid(false);
1435: removeSubscribedConversation(name);
1436: } catch (CollaborationException ce) {
1437: throw new CollabException(ce, ce.getMessage());
1438: }
1439: }
1440:
1441: /**
1442: * find the public conversation by its name
1443: * get the privileges of all the users affiliated with this public
1444: * conversation
1445: *
1446: * return array of ConversationPrivilege objects
1447: */
1448: public ConversationPrivilege[] getPublicConversationPrivileges(
1449: String name) throws CollabException {
1450: ArrayList result = new ArrayList();
1451:
1452: try {
1453: Map map = getConferenceService().getPublicConference(name)
1454: .listPrivileges();
1455: Iterator it = map.keySet().iterator();
1456:
1457: while (it.hasNext()) {
1458: String uid = (String) it.next();
1459: CollabPrincipal principal = getPrincipal(uid);
1460: int privilege = ((Integer) map.get(uid)).intValue();
1461: int access = convertPrivilegeToAccess(privilege);
1462:
1463: ConversationPrivilege conversationPrivilege = new ConversationPrivilege(
1464: principal, access);
1465: result.add(conversationPrivilege);
1466:
1467: // Debug.out.println(" public conf privilege: " + principal +
1468: // "with access level " + access);
1469: }
1470: } catch (CollaborationException ce) {
1471: throw new CollabException(ce);
1472: }
1473:
1474: return (ConversationPrivilege[]) result
1475: .toArray(new ConversationPrivilege[result.size()]);
1476: }
1477:
1478: /**
1479: *
1480: *
1481: */
1482: public void setPublicConversationPrivileges(String name,
1483: ConversationPrivilege[] privileges) throws CollabException {
1484: if (!canManagePublicConversation(name)) {
1485: return;
1486: }
1487:
1488: try {
1489: Conference conf = getConferenceService()
1490: .getPublicConference(name);
1491: Map map = new HashMap();
1492:
1493: for (int i = 0; i < privileges.length; i++) {
1494: String uid = privileges[i].getPrincipal()
1495: .getIdentifier();
1496: int access = privileges[i].getAccess();
1497:
1498: // Debug.out.println("Setting privilege: "+uid + "with access:" + access);
1499: map.put(uid, new Integer(
1500: convertAccessToPrivilege(access)));
1501: }
1502:
1503: conf.setPrivileges(map);
1504: } catch (CollaborationException ce) {
1505: Debug.logDebugException(
1506: "Exception in setPublicConversationPrivileges", ce,
1507: true);
1508: throw new CollabException(ce, ce.getMessage());
1509: }
1510: }
1511:
1512: /**
1513: * find the public conversation previlige of conversation=name and principal
1514: * get the privileges of all the users affiliated with this public
1515: * conversation
1516: *
1517: * return array of ConversationPrivilege objects
1518: */
1519: public ConversationPrivilege getPublicConversationPrivilege(
1520: String name, CollabPrincipal forPrincipal)
1521: throws CollabException {
1522: try {
1523: Map map = getConferenceService().getPublicConference(name)
1524: .listPrivileges();
1525: Iterator it = map.keySet().iterator();
1526:
1527: while (it.hasNext()) {
1528: String uid = (String) it.next();
1529: CollabPrincipal principal = getPrincipal(uid);
1530:
1531: //Debug.out.println(" uid: " + uid + " principal: "+principal.getIdentifier());
1532: if ((forPrincipal != null)
1533: && forPrincipal.getIdentifier().equals(uid)) {
1534: int privilege = ((Integer) map.get(uid)).intValue();
1535: int access = convertPrivilegeToAccess(privilege);
1536:
1537: //Debug.out.println(" public conf privilege: " + principal +
1538: // "with access level " + access);
1539: ConversationPrivilege conversationPrivilege = new ConversationPrivilege(
1540: principal, access);
1541:
1542: return conversationPrivilege;
1543: }
1544: }
1545: } catch (CollaborationException ce) {
1546: throw new CollabException(ce);
1547: }
1548:
1549: return getPublicConversationDefaultPrivilege(name);
1550: }
1551:
1552: /**
1553: *
1554: *
1555: */
1556: public boolean canManagePublicConversation(String name) {
1557: boolean canManage = false;
1558:
1559: if (!userPrincipal.hasConversationAdminRole())
1560: return false;
1561: try {
1562: Conference conf = getConferenceService()
1563: .getPublicConference(name);
1564:
1565: if (conf != null) {
1566: canManage = conf.hasPrivilege(Conference.MANAGE);
1567: }
1568: } catch (CollaborationException ce) {
1569: // Debug.logDebugException(
1570: // "Exception in canManagePublicConversation",ce,true);
1571: }
1572:
1573: return canManage;
1574: }
1575:
1576: /**
1577: *
1578: *
1579: */
1580: public ConversationPrivilege getPublicConversationDefaultPrivilege(
1581: String name) throws CollabException {
1582: int access;
1583:
1584: try {
1585: int privilege = getConferenceService().getPublicConference(
1586: name).getDefaultPrivilege();
1587: access = convertPrivilegeToAccess(privilege);
1588: } catch (CollaborationException e) {
1589: throw new CollabException(e);
1590: }
1591:
1592: return new ConversationPrivilege(null, access);
1593: }
1594:
1595: /** helper method to convert access level defined in IM api Conference
1596: * to access level defined in ConversationPrivilege
1597: *
1598: */
1599: public int convertPrivilegeToAccess(int privilege) {
1600: if ((privilege & Conference.MANAGE) != 0)
1601: return ConversationPrivilege.MANAGE;
1602: if ((privilege & Conference.PUBLISH) != 0)
1603: return ConversationPrivilege.WRITE;
1604: if ((privilege & Conference.LISTEN) != 0)
1605: return ConversationPrivilege.READ;
1606: return ConversationPrivilege.NONE;
1607: }
1608:
1609: /** helper method to convert access level defined in ConversationPrivilege
1610: * to access level defined in IM api Conference
1611: *
1612: */
1613: public int convertAccessToPrivilege(int access) {
1614: if (access == ConversationPrivilege.MANAGE)
1615: return Conference.MANAGE | Conference.PUBLISH
1616: | Conference.LISTEN;
1617: if (access == ConversationPrivilege.WRITE)
1618: return Conference.PUBLISH | Conference.LISTEN;
1619: if (access == ConversationPrivilege.READ)
1620: return Conference.LISTEN;
1621: return Conference.NONE;
1622: }
1623:
1624: /**
1625: *
1626: *
1627: */
1628: public void setPublicConversationDefaultPrivilege(String name,
1629: ConversationPrivilege privilege) throws CollabException {
1630: int access = privilege.getAccess();
1631:
1632: try {
1633: getConferenceService().getPublicConference(name)
1634: .setDefaultPrivilege(
1635: convertAccessToPrivilege(access));
1636: } catch (CollaborationException ce) {
1637: throw new CollabException(ce);
1638: }
1639: }
1640:
1641: /**
1642: * Terminates the conference.
1643: * This will have the effect of destroying all currently archived messages
1644: * and unsubscribing all current subscribe members.
1645: * It can only be called with MANAGE privilege.
1646: *
1647: */
1648: public void deletePublicConversation(String name)
1649: throws CollabException {
1650: if (!canManagePublicConversation(name)) {
1651: return;
1652: }
1653:
1654: try {
1655: getConferenceService().getPublicConference(name).close();
1656: } catch (CollaborationException ce) {
1657: throw new CollabException(ce);
1658: }
1659: }
1660:
1661: /**
1662: *
1663: *
1664: */
1665: public boolean publicConversationExists(String name) {
1666: /*
1667: String[] conv = findPublicConversations(
1668: personalStoreService.SEARCHTYPE_EQUALS, name);
1669: // personalStoreService.SEARCHTYPE_STARTSWITH, name);
1670: return (conv != null && conv.length>0 );
1671: */
1672: try {
1673: Conference conf = getConferenceService()
1674: .getPublicConference(name);
1675:
1676: if (conf != null) {
1677: return true;
1678: } else {
1679: return false;
1680: }
1681: } catch (CollaborationException e) {
1682: return false;
1683: }
1684: }
1685:
1686: /**
1687: *
1688: *
1689: */
1690: public void changePassword(String newPassword)
1691: throws CollabException {
1692: Account account = getAccount();
1693: RegistrationListener listener = new IMCollabManager.Registration(
1694: account, newPassword);
1695:
1696: try {
1697: Debug.out.println(" changing password");
1698: getCollaborationSession().changePassword(newPassword,
1699: listener);
1700: } catch (CollaborationException e) {
1701: throw new CollabException(e);
1702: }
1703: }
1704:
1705: /**
1706: * skip send message or status if cannot contact server on
1707: * critical error
1708: *
1709: * @return criticalServerError
1710: */
1711: public boolean skipSend() {
1712: if (criticalServerError) {
1713: Debug.out.println("Critical Server Error occured");
1714: }
1715:
1716: return criticalServerError;
1717: }
1718:
1719: public Collection getParticipantsFromPublicConference(
1720: String destinationPublicConversation) {
1721: try {
1722: ConferenceService service = getConferenceService();
1723: Conference conference = service
1724: .getPublicConference(destinationPublicConversation);
1725:
1726: if (conference != null) {
1727: return conference.getParticipants();
1728: }
1729: } catch (Exception e) {
1730: Debug.debugNotify(e);
1731: }
1732:
1733: return null;
1734: }
1735:
1736: }
|