Java 类org.jivesoftware.smackx.filetransfer.FileTransferRequest 实例源码

项目:NewCommunication-Android    文件:XmppManager.java   
public void getFile(){

    manager.addFileTransferListener(new FileTransferListener() {

    @Override
    public void fileTransferRequest(FileTransferRequest request) {

        IncomingFileTransfer fileTransfer = request.accept();

        try {
            fileTransfer.recieveFile(new File(Environment.getExternalStorageDirectory().getAbsolutePath(), "�����ļ�"));
        } catch (XMPPException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    }
});
  }
项目:commune    文件:IncomingTransfersManager.java   
private Map<String, String> getPropsMap(FileTransferRequest ftr) {
    String[ ] msgArray = ftr.getDescription().split(PROPERTIES_SEPARATOR);
    Map<String, String> props = new TreeMap<String, String>(); 

    for (String msg : msgArray) {

        if (msg == null) {
            continue;
        }

        String[] data = msg.split(PROPERTY_SEPARATOR);

        if (data == null || data.length == 0 || data.length > 2) {
            continue;
        }

        if (data.length == 1) {
            props.put(data[0], null);
        } else {
            props.put(data[0], data[1]);
        }
    }
    return props;
}
项目:synergynet3.1    文件:FileReceiver.java   
@Override
public void fileTransferRequest(final FileTransferRequest request)
{
    log.fine("Received file transfer request " + request);
    final String uniqueFileIdentifier = request.getDescription();
    final MD5Hash hash = new MD5Hash(uniqueFileIdentifier);
    final File temporaryIncomingFile = getTemporaryFileToStoreIncomingTransfer();
    log.fine("File " + request.getFileName() + " being saved as " + temporaryIncomingFile.getAbsolutePath());

    final IncomingFileTransfer transfer = request.accept();
    try
    {
        transfer.recieveFile(temporaryIncomingFile);
        FileTransferWorker fileTransferWorker = new FileTransferWorker(new FileTransferWorker.FileTransferWorkerDelegate()
        {
            @Override
            public void transferComplete()
            {
                fileTransferDidComplete(request.getFileName(), temporaryIncomingFile, hash, transfer);
            }

        }, transfer);
        fileTransferWorker.start();

    }
    catch (XMPPException ex)
    {
        log.log(Level.SEVERE, null, ex);
    }
}
项目:aceim    文件:XMPPFileTransferListener.java   
@Override
public void fileTransferRequest(FileTransferRequest request) {
    Logger.log("incoming file " + request.getFileName() + " from " + request.getRequestor(), LoggerLevel.VERBOSE);
    fileTransfers.put(Long.valueOf(request.getStreamID().hashCode()) , request);
    FileInfo fi = new FileInfo(getInternalService().getService().getServiceId());
    fi.setFilename(request.getFileName());
    fi.setSize(request.getFileSize());

    FileMessage fm = new FileMessage(getInternalService().getService().getServiceId(), getInternalService().getService().getEntityAdapter().normalizeJID(request.getRequestor()), Arrays.asList(fi));

    fm.setMessageId(request.getStreamID().hashCode());

    getInternalService().getService().getCoreService().message(fm);
}
项目:aceim    文件:XMPPFileTransferListener.java   
void fileRespond(final FileMessage fileMessage, final Boolean accept) {
    FileTransferRequest request = fileTransfers.remove(fileMessage.getMessageId());

    if (request != null) {
        if (accept) {
            Runnable r = new IncomingFileRunnable(fileMessage.getContactUid(), request);
            Executors.defaultThreadFactory().newThread(r).start();
        } else {
            request.reject();
        }
    } else {
        Logger.log("No file message to respond " + fileMessage.getMessageId(), LoggerLevel.INFO);
    }
}
项目:aceim    文件:XMPPFileTransferListener.java   
public void cancel(long messageId) {
    FileTransferRequest request = fileTransfers.get(messageId);

    if (request != null) {
        request.reject();
        fileTransfers.remove(messageId);
    }
}
项目:commune    文件:IncomingTransfersManager.java   
public IncomingTransfersManager(Module module, FileTransferManager manager, ReentrantLock transfersLock) {

        this.module = module;
        receiverListeners = new HashMap<DeploymentID,TransferReceiver>();
        handlersRequestMap = new HashMap<IncomingTransferHandle,FileTransferRequest>();
        transfers = new ConcurrentHashMap<TransferHandle,IncomingTransfer>();
        this.manager = manager;

        transferStateMonitor = new TransferStateMonitorThread();
        this.transfersLock = transfersLock;
    }
项目:commune    文件:IncomingTransfersManager.java   
public void accept(IncomingTransferHandle handle, DeploymentID listenerID) {

    File destination = handle.getLocalFile(); 
    long inactivityTimeout = handle.getInactivityTimeout();
    boolean receiveProgressUpdates = handle.isReceiveProgressUpdate();

    LOG.debug( "Accepting transfer. Handle: " + handle + ", dest: " + destination.getAbsolutePath() );

    createSubFolders(destination);

    FileTransferRequest fileTransferRequest = handlersRequestMap.get( handle );
    final IncomingFileTransfer transfer = fileTransferRequest.accept();

    IncomingTransfer fileTransfer = new IncomingTransfer(module, listenerID, destination, transfer, handle,
        inactivityTimeout, fileTransferRequest.getFileSize(), receiveProgressUpdates);

    if ( receiveProgressUpdates ) {
        TransferProgress transferProgress = new TransferProgress( handle, destination.getName(),
            fileTransferRequest.getFileSize(), transfer.getStatus(), 0L, 0D, 0, false );
        Message message = 
            AbstractTransfer.createUpdateTransferProgressMessage(module.getContainerID(), listenerID, 
                    transferProgress);
        module.sendMessage(message);
    }

    try {
        fileTransfer.start();
    } catch (IllegalArgumentException e) {
        LOG.error("Destination is not writable. Handle: " + handle + ", dest: " + destination.getAbsolutePath());
        reject(handle);
    }

    addTransfer(handle, fileTransfer);
}
项目:commune    文件:IncomingTransfersManager.java   
public void fileTransferRequest(FileTransferRequest ftr) {
    Map<String, String> props = getPropsMap(ftr);

    if (props.size() < 5) {
        rejectRequest(ftr);

    } else {
        DeploymentID receiverID = new DeploymentID(props.get(DESTINATION_PROPERTY));
        TransferReceiver receiver = receiverListeners.get(receiverID);
        if (receiver != null) {
            String transferDescription = null;
            transferDescription = props.get(DESCRIPTION_PROPERTY);

            try {
                long id = Long.parseLong(props.get(HANDLE_PROPERTY));
                ContainerID senderID = ContainerID.parse(ftr.getRequestor());

                IncomingTransferHandle handle = 
                    new IncomingTransferHandle(id, ftr.getFileName(), transferDescription, ftr.getFileSize(), senderID);

                handle.setReadable(Boolean.parseBoolean(props.get(READABLE_PROPERTY)));
                handle.setExecutable(Boolean.parseBoolean(props.get(EXECUTABLE_PROPERTY)));
                handle.setWritable(Boolean.parseBoolean(props.get(WRITABLE_PROPERTY)));

                handlersRequestMap.put(handle, ftr);

                Message message = new Message(module.getContainerID(), receiverID, "transferRequestReceived");
                message.addParameter(IncomingTransferHandle.class, handle);
                module.sendMessage(message);

            } catch (Exception e) {
                rejectRequest(ftr);                 
            }


        } else {
            rejectRequest(ftr);
        }
    }
}
项目:spark-svn-mirror    文件:SparkTransferManager.java   
private boolean fireTransferListeners(FileTransferRequest request) {
    for (FileTransferListener listener : new ArrayList<FileTransferListener>(listeners)) {
        boolean accepted = listener.handleTransfer(request);
        if (accepted) {
            return true;
        }
    }
    return false;
}
项目:spark-svn-mirror    文件:ReceiveFileTransfer.java   
private void rejectRequest(FileTransferRequest request) {
    request.reject();

    setBackground(new Color(239, 245, 250));
    acceptButton.setVisible(false);
    declineButton.setVisible(false);
    fileLabel.setText("");
    titleLabel.setText(Res.getString("message.file.transfer.canceled"));
    titleLabel.setForeground(new Color(65, 139, 179));

    invalidate();
    validate();
    repaint();
}
项目:spark-svn-mirror    文件:FileTransferSettingsPlugin.java   
/**
 * Tests the supplied {@link FileTransferRequest} against the supplied {@link FileTransferSettings}. Returns true if  the request
 * fails to match the configuration for allowed files.
 *
 * @param request  the transfer request to test.
 * @param settings the transfer settings to use in testing the request.
 * @return true if the request fails to match the configuration for allowed files.
 */
private boolean requestContainsBannedFile(FileTransferRequest request, FileTransferSettings settings) {
    if (settings.getCheckFileSize() && request.getFileSize() > settings.getMaxFileSize()) {
        return true;
    }
    if (settings.getBlockedJIDs().contains(trimJID(request.getRequestor()))) {
        return true;
    }
    if (settings.getBlockedExtensions().contains(getFileExtensionFromName(request.getFileName()))) {
        return true;
    }
    return false;

}
项目:spark-svn-mirror    文件:FileTransferSettingsPlugin.java   
/**
 * Adds a {@link FileTransferListener} to allow this plugin to intercept {@link FileTransferRequest}s.
 */
private void addTransferListener() {

    SparkTransferManager transferManager = SparkManager.getTransferManager();

    transferManager.addTransferListener(new FileTransferListener() {
        public boolean handleTransfer(FileTransferRequest request) {
            FileTransferSettings settings = (FileTransferSettings)prefManager.getPreferenceData("transferSettings");

            if (requestContainsBannedFile(request, settings)) {
                request.reject();

                String responseMessage = settings.getCannedRejectionMessage();
                if (responseMessage != null && responseMessage.length() > 0) {
                    Message message = new Message();
                    message.setTo(request.getRequestor());
                    message.setBody(responseMessage);
                    SparkManager.getConnection().sendPacket(message);
                }
                return true;
            }
            else {
                return false;
            }
        }
    });
}
项目:aceim    文件:XMPPFileTransferListener.java   
private IncomingFileRunnable(String senderJid, FileTransferRequest request) {
    this.senderJid = senderJid;
    this.request = request;
}
项目:commune    文件:IncomingTransfersManager.java   
public void reject(TransferHandle handle) {
    FileTransferRequest request = handlersRequestMap.get(handle);
    rejectRequest(request);
}
项目:commune    文件:IncomingTransfersManager.java   
private void rejectRequest(FileTransferRequest request) {
    LOG.debug("Rejecting transfer. " + " File name: " + request.getFileName() + ", description: "
            + request.getDescription());
    request.reject();
}
项目:commune    文件:TransferManager.java   
public void transferRequest(FileTransferRequest ftr) {
    LOG.debug("Incoming transfer request. File name: " + ftr.getFileName());
    incomingManager.fileTransferRequest(ftr);
}
项目:spark-svn-mirror    文件:SparkTransferManager.java   
private void handleTransferRequest(FileTransferRequest request, ContactList contactList) {
    // Check if a listener handled this request
    if (fireTransferListeners(request)) {
        return;
    }

    String requestor = request.getRequestor();
    String bareJID = StringUtils.parseBareAddress(requestor);
    String fileName = request.getFileName();


    ContactItem contactItem = contactList.getContactItemByJID(bareJID);

    ChatRoom chatRoom;
    if (contactItem != null) {
        chatRoom = SparkManager.getChatManager().createChatRoom(bareJID, contactItem.getDisplayName(), contactItem.getDisplayName());
    }
    else {
        chatRoom = SparkManager.getChatManager().createChatRoom(bareJID, bareJID, bareJID);
    }

    TranscriptWindow transcriptWindow = chatRoom.getTranscriptWindow();
    transcriptWindow.insertCustomText(Res.getString("message.file.transfer.chat.window"), true, false, Color.BLACK);        

    final ReceiveFileTransfer receivingMessageUI = new ReceiveFileTransfer();
    receivingMessageUI.acceptFileTransfer(request);

    chatRoom.addClosingListener(new ChatRoomClosingListener() {
        public void closing() {
            receivingMessageUI.cancelTransfer();
        }
    });

    transcriptWindow.addComponent(receivingMessageUI);

    chatRoom.increaseUnreadMessageCount();

    chatRoom.scrollToBottom();

    String fileTransMsg = contactItem.getDisplayName() + " " + Res.getString("message.file.transfer.short.message") + " " + fileName;
    SparkManager.getChatManager().getChatContainer().fireNotifyOnMessage(chatRoom, true, fileTransMsg, Res.getString("message.file.transfer.notification"));
}
项目:spark-svn-mirror    文件:FileTransferListener.java   
/**
 * Returns true if the object wishes to handle the file transfer itself. Otherwise,
 * it will default.
 *
 * @param request the <code>FileTransferRequest</code>
 * @return true if object handles transfer request.
 */
boolean handleTransfer(FileTransferRequest request);