Search in sources :

Example 1 with NSMutableArray

use of ch.cyberduck.binding.foundation.NSMutableArray in project cyberduck by iterate-ch.

the class PlistSerializer method setStringListForKey.

@Override
public void setStringListForKey(final Collection<String> value, final String key) {
    final NSMutableArray list = NSMutableArray.array();
    for (String serializable : value) {
        list.addObject(serializable);
    }
    dict.setObjectForKey(list, key);
}
Also used : NSMutableArray(ch.cyberduck.binding.foundation.NSMutableArray)

Example 2 with NSMutableArray

use of ch.cyberduck.binding.foundation.NSMutableArray in project cyberduck by iterate-ch.

the class KeychainCertificateStore method toDEREncodedCertificates.

public static NSArray toDEREncodedCertificates(final List<X509Certificate> certificates) {
    // Prepare the certificate chain
    try {
        final Object[] encoded = new DEREncoder().encode(certificates);
    } catch (CertificateException e) {
        log.error(String.format("Failure %s DER encoding certificates %s", e, certificates));
        return NSArray.array();
    }
    final NSMutableArray certs = NSMutableArray.arrayWithCapacity(new NSUInteger(certificates.size()));
    for (X509Certificate certificate : certificates) {
        try {
            final SecCertificateRef certificateRef = SecurityFunctions.library.SecCertificateCreateWithData(null, NSData.dataWithBase64EncodedString(Base64.encodeBase64String(certificate.getEncoded())));
            if (null == certificateRef) {
                log.error(String.format("Error creating converting from ASN.1 DER encoded certificate %s", certificate));
                continue;
            }
            certs.addObject(certificateRef);
        } catch (CertificateEncodingException e) {
            log.error(String.format("Failure %s retrieving encoded  certificate", e));
        }
    }
    return certs;
}
Also used : DEREncoder(ch.cyberduck.core.ssl.DEREncoder) NSMutableArray(ch.cyberduck.binding.foundation.NSMutableArray) CertificateException(java.security.cert.CertificateException) CertificateEncodingException(java.security.cert.CertificateEncodingException) NSUInteger(org.rococoa.cocoa.foundation.NSUInteger) X509Certificate(java.security.cert.X509Certificate) SecCertificateRef(ch.cyberduck.core.keychain.SecCertificateRef)

Example 3 with NSMutableArray

use of ch.cyberduck.binding.foundation.NSMutableArray in project cyberduck by iterate-ch.

the class BrowserController method securityLabelClicked.

@Action
public void securityLabelClicked(final ID sender) {
    final List<X509Certificate> certificates = Arrays.asList(pool.getFeature(X509TrustManager.class).getAcceptedIssuers());
    if (certificates.isEmpty()) {
        return;
    }
    try {
        final NSMutableArray certs = NSMutableArray.arrayWithCapacity(new NSUInteger(certificates.size()));
        for (X509Certificate certificate : certificates) {
            certs.addObject(SecurityFunctions.library.SecCertificateCreateWithData(null, NSData.dataWithBase64EncodedString(Base64.encodeBase64String(certificate.getEncoded()))));
        }
        final SFCertificatePanel panel = SFCertificatePanel.sharedCertificatePanel();
        panel.setShowsHelp(false);
        // Implementation of this delegate method is optional
        panel.beginSheetForWindow_modalDelegate_didEndSelector_contextInfo_certificates_showGroup(this.window, this.id(), Foundation.selector("certificateSheetDidEnd:returnCode:contextInfo:"), null, certs, true);
    } catch (CertificateException e) {
        log.warn(String.format("Failure decoding certificate %s", e.getMessage()));
    }
}
Also used : SFCertificatePanel(ch.cyberduck.core.keychain.SFCertificatePanel) NSMutableArray(ch.cyberduck.binding.foundation.NSMutableArray) CertificateException(java.security.cert.CertificateException) NSUInteger(org.rococoa.cocoa.foundation.NSUInteger) X509Certificate(java.security.cert.X509Certificate) WindowMainAction(ch.cyberduck.core.threading.WindowMainAction) BackgroundAction(ch.cyberduck.core.threading.BackgroundAction) DisconnectBackgroundAction(ch.cyberduck.core.threading.DisconnectBackgroundAction) TransferAction(ch.cyberduck.core.transfer.TransferAction) Action(ch.cyberduck.binding.Action) DefaultMainAction(ch.cyberduck.core.threading.DefaultMainAction) WorkerBackgroundAction(ch.cyberduck.core.threading.WorkerBackgroundAction) BrowserTransferBackgroundAction(ch.cyberduck.core.threading.BrowserTransferBackgroundAction)

Example 4 with NSMutableArray

use of ch.cyberduck.binding.foundation.NSMutableArray in project cyberduck by iterate-ch.

the class BookmarkTableDataSource method namesOfPromisedFilesDroppedAtDestination.

/**
 * @return the names (not full paths) of the files that the receiver promises to create at dropDestination. This
 * method is invoked when the drop has been accepted by the destination and the destination, in the case of another
 * Cocoa application, invokes the NSDraggingInfo method namesOfPromisedFilesDroppedAtDestination. For long
 * operations, you can cache dropDestination and defer the creation of the files until the finishedDraggingImage
 * method to avoid blocking the destination application.
 * @see NSTableView.DataSource
 */
@Override
public NSArray namesOfPromisedFilesDroppedAtDestination(final NSURL dropDestination) {
    if (log.isDebugEnabled()) {
        log.debug(String.format("Query promised files dropped dat destination %s", dropDestination.path()));
    }
    final NSMutableArray promisedDragNames = NSMutableArray.array();
    if (null != dropDestination) {
        for (Host bookmark : pasteboard) {
            final Local file = LocalFactory.get(dropDestination.path(), String.format("%s.duck", StringUtils.replace(BookmarkNameProvider.toString(bookmark), "/", ":")));
            try {
                HostWriterFactory.get().write(bookmark, file);
            } catch (AccessDeniedException e) {
                log.warn(e.getMessage());
            }
            // Adding the filename that is promised to be created at the dropDestination
            promisedDragNames.addObject(file.getName());
        }
        pasteboard.clear();
    }
    return promisedDragNames;
}
Also used : AccessDeniedException(ch.cyberduck.core.exception.AccessDeniedException) NSMutableArray(ch.cyberduck.binding.foundation.NSMutableArray)

Example 5 with NSMutableArray

use of ch.cyberduck.binding.foundation.NSMutableArray in project cyberduck by iterate-ch.

the class BrowserTableDataSource method namesOfPromisedFilesDroppedAtDestination.

/**
 * @return the names (not full paths) of the files that the receiver promises to create at dropDestination. This
 * method is invoked when the drop has been accepted by the destination and the destination, in the case of another
 * Cocoa application, invokes the NSDraggingInfo method namesOfPromisedFilesDroppedAtDestination. For long
 * operations, you can cache dropDestination and defer the creation of the files until the finishedDraggingImage
 * method to avoid blocking the destination application.
 */
@Override
public NSArray namesOfPromisedFilesDroppedAtDestination(final NSURL url) {
    if (log.isDebugEnabled()) {
        log.debug(String.format("Return names of promised files dropped at %s", url));
    }
    NSMutableArray promisedDragNames = NSMutableArray.array();
    if (null != url) {
        final Local destination = LocalFactory.get(url.path());
        final DownloadFilterOptions options = new DownloadFilterOptions(controller.getSession().getHost());
        if (destination.isChild(new TemporarySupportDirectoryFinder().find())) {
            options.icon = false;
            options.segments = false;
        }
        final PathPasteboard pasteboard = controller.getPasteboard();
        final List<TransferItem> downloads = new ArrayList<TransferItem>();
        for (Path p : pasteboard) {
            downloads.add(new TransferItem(p, LocalFactory.get(destination, p.getName())));
            // Add to returned path names
            promisedDragNames.addObject(p.getName());
        }
        if (downloads.size() == 1) {
            if (downloads.iterator().next().remote.isFile()) {
                final Local file = downloads.iterator().next().local;
                if (!file.exists()) {
                    try {
                        LocalTouchFactory.get().touch(file);
                        if (options.icon) {
                            IconServiceFactory.get().set(file, new TransferStatus().withLength(0L));
                        }
                    } catch (AccessDeniedException e) {
                        log.warn(String.format("Failure creating file %s %s", file, e.getMessage()));
                    }
                }
            }
            if (downloads.iterator().next().remote.isDirectory()) {
                final Local file = downloads.iterator().next().local;
                if (!file.exists()) {
                    try {
                        new DefaultLocalDirectoryFeature().mkdir(file);
                    } catch (AccessDeniedException e) {
                        log.warn(e.getMessage());
                    }
                }
            }
        }
        // kTemporaryFolderType
        final boolean dock = destination.equals(LocalFactory.get("~/Library/Caches/TemporaryItems"));
        if (dock) {
            for (Path p : pasteboard) {
                // Drag to application icon in dock.
                controller.edit(p);
            }
        } else {
            final Transfer transfer = new DownloadTransfer(controller.getSession().getHost(), downloads).withOptions(options);
            controller.transfer(transfer, Collections.emptyList());
        }
        pasteboard.clear();
    }
    // Filenames
    return promisedDragNames;
}
Also used : Path(ch.cyberduck.core.Path) AccessDeniedException(ch.cyberduck.core.exception.AccessDeniedException) DownloadFilterOptions(ch.cyberduck.core.transfer.download.DownloadFilterOptions) ArrayList(java.util.ArrayList) Local(ch.cyberduck.core.Local) PathPasteboard(ch.cyberduck.core.pasteboard.PathPasteboard) DownloadTransfer(ch.cyberduck.core.transfer.DownloadTransfer) NSMutableArray(ch.cyberduck.binding.foundation.NSMutableArray) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) DefaultLocalDirectoryFeature(ch.cyberduck.core.local.DefaultLocalDirectoryFeature) CopyTransfer(ch.cyberduck.core.transfer.CopyTransfer) UploadTransfer(ch.cyberduck.core.transfer.UploadTransfer) DownloadTransfer(ch.cyberduck.core.transfer.DownloadTransfer) Transfer(ch.cyberduck.core.transfer.Transfer) TransferItem(ch.cyberduck.core.transfer.TransferItem) TemporarySupportDirectoryFinder(ch.cyberduck.core.preferences.TemporarySupportDirectoryFinder)

Aggregations

NSMutableArray (ch.cyberduck.binding.foundation.NSMutableArray)6 AccessDeniedException (ch.cyberduck.core.exception.AccessDeniedException)2 CertificateException (java.security.cert.CertificateException)2 X509Certificate (java.security.cert.X509Certificate)2 NSUInteger (org.rococoa.cocoa.foundation.NSUInteger)2 Action (ch.cyberduck.binding.Action)1 Local (ch.cyberduck.core.Local)1 Path (ch.cyberduck.core.Path)1 Serializable (ch.cyberduck.core.Serializable)1 SFCertificatePanel (ch.cyberduck.core.keychain.SFCertificatePanel)1 SecCertificateRef (ch.cyberduck.core.keychain.SecCertificateRef)1 DefaultLocalDirectoryFeature (ch.cyberduck.core.local.DefaultLocalDirectoryFeature)1 PathPasteboard (ch.cyberduck.core.pasteboard.PathPasteboard)1 TemporarySupportDirectoryFinder (ch.cyberduck.core.preferences.TemporarySupportDirectoryFinder)1 DEREncoder (ch.cyberduck.core.ssl.DEREncoder)1 BackgroundAction (ch.cyberduck.core.threading.BackgroundAction)1 BrowserTransferBackgroundAction (ch.cyberduck.core.threading.BrowserTransferBackgroundAction)1 DefaultMainAction (ch.cyberduck.core.threading.DefaultMainAction)1 DisconnectBackgroundAction (ch.cyberduck.core.threading.DisconnectBackgroundAction)1 WindowMainAction (ch.cyberduck.core.threading.WindowMainAction)1