public String getMediumFormat(long milliseconds) { return this.getMediumFormat(milliseconds, true); }
public String getShortFormat(long milliseconds) { return this.getShortFormat(milliseconds, true); }
public String getLongFormat(long milliseconds) { return this.getLongFormat(milliseconds, true); } }
@Override public void apply(final Path file, final Local local, final TransferStatus status, final ProgressListener listener) throws BackgroundException { if(status.isExists()) { Local rename; do { String proposal = MessageFormat.format(PreferencesFactory.get().getProperty("queue.download.file.rename.format"), FilenameUtils.getBaseName(file.getName()), UserDateFormatterFactory.get().getMediumFormat(System.currentTimeMillis(), false).replace(local.getDelimiter(), '-').replace(':', '-'), StringUtils.isNotBlank(file.getExtension()) ? String.format(".%s", file.getExtension()) : StringUtils.EMPTY); rename = LocalFactory.get(local.getParent().getAbsolute(), proposal); } while(rename.exists()); if(log.isInfoEnabled()) { log.info(String.format("Rename existing file %s to %s", local, rename)); } local.rename(rename); if(log.isDebugEnabled()) { log.debug(String.format("Clear exist flag for file %s", local)); } status.setExists(false); } super.apply(file, local, status, listener); } }
@Override public NSView getAccessoryView(final NSAlert alert) { final NSView view = super.getAccessoryView(alert); String proposal = MessageFormat.format(PreferencesFactory.get().getProperty("browser.duplicate.format"), FilenameUtils.getBaseName(selected.getName()), UserDateFormatterFactory.get().getShortFormat(System.currentTimeMillis(), false).replace(Path.DELIMITER, ':'), StringUtils.isNotBlank(selected.getExtension()) ? String.format(".%s", selected.getExtension()) : StringUtils.EMPTY); this.updateField(inputField, proposal); return view; }
@Override public String getComment(final Host host) { Date timestamp = host.getTimestamp(); if(null != timestamp) { // Set comment to timestamp when server was last accessed return UserDateFormatterFactory.get().getLongFormat(timestamp.getTime()); } // There might be files from previous versions that have no timestamp yet. return null; }
@Override public DescriptiveUrlBag toUrl(final Path file) { final DescriptiveUrlBag list = new DescriptiveUrlBag(); if(file.isFile()) { try { // This link will expire in four hours and afterwards you will get 410 Gone. final String link = new DbxUserFilesRequests(session.getClient()).getTemporaryLink(file.getAbsolute()).getLink(); // Determine expiry time for URL final Calendar expiry = Calendar.getInstance(TimeZone.getTimeZone("UTC")); expiry.add(Calendar.HOUR, 4); list.add(new DescriptiveUrl(URI.create(link), DescriptiveUrl.Type.http, MessageFormat.format(LocaleFactory.localizedString("{0} URL"), LocaleFactory.localizedString("Temporary", "S3")) + " (" + MessageFormat.format(LocaleFactory.localizedString("Expires {0}", "S3") + ")", UserDateFormatterFactory.get().getMediumFormat(expiry.getTimeInMillis())) )); } catch(DbxException e) { log.warn(String.format("Failure retrieving shared link. %s", e.getMessage())); } } return list; } }
MessageFormat.format(LocaleFactory.localizedString("{0} URL"), LocaleFactory.localizedString("Pre-Signed", "S3")) + " (" + MessageFormat.format(LocaleFactory.localizedString("Expires {0}", "S3") + ")", UserDateFormatterFactory.get().getShortFormat(expiry * 1000)) ));
public void setMessage(final String message) { final String text; if(StringUtils.isBlank(message)) { // Do not display any progress text when transfer is stopped final Date timestamp = transfer.getTimestamp(); if(null != timestamp) { text = UserDateFormatterFactory.get().getLongFormat(timestamp.getTime(), false); } else { text = StringUtils.EMPTY; } } else { text = message; } messageField.setAttributedStringValue(NSAttributedString.attributedStringWithAttributes( text, TRUNCATE_MIDDLE_ATTRIBUTES)); }
/** * Rename existing file on server if there is a conflict. */ @Override public void apply(final Path file, final Local local, final TransferStatus status, final ProgressListener listener) throws BackgroundException { // Rename existing file before putting new file in place if(status.isExists()) { Path rename; do { final String proposal = MessageFormat.format(PreferencesFactory.get().getProperty("queue.upload.file.rename.format"), FilenameUtils.getBaseName(file.getName()), UserDateFormatterFactory.get().getMediumFormat(System.currentTimeMillis(), false).replace(Path.DELIMITER, '-').replace(':', '-'), StringUtils.isNotBlank(file.getExtension()) ? String.format(".%s", file.getExtension()) : StringUtils.EMPTY); rename = new Path(file.getParent(), proposal, file.getType()); } while(find.withCache(cache).find(rename)); if(log.isInfoEnabled()) { log.info(String.format("Rename existing file %s to %s", file, rename)); } move.move(file, rename, new TransferStatus().exists(false), new Delete.DisabledCallback(), new DisabledConnectionCallback()); if(log.isDebugEnabled()) { log.debug(String.format("Clear exist flag for file %s", file)); } status.setExists(false); } super.apply(file, local, status, listener); } }
@Override public DescriptiveUrl toUploadUrl(final Path file, final CreateUploadShareRequest options, final PasswordCallback callback) throws BackgroundException { try { final UploadShare share = new SharesApi(session.getClient()).createUploadShare( options.targetId(Long.parseLong(nodeid.getFileid(file, new DisabledListProgressListener()))), StringUtils.EMPTY, null); final String help; if(null == share.getExpireAt()) { help = MessageFormat.format(LocaleFactory.localizedString("{0} URL"), LocaleFactory.localizedString("Pre-Signed", "S3")); } else { final long expiry = share.getExpireAt().getMillis(); help = MessageFormat.format(LocaleFactory.localizedString("{0} URL"), LocaleFactory.localizedString("Pre-Signed", "S3")) + " (" + MessageFormat.format(LocaleFactory.localizedString("Expires {0}", "S3") + ")", UserDateFormatterFactory.get().getShortFormat(expiry * 1000) ); } return new DescriptiveUrl( URI.create(String.format("%s://%s/#/public/shares-uploads/%s", session.getHost().getProtocol().getScheme(), session.getHost().getHostname(), share.getAccessKey()) ), DescriptiveUrl.Type.signed, help); } catch(ApiException e) { throw new SDSExceptionMappingService().map(e); } } }
protected void add(final String fullname, final String hostname, final int port, final String user, final String password, final String path) { final Protocol protocol = this.getProtocol(fullname); if(null == protocol) { log.warn(String.format("Unknown service type for %s", fullname)); return; } final Host host = new Host(protocol, hostname, port); host.getCredentials().setUsername(user); host.getCredentials().setPassword(password); if(StringUtils.isNotBlank(path)) { host.setDefaultPath(PathNormalizer.normalize(path)); } host.setComment(UserDateFormatterFactory.get().getLongFormat(new Date().getTime())); this.add(fullname, host); }
MessageFormat.format(LocaleFactory.localizedString("{0} URL"), LocaleFactory.localizedString("Pre-Signed", "S3")) + " (" + MessageFormat.format(LocaleFactory.localizedString("Expires {0}", "S3") + ")", UserDateFormatterFactory.get().getMediumFormat(System.currentTimeMillis() + expiresIn.toMillis())))); MessageFormat.format(LocaleFactory.localizedString("{0} URL"), LocaleFactory.localizedString("Pre-Signed", "S3")) + " (" + MessageFormat.format(LocaleFactory.localizedString("Expires {0}", "S3") + ")", UserDateFormatterFactory.get().getMediumFormat(System.currentTimeMillis() + expiresIn.toMillis())))); MessageFormat.format(LocaleFactory.localizedString("{0} URL"), LocaleFactory.localizedString("Pre-Signed", "S3")) + " (" + MessageFormat.format(LocaleFactory.localizedString("Expires {0}", "S3") + ")", UserDateFormatterFactory.get().getMediumFormat(System.currentTimeMillis() + expiresIn.toMillis()))));
private DescriptiveUrl createSignedUrl(final Path file, int seconds) { final CloudBlob blob; try { if(!session.isConnected()) { return DescriptiveUrl.EMPTY; } blob = session.getClient().getContainerReference(containerService.getContainer(file).getName()) .getBlobReferenceFromServer(containerService.getKey(file)); } catch(URISyntaxException | StorageException e) { return DescriptiveUrl.EMPTY; } final String token; try { token = blob.generateSharedAccessSignature(this.getPolicy(seconds), null); } catch(InvalidKeyException | StorageException e) { return DescriptiveUrl.EMPTY; } return new DescriptiveUrl(URI.create(String.format("%s://%s%s?%s", Scheme.https.name(), session.getHost().getHostname(), URIEncoder.encode(file.getAbsolute()), token)), DescriptiveUrl.Type.signed, MessageFormat.format(LocaleFactory.localizedString("{0} URL"), LocaleFactory.localizedString("Pre-Signed", "S3")) + " (" + MessageFormat.format(LocaleFactory.localizedString("Expires {0}", "S3") + ")", UserDateFormatterFactory.get().getShortFormat(this.getExpiry(seconds)))); }
this.updateField(modifiedField, UserDateFormatterFactory.get().getLongFormat( file.attributes().getModificationDate()), TRUNCATE_MIDDLE_ATTRIBUTES this.updateField(createdField, UserDateFormatterFactory.get().getLongFormat( file.attributes().getCreationDate()), TRUNCATE_MIDDLE_ATTRIBUTES
@Override public DescriptiveUrl toDownloadUrl(final Path file, final Void none, final PasswordCallback callback) throws BackgroundException { if(file.isFile()) { final String download = String.format("%s/file/%s/%s", session.getClient().getDownloadUrl(), URIEncoder.encode(containerService.getContainer(file).getName()), URIEncoder.encode(containerService.getKey(file))); try { final int seconds = 604800; // Determine expiry time for URL final Calendar expiry = Calendar.getInstance(TimeZone.getTimeZone("UTC")); expiry.add(Calendar.SECOND, seconds); final String token = session.getClient().getDownloadAuthorization(fileid.getFileid(containerService.getContainer(file), new DisabledListProgressListener()), StringUtils.EMPTY, seconds); return new DescriptiveUrl(URI.create(String.format("%s?Authorization=%s", download, token)), DescriptiveUrl.Type.signed, MessageFormat.format(LocaleFactory.localizedString("{0} URL"), LocaleFactory.localizedString("Pre-Signed", "S3")) + " (" + MessageFormat.format(LocaleFactory.localizedString("Expires {0}", "S3") + ")", UserDateFormatterFactory.get().getMediumFormat(expiry.getTimeInMillis())) ); } catch(B2ApiException e) { throw new B2ExceptionMappingService().map(e); } catch(IOException e) { throw new DefaultIOExceptionMappingService().map(e); } } return DescriptiveUrl.EMPTY; }
dateFormatter.getShortFormat(item.attributes().getModificationDate(), preferences.getBoolean("browser.date.natural")), TableCellAttributes.browserFontLeftAlignment()
if(null != timestamp) { title.appendAttributedString(NSAttributedString.attributedStringWithAttributes( UserDateFormatterFactory.get().getLongFormat(timestamp.getTime()), BundleController.MENU_HELP_FONT_ATTRIBUTES));
MessageFormat.format(LocaleFactory.localizedString("{0} URL"), LocaleFactory.localizedString("Pre-Signed", "S3")) + " (" + MessageFormat.format(LocaleFactory.localizedString("Expires {0}", "S3") + ")", UserDateFormatterFactory.get().getMediumFormat(expiry.getTimeInMillis())) );
try { listener.message(MessageFormat.format(LocaleFactory.localizedString("Changing timestamp of {0} to {1}", "Status"), file.getName(), UserDateFormatterFactory.get().getShortFormat(status.getTimestamp()))); feature.setTimestamp(file, status.getTimestamp());