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);
}
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;
}
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()));
}
}
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;
}
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;
}
Aggregations