Search in sources :

Example 16 with IFileTransferListener

use of org.eclipse.ecf.filetransfer.IFileTransferListener in project ecf by eclipse.

the class BitTorrentConnectWizard method performFinish.

public boolean performFinish() {
    workbenchPage = workbench.getActiveWorkbenchWindow().getActivePage();
    final IRetrieveFileTransferContainerAdapter irftca = (IRetrieveFileTransferContainerAdapter) container.getAdapter(IRetrieveFileTransferContainerAdapter.class);
    try {
        targetID = FileIDFactory.getDefault().createFileID(irftca.getRetrieveNamespace(), page.getTorrentName());
    } catch (final FileCreateException e) {
        new ContainerConnectErrorDialog(workbench.getActiveWorkbenchWindow().getShell(), 1, "The target ID to connect to could not be created", page.getTorrentName(), e).open();
        return true;
    }
    try {
        irftca.sendRetrieveRequest(targetID, new IFileTransferListener() {

            public void handleTransferEvent(final IFileTransferEvent e) {
                if (e instanceof IIncomingFileTransferReceiveStartEvent) {
                    try {
                        final IFileTransfer ift = ((IIncomingFileTransferReceiveStartEvent) e).receive(new File(page.getTargetName()));
                        workbenchPage.getWorkbenchWindow().getShell().getDisplay().asyncExec(new Runnable() {

                            public void run() {
                                FileTransfersView.addTransfer(ift);
                            }
                        });
                    } catch (final IOException ioe) {
                        new ContainerConnectErrorDialog(workbench.getActiveWorkbenchWindow().getShell(), 1, "Could not write to " + page.getTargetName(), page.getTargetName(), null).open();
                    }
                } else if (e instanceof IIncomingFileTransferEvent) {
                    final FileTransfersView ftv = (FileTransfersView) workbenchPage.findView(FileTransfersView.ID);
                    if (ftv != null) {
                        workbenchPage.getWorkbenchWindow().getShell().getDisplay().asyncExec(new Runnable() {

                            public void run() {
                                ftv.update(((IIncomingFileTransferEvent) e).getSource());
                            }
                        });
                    }
                }
            }
        }, null);
    } catch (final IncomingFileTransferException e) {
        new ContainerConnectErrorDialog(workbench.getActiveWorkbenchWindow().getShell(), 1, "Could not send retrieval request.", targetID.getName(), e).open();
    }
    return true;
}
Also used : FileCreateException(org.eclipse.ecf.filetransfer.identity.FileCreateException) IRetrieveFileTransferContainerAdapter(org.eclipse.ecf.filetransfer.IRetrieveFileTransferContainerAdapter) IIncomingFileTransferReceiveStartEvent(org.eclipse.ecf.filetransfer.events.IIncomingFileTransferReceiveStartEvent) FileTransfersView(org.eclipse.ecf.filetransfer.ui.FileTransfersView) ContainerConnectErrorDialog(org.eclipse.ecf.ui.dialogs.ContainerConnectErrorDialog) IFileTransferListener(org.eclipse.ecf.filetransfer.IFileTransferListener) IOException(java.io.IOException) IFileTransferEvent(org.eclipse.ecf.filetransfer.events.IFileTransferEvent) IIncomingFileTransferEvent(org.eclipse.ecf.filetransfer.events.IIncomingFileTransferEvent) IncomingFileTransferException(org.eclipse.ecf.filetransfer.IncomingFileTransferException) IFileTransfer(org.eclipse.ecf.filetransfer.IFileTransfer) File(java.io.File)

Example 17 with IFileTransferListener

use of org.eclipse.ecf.filetransfer.IFileTransferListener in project ecf by eclipse.

the class XMPPFileTransferRequestListener method fileTransferRequest.

/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.jivesoftware.smackx.filetransfer.FileTransferListener#fileTransferRequest
	 * (org.jivesoftware.smackx.filetransfer.FileTransferRequest)
	 */
public void fileTransferRequest(final FileTransferRequest request) {
    requestListener.handleFileTransferRequest(new IFileTransferRequestEvent() {

        boolean requestAccepted = false;

        IFileTransferInfo fileTransferInfo = new IFileTransferInfo() {

            Map props = new HashMap();

            File f = new File(request.getFileName());

            public String getDescription() {
                return request.getDescription();
            }

            public File getFile() {
                return f;
            }

            public Map getProperties() {
                return props;
            }

            public Object getAdapter(Class adapter) {
                if (adapter == null)
                    return null;
                if (adapter.isInstance(this))
                    return this;
                final IAdapterManager adapterManager = XmppPlugin.getDefault().getAdapterManager();
                return (adapterManager == null) ? null : adapterManager.loadAdapter(this, adapter.getName());
            }

            public long getFileSize() {
                return request.getFileSize();
            }

            public String getMimeType() {
                return request.getMimeType();
            }

            public String toString() {
                final StringBuffer buf = new StringBuffer("FileTransferInfo[");
                buf.append("file=").append(f);
                buf.append(";size=").append(getFileSize());
                buf.append(";description=" + getDescription());
                buf.append(";mimeType=").append(getMimeType()).append("]");
                return buf.toString();
            }
        };

        public IIncomingFileTransfer accept(File localFileToSave) throws IncomingFileTransferException {
            try {
                final OutputStream outs = new FileOutputStream(localFileToSave);
                return accept(outs, new IFileTransferListener() {

                    public void handleTransferEvent(IFileTransferEvent event) {
                        if (event instanceof IIncomingFileTransferReceiveDoneEvent) {
                            try {
                                outs.close();
                            } catch (final IOException e) {
                            }
                        }
                    }
                });
            } catch (final FileNotFoundException e) {
                throw new IncomingFileTransferException("Exception opening file for writing", e);
            }
        }

        public IFileTransferInfo getFileTransferInfo() {
            return fileTransferInfo;
        }

        public ID getRequesterID() {
            return createIDFromName(request.getRequestor());
        }

        public void reject() {
            request.reject();
        }

        public boolean requestAccepted() {
            return requestAccepted;
        }

        public String toString() {
            final StringBuffer buf = new StringBuffer("FileTransferRequestEvent[");
            buf.append("requester=").append(getRequesterID());
            buf.append(";requestAccepted=").append(requestAccepted());
            buf.append(";transferInfo=").append(getFileTransferInfo()).append("]");
            return buf.toString();
        }

        public IIncomingFileTransfer accept(OutputStream outputStream, IFileTransferListener listener) throws IncomingFileTransferException {
            if (requestAccepted)
                throw new IncomingFileTransferException("Incoming request previously accepted");
            if (outputStream == null)
                throw new IncomingFileTransferException("outputStream cannot be null");
            incoming = request.accept();
            requestAccepted = true;
            try {
                return new XMPPIncomingFileTransfer(IDFactory.getDefault().createStringID(request.getStreamID()), request.getFileName(), incoming.recieveFile(), outputStream, request.getFileSize(), listener);
            } catch (final Exception e) {
                throw new IncomingFileTransferException("Exception receiving file", e);
            }
        }
    });
}
Also used : HashMap(java.util.HashMap) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileNotFoundException(java.io.FileNotFoundException) IFileTransferInfo(org.eclipse.ecf.filetransfer.IFileTransferInfo) IFileTransferListener(org.eclipse.ecf.filetransfer.IFileTransferListener) IOException(java.io.IOException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) IncomingFileTransferException(org.eclipse.ecf.filetransfer.IncomingFileTransferException) IIncomingFileTransfer(org.eclipse.ecf.filetransfer.IIncomingFileTransfer) IFileTransferEvent(org.eclipse.ecf.filetransfer.events.IFileTransferEvent) FileOutputStream(java.io.FileOutputStream) IIncomingFileTransferReceiveDoneEvent(org.eclipse.ecf.filetransfer.events.IIncomingFileTransferReceiveDoneEvent) IAdapterManager(org.eclipse.core.runtime.IAdapterManager) IncomingFileTransferException(org.eclipse.ecf.filetransfer.IncomingFileTransferException) XMPPID(org.eclipse.ecf.provider.xmpp.identity.XMPPID) ID(org.eclipse.ecf.core.identity.ID) HashMap(java.util.HashMap) Map(java.util.Map) File(java.io.File) IFileTransferRequestEvent(org.eclipse.ecf.filetransfer.events.IFileTransferRequestEvent)

Example 18 with IFileTransferListener

use of org.eclipse.ecf.filetransfer.IFileTransferListener in project ecf by eclipse.

the class XMPPOutgoingFileTransferHelper method fireFileTransferEvent.

protected void fireFileTransferEvent(IFileTransferEvent event) {
    synchronized (transferListeners) {
        for (final Iterator i = transferListeners.iterator(); i.hasNext(); ) {
            final IFileTransferListener l = (IFileTransferListener) i.next();
            l.handleTransferEvent(event);
        }
    }
}
Also used : Iterator(java.util.Iterator) IFileTransferListener(org.eclipse.ecf.filetransfer.IFileTransferListener)

Aggregations

IFileTransferListener (org.eclipse.ecf.filetransfer.IFileTransferListener)18 IOException (java.io.IOException)9 IFileID (org.eclipse.ecf.filetransfer.identity.IFileID)7 File (java.io.File)5 URL (java.net.URL)5 FileTransferJob (org.eclipse.ecf.filetransfer.FileTransferJob)5 IFileTransferConnectStartEvent (org.eclipse.ecf.filetransfer.events.IFileTransferConnectStartEvent)5 IFileTransferEvent (org.eclipse.ecf.filetransfer.events.IFileTransferEvent)5 IIncomingFileTransferReceiveStartEvent (org.eclipse.ecf.filetransfer.events.IIncomingFileTransferReceiveStartEvent)5 IIncomingFileTransferReceiveDoneEvent (org.eclipse.ecf.filetransfer.events.IIncomingFileTransferReceiveDoneEvent)4 FileOutputStream (java.io.FileOutputStream)3 HttpRequestHandler (org.apache.commons.httpclient.server.HttpRequestHandler)3 SimpleHttpServer (org.apache.commons.httpclient.server.SimpleHttpServer)3 SimpleHttpServerConnection (org.apache.commons.httpclient.server.SimpleHttpServerConnection)3 SimpleRequest (org.apache.commons.httpclient.server.SimpleRequest)3 IncomingFileTransferException (org.eclipse.ecf.filetransfer.IncomingFileTransferException)3 SimpleServer (org.eclipse.ecf.internal.tests.filetransfer.httpserver.SimpleServer)3 UnknownHostException (java.net.UnknownHostException)2 ResponseWriter (org.apache.commons.httpclient.server.ResponseWriter)2 IFileTransferPausable (org.eclipse.ecf.filetransfer.IFileTransferPausable)2