Mp3dings 
20100427

net.sourceforge.mp3dings.export
Class AbstractExporter

java.lang.Object
  extended by net.sourceforge.mp3dings.export.AbstractExporter
All Implemented Interfaces:
Serializable, Exporter
Direct Known Subclasses:
CSVExporter, M3uExporter, PLSExporter, SansaPLAExporter, WinampXMLPlaylistExporter

public abstract class AbstractExporter
extends Object
implements Exporter, Serializable

An Exporter that exports a file composed of a header section, a main section with one block per record and a footer section.

Version:
$Revision: 103 $ ($Date: 2007-11-05 12:31:35 +0100 (Mo, 05 Nov 2007) $)
Author:
Moritz Ringler
See Also:
Serialized Form

Constructor Summary
AbstractExporter()
           
 
Method Summary
 int export(Object[] keys, Object[][] data)
          Equivalent to export(field, data, null).
 int export(Object[] keys, Object[][] data, StringBuffer filename)
          Opens a JFileChooser using the file filter returned by getFileFilter() and exports the current data to the selected file.
protected abstract  String getBlock(int blockIndex, Map blockdata)
          Produces a single data entry in the exported file.
 Object[] getBlockKeys()
          Returns the block keys used by this exporter.
 String getExtension()
          Returns the file extension for an exporter's target file type.
 boolean getFileFallback()
          Returns whether the client should try to read data that is not found in the table directly from the mp3 file.
 FileFilter getFileFilter()
          Retrieve the file filter that determines which files can be selected as an export target.
protected abstract  String getFooter(int NumEntries)
          Produces the footer section of the exported file.
 Map getFooterData()
          Returns the current footer data.
 Object[] getFooterKeys()
          Returns the footer keys used by this exporter.
protected abstract  String getHeader()
          Produces the header section of the exported file.
 Map getHeaderData()
          Returns the current header data.
 Object[] getHeaderKeys()
          Returns the header keys used by this exporter.
static String[] getImplementations()
          Returns known instantiable sub-classes with a public no-argument constructor.
 Object[] getKeys()
          Returns all keys used by this exporter in a single array.
abstract  String getName()
          Returns a string description of an exporter's target type.
 int getNumberOfEntries()
          Gets the number of datasets in the last call to export(Object[] fields, Object[][] data)
 boolean setEncoding(String enc)
          Sets the charset that will be used to encode the strings for exporting.
 void setFileFallback(boolean b)
          Sets whether the client should try to read data that is not found in the table directly from the mp3 file.
 void setFooterData(Map fd)
          Sets the footer data that getFooter(int) will use to generate the footer section
 void setHeaderData(Map hd)
          Sets the header data that getHeader() will use to generate the header section.
 void setKeys(Object[] headerKeys, Object[] blockKeys, Object[] footerKeys)
          Sets the keys for a specific implementation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractExporter

public AbstractExporter()
Method Detail

setEncoding

public boolean setEncoding(String enc)
Sets the charset that will be used to encode the strings for exporting. The default is "ISO-8859-1".

Specified by:
setEncoding in interface Exporter
Parameters:
enc - The name of the charset; may be either a canonical name or an alias
See Also:
Exporter.setEncoding(String enc)

getKeys

public Object[] getKeys()
Returns all keys used by this exporter in a single array. The keys will usually be the required Fields.

Specified by:
getKeys in interface Exporter
Returns:
An Object array containing all keys (header, block and footer)
See Also:
Exporter.getKeys(), getHeaderKeys(), getBlockKeys(), getFooterKeys()

setKeys

public void setKeys(Object[] headerKeys,
                    Object[] blockKeys,
                    Object[] footerKeys)
Sets the keys for a specific implementation. Use null for no keys.

Parameters:
headerKeys - the fields for the header
blockKeys - the fields for the main section
footerKeys - the fields for the footer
See Also:
getKeys()

setHeaderData

public void setHeaderData(Map hd)
Sets the header data that getHeader() will use to generate the header section. Changes to the specified Map will result in changes in the exported data.

Parameters:
hd - Map containing the header data. The keys whose values should be populated can be retrieved using getHeaderKeys().

getHeaderData

public Map getHeaderData()
Returns the current header data.

Returns:
the Map passed in by the last call to setHeaderData(Map )

setFooterData

public void setFooterData(Map fd)
Sets the footer data that getFooter(int) will use to generate the footer section

Parameters:
fd - Map containing the footer data. Its keys can be retrieved using getFooterKeys().

getFooterData

public Map getFooterData()
Returns the current footer data.

Returns:
the data passed in by the last call to setFooterData(Map )

getNumberOfEntries

public int getNumberOfEntries()
Gets the number of datasets in the last call to export(Object[] fields, Object[][] data)


getHeaderKeys

public Object[] getHeaderKeys()
Returns the header keys used by this exporter. The keys will usually be the required Fields.

Returns:
An Object array containing all header keys
See Also:
getKeys(), setHeaderData(Map )

getBlockKeys

public Object[] getBlockKeys()
Returns the block keys used by this exporter. The keys will usually be the required Fields.

Returns:
An Object array containing all block keys
See Also:
getKeys()

getFooterKeys

public Object[] getFooterKeys()
Returns the footer keys used by this exporter. The keys will usually be the required Fields.

Returns:
An Object array containing all footer keys
See Also:
getKeys()

export

public int export(Object[] keys,
                  Object[][] data)
           throws ExportException
Equivalent to export(field, data, null).

Specified by:
export in interface Exporter
data - data[i][j] is the value for keys[j] in the ith record
Returns:
the number of records that were successfully exported
Throws:
ExportException
See Also:
export(Object[], Object[][], StringBuffer)

export

public int export(Object[] keys,
                  Object[][] data,
                  StringBuffer filename)
           throws ExportException
Opens a JFileChooser using the file filter returned by getFileFilter() and exports the current data to the selected file. The exported file is composed of
  1. a single return value of getHeader()
  2. one block (getBlock(int, Map)) for each dataset in the data array
  3. a single return value of getFooter(int).

Parameters:
keys - an array containing the fields the data contains.
data - a 2D array of block data. The first index designates the number of the dataset, the second index designates the data field. data[i][j] is the value of field keys[j] for the ith dataset.
filename - name of the file to export to. If null or empty the user will be prompted for a value. A non-null object will hold the finally used filename after a succesfull call, and null after an unsuccessful call.
Returns:
the number of successfully exported rows
Throws:
ExportException

getBlock

protected abstract String getBlock(int blockIndex,
                                   Map blockdata)
Produces a single data entry in the exported file. Overwrite this method to produce formatted output of blockdata.

See Also:
export(Object[] keys, Object[][] data)

getHeader

protected abstract String getHeader()
Produces the header section of the exported file. Overwrite this method to produce formatted output of the data returned by getHeaderData().


getFooter

protected abstract String getFooter(int NumEntries)
Produces the footer section of the exported file. Overwrite this method to produce formatted output of the data returned by getFooterData().


getFileFilter

public FileFilter getFileFilter()
Retrieve the file filter that determines which files can be selected as an export target. The default implementation accepts all files.


getFileFallback

public boolean getFileFallback()
Returns whether the client should try to read data that is not found in the table directly from the mp3 file. Defaults to true.

Specified by:
getFileFallback in interface Exporter
Returns:
whether to read id3 tags as a fallback

setFileFallback

public void setFileFallback(boolean b)
Sets whether the client should try to read data that is not found in the table directly from the mp3 file. Defaults to true.

Parameters:
b - whether to read id3 tags as a fallback

getImplementations

public static String[] getImplementations()
Returns known instantiable sub-classes with a public no-argument constructor.

Returns:
the known instantiable sub-classes

getName

public abstract String getName()
Returns a string description of an exporter's target type.

Specified by:
getName in interface Exporter
Returns:
the name of the target type

getExtension

public String getExtension()
Returns the file extension for an exporter's target file type.

Returns:
a file extension including the leading dot

Mp3dings 
20100427