Class FolderExportContainer
- java.lang.Object
-
- ca.cgjennings.apps.arkham.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
-
-
Constructor Summary
Constructors Constructor Description FolderExportContainer()
-
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()
Returnstrue
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.
-
-
-
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 interfaceExportContainer
- 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 returntrue
if there is nothing for the user to decide.- Specified by:
selectLocation
in interfaceExportContainer
- Parameters:
baseName
- a suggested base name that can be used to compose a file or folder name for the containerlocationHint
- 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, orfalse
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 asFolderExportContainer
andZIPExportContainer
. The method is provided for testing and for use with explicitly created containers.- Specified by:
setLocation
in interfaceExportContainer
- 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 interfaceExportContainer
- 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 callingclose()
on the output stream.- Specified by:
addEntry
in interfaceExportContainer
- 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 interfaceExportContainer
- Parameters:
display
- iftrue
, the user has requested that the container be "displayed"- Throws:
java.io.IOException
- if an I/O exception occurs
-
destroyContainer
public void destroyContainer()
Description copied from interface:ExportContainer
Destroys the current container instead of closing it. This can be called instead ofExportContainer.closeContainer(boolean)
if an I/O error occurs while writing the container. Ideally, it should delete the partially-created container.- Specified by:
destroyContainer
in interfaceExportContainer
-
isConfigurable
public boolean isConfigurable()
Description copied from interface:ExportContainer
Returnstrue
if the container has user-configurable options.- Specified by:
isConfigurable
in interfaceExportContainer
- Returns:
true
if the container can beExportContainer.configure(java.awt.Component)
d
-
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 interfaceExportContainer
- 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 returnstrue
if the file type is definitely supported. It returnsfalse
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 interfaceExportContainer
- 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, andfalse
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 interfaceExportContainer
- Overrides:
toString
in classjava.lang.Object
- Returns:
- a description of the container, such as "ZIP Archive"
-
-