Search in sources :

Example 6 with IFileID

use of org.eclipse.ecf.filetransfer.identity.IFileID in project ecf by eclipse.

the class FileIDFactoryTest method testCreateFromString.

public void testCreateFromString() throws Exception {
    final IFileID fileID = createFileID(getRetrieveAdapter().getRetrieveNamespace(), "http://www.eclipse.org/ecf");
    assertNotNull(fileID);
}
Also used : IFileID(org.eclipse.ecf.filetransfer.identity.IFileID)

Example 7 with IFileID

use of org.eclipse.ecf.filetransfer.identity.IFileID in project ecf by eclipse.

the class AbstractBrowseTestCase method verifyRemoteFiles.

/**
 * @param remoteFiles
 */
protected void verifyRemoteFiles(final IRemoteFile[] remoteFiles) {
    for (int i = 0; i < remoteFiles.length; i++) {
        final IRemoteFile first = remoteFiles[i];
        final IRemoteFileInfo firstInfo = first.getInfo();
        assertNotNull(firstInfo);
        final IFileID firstID = first.getID();
        assertNotNull(firstID);
        trace("firstID=" + firstID);
        // Now check out info
        assertNotNull(firstInfo.getName());
        assertTrue(firstInfo.getLastModified() > 0);
        trace("lastModified=" + new SimpleDateFormat().format(new Date(firstInfo.getLastModified())));
        trace("length=" + firstInfo.getLength());
        trace("isDirectory=" + firstInfo.isDirectory());
        final IRemoteFileAttributes attributes = firstInfo.getAttributes();
        assertNotNull(attributes);
        final Iterator attrNames = attributes.getAttributeKeys();
        for (; attrNames.hasNext(); ) {
            final String key = (String) attrNames.next();
            String s = "attrname=" + key;
            s += " attrvalue=" + attributes.getAttribute(key);
            trace(s);
        }
    }
}
Also used : IFileID(org.eclipse.ecf.filetransfer.identity.IFileID) IRemoteFileInfo(org.eclipse.ecf.filetransfer.IRemoteFileInfo) IRemoteFile(org.eclipse.ecf.filetransfer.IRemoteFile) Iterator(java.util.Iterator) IRemoteFileAttributes(org.eclipse.ecf.filetransfer.IRemoteFileAttributes) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 8 with IFileID

use of org.eclipse.ecf.filetransfer.identity.IFileID in project ecf by eclipse.

the class URLRetrieveTestWithCustomJob method testReceive.

protected void testReceive(String url) throws Exception {
    assertNotNull(retrieveAdapter);
    final IFileTransferListener listener = createFileTransferListener();
    final IFileID fileID = createFileID(new URL(url));
    fileTransferJob = new FileTransferJob(fileID.getName());
    fileTransferJob.addJobChangeListener(new JobChangeTraceListener(startTime));
    retrieveAdapter.sendRetrieveRequest(fileID, listener, null);
    waitForDone(10000);
    final IStatus result = fileTransferJob.getResult();
    System.out.println("job=" + fileTransferJob.getName() + " result=" + result);
    assertTrue(result != null);
    assertHasEvent(startEvents, IIncomingFileTransferReceiveStartEvent.class);
    assertHasMoreThanEventCount(dataEvents, IIncomingFileTransferReceiveDataEvent.class, 0);
    assertDoneOK();
    assertTrue(tmpFile.exists());
    assertTrue(tmpFile.length() > 0);
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) IFileID(org.eclipse.ecf.filetransfer.identity.IFileID) FileTransferJob(org.eclipse.ecf.filetransfer.FileTransferJob) IFileTransferListener(org.eclipse.ecf.filetransfer.IFileTransferListener) URL(java.net.URL)

Example 9 with IFileID

use of org.eclipse.ecf.filetransfer.identity.IFileID in project ecf by eclipse.

the class XMPPCompoundContributionItem method sendFileToTarget.

private void sendFileToTarget(ISendFileTransferContainerAdapter fileTransfer, final ID targetID) {
    final Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
    final FileDialog fd = new FileDialog(shell, SWT.OPEN);
    // XXX this should be some default path set by preferences
    // $NON-NLS-1$
    fd.setFilterPath(System.getProperty("user.home"));
    fd.setText(NLS.bind(Messages.XMPPCompoundContributionItem_CHOOSE_FILE, targetID.getName()));
    final String res = fd.open();
    if (res != null) {
        final File aFile = new File(res);
        try {
            final IFileID targetFileID = FileIDFactory.getDefault().createFileID(fileTransfer.getOutgoingNamespace(), new Object[] { targetID, res });
            fileTransfer.sendOutgoingRequest(targetFileID, aFile, new IFileTransferListener() {

                public void handleTransferEvent(final IFileTransferEvent event) {
                    Display.getDefault().asyncExec(new Runnable() {

                        public void run() {
                            // bar?)
                            if (event instanceof IOutgoingFileTransferResponseEvent) {
                                if (!((IOutgoingFileTransferResponseEvent) event).requestAccepted())
                                    MessageDialog.openInformation(shell, Messages.XMPPCompoundContributionItem_FILE_SEND_REFUSED_TITLE, NLS.bind(Messages.XMPPCompoundContributionItem_FILE_SEND_REFUSED_MESSAGE, res, targetID.getName()));
                            }
                        }
                    });
                }
            }, null);
        } catch (final Exception e) {
            MessageDialog.openError(shell, Messages.XMPPCompoundContributionItem_SEND_ERROR_TITLE, NLS.bind(Messages.XMPPCompoundContributionItem_SEND_ERROR_MESSAGE, res, e.getLocalizedMessage()));
        }
    }
}
Also used : Shell(org.eclipse.swt.widgets.Shell) IFileTransferEvent(org.eclipse.ecf.filetransfer.events.IFileTransferEvent) IFileID(org.eclipse.ecf.filetransfer.identity.IFileID) IOutgoingFileTransferResponseEvent(org.eclipse.ecf.filetransfer.events.IOutgoingFileTransferResponseEvent) IFileTransferListener(org.eclipse.ecf.filetransfer.IFileTransferListener) FileDialog(org.eclipse.swt.widgets.FileDialog) File(java.io.File)

Example 10 with IFileID

use of org.eclipse.ecf.filetransfer.identity.IFileID in project ecf by eclipse.

the class HttpClientBrowseFileTransferFactory method newInstance.

public IRemoteFileSystemBrowser newInstance() {
    return new IRemoteFileSystemBrowser() {

        private Proxy proxy;

        private IConnectContext connectContext;

        public Namespace getBrowseNamespace() {
            return IDFactory.getDefault().getNamespaceByName(FileTransferNamespace.PROTOCOL);
        }

        public IRemoteFileSystemRequest sendBrowseRequest(IFileID directoryOrFileId, IRemoteFileSystemListener listener) throws RemoteFileSystemException {
            Assert.isNotNull(directoryOrFileId);
            Assert.isNotNull(listener);
            URL url;
            try {
                url = directoryOrFileId.getURL();
            } catch (final MalformedURLException e) {
                // $NON-NLS-1$
                throw new RemoteFileSystemException(NLS.bind("Exception creating URL for {0}", directoryOrFileId));
            }
            HttpClientFileSystemBrowser browser = new HttpClientFileSystemBrowser(new SNIAwareHttpClient(), directoryOrFileId, listener, url, connectContext, proxy);
            return browser.sendBrowseRequest();
        }

        public void setConnectContextForAuthentication(IConnectContext connectContext) {
            this.connectContext = connectContext;
        }

        public void setProxy(Proxy proxy) {
            this.proxy = proxy;
        }

        public Object getAdapter(Class adapter) {
            return null;
        }
    };
}
Also used : IConnectContext(org.eclipse.ecf.core.security.IConnectContext) RemoteFileSystemException(org.eclipse.ecf.filetransfer.RemoteFileSystemException) IRemoteFileSystemBrowser(org.eclipse.ecf.filetransfer.service.IRemoteFileSystemBrowser) Proxy(org.eclipse.ecf.core.util.Proxy) MalformedURLException(java.net.MalformedURLException) IFileID(org.eclipse.ecf.filetransfer.identity.IFileID) IRemoteFileSystemListener(org.eclipse.ecf.filetransfer.IRemoteFileSystemListener) URL(java.net.URL)

Aggregations

IFileID (org.eclipse.ecf.filetransfer.identity.IFileID)20 URL (java.net.URL)10 IFileTransferListener (org.eclipse.ecf.filetransfer.IFileTransferListener)7 File (java.io.File)3 IOException (java.io.IOException)3 FileTransferJob (org.eclipse.ecf.filetransfer.FileTransferJob)3 IIncomingFileTransferReceiveStartEvent (org.eclipse.ecf.filetransfer.events.IIncomingFileTransferReceiveStartEvent)3 MalformedURLException (java.net.MalformedURLException)2 Iterator (java.util.Iterator)2 Map (java.util.Map)2 IConnectContext (org.eclipse.ecf.core.security.IConnectContext)2 Proxy (org.eclipse.ecf.core.util.Proxy)2 IRemoteFile (org.eclipse.ecf.filetransfer.IRemoteFile)2 IRemoteFileAttributes (org.eclipse.ecf.filetransfer.IRemoteFileAttributes)2 IRemoteFileInfo (org.eclipse.ecf.filetransfer.IRemoteFileInfo)2 IFileTransferEvent (org.eclipse.ecf.filetransfer.events.IFileTransferEvent)2 IRemoteFileSystemBrowser (org.eclipse.ecf.filetransfer.service.IRemoteFileSystemBrowser)2 FileOutputStream (java.io.FileOutputStream)1 OutputStream (java.io.OutputStream)1 ConnectException (java.net.ConnectException)1