Class FolderExportContainer

  • All Implemented Interfaces:
    ExportContainer

    public class FolderExportContainer
    extends java.lang.Object
    implements ExportContainer
    An export container that writes files to a folder.
    Since:
    3.0
    Author:
    Chris Jennings
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.io.OutputStream addEntry​(java.lang.String name)
      Creates a new file in the container with the given name and returns an output stream for the caller to write the file to.
      void closeContainer​(boolean display)
      Close the current container, allowing a new container to be created.
      void configure​(java.awt.Component locationHint)
      Show a dialog allow the user to configure the container options.
      void createContainer()
      Begins an export operation by creating an empty container.
      void destroyContainer()
      Destroys the current container instead of closing it.
      java.lang.String getIdentifier()
      Returns an identifier unique to this container type.
      boolean isConfigurable()
      Returns true if the container has user-configurable options.
      boolean isFileFormatSupported​(java.lang.String extension)
      Returns a hint as to whether a file format is supported.
      boolean selectLocation​(java.lang.String baseName, java.awt.Component locationHint)
      Displays a dialog that allows the user to select a destination for the container.
      void setLocation​(java.io.File location)
      This method can be used to set an explicit location for the container instead of asking the user to select a location.
      java.lang.String toString()
      Returns a description of the container format, ideally in the user interface locale.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • FolderExportContainer

        public FolderExportContainer()
    • Method Detail

      • getIdentifier

        public java.lang.String getIdentifier()
        Description copied from interface: ExportContainer
        Returns an identifier unique to this container type. It is never shown to the user and must not be localized; it is used to identify the user's preferred container in user settings.
        Specified by:
        getIdentifier in interface ExportContainer
        Returns:
        a unique identifier for the container
      • selectLocation

        public boolean selectLocation​(java.lang.String baseName,
                                      java.awt.Component locationHint)
        Description copied from interface: ExportContainer
        Displays a dialog that allows the user to select a destination for the container. The dialog is not necessarily a file dialog; for example, it might prompt the user to enter account credentials for an online service or enter the address of an FTP server. It is not required to show any dialog at all, and may simply return true if there is nothing for the user to decide.
        Specified by:
        selectLocation in interface ExportContainer
        Parameters:
        baseName - a suggested base name that can be used to compose a file or folder name for the container
        locationHint - an optional component that may be used as a hint to locate any dialogs that must be created
        Returns:
        true if the export should proceed, or false if the user cancels the operation
      • setLocation

        public void setLocation​(java.io.File location)
        Description copied from interface: ExportContainer
        This method can be used to set an explicit location for the container instead of asking the user to select a location. It can only work with containers that write to the local file system, such as FolderExportContainer and ZIPExportContainer. The method is provided for testing and for use with explicitly created containers.
        Specified by:
        setLocation in interface ExportContainer
        Parameters:
        location - the parent folder where the container should be created
      • createContainer

        public void createContainer()
                             throws java.io.IOException
        Description copied from interface: ExportContainer
        Begins an export operation by creating an empty container.
        Specified by:
        createContainer in interface ExportContainer
        Throws:
        java.io.IOException - if an I/O error occurs
      • addEntry

        public java.io.OutputStream addEntry​(java.lang.String name)
                                      throws java.io.IOException
        Description copied from interface: ExportContainer
        Creates a new file in the container with the given name and returns an output stream for the caller to write the file to. After writing the file, you are responsible for calling close() on the output stream.
        Specified by:
        addEntry in interface ExportContainer
        Parameters:
        name - the name of the file to create in the container
        Returns:
        an output stream to which the "file" should be written
        Throws:
        java.io.IOException - if an I/O error occurs
      • closeContainer

        public void closeContainer​(boolean display)
                            throws java.io.IOException
        Description copied from interface: ExportContainer
        Close the current container, allowing a new container to be created.
        Specified by:
        closeContainer in interface ExportContainer
        Parameters:
        display - if true, the user has requested that the container be "displayed"
        Throws:
        java.io.IOException - if an I/O exception occurs
      • configure

        public void configure​(java.awt.Component locationHint)
        Description copied from interface: ExportContainer
        Show a dialog allow the user to configure the container options.
        Specified by:
        configure in interface ExportContainer
        Parameters:
        locationHint - an optional hint as to where to locate the dialog
      • isFileFormatSupported

        public boolean isFileFormatSupported​(java.lang.String extension)
        Description copied from interface: ExportContainer
        Returns a hint as to whether a file format is supported. This method returns true if the file type is definitely supported. It returns false if the file type is not supported, or if the container cannot determine whether the file type is supported.

        A common use of this method is to determine whether a container is compatible with some kind of task being presented to the user. In these cases, implementations that always return false will not be included in the list of container choices presented to the user.

        Some export containers may not support files in some formats: while a ZIP archive can hold any kind of file, an image hosting service might only accept, say, PNG and JPG images. This method allows an export container to return a hint to exporters as to whether a file format is compatible with the container. To use it, the caller passes in a string representing the typical file name extension for files of the format in question.

        Note that the ExportContainer.addEntry(java.lang.String) method is required to accept any content that it is given, but an export container may choose to do anything it wishes with unsupported formats. For example, it may skip the file by returning a dummy output stream. Or it may accept the file but silently convert it into an acceptable format. (The documentation for the container should specify how unsupported files are handled.)

        Specified by:
        isFileFormatSupported in interface ExportContainer
        Parameters:
        extension - the typical file format extension for the file, such as "png" for PNG images
        Returns:
        true if the file type is definitely supported, and false otherwise
      • toString

        public java.lang.String toString()
        Description copied from interface: ExportContainer
        Returns a description of the container format, ideally in the user interface locale.
        Specified by:
        toString in interface ExportContainer
        Overrides:
        toString in class java.lang.Object
        Returns:
        a description of the container, such as "ZIP Archive"