Search in sources :

Example 1 with IRetrieveFileTransferContainerAdapter

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

the class MultiProtocolRetrieveAdapter method sendRetrieveRequest.

/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.ecf.filetransfer.IRetrieveFileTransferContainerAdapter#sendRetrieveRequest(org.eclipse.ecf.filetransfer.identity.IFileID,
	 *      org.eclipse.ecf.filetransfer.IFileRangeSpecification,
	 *      org.eclipse.ecf.filetransfer.IFileTransferListener, java.util.Map)
	 */
public void sendRetrieveRequest(IFileID remoteFileID, IFileRangeSpecification rangeSpecification, IFileTransferListener transferListener, Map options) throws IncomingFileTransferException {
    Assert.isNotNull(remoteFileID);
    Assert.isNotNull(transferListener);
    String protocol = null;
    try {
        protocol = remoteFileID.getURI().getScheme();
    } catch (URISyntaxException e) {
        try {
            protocol = remoteFileID.getURL().getProtocol();
        } catch (final MalformedURLException e1) {
            throw new IncomingFileTransferException(Messages.AbstractRetrieveFileTransfer_MalformedURLException);
        }
    }
    IRetrieveFileTransferContainerAdapter fileTransfer = Activator.getDefault().getFileTransfer(protocol);
    // for given protocol
    if (fileTransfer == null)
        fileTransfer = new UrlConnectionRetrieveFileTransfer();
    // Set connect context
    fileTransfer.setConnectContextForAuthentication(connectContext);
    // Set Proxy
    fileTransfer.setProxy(proxy);
    // send request using given file transfer protocol
    fileTransfer.sendRetrieveRequest(remoteFileID, rangeSpecification, transferListener, options);
}
Also used : MalformedURLException(java.net.MalformedURLException) IRetrieveFileTransferContainerAdapter(org.eclipse.ecf.filetransfer.IRetrieveFileTransferContainerAdapter) URISyntaxException(java.net.URISyntaxException) IncomingFileTransferException(org.eclipse.ecf.filetransfer.IncomingFileTransferException)

Example 2 with IRetrieveFileTransferContainerAdapter

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

the class MultiProtocolRetrieveAdapter method sendRetrieveRequest.

/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.ecf.filetransfer.IRetrieveFileTransferContainerAdapter#sendRetrieveRequest(org.eclipse.ecf.filetransfer.identity.IFileID,
	 *      org.eclipse.ecf.filetransfer.IFileTransferListener, java.util.Map)
	 */
public void sendRetrieveRequest(IFileID remoteFileID, IFileTransferListener transferListener, Map options) throws IncomingFileTransferException {
    Assert.isNotNull(remoteFileID);
    Assert.isNotNull(transferListener);
    String protocol = null;
    try {
        protocol = remoteFileID.getURI().getScheme();
    } catch (URISyntaxException e) {
        try {
            protocol = remoteFileID.getURL().getProtocol();
        } catch (final MalformedURLException e1) {
            throw new IncomingFileTransferException(Messages.AbstractRetrieveFileTransfer_MalformedURLException);
        }
    }
    IRetrieveFileTransferContainerAdapter fileTransfer = Activator.getDefault().getFileTransfer(protocol);
    // for given protocol
    if (fileTransfer == null)
        fileTransfer = new UrlConnectionRetrieveFileTransfer();
    // Set connect context
    fileTransfer.setConnectContextForAuthentication(connectContext);
    // Set Proxy
    fileTransfer.setProxy(proxy);
    // send request using given file transfer protocol
    fileTransfer.sendRetrieveRequest(remoteFileID, transferListener, options);
}
Also used : MalformedURLException(java.net.MalformedURLException) IRetrieveFileTransferContainerAdapter(org.eclipse.ecf.filetransfer.IRetrieveFileTransferContainerAdapter) URISyntaxException(java.net.URISyntaxException) IncomingFileTransferException(org.eclipse.ecf.filetransfer.IncomingFileTransferException)

Example 3 with IRetrieveFileTransferContainerAdapter

use of org.eclipse.ecf.filetransfer.IRetrieveFileTransferContainerAdapter 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)

Aggregations

IRetrieveFileTransferContainerAdapter (org.eclipse.ecf.filetransfer.IRetrieveFileTransferContainerAdapter)3 IncomingFileTransferException (org.eclipse.ecf.filetransfer.IncomingFileTransferException)3 MalformedURLException (java.net.MalformedURLException)2 URISyntaxException (java.net.URISyntaxException)2 File (java.io.File)1 IOException (java.io.IOException)1 IFileTransfer (org.eclipse.ecf.filetransfer.IFileTransfer)1 IFileTransferListener (org.eclipse.ecf.filetransfer.IFileTransferListener)1 IFileTransferEvent (org.eclipse.ecf.filetransfer.events.IFileTransferEvent)1 IIncomingFileTransferEvent (org.eclipse.ecf.filetransfer.events.IIncomingFileTransferEvent)1 IIncomingFileTransferReceiveStartEvent (org.eclipse.ecf.filetransfer.events.IIncomingFileTransferReceiveStartEvent)1 FileCreateException (org.eclipse.ecf.filetransfer.identity.FileCreateException)1 FileTransfersView (org.eclipse.ecf.filetransfer.ui.FileTransfersView)1 ContainerConnectErrorDialog (org.eclipse.ecf.ui.dialogs.ContainerConnectErrorDialog)1