Home | History | Annotate | Download | only in filetransfer
      1 /**
      2  * $RCSfile$
      3  * $Revision$
      4  * $Date$
      5  *
      6  * Copyright 2003-2006 Jive Software.
      7  *
      8  * All rights reserved. Licensed under the Apache License, Version 2.0 (the "License");
      9  * you may not use this file except in compliance with the License.
     10  * You may obtain a copy of the License at
     11  *
     12  *     http://www.apache.org/licenses/LICENSE-2.0
     13  *
     14  * Unless required by applicable law or agreed to in writing, software
     15  * distributed under the License is distributed on an "AS IS" BASIS,
     16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     17  * See the License for the specific language governing permissions and
     18  * limitations under the License.
     19  */
     20 package org.jivesoftware.smackx.filetransfer;
     21 
     22 import org.jivesoftware.smackx.packet.StreamInitiation;
     23 
     24 /**
     25  * A request to send a file recieved from another user.
     26  *
     27  * @author Alexander Wenckus
     28  *
     29  */
     30 public class FileTransferRequest {
     31 	private final StreamInitiation streamInitiation;
     32 
     33 	private final FileTransferManager manager;
     34 
     35 	/**
     36 	 * A recieve request is constructed from the Stream Initiation request
     37 	 * received from the initator.
     38 	 *
     39 	 * @param manager
     40 	 *            The manager handling this file transfer
     41 	 *
     42 	 * @param si
     43 	 *            The Stream initiaton recieved from the initiator.
     44 	 */
     45 	public FileTransferRequest(FileTransferManager manager, StreamInitiation si) {
     46 		this.streamInitiation = si;
     47 		this.manager = manager;
     48 	}
     49 
     50 	/**
     51 	 * Returns the name of the file.
     52 	 *
     53 	 * @return Returns the name of the file.
     54 	 */
     55 	public String getFileName() {
     56 		return streamInitiation.getFile().getName();
     57 	}
     58 
     59 	/**
     60 	 * Returns the size in bytes of the file.
     61 	 *
     62 	 * @return Returns the size in bytes of the file.
     63 	 */
     64 	public long getFileSize() {
     65 		return streamInitiation.getFile().getSize();
     66 	}
     67 
     68 	/**
     69 	 * Returns the description of the file provided by the requestor.
     70 	 *
     71 	 * @return Returns the description of the file provided by the requestor.
     72 	 */
     73 	public String getDescription() {
     74 		return streamInitiation.getFile().getDesc();
     75 	}
     76 
     77 	/**
     78 	 * Returns the mime-type of the file.
     79 	 *
     80 	 * @return Returns the mime-type of the file.
     81 	 */
     82 	public String getMimeType() {
     83 		return streamInitiation.getMimeType();
     84 	}
     85 
     86 	/**
     87 	 * Returns the fully-qualified jabber ID of the user that requested this
     88 	 * file transfer.
     89 	 *
     90 	 * @return Returns the fully-qualified jabber ID of the user that requested
     91 	 *         this file transfer.
     92 	 */
     93 	public String getRequestor() {
     94 		return streamInitiation.getFrom();
     95 	}
     96 
     97 	/**
     98 	 * Returns the stream ID that uniquely identifies this file transfer.
     99 	 *
    100 	 * @return Returns the stream ID that uniquely identifies this file
    101 	 *         transfer.
    102 	 */
    103 	public String getStreamID() {
    104 		return streamInitiation.getSessionID();
    105 	}
    106 
    107 	/**
    108 	 * Returns the stream initiation packet that was sent by the requestor which
    109 	 * contains the parameters of the file transfer being transfer and also the
    110 	 * methods available to transfer the file.
    111 	 *
    112 	 * @return Returns the stream initiation packet that was sent by the
    113 	 *         requestor which contains the parameters of the file transfer
    114 	 *         being transfer and also the methods available to transfer the
    115 	 *         file.
    116 	 */
    117 	protected StreamInitiation getStreamInitiation() {
    118 		return streamInitiation;
    119 	}
    120 
    121 	/**
    122 	 * Accepts this file transfer and creates the incoming file transfer.
    123 	 *
    124 	 * @return Returns the <b><i>IncomingFileTransfer</b></i> on which the
    125 	 *         file transfer can be carried out.
    126 	 */
    127 	public IncomingFileTransfer accept() {
    128 		return manager.createIncomingFileTransfer(this);
    129 	}
    130 
    131 	/**
    132 	 * Rejects the file transfer request.
    133 	 */
    134 	public void reject() {
    135 		manager.rejectIncomingFileTransfer(this);
    136 	}
    137 
    138 }
    139