Package org.zkoss.zul

Class Filedownload

java.lang.Object
org.zkoss.zul.Filedownload

public class Filedownload extends Object
File download utilities.
Author:
tomyeh
See Also:
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    Helper class for specifying media and optional custom filename for multiple file downloads.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    save(byte[] content, String contentType, String flnm)
    Open a download dialog to save the specified content at the client with the suggested file name.
    static void
    save(File file, String contentType)
    Open a download dialog to save the specified file at the client.
    static void
    save(InputStream content, String contentType, String flnm)
    Open a download dialog to save the specified content at the client with the suggested file name.
    Note: You don't need to close the content (a InputStream), it will be closed automatically after download.
    static void
    save(Reader content, String contentType, String flnm)
    Open a download dialog to save the specified content at the client with the suggested file name.
    Note: You don't need to close the content (a Reader), it will be closed automatically after download.
    static void
    save(String path, String contentType)
    Open a download dialog to save the resource of the specified path at the client.
    static void
    save(String content, String contentType, String flnm)
    Open a download dialog to save the specified content at the client with the suggested file name.
    static void
    save(URL url, String contentType)
    Open a download dialog to save the resource of the specified URL at the client.
    static void
    save(org.zkoss.util.media.Media media)
    Open a download dialog to save the specified content at the client.
    static void
    save(org.zkoss.util.media.Media media, String flnm)
    Open a download dialog to save the specified content at the client with the suggested file name.
    static void
    saveAsZip(Map<org.zkoss.util.media.Media,String> mediaMap, String zipFilename)
    Downloads multiple media files with custom names as a single ZIP archive.
    static void
    saveAsZip(org.zkoss.util.media.Media[] medias, String zipFilename)
    Downloads multiple media files as a single ZIP archive.
    static void
    Downloads multiple files using DownloadItem objects as a single ZIP archive.
    static void
    saveMultiple(Map<org.zkoss.util.media.Media,String> mediaMap)
    Downloads multiple media files with custom filenames.
    static void
    saveMultiple(org.zkoss.util.media.Media... medias)
    Downloads multiple media files using their original filenames.
    static void
    Downloads multiple files using DownloadItem objects.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Filedownload

      public Filedownload()
  • Method Details

    • save

      public static void save(org.zkoss.util.media.Media media)
      Open a download dialog to save the specified content at the client.
    • save

      public static void save(org.zkoss.util.media.Media media, String flnm)
      Open a download dialog to save the specified content at the client with the suggested file name.
      Parameters:
      media - the media to download
      flnm - the suggested file name, e.g., myfile.pdf. If null, Media.getName() is assumed.
    • save

      public static void save(byte[] content, String contentType, String flnm)
      Open a download dialog to save the specified content at the client with the suggested file name.
      Parameters:
      content - the content
      contentType - the content type (a.k.a., MIME type), e.g., application/pdf
      flnm - the suggested file name, e.g., myfile.pdf. If null, no suggested name is provided.
    • save

      public static void save(String content, String contentType, String flnm)
      Open a download dialog to save the specified content at the client with the suggested file name.
      Parameters:
      content - the content
      contentType - the content type (a.k.a., MIME type), e.g., application/pdf
      flnm - the suggested file name, e.g., myfile.pdf. If null, no suggested name is provided.
    • save

      public static void save(InputStream content, String contentType, String flnm)
      Open a download dialog to save the specified content at the client with the suggested file name.
      Note: You don't need to close the content (a InputStream), it will be closed automatically after download.
      Parameters:
      content - the content
      contentType - the content type (a.k.a., MIME type), e.g., application/pdf
      flnm - the suggested file name, e.g., myfile.pdf. If null, no suggested name is provided.
    • save

      public static void save(Reader content, String contentType, String flnm)
      Open a download dialog to save the specified content at the client with the suggested file name.
      Note: You don't need to close the content (a Reader), it will be closed automatically after download.
      Parameters:
      content - the content
      contentType - the content type (a.k.a., MIME type), e.g., application/pdf
      flnm - the suggested file name, e.g., myfile.pdf. If null, no suggested name is provided.
    • save

      public static void save(File file, String contentType) throws FileNotFoundException
      Open a download dialog to save the specified file at the client.
      Parameters:
      file - the file to download to the client
      contentType - the content type, e.g., application/pdf. Unlike other save methods, it is optional. If null, the file name's extension is used to determine the content type.
      Throws:
      FileNotFoundException - if the file is not found.
      Since:
      3.0.8
    • save

      public static void save(URL url, String contentType) throws FileNotFoundException
      Open a download dialog to save the resource of the specified URL at the client. The path must be retrievable by use of WebApp.getResource(java.lang.String).
      Parameters:
      url - the URL to get the resource
      contentType - the content type, e.g., application/pdf. Unlike other save methods, it is optional. If null, the path's extension is used to determine the content type.
      Throws:
      FileNotFoundException - if the resource is not found.
      Since:
      3.0.8
    • save

      public static void save(String path, String contentType) throws FileNotFoundException
      Open a download dialog to save the resource of the specified path at the client.
      Parameters:
      path - the path of the resource. It must be retrievable by use of WebApp.getResource(java.lang.String).
      contentType - the content type, e.g., application/pdf. Unlike other save methods, it is optional. If null, the path's extension is used to determine the content type.
      Throws:
      FileNotFoundException - if the resource is not found.
      Since:
      3.0.8
    • saveMultiple

      public static void saveMultiple(org.zkoss.util.media.Media... medias)
      Downloads multiple media files using their original filenames. The files will be downloaded sequentially to avoid browser cancellation issues.
      Parameters:
      medias - the media files to download
      Since:
      10.3.0
    • saveMultiple

      public static void saveMultiple(Map<org.zkoss.util.media.Media,String> mediaMap)
      Downloads multiple media files with custom filenames. The files will be downloaded sequentially to avoid browser cancellation issues.
      Parameters:
      mediaMap - a map of media to filename pairs. If filename is null, the original media name is used.
      Since:
      10.3.0
    • saveMultiple

      public static void saveMultiple(Filedownload.DownloadItem... items)
      Downloads multiple files using DownloadItem objects. The files will be downloaded sequentially to avoid browser cancellation issues.
      Parameters:
      items - the download items containing media and optional custom filenames
      Since:
      10.3.0
    • saveAsZip

      public static void saveAsZip(org.zkoss.util.media.Media[] medias, String zipFilename)
      Downloads multiple media files as a single ZIP archive.
      Parameters:
      medias - the media files to include in the ZIP
      zipFilename - the name of the ZIP file (e.g., "download.zip")
      Since:
      10.3.0
    • saveAsZip

      public static void saveAsZip(Map<org.zkoss.util.media.Media,String> mediaMap, String zipFilename)
      Downloads multiple media files with custom names as a single ZIP archive.
      Parameters:
      mediaMap - a map of media to filename pairs. If filename is null, the original media name is used.
      zipFilename - the name of the ZIP file (e.g., "download.zip")
      Since:
      10.3.0
    • saveAsZip

      public static void saveAsZip(Filedownload.DownloadItem[] items, String zipFilename)
      Downloads multiple files using DownloadItem objects as a single ZIP archive.
      Parameters:
      items - the download items to include in the ZIP
      zipFilename - the name of the ZIP file (e.g., "download.zip")
      Since:
      10.3.0