001 /* 002 003 $Id: SharedFilesResponse.java,v 1.5 2003/05/02 20:29:47 culdesac Exp $ 004 005 */ 006 007 package sharpster.common; 008 009 import sharpster.common.FileCollection; 010 import sharpster.common.Response; 011 import java.util.LinkedList; 012 013 /** 014 * A response containing information about a file share. 015 */ 016 public class SharedFilesResponse extends Response { 017 018 /** 019 * Represents the command which has caused the response (share, unshare etc). 020 */ 021 private int action; 022 023 /** 024 * The collection of files. 025 */ 026 private FileCollection files; 027 028 private LinkedList sharedToUsers; 029 030 /** 031 * 032 */ 033 public SharedFilesResponse() { 034 sharedToUsers = new LinkedList(); 035 } 036 037 /** 038 * Returns the type of this response. 039 */ 040 public int getType() { 041 return sharpster.common.ResponseType.SHARED_FILES; 042 } 043 044 /** 045 * Returns the FileCollection of the response. 046 * 047 * @return FileCollection. 048 */ 049 public FileCollection getFiles() { 050 return files; 051 } 052 053 /** 054 * Sets the file collection. 055 * 056 * @param files The files to be set. 057 */ 058 public void setFiles(FileCollection files) { 059 this.files = files; 060 } 061 062 /** Returns an integer representing the command which has caused the response (share, unshare etc). 063 * 064 * @return An action integer 065 */ 066 public int getAction() { 067 return action; 068 } 069 070 /** 071 * Sets the command which has caused the response (share, unshare etc). 072 * 073 * @param action An action integer 074 */ 075 public void setAction(int action) { 076 this.action = action; 077 } 078 079 public void addSharedToUsers(String user) { 080 sharedToUsers.add(user); 081 } 082 083 public String[] getSharedToUsers() { 084 String[] users = new String[sharedToUsers.size()]; 085 for(int i=0;i<sharedToUsers.size();i++) { 086 users[i]=(String)sharedToUsers.get(i); 087 } 088 return users; 089 } 090 091 /** 092 * 093 */ 094 public String toString() { 095 String msg = super.toString(); 096 097 msg = "Shared files response\n" + msg; 098 099 if(action == 0) msg += "- Action: " + "none" + "\n"; 100 else if(action == 1) msg += "- Action: " + "share" + "\n"; 101 else msg += "- Action: " + "unshare" + "\n"; 102 103 msg += "- Affected users: "; 104 for(int i=0;i<sharedToUsers.size();i++) { 105 msg += (String)sharedToUsers.get(i) + "\n "; 106 } 107 msg += "\r"; 108 109 msg += "- Files: "; 110 111 for(int i=0;i<files.getFileCount();i++) { 112 SharedFile file = files.getFile(i); 113 if(file != null) { 114 msg += file.getFileName() + " | "; 115 msg += file.getAccessRightString() + " | "; 116 msg += file.getPluginDataString(); 117 msg += "\n "; 118 } 119 } 120 121 if(files.getFileCount() == 0) msg += "\n"; 122 123 return msg; 124 } 125 } 126 127 128 129 130 131 132