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.channel.filesharing;
0042:
0043: import com.sun.collablet.*;
0044: import org.netbeans.modules.collab.channel.filesharing.eventhandler.LockRegionManager;
0045: import org.netbeans.modules.collab.channel.filesharing.filehandler.RegionInfo;
0046: import org.netbeans.modules.collab.channel.filesharing.msgbean.LockRegion;
0047: import org.netbeans.modules.collab.channel.filesharing.msgbean.LockRegionData;
0048:
0049: import org.openide.cookies.*;
0050: import org.openide.filesystems.*;
0051: import org.openide.nodes.Node;
0052:
0053: import java.io.*;
0054:
0055: import java.util.*;
0056:
0057: import javax.swing.*;
0058:
0059: import org.netbeans.modules.collab.channel.filesharing.annotations.CollabRegionAnnotation;
0060: import org.netbeans.modules.collab.channel.filesharing.annotations.RegionAnnotation1;
0061: import org.netbeans.modules.collab.channel.filesharing.annotations.RegionAnnotation2;
0062: import org.netbeans.modules.collab.channel.filesharing.annotations.RegionAnnotation3;
0063: import org.netbeans.modules.collab.channel.filesharing.annotations.RegionAnnotation4;
0064: import org.netbeans.modules.collab.channel.filesharing.annotations.RegionAnnotation5;
0065: import org.netbeans.modules.collab.channel.filesharing.annotations.RegionAnnotation6;
0066: import org.netbeans.modules.collab.channel.filesharing.annotations.RegionAnnotation7;
0067: import org.netbeans.modules.collab.channel.filesharing.annotations.RegionAnnotation8;
0068: import org.netbeans.modules.collab.channel.filesharing.annotations.RegionAnnotation9;
0069: import org.netbeans.modules.collab.channel.filesharing.config.FilesharingNotifierConfig;
0070: import org.netbeans.modules.collab.channel.filesharing.config.FilesharingProcessorConfig;
0071: import org.netbeans.modules.collab.channel.filesharing.context.ProjectContext;
0072: import org.netbeans.modules.collab.channel.filesharing.event.JoinFilesharingEnd;
0073: import org.netbeans.modules.collab.channel.filesharing.event.PauseFilesharingEvent;
0074: import org.netbeans.modules.collab.channel.filesharing.event.ProjectActionListEvent;
0075: import org.netbeans.modules.collab.channel.filesharing.event.SendFileEvent;
0076: import org.netbeans.modules.collab.channel.filesharing.eventlistener.FilesharingTimerTask;
0077: import org.netbeans.modules.collab.channel.filesharing.eventlistener.JoinEndTimerTask;
0078: import org.netbeans.modules.collab.channel.filesharing.eventlistener.PauseTimerTask;
0079: import org.netbeans.modules.collab.channel.filesharing.eventlistener.ProjectActionListTimerTask;
0080: import org.netbeans.modules.collab.channel.filesharing.eventlistener.SendFileTimerTask;
0081: import org.netbeans.modules.collab.channel.filesharing.filehandler.CollabFileHandler;
0082: import org.netbeans.modules.collab.channel.filesharing.filehandler.CollabFileHandlerSupport;
0083: import org.netbeans.modules.collab.channel.filesharing.filehandler.SharedFileGroup;
0084: import org.netbeans.modules.collab.channel.filesharing.filehandler.SharedFileGroupManager;
0085: import org.netbeans.modules.collab.channel.filesharing.mdc.CollabContext;
0086: import org.netbeans.modules.collab.channel.filesharing.mdc.CollabEvent;
0087: import org.netbeans.modules.collab.channel.filesharing.mdc.EventContext;
0088: import org.netbeans.modules.collab.channel.filesharing.mdc.EventNotifier;
0089: import org.netbeans.modules.collab.channel.filesharing.mdc.eventlistener.CollabDocumentListener;
0090: import org.netbeans.modules.collab.channel.filesharing.msgbean.CCollab;
0091: import org.netbeans.modules.collab.channel.filesharing.msgbean.FileGroup;
0092: import org.netbeans.modules.collab.channel.filesharing.msgbean.FileGroups;
0093: import org.netbeans.modules.collab.channel.filesharing.msgbean.User;
0094: import org.netbeans.modules.collab.channel.filesharing.msgbean.Users;
0095: import org.netbeans.modules.collab.channel.filesharing.projecthandler.SharedProject;
0096: import org.netbeans.modules.collab.channel.filesharing.projecthandler.SharedProjectManager;
0097: import org.netbeans.modules.collab.channel.filesharing.ui.FilesystemExplorerPanel;
0098: import org.netbeans.modules.collab.channel.filesharing.util.CollabQueue;
0099: import org.netbeans.modules.collab.core.Debug;
0100:
0101: /**
0102: * Bean that holds channel context
0103: *
0104: * @author Ayub Khan, ayub.khan@sun.com
0105: * @version 1.0
0106: */
0107: public class FilesharingContext extends CollabContext implements
0108: FilesharingConstants {
0109: ////////////////////////////////////////////////////////////////////////////
0110: // Instance variables
0111: ////////////////////////////////////////////////////////////////////////////
0112:
0113: /* conversation */
0114: private Conversation conversation = null;
0115:
0116: /* filesharing channel content type */
0117: private final String contentType = ContentTypes.XML;
0118: private SharedFileGroupManager sharedFileGroupManager = null;
0119: private SharedProjectManager sharedProjectManager = null;
0120:
0121: /* user */
0122: private String loginUser = null;
0123:
0124: /* filesystemID */
0125: private String filesystemID = null;
0126:
0127: /* filesystem */
0128: private FileSystem filesystem = null;
0129:
0130: /* to test if this channel is valid */
0131: private boolean valid = true;
0132:
0133: /* message */
0134: private CollabMessage message = null;
0135:
0136: /* channel notifier */
0137: private EventNotifier channelEventNotifier = null;
0138:
0139: /* filechange notifier */
0140: private EventNotifier fileChangeEventNotifier = null;
0141:
0142: /* currentState */
0143: private int currentState = FilesharingContext.STATE_UNKNOWN;
0144:
0145: /* document listener map */
0146: private HashMap collabDocumentListenerMap = new HashMap();
0147:
0148: /* save join user */
0149: private String saveJoinUser = null;
0150:
0151: /* saved expected files for sync-up */
0152: private HashMap saveExpectedFileMap = new HashMap();
0153:
0154: /* flag to indicate the join user is this user */
0155: private boolean setJoinFlag = false;
0156:
0157: /* to indicate this user as moderator */
0158: private boolean isModerator = false;
0159:
0160: /* user to fileGroup name map */
0161: private HashMap userFileGroupMap = new HashMap();
0162:
0163: /* file to owner map for file annotations*/
0164: private HashMap ownerFileMap = new HashMap();
0165:
0166: /* file owners */
0167: private List fileOwners = new ArrayList();
0168:
0169: /* users in conversation */
0170: private List allUsers = new ArrayList();
0171:
0172: /* to indicate receive message in progress */
0173: private boolean receiveMessageInProgressFlag = false;
0174:
0175: /* flag set so that the originator of conversation can send join message */
0176: private boolean messageJoinSend = false;
0177:
0178: /* flag set to disable sending files during filesystem changes */
0179: private boolean isReadyToSendFile = false;
0180:
0181: /* flag set to disable sending files during pause */
0182: private boolean inPauseState = false;
0183:
0184: /* skipSendFile map*/
0185: private HashMap skipSendFileMap = new HashMap();
0186:
0187: /* skipSendDeleteFile map*/
0188: private HashMap skipSendDeleteFileMap = new HashMap();
0189:
0190: /* the timer */
0191: private java.util.Timer timer = null;
0192:
0193: /* notifierConfig */
0194: private FilesharingNotifierConfig notifierConfig = null;
0195:
0196: /* processor config */
0197: private FilesharingProcessorConfig processorConfig = null;
0198:
0199: /* queue */
0200: private CollabQueue queue = null;
0201: private CollabRegionAnnotation[] annotationTypes;
0202: private Map annotationStyles = new HashMap();
0203: private int lastAnnotationIndex = 0;
0204: private FilesystemExplorerPanel explorerPanel = null;
0205: private HashMap timertaskMap = new HashMap();
0206:
0207: /* userStyles */
0208: private HashMap userStyles = new HashMap();
0209: private int[] stylesArray = new int[22];
0210: private long joinTimeStamp = -1;
0211: private boolean readOnlyConversation = false;
0212: private FileChangeListener scfl;
0213: private FileSystem scfs = null;
0214:
0215: /**
0216: * @param version
0217: * @param channel
0218: */
0219: public FilesharingContext(String currentVersion, Collablet collablet) {
0220: super (currentVersion, collablet);
0221:
0222: //init queue
0223: queue = new CollabQueue(this );
0224:
0225: //init annotation types
0226: initAnnotationTypes();
0227:
0228: //init timestamp
0229: getJoinTimeStamp();
0230: }
0231:
0232: ////////////////////////////////////////////////////////////////////////////
0233: // methods
0234: ////////////////////////////////////////////////////////////////////////////
0235:
0236: /**
0237: * getConversation
0238: *
0239: * @return conversation
0240: */
0241: public Conversation getConversation() {
0242: return this .conversation;
0243: }
0244:
0245: /**
0246: * setConversation
0247: *
0248: * @param conversation
0249: */
0250: public void setConversation(Conversation conversation) {
0251: this .conversation = conversation;
0252: }
0253:
0254: /**
0255: *
0256: * @return input content type
0257: */
0258: public String getInputContentType() {
0259: return this .contentType;
0260: }
0261:
0262: /**
0263: * getSharedFileGroupManager
0264: *
0265: * @return sharedFileGroupManager
0266: */
0267: public SharedFileGroupManager getSharedFileGroupManager() {
0268: return this .sharedFileGroupManager;
0269: }
0270:
0271: /**
0272: * setSharedFileGroupManager
0273: *
0274: * @param sharedFileGroupManager
0275: */
0276: public void setSharedFileGroupManager(
0277: SharedFileGroupManager sharedFileGroupManager) {
0278: this .sharedFileGroupManager = sharedFileGroupManager;
0279: }
0280:
0281: /**
0282: * getSharedProjectManager
0283: *
0284: * @return sharedProjectManager
0285: */
0286: public SharedProjectManager getSharedProjectManager() {
0287: return this .sharedProjectManager;
0288: }
0289:
0290: /**
0291: * setSharedProjectManager
0292: *
0293: * @param sharedProjectManager
0294: */
0295: public void setSharedProjectManager(
0296: SharedProjectManager sharedProjectManager) {
0297: this .sharedProjectManager = sharedProjectManager;
0298: }
0299:
0300: ////////////////////////////////////////////////////////////////////////////
0301: // Message handling methods
0302: ////////////////////////////////////////////////////////////////////////////
0303:
0304: /**
0305: * getQueue
0306: *
0307: * @return queue
0308: */
0309: public CollabQueue getQueue() {
0310: return this .queue;
0311: }
0312:
0313: /**
0314: * getProcessorConfig
0315: *
0316: * @return notifier config
0317: */
0318: public FilesharingNotifierConfig getNotifierConfig() {
0319: return this .notifierConfig;
0320: }
0321:
0322: /**
0323: * setProcessorConfig
0324: *
0325: * @param notifierConfig
0326: */
0327: public void setNotifierConfig(
0328: FilesharingNotifierConfig notifierConfig) {
0329: this .notifierConfig = notifierConfig;
0330: }
0331:
0332: /**
0333: * getProcessorConfig
0334: *
0335: * @return processor config
0336: */
0337: public FilesharingProcessorConfig getProcessorConfig() {
0338: return this .processorConfig;
0339: }
0340:
0341: /**
0342: * setProcessorConfig
0343: *
0344: * @param processorConfig
0345: */
0346: public void setProcessorConfig(
0347: FilesharingProcessorConfig processorConfig) {
0348: this .processorConfig = processorConfig;
0349: }
0350:
0351: /**
0352: * getChannelEventNotifier
0353: *
0354: * @return event notifier for the channel events
0355: */
0356: public EventNotifier getChannelEventNotifier() {
0357: return this .channelEventNotifier;
0358: }
0359:
0360: /**
0361: * setChannelEventNotifier
0362: *
0363: * @param eventNotifier
0364: */
0365: public void setChannelEventNotifier(EventNotifier eventNotifier) {
0366: this .channelEventNotifier = eventNotifier;
0367: }
0368:
0369: /**
0370: * getFileChangeEventNotifier
0371: *
0372: * @return event notifier for the channel events
0373: */
0374: public EventNotifier getFileChangeEventNotifier() {
0375: return this .fileChangeEventNotifier;
0376: }
0377:
0378: /**
0379: * setFileChangeEventNotifier
0380: *
0381: * @param eventNotifier
0382: */
0383: public void setFileChangeEventNotifier(EventNotifier eventNotifier) {
0384: this .fileChangeEventNotifier = eventNotifier;
0385: }
0386:
0387: /**
0388: * getCollabFilesystem
0389: *
0390: * @return filesystem
0391: */
0392: public FileSystem getCollabFilesystem() {
0393: return filesystem;
0394: }
0395:
0396: /**
0397: * setCollabFilesystem
0398: *
0399: * @param filesystem
0400: */
0401: public void setCollabFilesystem(FileSystem filesystem) {
0402: this .filesystem = filesystem;
0403: }
0404:
0405: /**
0406: * setFilesystemExplorer
0407: *
0408: * @param explorerPanel
0409: */
0410: public void setFilesystemExplorer(
0411: FilesystemExplorerPanel explorerPanel) {
0412: this .explorerPanel = explorerPanel;
0413: }
0414:
0415: /**
0416: * getFilesystemExplorer
0417: *
0418: * @return explorerPanel
0419: */
0420: public FilesystemExplorerPanel getFilesystemExplorer() {
0421: return this .explorerPanel;
0422: }
0423:
0424: ////////////////////////////////////////////////////////////////////////////
0425: // Support methods
0426: ////////////////////////////////////////////////////////////////////////////
0427:
0428: /**
0429: *
0430: * @return filesystem id
0431: */
0432: public String getFilesystemID() {
0433: return filesystemID;
0434: }
0435:
0436: /**
0437: *
0438: * @param filesystemID
0439: */
0440: public void setFilesystemID(String filesystemID) {
0441: this .filesystemID = filesystemID;
0442: }
0443:
0444: /**
0445: *
0446: *
0447: */
0448: public void sendMessage(String content) {
0449: // Send a message to the conference
0450: try {
0451: CollabMessage message = conversation.createMessage();
0452:
0453: // Prep the message with the content
0454: //message.setContentName("FILESHARING");
0455: message.setContentName(FILESHARING_NAMESPACE);
0456: message.setContent(content);
0457: message.setContentType(ContentTypes.TEXT);
0458:
0459: // Set the actual content type to a different, chat-specific header.
0460: // The message content type will always be text/plain
0461: message.setHeader(FILESHARING_CONTENT_TYPE_HEADER,
0462: getInputContentType());
0463:
0464: // TODO: Temp impl
0465: message.setHeader(COLLAB_CHANNEL_TYPE,
0466: FILESHARING_NAMESPACE); //NoI18n
0467:
0468: // TODO: Tag the message as belonging to the chat channel
0469: // Send the message
0470: conversation.sendMessage(message);
0471: } catch (CollabException e) {
0472: //Hack for empty conversation
0473: if (!e.getMessage().trim().equals("First invite a user")) //NoI18n
0474: {
0475: Debug.errorManager.notify(e);
0476: }
0477: }
0478: }
0479:
0480: /**
0481: *
0482: * @return message
0483: */
0484: public CollabMessage getMessage() {
0485: return this .message;
0486: }
0487:
0488: /**
0489: *
0490: * @return login user id
0491: */
0492: public String getLoginUser() {
0493: if (loginUser == null) {
0494: loginUser = conversation.getCollabSession()
0495: .getUserPrincipal().getName();
0496: }
0497:
0498: return loginUser;
0499: }
0500:
0501: /**
0502: *
0503: * @return timer
0504: */
0505: public java.util.Timer getTimer() {
0506: return getTimer(false);
0507: }
0508:
0509: /**
0510: * @param forceCreation
0511: * @return timer
0512: */
0513: public java.util.Timer getTimer(boolean forceCreation) {
0514: if (forceCreation || (timer == null)) {
0515: //unfortunately conversation timer cannot be used, since it gets
0516: //canceled during conversation at some point
0517: //return channel.getConversation().getTimer();
0518: //set demeon true
0519: this .timer = new java.util.Timer(true);
0520: }
0521:
0522: return this .timer;
0523: }
0524:
0525: /**
0526: * schedule
0527: *
0528: * @param task
0529: * @param delay
0530: */
0531: public void schedule(TimerTask task, long delay) {
0532: try {
0533: getTimer().schedule(task, delay);
0534: } catch (java.lang.IllegalStateException ise) {
0535: try {
0536: //force creation of timer
0537: getTimer(true).schedule(task, delay);
0538: } catch (java.lang.Throwable th) {
0539: Debug.log("CollabFileHandlerSupport", //NoI18n
0540: "CollabFileHandlerSupport, timer null, cannot schedule "
0541: + //NoI18n
0542: "task for delay: " + //NoI18n
0543: delay);
0544: }
0545: } catch (java.lang.Throwable th) {
0546: try {
0547: //force creation of timer
0548: getTimer(true).schedule(task, delay);
0549: } catch (java.lang.Throwable th1) {
0550: Debug.log("CollabFileHandlerSupport", //NoI18n
0551: "CollabFileHandlerSupport, timer null, cannot schedule "
0552: + //NoI18n
0553: "task for delay: " + //NoI18n
0554: delay);
0555: }
0556: }
0557: }
0558:
0559: /**
0560: * scheduleAtFixedRate
0561: *
0562: * @param task
0563: * @param delay
0564: * @param rate
0565: */
0566: public void scheduleAtFixedRate(TimerTask task, long delay,
0567: long rate) {
0568: try {
0569: getTimer().scheduleAtFixedRate(task, delay, rate);
0570: } catch (java.lang.IllegalStateException ise) {
0571: try {
0572: //force creation of timer
0573: getTimer(true).scheduleAtFixedRate(task, delay, rate);
0574: } catch (java.lang.Throwable th) {
0575: Debug.log("CollabFileHandlerSupport", //NoI18n
0576: "CollabFileHandlerSupport, timer null, cannot schedule task "
0577: + "for delay: " + delay + ", rate: "
0578: + rate); //NoI18n
0579: }
0580: } catch (java.lang.Throwable th) {
0581: try {
0582: //force creation of timer
0583: getTimer(true).scheduleAtFixedRate(task, delay, rate);
0584: } catch (java.lang.Throwable th1) {
0585: Debug.log("CollabFileHandlerSupport", //NoI18n
0586: "CollabFileHandlerSupport, timer null, cannot schedule task "
0587: + "for delay: " + delay + ", rate: "
0588: + rate); //NoI18n
0589: }
0590: }
0591: }
0592:
0593: /**
0594: *
0595: * @param fileGroups
0596: * @param sharedFileGroups
0597: */
0598: public void constructFileGroups(FileGroups fileGroups,
0599: SharedFileGroup[] sharedFileGroups) {
0600: for (int i = 0; i < sharedFileGroups.length; i++) {
0601: if (sharedFileGroups[i] == null) {
0602: continue;
0603: }
0604:
0605: FileGroup fileGroup = new FileGroup();
0606: fileGroup.setFileGroupName(sharedFileGroups[i].getName());
0607:
0608: User user = new User();
0609: user.setId(sharedFileGroups[i].getUser());
0610: fileGroup.setUser(user);
0611:
0612: CollabFileHandler[] fileHandlers = sharedFileGroups[i]
0613: .getFileHandlers();
0614: String[] fileNames = new String[fileHandlers.length];
0615:
0616: for (int j = 0; j < fileHandlers.length; j++) {
0617: fileNames[j] = fileHandlers[j].getName();
0618: }
0619:
0620: fileGroup.setFileName(fileNames);
0621: fileGroups.addFileGroup(fileGroup);
0622: }
0623: }
0624:
0625: /**
0626: *
0627: * @param fileGroups
0628: * @param sharedFileGroup
0629: */
0630: public void constructFileGroups(FileGroups fileGroups,
0631: SharedFileGroup sharedFileGroup) {
0632: FileGroup fileGroup = new FileGroup();
0633: fileGroup.setFileGroupName(sharedFileGroup.getName());
0634:
0635: User user = new User();
0636: user.setId(sharedFileGroup.getUser());
0637: fileGroup.setUser(user);
0638:
0639: CollabFileHandler[] fileHandlers = sharedFileGroup
0640: .getFileHandlers();
0641: String[] fileNames = new String[fileHandlers.length];
0642:
0643: for (int j = 0; j < fileHandlers.length; j++) {
0644: fileNames[j] = fileHandlers[j].getName();
0645: }
0646:
0647: fileGroup.setFileName(fileNames);
0648: fileGroups.addFileGroup(fileGroup);
0649: }
0650:
0651: /**
0652: *
0653: * @param fromSharedFileGroups
0654: * @param toFileGroups
0655: */
0656: public void copyFileGroups(SharedFileGroup[] fromSharedFileGroups,
0657: FileGroups toFileGroups) {
0658: if ((fromSharedFileGroups == null)
0659: || (fromSharedFileGroups.length == 0)) {
0660: return;
0661: }
0662:
0663: for (int i = 0; i < fromSharedFileGroups.length; i++) {
0664: FileGroup fileGroup = new FileGroup();
0665: SharedFileGroup sharedFileGroup = fromSharedFileGroups[i];
0666: String fileGroupName = sharedFileGroup.getName();
0667: fileGroup.setFileGroupName(fileGroupName);
0668:
0669: User user = new User();
0670: user.setId(sharedFileGroup.getUser());
0671: fileGroup.setUser(user);
0672:
0673: CollabFileHandler[] fileHandlers = sharedFileGroup
0674: .getFileHandlers();
0675: String[] fileNames = new String[fileHandlers.length];
0676:
0677: for (int j = 0; j < fileHandlers.length; j++) {
0678: fileNames[j] = fileHandlers[j].getName();
0679: }
0680:
0681: toFileGroups.addFileGroup(fileGroup);
0682: }
0683: }
0684:
0685: /**
0686: *
0687: * @param userid
0688: * @return User object
0689: */
0690: public Users constructUsers(String userId) {
0691: Users users = new Users();
0692: User user = new User();
0693: user.setId(userId);
0694: users.addUser(user);
0695:
0696: return users;
0697: }
0698:
0699: /**
0700: *
0701: * @param userid
0702: * @return User object
0703: */
0704: public Users constructUsers(String[] userids) {
0705: Users users = new Users();
0706:
0707: for (int i = 0; i < userids.length; i++) {
0708: User user = new User();
0709: user.setId(userids[i]);
0710: users.addUser(user);
0711: }
0712:
0713: return users;
0714: }
0715:
0716: /**
0717: *
0718: * @param moderator object
0719: * @return String modeartor id
0720: */
0721: public String getModerator(Users users) {
0722: if (users != null) {
0723: User[] user = users.getUser();
0724:
0725: if ((user != null) && (user.length > 0)) {
0726: return user[0].getId();
0727: }
0728: }
0729:
0730: return null;
0731: }
0732:
0733: /**
0734: *
0735: * @param NewFileOwner object
0736: * @return String newFileOwner id
0737: */
0738: public String getNewFileOwner(Users users) {
0739: if (users != null) {
0740: User[] user = users.getUser();
0741:
0742: if ((user != null) && (user.length > 0)) {
0743: return user[0].getId();
0744: }
0745: }
0746:
0747: return null;
0748: }
0749:
0750: /**
0751: *
0752: * @param NewFileOwner object
0753: * @return String newFileOwner id
0754: */
0755: public String getNewModerator(Users users) {
0756: if (users != null) {
0757: User[] user = users.getUser();
0758:
0759: if ((user != null) && (user.length > 0)) {
0760: return user[0].getId();
0761: }
0762: }
0763:
0764: return null;
0765: }
0766:
0767: /**
0768: *
0769: * @param collabBean
0770: * @throws CollabException
0771: */
0772: public void sendMessage(CCollab collabBean) throws CollabException {
0773: // Send a message to the conference
0774: try {
0775: ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
0776: collabBean.write(outputStream);
0777: sendMessage(new String(outputStream.toByteArray(), "UTF-8")); //NoI18n
0778: } catch (IOException iox) {
0779: throw new CollabException(iox);
0780: }
0781: }
0782:
0783: /**
0784: *
0785: * @param message
0786: * @throws CollabException
0787: * @return
0788: */
0789: public CCollab parse(CollabMessage message) throws CollabException {
0790: CCollab collab = null;
0791: StringBuffer buffer = new StringBuffer();
0792:
0793: try {
0794: CollabMessagePart[] parts = message.getParts();
0795: int countPartsWithoutFileSharing = 0;
0796:
0797: for (int i = 0; i < parts.length; i++) {
0798: String contentName = parts[i].getContentName();
0799: String contentType = parts[i].getContentType();
0800: buffer.append(parts[i].getContent());
0801: }
0802: } catch (Throwable e) {
0803: throw new CollabException(e);
0804: }
0805:
0806: String content = buffer.toString();
0807:
0808: try {
0809: ByteArrayInputStream inputStream = new ByteArrayInputStream(
0810: content.getBytes("UTF-8"));
0811: collab = CCollab.read(inputStream);
0812: } catch (IOException iox) {
0813: throw new CollabException(iox);
0814: } catch (javax.xml.parsers.ParserConfigurationException pce) {
0815: throw new CollabException(pce);
0816: } catch (org.xml.sax.SAXException pce) {
0817: throw new CollabException(pce);
0818: }
0819:
0820: return collab;
0821: }
0822:
0823: /**
0824: *
0825: * @return fileOwners
0826: */
0827: public String[] getSavedFileOwners() {
0828: synchronized (fileOwners) {
0829: return (String[]) getFileOwners().toArray(new String[0]);
0830: }
0831: }
0832:
0833: /**
0834: *
0835: * @return fileOwners
0836: */
0837: public List getFileOwners() {
0838: return fileOwners;
0839: }
0840:
0841: /**
0842: *
0843: * @param user
0844: */
0845: public void addFileOwner(String user) {
0846: synchronized (fileOwners) {
0847: if (!fileOwners.contains(user)) {
0848: fileOwners.add(user);
0849: }
0850: }
0851: }
0852:
0853: /**
0854: * removeFileOwner
0855: *
0856: * @param user
0857: * @return status
0858: */
0859: public boolean removeFileOwner(String user) {
0860: synchronized (fileOwners) {
0861: return fileOwners.remove(user);
0862: }
0863: }
0864:
0865: /**
0866: * removeAllFileOwner
0867: *
0868: * @return
0869: */
0870: public void removeAllFileOwner() {
0871: synchronized (fileOwners) {
0872: fileOwners.clear();
0873: }
0874: }
0875:
0876: /**
0877: *
0878: * @param fileGroups
0879: * @throws CollabException
0880: */
0881: public void addToFileOwnerMap(FileGroup[] fileGroups)
0882: throws CollabException {
0883: Debug.log(this , "FilesharingContext, addToFileOwnerMap size: "
0884: + fileGroups.length);
0885:
0886: for (int i = 0; i < fileGroups.length; i++) {
0887: String user = fileGroups[i].getUser().getId();
0888: Debug.log(this , "FilesharingContext, user: " + user);
0889:
0890: String[] fileNames = fileGroups[i].getFileName();
0891:
0892: for (int j = 0; j < fileNames.length; j++) {
0893: Debug.log(this , "FilesharingContext, fileNames[" + j
0894: + "]: " + fileNames[j]);
0895: addToFileOwnerMap(fileNames[j], user);
0896: }
0897: }
0898: }
0899:
0900: /**
0901: *
0902: * @param fileGroups
0903: * @throws CollabException
0904: */
0905: public void addToFileOwnerMap(SharedFileGroup sharedFileGroup)
0906: throws CollabException {
0907: CollabFileHandler[] fileHandlers = sharedFileGroup
0908: .getFileHandlers();
0909: String[] fileNames = new String[fileHandlers.length];
0910:
0911: for (int j = 0; j < fileHandlers.length; j++) {
0912: fileNames[j] = fileHandlers[j].getName();
0913: }
0914:
0915: String user = sharedFileGroup.getUser();
0916:
0917: if (fileNames != null) {
0918: for (int i = 0; i < fileNames.length; i++) {
0919: addToFileOwnerMap(fileNames[i], user);
0920: }
0921: }
0922: }
0923:
0924: /**
0925: *
0926: * @param fileName
0927: * @throws CollabException
0928: */
0929: public void addToFileOwnerMap(String fileName)
0930: throws CollabException {
0931: synchronized (ownerFileMap) {
0932: if (!ownerFileMap.containsKey(fileName)) {
0933: ownerFileMap.put(fileName, getLoginUser());
0934: }
0935: }
0936: }
0937:
0938: /**
0939: *
0940: * @param fileName
0941: * @throws CollabException
0942: */
0943: public void addToFileOwnerMap(String fileName, String user)
0944: throws CollabException {
0945: synchronized (ownerFileMap) {
0946: if (!ownerFileMap.containsKey(fileName)) {
0947: Debug.log(this ,
0948: "FilesharingContext, addToFileOwnerMap fileName: "
0949: + fileName + " user:" + getLoginUser());
0950: ownerFileMap.put(fileName, user);
0951: }
0952: }
0953: }
0954:
0955: /**
0956: *
0957: * @param fileName
0958: * @return owner
0959: */
0960: public String getOwnerForFile(String fileName) {
0961: synchronized (ownerFileMap) {
0962: return (String) ownerFileMap.get(fileName);
0963: }
0964: }
0965:
0966: /**
0967: *
0968: * @param fileName
0969: * @return
0970: */
0971: public String removeFileOwnerMap(String fileName) {
0972: synchronized (ownerFileMap) {
0973: return (String) ownerFileMap.remove(fileName);
0974: }
0975: }
0976:
0977: /**
0978: *
0979: * @param SharedFileGroup
0980: * @return
0981: */
0982: public void removeFileOwnerMap(SharedFileGroup sharedFileGroup) {
0983: CollabFileHandler[] fileHandlers = sharedFileGroup
0984: .getFileHandlers();
0985: String[] fileNames = new String[fileHandlers.length];
0986:
0987: for (int j = 0; j < fileHandlers.length; j++) {
0988: fileNames[j] = fileHandlers[j].getName();
0989: }
0990:
0991: String user = sharedFileGroup.getUser();
0992:
0993: if (fileNames != null) {
0994: for (int i = 0; i < fileNames.length; i++) {
0995: removeFileOwnerMap(fileNames[i]);
0996: }
0997: }
0998: }
0999:
1000: /**
1001: *
1002: * @param fileGroups
1003: */
1004: public void saveExpectedFile(FileGroup[] fileGroups) {
1005: if (fileGroups == null) {
1006: return;
1007: }
1008:
1009: for (int i = 0; i < fileGroups.length; i++) {
1010: String fileGroupName = fileGroups[i].getFileGroupName();
1011:
1012: synchronized (saveExpectedFileMap) {
1013: saveExpectedFileMap.put(fileGroupName, fileGroups[i]);
1014: }
1015: }
1016: }
1017:
1018: /**
1019: *
1020: * @param user
1021: * @return
1022: */
1023: public boolean isModerator(String user) {
1024: return true;
1025: }
1026:
1027: /**
1028: *
1029: * @param user
1030: */
1031: public void addUser(String user) {
1032: synchronized (allUsers) {
1033: if (!allUsers.contains(user)) {
1034: allUsers.add(user);
1035: }
1036: }
1037: }
1038:
1039: /**
1040: *
1041: * @return
1042: */
1043: public String[] getUser() {
1044: synchronized (allUsers) {
1045: return (String[]) allUsers.toArray(new String[0]);
1046: }
1047: }
1048:
1049: /**
1050: *
1051: * @param user
1052: * @return
1053: */
1054: public boolean removeUser(String user) {
1055: synchronized (allUsers) {
1056: return allUsers.remove(user);
1057: }
1058: }
1059:
1060: public String getVersion() {
1061: return COLLAB_VERSION;
1062: }
1063:
1064: /**
1065: *
1066: * @param fileName
1067: * @param count
1068: * @return
1069: */
1070: public String createUniqueRegionName(String fileName, int count) {
1071: return getLoginUser() + fileName + String.valueOf(count);
1072: }
1073:
1074: /**
1075: *
1076: * @param user
1077: * @return
1078: */
1079: public boolean isFileOwner(String user, String fileName) {
1080: if ((user != null) && !user.equals("")) {
1081: String owner = getOwnerForFile(fileName);
1082:
1083: if ((owner != null) && !owner.equals("")) {
1084: return user.equals(owner);
1085: }
1086: }
1087:
1088: return false;
1089: }
1090:
1091: /**
1092: *
1093: * @param user
1094: * @return
1095: */
1096: public boolean isFileOwner(String user) {
1097: if ((user != null) && !user.equals("")) {
1098: return getLoginUser().equals(user);
1099: }
1100:
1101: return false;
1102: }
1103:
1104: /**
1105: *
1106: * @param users
1107: * @return
1108: */
1109: public boolean isFileOwner(String[] users) {
1110: if ((users != null) && (users.length > 0)) {
1111: for (int i = 0; i < users.length; i++) {
1112: String user = users[i];
1113:
1114: if (getLoginUser().equals(user)) {
1115: return true;
1116: }
1117: }
1118: }
1119:
1120: return false;
1121: }
1122:
1123: /**
1124: *
1125: * @param users
1126: * @return
1127: */
1128: public boolean isFileOwner(User[] users) {
1129: Debug.log(this , "FilesharingContext, isFileOwner : "
1130: + getLoginUser());
1131:
1132: if ((users != null) && (users.length > 0)) {
1133: for (int i = 0; i < users.length; i++) {
1134: String user = users[i].getId();
1135: Debug.log(this , "FilesharingContext, user : " + user);
1136:
1137: if ((user != null) && !user.trim().equals("")
1138: && getLoginUser().equals(user)) {
1139: return true;
1140: }
1141: }
1142: }
1143:
1144: return false;
1145: }
1146:
1147: /**
1148: *
1149: * @return
1150: */
1151: public String[] getUserSharedFileGroupNames(String user) {
1152: synchronized (userFileGroupMap) {
1153: List filegroups = (List) userFileGroupMap.get(user);
1154:
1155: if ((filegroups != null) && !filegroups.isEmpty()) {
1156: return (String[]) filegroups.toArray(new String[0]);
1157: }
1158:
1159: return null;
1160: }
1161: }
1162:
1163: /**
1164: *
1165: * @param name
1166: * @param object
1167: */
1168: public void addToUserSharedFileGroupNames(String user,
1169: String fileGroupName) {
1170: synchronized (userFileGroupMap) {
1171: if (!userFileGroupMap.containsKey(user)) {
1172: List aList = new ArrayList();
1173: aList.add(fileGroupName);
1174: userFileGroupMap.put(user, aList);
1175: } else {
1176: List aList = (List) userFileGroupMap.get(user);
1177:
1178: if ((aList != null) && !aList.contains(fileGroupName)) {
1179: aList.add(fileGroupName);
1180: }
1181: }
1182: }
1183: }
1184:
1185: /**
1186: * removeFromUserFileGroup
1187: *
1188: * @param user
1189: * @param fileGroupName
1190: * @throws CollabException
1191: */
1192: public void removeFromUserFileGroup(String user,
1193: String fileGroupName) throws CollabException {
1194: synchronized (userFileGroupMap) {
1195: if (userFileGroupMap.containsKey(user)) {
1196: List aList = (List) userFileGroupMap.get(user);
1197:
1198: if ((aList != null) && aList.contains(fileGroupName)) {
1199: aList.remove(fileGroupName);
1200: }
1201:
1202: if (aList.size() == 0) {
1203: userFileGroupMap.remove(user);
1204: }
1205: }
1206: }
1207: }
1208:
1209: /**
1210: * removeAllUserFileGroup
1211: *
1212: * @throws CollabException
1213: */
1214: public void removeAllUserFileGroup() throws CollabException {
1215: synchronized (userFileGroupMap) {
1216: userFileGroupMap.clear();
1217: }
1218: }
1219:
1220: /**
1221: *
1222: * @return
1223: */
1224: public boolean isValid() {
1225: return valid;
1226: }
1227:
1228: /**
1229: *
1230: * @param valid
1231: */
1232: public void setValid(boolean valid) {
1233: this .valid = valid;
1234: }
1235:
1236: /**
1237: *
1238: * @return
1239: */
1240: public boolean isSkipSendFile(String fileName) {
1241: synchronized (skipSendFileMap) {
1242: Debug.log(this , //NoI18n
1243: "FilesharingContext, isSkipSendFile: "
1244: + //NoI18n
1245: skipSendFileMap.containsKey(fileName)
1246: + " for file: " + //NoI18n
1247: fileName);
1248:
1249: return skipSendFileMap.containsKey(fileName);
1250: }
1251: }
1252:
1253: /**
1254: *
1255: * @return
1256: */
1257: public boolean isPauseState() {
1258: return inPauseState;
1259: }
1260:
1261: public void setInPauseState(boolean flag) {
1262: inPauseState = flag;
1263: }
1264:
1265: /**
1266: *
1267: * @return
1268: */
1269: public boolean isSkipSendDeleteFile(String fileName) {
1270: synchronized (skipSendDeleteFileMap) {
1271: Debug.log(this , //NoI18n
1272: "FilesharingContext, isSkipSendDeleteFile: "
1273: + //NoI18n
1274: skipSendDeleteFileMap.containsKey(fileName)
1275: + " for file: " + //NoI18n
1276: fileName);
1277:
1278: return skipSendDeleteFileMap.containsKey(fileName);
1279: }
1280: }
1281:
1282: ////////////////////////////////////////////////////////////////////////////
1283: // Management methods
1284: ////////////////////////////////////////////////////////////////////////////
1285:
1286: /**
1287: *
1288: *
1289: */
1290: public void setReceivedMessageState(boolean flag) {
1291: this .receiveMessageInProgressFlag = flag;
1292: }
1293:
1294: /**
1295: *
1296: *
1297: */
1298: private boolean receiveMessageInProgress() {
1299: return this .receiveMessageInProgressFlag;
1300: }
1301:
1302: /**
1303: * remove All FileHandler References
1304: *
1305: * @param fileGroupName
1306: * @param user
1307: * @throws CollabException
1308: */
1309: public void removeAllFileHandlerRef() throws CollabException {
1310: SharedFileGroup[] sharedFileGroups = sharedFileGroupManager
1311: .getAllSharedFileGroup();
1312:
1313: for (int i = 0; i < sharedFileGroups.length; i++) {
1314: removeAllFileHandlerRef(sharedFileGroups[i], getLoginUser());
1315: }
1316:
1317: removeAllUserFileGroup();
1318:
1319: //clear all ref in managers
1320: sharedFileGroupManager.clear();
1321: sharedProjectManager.clear();
1322:
1323: //remove shared common filelistener
1324: Debug.out.println("removing scfl");
1325:
1326: if ((scfs != null) && (scfl != null)) {
1327: scfs.removeFileChangeListener(scfl);
1328: }
1329: }
1330:
1331: /**
1332: * remove All FileHandler References
1333: *
1334: * @param fileGroupName
1335: * @param user
1336: * @throws CollabException
1337: */
1338: public void removeAllFileHandlerRef(
1339: SharedFileGroup sharedFileGroup, String user)
1340: throws CollabException {
1341: String fileGroupName = sharedFileGroup.getName();
1342: Debug
1343: .log("FilesharingContext",
1344: "In removeAllFileHandlerRef for file: "
1345: + fileGroupName);
1346:
1347: //remove file to owner map for this sfg
1348: removeFileOwnerMap(sharedFileGroup);
1349:
1350: CollabFileHandler[] fileHandlers = sharedFileGroup
1351: .getFileHandlers();
1352: String primaryFile = null;
1353:
1354: if (fileHandlers.length > 0) {
1355: primaryFile = fileHandlers[0].getName();
1356: }
1357:
1358: for (int i = 0; i < fileHandlers.length; i++) {
1359: String fileName = fileHandlers[i].getName();
1360: removeDocumentListener(fileName);
1361: sharedFileGroup.removeFileHandler(fileName);
1362: }
1363:
1364: sharedFileGroupManager
1365: .removeFromAllSharedFileGroup(sharedFileGroup);
1366: sharedFileGroupManager
1367: .removeFromOwnerSharedFileGroup(sharedFileGroup);
1368:
1369: if (primaryFile != null) { //remove fileowner if last file belong to this user is deleted
1370:
1371: String owner = getOwnerForFile(primaryFile);
1372: String[] userFileGroupNames = getUserSharedFileGroupNames(owner);
1373:
1374: if ((userFileGroupNames != null)
1375: && (userFileGroupNames.length == 1)
1376: && userFileGroupNames[0].equals(fileGroupName)) {
1377: removeFileOwner(owner);
1378: }
1379: }
1380:
1381: //clear all owners if there is no sharedfiles in the system
1382: if (sharedFileGroupManager.getAllSharedFileGroup().length == 0) {
1383: removeAllFileOwner();
1384: removeAllUserFileGroup();
1385: }
1386:
1387: removeFromUserFileGroup(user, fileGroupName);
1388: }
1389:
1390: /**
1391: * printAllData
1392: *
1393: */
1394: public void printAllData(String message) {
1395: if (!Debug.isAllowed(this )) {
1396: return;
1397: }
1398:
1399: Debug.log(this , "\n\n========Printing Context for user: " + //NoI18n
1400: getLoginUser() + " " + message + "=========="); //NoI18n
1401: sharedProjectManager.print();
1402: sharedFileGroupManager.print();
1403:
1404: synchronized (collabDocumentListenerMap) {
1405: Debug.log(this , "collabDocumentListenerMap: " + //NoI18n
1406: collabDocumentListenerMap.keySet().toString()); //NoI18n
1407: }
1408:
1409: synchronized (saveExpectedFileMap) {
1410: Debug.log(this , "saveExpectedFileMap: " + //NoI18n
1411: saveExpectedFileMap.toString());
1412: }
1413:
1414: synchronized (userFileGroupMap) {
1415: Debug.log(this , "userFileGroupMap: "
1416: + userFileGroupMap.toString()); //NoI18n
1417: }
1418:
1419: synchronized (ownerFileMap) {
1420: Debug.log(this , "ownerFileMap: " + ownerFileMap.toString()); //NoI18n
1421: }
1422:
1423: synchronized (fileOwners) {
1424: Debug.log(this , "fileOwners: " + fileOwners.toString()); //NoI18n
1425: }
1426:
1427: synchronized (allUsers) {
1428: Debug.log(this , "allUsers: " + allUsers.toString()); //NoI18n
1429: }
1430:
1431: synchronized (skipSendFileMap) {
1432: Debug.log(this , "skipSendFileMap: "
1433: + skipSendFileMap.toString()); //NoI18n
1434: }
1435:
1436: synchronized (skipSendDeleteFileMap) {
1437: Debug.log(this , "skipSendDeleteFileMap: " + //NoI18n
1438: skipSendDeleteFileMap.keySet().toString());
1439: }
1440:
1441: synchronized (timertaskMap) {
1442: Debug.log(this , "timertaskMap: " + timertaskMap.toString()); //NoI18n
1443: }
1444:
1445: synchronized (userStyles) {
1446: Debug.log(this , "userStyles: " + userStyles.toString()); //NoI18n
1447: }
1448:
1449: Debug.log(this ,
1450: "=================================Done============================"
1451: + //NoI18n
1452: "==========================\n\n"); //NoI18n
1453: }
1454:
1455: /**
1456: *
1457: * @param fileName
1458: * @param listener
1459: * @throws CollabException
1460: */
1461: public void addCollabDocumentListener(String fileName,
1462: CollabDocumentListener listener) throws CollabException {
1463: synchronized (collabDocumentListenerMap) {
1464: if (collabDocumentListenerMap.containsKey(fileName)) {
1465: collabDocumentListenerMap.remove(fileName);
1466: }
1467:
1468: collabDocumentListenerMap.put(fileName, listener);
1469: }
1470: }
1471:
1472: /**
1473: *
1474: * @param fileName
1475: * @throws CollabException
1476: * @return
1477: */
1478: public CollabDocumentListener getCollabDocumentListener(
1479: String fileName) throws CollabException {
1480: synchronized (collabDocumentListenerMap) {
1481: return (CollabDocumentListener) collabDocumentListenerMap
1482: .get(fileName);
1483: }
1484: }
1485:
1486: /**
1487: * removeDocumentListener
1488: *
1489: * @param fileName
1490: * @throws CollabException
1491: */
1492: public void removeDocumentListener(String fileName)
1493: throws CollabException {
1494: synchronized (collabDocumentListenerMap) {
1495: if (collabDocumentListenerMap.containsKey(fileName)) {
1496: collabDocumentListenerMap.remove(fileName);
1497: }
1498: }
1499: }
1500:
1501: /**
1502: *
1503: * @return
1504: */
1505: protected int getCurrentState() {
1506: return currentState;
1507: }
1508:
1509: /**
1510: *
1511: * @param currentState
1512: */
1513: public void setCurrentState(int currentState) {
1514: this .currentState = currentState;
1515: }
1516:
1517: /**
1518: *
1519: * @param currentState
1520: */
1521: public void setSkipSendFile(String fileName, boolean skipSendFile) {
1522: Debug.log(this , //NoI18n
1523: "FilesharingContext, setSkipSendFile: " + //NoI18n
1524: skipSendFile + " for file: " + fileName); //NoI18n
1525:
1526: synchronized (skipSendFileMap) {
1527: if (skipSendFile) {
1528: skipSendFileMap.remove(fileName);
1529: skipSendFileMap
1530: .put(fileName, new Boolean(skipSendFile));
1531: } else {
1532: skipSendFileMap.remove(fileName);
1533: }
1534: }
1535: }
1536:
1537: /**
1538: *
1539: * @param currentState
1540: */
1541: public void setSkipSendDeleteFile(String fileName,
1542: boolean skipSendDeleteFile) {
1543: Debug.log(this , //NoI18n
1544: "FilesharingContext, setSkipSendDeleteFile: " + //NoI18n
1545: skipSendDeleteFile + " for file: " + fileName); //NoI18n
1546:
1547: synchronized (skipSendDeleteFileMap) {
1548: //remove previous entry
1549: if (skipSendDeleteFileMap.containsKey(fileName)) {
1550: skipSendDeleteFileMap.remove(fileName);
1551: }
1552:
1553: if (skipSendDeleteFile) {
1554: skipSendDeleteFileMap.put(fileName, new Boolean(
1555: skipSendDeleteFile));
1556: }
1557: }
1558: }
1559:
1560: /**
1561: * addTimerTask
1562: *
1563: */
1564: public void addTimerTask(String taskName, Object task) {
1565: addTimerTask(taskName, task.toString(), task);
1566: }
1567:
1568: /**
1569: * addTimerTask
1570: *
1571: */
1572: public boolean addTimerTask(String taskName, String subTaskName,
1573: Object task) {
1574: synchronized (timertaskMap) {
1575: HashMap tasksMap = null;
1576:
1577: if (!timertaskMap.containsKey(taskName)) {
1578: tasksMap = new HashMap();
1579: } else {
1580: tasksMap = (HashMap) timertaskMap.get(taskName);
1581: }
1582:
1583: if (tasksMap == null) {
1584: return false;
1585: }
1586:
1587: if ((subTaskName != null) && !subTaskName.trim().equals("")) {
1588: tasksMap.put(subTaskName, task);
1589: } else {
1590: tasksMap.put(task.toString(), task);
1591: }
1592:
1593: timertaskMap.put(taskName, tasksMap);
1594: }
1595:
1596: return true;
1597: }
1598:
1599: /**
1600: * getTimerTask
1601: *
1602: */
1603: public HashMap getTimerTask(String key) {
1604: synchronized (timertaskMap) {
1605: if (timertaskMap.containsKey(key)) {
1606: HashMap timerTasks = (HashMap) timertaskMap.get(key);
1607:
1608: return timerTasks;
1609: } else {
1610: return null;
1611: }
1612: }
1613: }
1614:
1615: /**
1616: * getTimerTask
1617: *
1618: */
1619: public TimerTask getTimerTask(String key, String subKey) {
1620: synchronized (timertaskMap) {
1621: if (timertaskMap.containsKey(key)) {
1622: HashMap timerTasks = (HashMap) timertaskMap.get(key);
1623:
1624: if ((subKey != null) && !subKey.trim().equals("")) {
1625: return (TimerTask) timerTasks.get(subKey);
1626: }
1627: }
1628: }
1629:
1630: return null;
1631: }
1632:
1633: /**
1634: * cancelAllTimerTask
1635: *
1636: */
1637: public void cancelAllTimerTask() {
1638: Debug.log(this , "FilesharingContext, cancel all timer tasks ");
1639:
1640: String[] taskNames = null;
1641:
1642: synchronized (timertaskMap) {
1643: taskNames = (String[]) timertaskMap.keySet().toArray(
1644: new String[0]);
1645: }
1646:
1647: if (taskNames != null) {
1648: for (int i = 0; i < taskNames.length; i++) {
1649: cancelTimerTask(taskNames[i]);
1650: }
1651: }
1652:
1653: synchronized (timertaskMap) {
1654: timertaskMap.clear();
1655: }
1656: }
1657:
1658: /**
1659: * cancelTimerTask
1660: *
1661: */
1662: public void cancelTimerTask(String key) {
1663: cancelTimerTask(key, null);
1664: }
1665:
1666: /**
1667: * cancelTimerTask
1668: *
1669: */
1670: public void cancelTimerTask(String key, String subKey) {
1671: synchronized (timertaskMap) {
1672: if (timertaskMap.containsKey(key)) {
1673: HashMap timerTasks = (HashMap) timertaskMap.get(key);
1674:
1675: if (subKey != null) {
1676: TimerTask timerTask = (TimerTask) timerTasks
1677: .get(subKey);
1678:
1679: if (timerTask != null) {
1680: timerTask.cancel();
1681: timerTask = null;
1682: timerTasks.remove(subKey);
1683: }
1684: } else {
1685: Debug.log(this , "FilesharingContext, current "
1686: + //NoI18n
1687: "timerTasks length for taskName: " + key
1688: + " before cancel: " + //NoI18n
1689: timerTasks.size());
1690:
1691: Iterator it = timerTasks.keySet().iterator();
1692:
1693: while (it.hasNext()) {
1694: String taskName = (String) it.next();
1695: Debug.log(this , "FilesharingContext, cancel "
1696: + "taskName:" + taskName);
1697:
1698: TimerTask timerTask = (TimerTask) timerTasks
1699: .get(taskName);
1700:
1701: if (((subKey == null) && (timerTask != null))
1702: || ((subKey != null)
1703: && (timerTask != null) && subKey
1704: .trim().equals(taskName))) {
1705: timerTask.cancel();
1706: timerTask = null;
1707: }
1708: }
1709:
1710: timertaskMap.remove(key);
1711: }
1712: }
1713: }
1714: }
1715:
1716: /**
1717: * cancelSendResumeMessageTimerTask
1718: *
1719: */
1720: public void cancelSendResumeMessageTimerTask() {
1721: cancelTimerTask(SEND_RESUME_TIMER_TASK);
1722: }
1723:
1724: /**
1725: * getSendFileMessageTimerTask
1726: *
1727: * @param fileGroupName
1728: */
1729: public SendFileTimerTask getSendFileMessageTimerTask(
1730: String fileGroupName) {
1731: return (SendFileTimerTask) getTimerTask(
1732: SEND_SENDFILE_TIMER_TASK, fileGroupName);
1733: }
1734:
1735: /**
1736: * cancelSendFileMessageTimerTask
1737: *
1738: * @param fileGroupName
1739: */
1740: public void cancelSendFileMessageTimerTask(String fileGroupName) {
1741: cancelTimerTask(SEND_SENDFILE_TIMER_TASK, fileGroupName);
1742: }
1743:
1744: /**
1745: * cancelSendFileMessageTimerTask
1746: *
1747: */
1748: public void cancelSendFileMessageTimerTask() {
1749: cancelTimerTask(SEND_SENDFILE_TIMER_TASK);
1750: }
1751:
1752: /**
1753: * cancelProjectActionListTimerTask
1754: *
1755: * @param projectName
1756: */
1757: public void cancelProjectActionListTimerTask(String projectName) {
1758: cancelTimerTask(SEND_PROJECTACTIONLIST_TIMER_TASK, projectName);
1759: }
1760:
1761: /**
1762: * cancelProjectActionListTimerTask
1763: *
1764: */
1765: public void cancelProjectActionListTimerTask() {
1766: cancelTimerTask(SEND_PROJECTACTIONLIST_TIMER_TASK);
1767: }
1768:
1769: /**
1770: * cancelSendPauseMessageTimerTask
1771: *
1772: */
1773: public void cancelSendPauseMessageTimerTask() {
1774: cancelTimerTask(SEND_PAUSE_TIMER_TASK);
1775: }
1776:
1777: /**
1778: * cancelSendJoinBeginMessageTimerTask
1779: *
1780: */
1781: public void cancelSendJoinBeginMessageTimerTask() {
1782: cancelTimerTask(SEND_JOINBEGIN_TIMER_TASK);
1783: }
1784:
1785: /**
1786: * cancelSendJoinEndMessageTimerTask
1787: *
1788: */
1789: public void cancelSendJoinEndMessageTimerTask() {
1790: cancelTimerTask(SEND_JOINEND_TIMER_TASK);
1791: }
1792:
1793: /**
1794: * startSendFileMessageTimerTask
1795: *
1796: * @param sendFileMap
1797: * @param delay
1798: */
1799: public SendFileTimerTask[] startSendFileMessageTimerTask(
1800: HashMap sendFileMap, long delay) {
1801: String[] fileGroupNames = null;
1802:
1803: synchronized (sendFileMap) {
1804: fileGroupNames = (String[]) sendFileMap.keySet().toArray(
1805: new String[0]);
1806: }
1807:
1808: if ((fileGroupNames == null) || (fileGroupNames.length == 0)) {
1809: return null;
1810: }
1811:
1812: List sendFileMessageTimerTaskList = new ArrayList();
1813:
1814: for (int i = 0; i < fileGroupNames.length; i++) {
1815: String fileGroupName = fileGroupNames[i];
1816: SharedFileGroup sharedFileGroup = sharedFileGroupManager
1817: .getSharedFileGroup(fileGroupName);
1818:
1819: if (sharedFileGroup != null) {
1820: EventNotifier fileChangeEventNotifier = getFileChangeEventNotifier();
1821: CollabEvent sendFileEvent = new SendFileEvent(
1822: new EventContext(SendFileEvent.getEventID(),
1823: sharedFileGroup));
1824: SendFileTimerTask sendFileMessageTimerTask = new SendFileTimerTask(
1825: fileChangeEventNotifier, sendFileEvent, this );
1826: addTimerTask(SEND_SENDFILE_TIMER_TASK, fileGroupName,
1827: sendFileMessageTimerTask);
1828: Debug
1829: .log(this ,
1830: "FilesharingContext, scheduling to SendFileMessage"); //NoI18n
1831: sendFileMessageTimerTask.schedule(delay);
1832:
1833: synchronized (timertaskMap) {
1834: Debug.log(this , "FilesharingContext, timertaskMap "
1835: + //NoI18n
1836: "length after scheduling: "
1837: + timertaskMap.size()); //NoI18n
1838: }
1839:
1840: sendFileMessageTimerTaskList
1841: .add(sendFileMessageTimerTask);
1842: }
1843: }
1844:
1845: return (SendFileTimerTask[]) sendFileMessageTimerTaskList
1846: .toArray(new SendFileTimerTask[0]);
1847: }
1848:
1849: /**
1850: * startSendFileMessageTimerTask
1851: *
1852: * @param fileGroupName
1853: * @param delay
1854: */
1855: public SendFileTimerTask startSendFileMessageTimerTask(
1856: String fileGroupName, long delay) {
1857: Debug.log(this ,
1858: "FilesharingContext, scheduling to SendFileMessage: "
1859: + fileGroupName + "after : " + delay); //NoI18n
1860:
1861: SharedFileGroup sharedFileGroup = sharedFileGroupManager
1862: .getSharedFileGroup(fileGroupName);
1863:
1864: if (sharedFileGroup != null) {
1865: EventNotifier fileChangeEventNotifier = getFileChangeEventNotifier();
1866: CollabEvent sendFileEvent = new SendFileEvent(
1867: new EventContext(SendFileEvent.getEventID(),
1868: sharedFileGroup));
1869: SendFileTimerTask sendFileMessageTimerTask = new SendFileTimerTask(
1870: fileChangeEventNotifier, sendFileEvent, this );
1871: addTimerTask(SEND_SENDFILE_TIMER_TASK, fileGroupName,
1872: sendFileMessageTimerTask);
1873: Debug
1874: .log(this ,
1875: "FilesharingContext, scheduling to SendFileMessage"); //NoI18n
1876: sendFileMessageTimerTask.schedule(delay);
1877:
1878: synchronized (timertaskMap) {
1879: Debug.log(this , "FilesharingContext, timertaskMap "
1880: + //NoI18n
1881: "length after scheduling: "
1882: + timertaskMap.size()); //NoI18n
1883: }
1884:
1885: return sendFileMessageTimerTask;
1886: }
1887:
1888: return null;
1889: }
1890:
1891: /**
1892: * startSendFileMessageTimerTask
1893: *
1894: * @param ownerFilesOnly
1895: * @param delay
1896: */
1897: public void startSendFileMessageTimerTask(boolean ownerFilesOnly,
1898: long delay) {
1899: SharedFileGroup[] sharedFileGroups = null;
1900:
1901: if (ownerFilesOnly) {
1902: sharedFileGroups = sharedFileGroupManager
1903: .getOwnerSharedFileGroup();
1904: } else {
1905: sharedFileGroups = sharedFileGroupManager
1906: .getAllSharedFileGroup();
1907: }
1908:
1909: if ((sharedFileGroups != null) && (sharedFileGroups.length > 0)) {
1910: //sendFileMessageTimerTasks = new ArrayList();
1911: for (int i = 0; i < sharedFileGroups.length; i++) {
1912: String fileGroupName = sharedFileGroups[i].getName();
1913: SendFileTimerTask sendFileTimerTask = startSendFileMessageTimerTask(
1914: fileGroupName, delay);
1915:
1916: if (sendFileTimerTask == null) {
1917: continue;
1918: }
1919: }
1920: }
1921:
1922: //schedule to send Project actions
1923: if (ownerFilesOnly) {
1924: SharedProject[] sharedProjects = getSharedProjectManager()
1925: .getOwnerSharedProjects(getLoginUser());
1926:
1927: for (int i = 0; i < sharedProjects.length; i++) {
1928: SharedProject sharedProject = sharedProjects[i];
1929:
1930: //Send Action List
1931: EventContext evContext = new ProjectContext(
1932: ProjectActionListEvent.getEventID(),
1933: sharedProject.getProjectOwner(), sharedProject
1934: .getName(), sharedProject
1935: .getProjectActions());
1936: final CollabEvent ce = new ProjectActionListEvent(
1937: evContext);
1938:
1939: /* send projectActionList message after a delay */
1940: ProjectActionListTimerTask sendProjectActionListTimerTask = new ProjectActionListTimerTask(
1941: getChannelEventNotifier(),
1942: new ProjectActionListEvent(evContext), this );
1943: addTimerTask(SEND_PROJECTACTIONLIST_TIMER_TASK,
1944: sharedProject.getName(),
1945: sendProjectActionListTimerTask);
1946: sendProjectActionListTimerTask
1947: .schedule(FilesharingTimerTask.PERIOD * 3);
1948: }
1949: }
1950: }
1951:
1952: /**
1953: * setJoinUser
1954: *
1955: * @param joinUser
1956: */
1957: public void setJoinUser(String joinUser) {
1958: this .saveJoinUser = joinUser;
1959: }
1960:
1961: /**
1962: * getJoinUser
1963: *
1964: * @return saveJoinUser
1965: */
1966: public String getJoinUser() {
1967: return this .saveJoinUser;
1968: }
1969:
1970: /**
1971: * isJoinState
1972: *
1973: * @return setJoinFlag
1974: */
1975: public boolean isJoinState() {
1976: return this .setJoinFlag;
1977: }
1978:
1979: /**
1980: * setJoinFlag
1981: *
1982: * @param flag
1983: */
1984: public void setJoinFlag(boolean flag) {
1985: Debug.log(this , "FilesharingContext, setting isJoinState: " + //NoI18n
1986: flag + " for user: " + getLoginUser()); //NoI18n
1987: this .setJoinFlag = flag;
1988: }
1989:
1990: /**
1991: * getSendPauseMessageTimerTask
1992: *
1993: */
1994: public PauseTimerTask[] getSendPauseMessageTimerTask() {
1995: return (PauseTimerTask[]) getTimerTask(SEND_PAUSE_TIMER_TASK)
1996: .values().toArray(new PauseTimerTask[0]);
1997: }
1998:
1999: /**
2000: * clearExpectedFileMap
2001: *
2002: */
2003: public void clearExpectedFileMap() {
2004: synchronized (saveExpectedFileMap) {
2005: saveExpectedFileMap.clear();
2006: }
2007: }
2008:
2009: /**
2010: * getSaveExpectedFiles
2011: *
2012: * @return saveExpectedFileMap
2013: */
2014: public HashMap getSaveExpectedFiles() {
2015: synchronized (saveExpectedFileMap) {
2016: return this .saveExpectedFileMap;
2017: }
2018: }
2019:
2020: /**
2021: * containsSaveExpectedFiles
2022: *
2023: * @param fileGroupName
2024: * @return flag
2025: */
2026: public boolean containsSaveExpectedFiles(String fileGroupName) {
2027: synchronized (saveExpectedFileMap) {
2028: return saveExpectedFileMap.containsKey(fileGroupName);
2029: }
2030: }
2031:
2032: /**
2033: * onJoinBegin
2034: *
2035: * @throws CollabException
2036: */
2037: public void onJoinBegin() throws CollabException {
2038: //Pause all operation including edit (only exception is fileOwner sendFile)
2039: disableExplorerPanel();
2040:
2041: SharedFileGroup[] allSharedFileGroups = sharedFileGroupManager
2042: .getAllSharedFileGroup();
2043:
2044: if (allSharedFileGroups != null) {
2045: for (int i = 0; i < allSharedFileGroups.length; i++) {
2046: CollabFileHandler[] fileHandlers = allSharedFileGroups[i]
2047: .getFileHandlers();
2048:
2049: for (int j = 0; j < fileHandlers.length; j++) {
2050: CollabFileHandler collabFileHandler = fileHandlers[j];
2051:
2052: if (collabFileHandler != null) {
2053: collabFileHandler.handlePause();
2054: }
2055: }
2056: }
2057: }
2058: }
2059:
2060: /**
2061: * Pause all operation
2062: *
2063: * @throws CollabException
2064: */
2065: public void pauseAll() throws CollabException {
2066: pauseAll(false);
2067: }
2068:
2069: /**
2070: * Pause all operation, skip cancel sendjoin if specified
2071: *
2072: * param noCancelSendJoinEnd
2073: * @throws CollabException
2074: */
2075: public void pauseAll(boolean noCancelSendJoinEnd)
2076: throws CollabException {
2077: inPauseState = true;
2078:
2079: //remove any pause timer task
2080: cancelSendPauseMessageTimerTask();
2081:
2082: //remove any resume timer task
2083: cancelSendResumeMessageTimerTask();
2084:
2085: //remove any join begin timer task
2086: cancelSendJoinBeginMessageTimerTask();
2087:
2088: //remove any join end timer task
2089: if (!noCancelSendJoinEnd) {
2090: cancelSendJoinEndMessageTimerTask();
2091: }
2092:
2093: //remove any sendFile timer task
2094: cancelSendFileMessageTimerTask();
2095:
2096: //Pause all operation including edit (only exception is fileOwner sendFile)
2097: disableExplorerPanel();
2098:
2099: SharedFileGroup[] allSharedFileGroups = sharedFileGroupManager
2100: .getAllSharedFileGroup();
2101:
2102: if (allSharedFileGroups != null) {
2103: for (int i = 0; i < allSharedFileGroups.length; i++) {
2104: CollabFileHandler[] fileHandlers = allSharedFileGroups[i]
2105: .getFileHandlers();
2106:
2107: for (int j = 0; j < fileHandlers.length; j++) {
2108: CollabFileHandler collabFileHandler = fileHandlers[j];
2109:
2110: if (collabFileHandler != null) {
2111: collabFileHandler.handlePause();
2112: }
2113: }
2114: }
2115: }
2116: }
2117:
2118: /**
2119: * Resume all operation
2120: *
2121: * @throws CollabException
2122: */
2123: public void resumeAll() throws CollabException {
2124: inPauseState = false;
2125:
2126: //remove any pause timer task
2127: cancelSendPauseMessageTimerTask();
2128:
2129: //remove any resume timer task
2130: cancelSendResumeMessageTimerTask();
2131:
2132: //remove any join begin timer task
2133: cancelSendJoinBeginMessageTimerTask();
2134:
2135: //remove any join end timer task
2136: cancelSendJoinEndMessageTimerTask();
2137:
2138: //remove any sendFile timer task
2139: cancelSendFileMessageTimerTask();
2140:
2141: //Resume all edit operation
2142: SharedFileGroup[] sharedFileGroups = sharedFileGroupManager
2143: .getAllSharedFileGroup();
2144:
2145: if (sharedFileGroups != null) {
2146: for (int i = 0; i < sharedFileGroups.length; i++) {
2147: CollabFileHandler[] fileHandlers = sharedFileGroups[i]
2148: .getFileHandlers();
2149:
2150: for (int j = 0; j < fileHandlers.length; j++) {
2151: CollabFileHandler collabFileHandler = fileHandlers[j];
2152:
2153: if (collabFileHandler != null) {
2154: collabFileHandler.handleResume();
2155: }
2156: }
2157: }
2158: }
2159:
2160: enableExplorerPanel();
2161: }
2162:
2163: protected void initAnnotationTypes() {
2164: RegionAnnotation1 annotation1 = new RegionAnnotation1();
2165: RegionAnnotation2 annotation2 = new RegionAnnotation2();
2166: RegionAnnotation3 annotation3 = new RegionAnnotation3();
2167: RegionAnnotation4 annotation4 = new RegionAnnotation4();
2168: RegionAnnotation5 annotation5 = new RegionAnnotation5();
2169: RegionAnnotation6 annotation6 = new RegionAnnotation6();
2170: RegionAnnotation7 annotation7 = new RegionAnnotation7();
2171: RegionAnnotation8 annotation8 = new RegionAnnotation8();
2172: RegionAnnotation9 annotation9 = new RegionAnnotation9();
2173: annotationTypes = new CollabRegionAnnotation[] { annotation1,
2174: annotation2, annotation3, annotation4, annotation5,
2175: annotation6, annotation7, annotation8, annotation9 };
2176: }
2177:
2178: /**
2179: * allocate an annotation style to a user
2180: *
2181: */
2182: public CollabRegionAnnotation allocateAnnotation(String user) {
2183: CollabRegionAnnotation style = null;
2184:
2185: if (lastAnnotationIndex < annotationTypes.length) {
2186: style = annotationTypes[lastAnnotationIndex++];
2187: } else {
2188: style = annotationTypes[annotationTypes.length - 1];
2189: }
2190:
2191: getAnnotationStyles().put(user, style);
2192:
2193: return style;
2194: }
2195:
2196: public Map getAnnotationStyles() {
2197: return annotationStyles;
2198: }
2199:
2200: /**
2201: * get the annotation style allocated to a user
2202: *
2203: */
2204: public CollabRegionAnnotation getUserAnnotationStyle(String user) {
2205: if (getAnnotationStyles().containsKey(user)) {
2206: return (CollabRegionAnnotation) getAnnotationStyles().get(
2207: user);
2208: } else {
2209: return allocateAnnotation(user);
2210: }
2211: }
2212:
2213: /**
2214: *
2215: *
2216: */
2217: public CollabPrincipal getPrincipal(String id) {
2218: CollabPrincipal principal = null;
2219:
2220: int index = getConversation().getCollabSession()
2221: .getUserPrincipal().getIdentifier().indexOf("@");
2222: String domain = "";
2223: if (index != -1) {
2224: domain = getConversation().getCollabSession()
2225: .getUserPrincipal().getIdentifier()
2226: .substring(index);
2227: }
2228:
2229: try {
2230: principal = getConversation().getCollabSession()
2231: .getPrincipal(id + domain);
2232: } catch (CollabException ce) {
2233: Debug.errorManager.notify(ce);
2234: }
2235:
2236: return principal;
2237: }
2238:
2239: /*
2240: * enableExplorerPanel
2241: *
2242: */
2243: public void enableExplorerPanel() {
2244: SwingUtilities.invokeLater(new Runnable() {
2245: public void run() {
2246: if (explorerPanel != null) {
2247: Debug
2248: .log(this ,
2249: "FilesharingContext, enabling ExplorerPanel");
2250: explorerPanel.enablePanel();
2251: }
2252: }
2253: });
2254: }
2255:
2256: /*
2257: * disableExplorerPanel
2258: *
2259: */
2260: public void disableExplorerPanel() {
2261: SwingUtilities.invokeLater(new Runnable() {
2262: public void run() {
2263: if (explorerPanel != null) {
2264: Debug
2265: .log(this ,
2266: "FilesharingContext, disabling ExplorerPanel");
2267: explorerPanel.disablePanel();
2268: }
2269: }
2270: });
2271: }
2272:
2273: /*
2274: * createProjectNode
2275: *
2276: * @return projectNode
2277: */
2278: public Node createProjectNode(String name, String projectName)
2279: throws IOException {
2280: //getSharedProjectManager().
2281: // createCollabProject(name, projectName);
2282: if (explorerPanel != null) {
2283: return explorerPanel.createProjectNode(name, projectName);
2284: }
2285:
2286: return null;
2287: }
2288:
2289: /**
2290: * getUserStyle
2291: *
2292: * @return
2293: */
2294: public Integer getUserStyle(String user) {
2295: synchronized (userStyles) {
2296: Integer style = (Integer) userStyles.get(user);
2297:
2298: if (style == null) {
2299: Debug.log("CollabFileHandlerSupport",
2300: "CollabFileHandlerSupport, getUserStyle for user"
2301: + user); //NoI18n
2302:
2303: int count = 0;
2304:
2305: for (int i = 0; i < user.length(); i++) {
2306: count += user.charAt(i);
2307: Debug.log("CollabFileHandlerSupport",
2308: "CollabFileHandlerSupport, char: "
2309: + //NoI18n
2310: user.charAt(i)
2311: + "total char count: " + count); //NoI18n
2312: }
2313:
2314: while (count > 10) {
2315: count /= 10;
2316: }
2317:
2318: if (stylesArray[count] == 0) {
2319: Debug.log("CollabFileHandlerSupport",
2320: "CollabFileHandlerSupport, unique count found "
2321: + //NoI18n
2322: "in first attempt, unique count: "
2323: + count); //NoI18n
2324: stylesArray[count] = 1;
2325: } else {
2326: for (int i = 0; i < stylesArray.length; i++) {
2327: if (stylesArray[i] == 0) {
2328: Debug
2329: .log(
2330: "CollabFileHandlerSupport",
2331: "CollabFileHandlerSupport, unique "
2332: + //NoI18n
2333: "count found in "
2334: + i
2335: + " attempt, unique count: "
2336: + count); //NoI18n
2337: stylesArray[i] = 1;
2338: count = i;
2339:
2340: break;
2341: }
2342: }
2343: }
2344:
2345: style = new Integer(count);
2346: userStyles.put(user, style);
2347: }
2348:
2349: Debug.log("CollabFileHandlerSupport",
2350: "CollabFileHandlerSupport, userStyle for user: "
2351: + user + //NoI18n
2352: " is: " + style.intValue()); //NoI18n
2353:
2354: return style;
2355: }
2356: }
2357:
2358: /**
2359: * getJoinTimeStamp
2360: *
2361: * @return
2362: */
2363: public long getJoinTimeStamp() {
2364: Debug.log(this , "FilesharingContext, joinTimeStamp before"
2365: + joinTimeStamp);
2366:
2367: if (joinTimeStamp == -1) {
2368: //timestamp when the user first send/received file
2369: joinTimeStamp = System.currentTimeMillis();
2370: }
2371:
2372: Debug.log(this , "FilesharingContext, joinTimeStamp after"
2373: + joinTimeStamp);
2374:
2375: return joinTimeStamp;
2376: }
2377:
2378: /**
2379: * isReadOnlyConversation
2380: *
2381: * @return flag
2382: */
2383: public boolean isReadOnlyConversation() {
2384: return this .readOnlyConversation;
2385: }
2386:
2387: /**
2388: * isReadOnlyConversation
2389: *
2390: * @return flag
2391: */
2392: private void setIsReadOnlyConversation(boolean readOnlyConversation) {
2393: this .readOnlyConversation = readOnlyConversation;
2394: }
2395:
2396: /**
2397: * setIsReadOnlyConversation
2398: *
2399: * @return flag
2400: */
2401: public void findIsReadOnlyConversation(Conversation conversation) {
2402: String conversationName = conversation.getIdentifier();
2403:
2404: if (conversation == null) {
2405: return;
2406: }
2407:
2408: String userID = conversation.getCollabSession()
2409: .getUserPrincipal().getIdentifier();
2410:
2411: Debug.log(this ,
2412: "FilesharingContext, isReadOnlyConversation: conversationName: "
2413: + conversationName + "userID: " + userID); //NoI18n
2414:
2415: try {
2416: if ((conversation.getPrivilege() == ConversationPrivilege.MANAGE)
2417: || (conversation.getPrivilege() == ConversationPrivilege.WRITE)) {
2418: setIsReadOnlyConversation(false);
2419:
2420: return;
2421: }
2422:
2423: setIsReadOnlyConversation(true);
2424: } catch (CollabException e) {
2425: setIsReadOnlyConversation(true);
2426: }
2427: }
2428:
2429: /**
2430: * closeFile
2431: *
2432: */
2433: public boolean closeFile(String fileName) {
2434: Debug.log("FilesharingContext", //NoI18n
2435: "closeFile: " + fileName); //NoI18n
2436:
2437: try {
2438: CollabFileHandler collabFileHandler = sharedFileGroupManager
2439: .getFileHandler(fileName);
2440:
2441: if (collabFileHandler != null) {
2442: EditorCookie cookie = ((CollabFileHandlerSupport) collabFileHandler)
2443: .getEditorCookie();
2444:
2445: if (cookie != null) {
2446: return cookie.close();
2447: }
2448: }
2449: } catch (Throwable th) {
2450: Debug.log("FilesharingContext",
2451: "FilesharingContext, closeFile() failed"); //NoI18n
2452: Debug.logDebugException(
2453: "CollabFilesystem, closeFile() failed", th, true); //NoI18n
2454: }
2455:
2456: return false;
2457: }
2458:
2459: /**
2460: * doSyncOperation
2461: *
2462: * @param context
2463: */
2464: public void doSyncOperation() {
2465: doSyncOperation(true);
2466: }
2467:
2468: /**
2469: * doSyncOperation
2470: *
2471: * @param context
2472: */
2473: public void doSyncOperation(boolean sendInitialJoinEnd) {
2474: Debug.log(this , "SyncAction, sending sync"); //NoI18n
2475:
2476: //send to all
2477: setJoinUser("");
2478:
2479: long pauseDelay = FilesharingTimerTask.PAUSE_DELAY;
2480:
2481: if (sendInitialJoinEnd) {
2482: JoinEndTimerTask sendJoinMessageTimerTask = new JoinEndTimerTask(
2483: getChannelEventNotifier(), new JoinFilesharingEnd(
2484: new EventContext(JoinFilesharingEnd
2485: .getEventID(), null)), this );
2486: addTimerTask(SEND_JOINEND_TIMER_TASK,
2487: sendJoinMessageTimerTask);
2488: sendJoinMessageTimerTask
2489: .schedule(FilesharingTimerTask.INTER_DELAY);
2490:
2491: try {
2492: Thread.sleep(FilesharingTimerTask.PERIOD * 5);
2493: } catch (java.lang.Throwable th) {
2494: //ignore
2495: }
2496: } else {
2497: pauseDelay = FilesharingTimerTask.INTER_DELAY;
2498: }
2499:
2500: PauseTimerTask sendPauseMessageTimerTask = new PauseTimerTask(
2501: getChannelEventNotifier(), new PauseFilesharingEvent(
2502: new EventContext(PauseFilesharingEvent
2503: .getEventID(), null)), this );
2504: addTimerTask(SEND_PAUSE_TIMER_TASK, sendPauseMessageTimerTask);
2505: sendPauseMessageTimerTask.schedule(pauseDelay);
2506:
2507: //sendMessage join-end
2508: long delay = FilesharingTimerTask.PERIOD;
2509: SharedFileGroup[] allSharedFileGroups = sharedFileGroupManager
2510: .getAllSharedFileGroup();
2511:
2512: if ((allSharedFileGroups != null)
2513: && (allSharedFileGroups.length > 0)) {
2514: int totalFileSize = 0;
2515:
2516: for (int i = 0; i < allSharedFileGroups.length; i++) {
2517: CollabFileHandler[] fileHandlers = allSharedFileGroups[i]
2518: .getFileHandlers();
2519:
2520: for (int j = 0; j < fileHandlers.length; j++) {
2521: CollabFileHandler collabFileHandler = fileHandlers[j];
2522:
2523: if (collabFileHandler != null) {
2524: Debug.log(this , "SyncAction, fileName: "
2525: + collabFileHandler.getName()); //NoI18n
2526:
2527: try {
2528: Debug.log(this , "SyncAction, fileSize: "
2529: + collabFileHandler.getFileSize()); //NoI18n
2530: totalFileSize += collabFileHandler
2531: .getFileSize();
2532: } catch (CollabException ce) {
2533: //ignore
2534: continue;
2535: }
2536: }
2537: }
2538:
2539: Debug.log(this , "SyncAction, totalFileSize: "
2540: + totalFileSize); //NoI18n
2541: delay = CollabQueue.calculateDelay(totalFileSize);
2542: Debug.log(this , "SyncAction, calculated delay: "
2543: + delay); //NoI18n
2544:
2545: if (delay < FilesharingTimerTask.PERIOD) {
2546: delay = FilesharingTimerTask.PERIOD;
2547: }
2548: }
2549: }
2550:
2551: delay += FilesharingTimerTask.PAUSE_DELAY;
2552:
2553: if (delay < (FilesharingTimerTask.PAUSE_DELAY * 2)) {
2554: delay = FilesharingTimerTask.PAUSE_DELAY * 2;
2555: }
2556:
2557: Debug.log(this , "SyncAction, JoinEndTimerTask scheduled after "
2558: + "millis: " + delay); //NoI18n
2559:
2560: JoinEndTimerTask sendJoinMessageTimerTask1 = new JoinEndTimerTask(
2561: getChannelEventNotifier(), new JoinFilesharingEnd(
2562: new EventContext(JoinFilesharingEnd
2563: .getEventID(), null)), this );
2564: addTimerTask(SEND_JOINEND_TIMER_TASK, sendJoinMessageTimerTask1);
2565: sendJoinMessageTimerTask1.schedule(delay);
2566: }
2567:
2568: public void setSharedCommonFileListener(FileSystem scfs,
2569: FileChangeListener scfl) {
2570: this.scfs = scfs;
2571: this.scfl = scfl;
2572: }
2573: }
|