001/** 002 * 003 * Copyright 2003-2006 Jive Software. 004 * 005 * Licensed under the Apache License, Version 2.0 (the "License"); 006 * you may not use this file except in compliance with the License. 007 * You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.jivesoftware.smackx.filetransfer; 018 019import org.jivesoftware.smack.SmackException.NotConnectedException; 020 021import org.jivesoftware.smackx.si.packet.StreamInitiation; 022 023import org.jxmpp.jid.Jid; 024 025/** 026 * A request to send a file received from another user. 027 * 028 * @author Alexander Wenckus 029 * 030 */ 031public class FileTransferRequest { 032 private final StreamInitiation streamInitiation; 033 034 private final FileTransferManager manager; 035 036 /** 037 * A receive request is constructed from the Stream Initiation request 038 * received from the initiator. 039 * 040 * @param manager TODO javadoc me please 041 * The manager handling this file transfer 042 * 043 * @param si TODO javadoc me please 044 * The Stream initiation received from the initiator. 045 */ 046 public FileTransferRequest(FileTransferManager manager, StreamInitiation si) { 047 this.streamInitiation = si; 048 this.manager = manager; 049 } 050 051 /** 052 * Returns the name of the file. 053 * 054 * @return Returns the name of the file. 055 */ 056 public String getFileName() { 057 return streamInitiation.getFile().getName(); 058 } 059 060 /** 061 * Returns the size in bytes of the file. 062 * 063 * @return Returns the size in bytes of the file. 064 */ 065 public long getFileSize() { 066 return streamInitiation.getFile().getSize(); 067 } 068 069 /** 070 * Returns the description of the file provided by the requester. 071 * 072 * @return Returns the description of the file provided by the requester. 073 */ 074 public String getDescription() { 075 return streamInitiation.getFile().getDesc(); 076 } 077 078 /** 079 * Returns the mime-type of the file. 080 * 081 * @return Returns the mime-type of the file. 082 */ 083 public String getMimeType() { 084 return streamInitiation.getMimeType(); 085 } 086 087 /** 088 * Returns the fully-qualified jabber ID of the user that requested this 089 * file transfer. 090 * 091 * @return Returns the fully-qualified jabber ID of the user that requested 092 * this file transfer. 093 */ 094 public Jid getRequestor() { 095 return streamInitiation.getFrom(); 096 } 097 098 /** 099 * Returns the stream ID that uniquely identifies this file transfer. 100 * 101 * @return Returns the stream ID that uniquely identifies this file 102 * transfer. 103 */ 104 public String getStreamID() { 105 return streamInitiation.getSessionID(); 106 } 107 108 /** 109 * Returns the stream initiation stanza that was sent by the requester which 110 * contains the parameters of the file transfer being transfer and also the 111 * methods available to transfer the file. 112 * 113 * @return Returns the stream initiation stanza that was sent by the 114 * requester which contains the parameters of the file transfer 115 * being transfer and also the methods available to transfer the 116 * file. 117 */ 118 protected StreamInitiation getStreamInitiation() { 119 return streamInitiation; 120 } 121 122 /** 123 * Accepts this file transfer and creates the incoming file transfer. 124 * 125 * @return Returns the IncomingFileTransfer on which the 126 * file transfer can be carried out. 127 */ 128 public IncomingFileTransfer accept() { 129 return manager.createIncomingFileTransfer(this); 130 } 131 132 /** 133 * Rejects the file transfer request. 134 * @throws NotConnectedException if the XMPP connection is not connected. 135 * @throws InterruptedException if the calling thread was interrupted. 136 */ 137 public void reject() throws NotConnectedException, InterruptedException { 138 manager.rejectIncomingFileTransfer(this); 139 } 140 141}