| Author | DaveJarvis <email> |
|---|---|
| Date | 2022-12-17 17:36:42 GMT-0800 |
| Commit | 8d794de1d2a881c4622f43a5934d45bc205d582c |
| Parent | e767901 |
| Delta | 97 lines added, 1 line removed, 96-line increase |
| Main.status.image.request.init=Initializing HTTP request | ||
| -Main.status.image.request.fetch=Requesting content type from ''{0}'' | ||
| +Main.status.image.request.fetch=Downloaded image ''{0}'' | ||
| Main.status.image.request.success=Determined content type ''{0}'' | ||
| Main.status.image.request.error.media=No media type for ''{0}'' |
| +/* Copyright 2022 White Magic Software, Ltd. -- All rights reserved. */ | ||
| +package com.keenwrite.io.downloads.events; | ||
| + | ||
| +import com.keenwrite.events.AppEvent; | ||
| + | ||
| +import java.net.URL; | ||
| +import java.time.Instant; | ||
| + | ||
| +/** | ||
| + * The parent class to all download-related status events. | ||
| + */ | ||
| +public class DownloadEvent implements AppEvent { | ||
| + | ||
| + private final Instant mInstant = Instant.now(); | ||
| + private final URL mUrl; | ||
| + | ||
| + /** | ||
| + * Constructs a new event that tracks the status of downloading a file. | ||
| + * | ||
| + * @param url The {@link URL} that has triggered a download event. | ||
| + */ | ||
| + public DownloadEvent( final URL url ) { | ||
| + mUrl = url; | ||
| + } | ||
| + | ||
| + /** | ||
| + * Returns the download link as an instance of {@link URL}. | ||
| + * | ||
| + * @return The {@link URL} being downloaded. | ||
| + */ | ||
| + public URL getUrl() { | ||
| + return mUrl; | ||
| + } | ||
| + | ||
| + /** | ||
| + * Returns the moment in time that this event was published. | ||
| + * | ||
| + * @return The published date and time. | ||
| + */ | ||
| + public Instant when() { | ||
| + return mInstant; | ||
| + } | ||
| +} | ||
| +/* Copyright 2022 White Magic Software, Ltd. -- All rights reserved. */ | ||
| +package com.keenwrite.io.downloads.events; | ||
| + | ||
| +import java.net.URL; | ||
| + | ||
| +public class DownloadFailedEvent extends DownloadEvent { | ||
| + | ||
| + private final int mResponseCode; | ||
| + | ||
| + /** | ||
| + * Constructs a new event that indicates downloading a file was not | ||
| + * successful. | ||
| + * | ||
| + * @param url The {@link URL} that has triggered a download event. | ||
| + * @param responseCode The HTTP response code associated with the failure. | ||
| + */ | ||
| + public DownloadFailedEvent( final URL url, final int responseCode ) { | ||
| + super( url ); | ||
| + | ||
| + mResponseCode = responseCode; | ||
| + } | ||
| + | ||
| + public static void fire( final URL url, final int responseCode ) { | ||
| + new DownloadFailedEvent( url, responseCode ).publish(); | ||
| + } | ||
| + | ||
| + /** | ||
| + * Returns the HTTP response code for a failed download. | ||
| + * | ||
| + * @return An HTTP response code. | ||
| + */ | ||
| + public int getResponseCode() { | ||
| + return mResponseCode; | ||
| + } | ||
| +} | ||
| +/* Copyright 2022 White Magic Software, Ltd. -- All rights reserved. */ | ||
| +package com.keenwrite.io.downloads.events; | ||
| + | ||
| +import java.net.URL; | ||
| + | ||
| +/** | ||
| + * Collates information about a document that has started downloading. | ||
| + */ | ||
| +public class DownloadStartedEvent extends DownloadEvent { | ||
| + | ||
| + public DownloadStartedEvent( final URL url ) { | ||
| + super( url ); | ||
| + } | ||
| + | ||
| + public static void fire( final URL url ) { | ||
| + new DownloadStartedEvent( url ).publish(); | ||
| + } | ||
| +} | ||