net.datacrow.fileimporters
Class FileImporter

java.lang.Object
  extended by net.datacrow.fileimporters.FileImporter
All Implemented Interfaces:
ISynchronizerClient
Direct Known Subclasses:
EbookImport, ImageImporter, MovieImporter, MusicAlbumImporter, SoftwareImporter

public abstract class FileImporter
extends java.lang.Object
implements ISynchronizerClient

Base for all file importers. A file importer is capable of scanning a specific location for specific file types. These files are parsed and their information is stored in a DcObject.

Author:
Robert Jan van der Waals

Constructor Summary
FileImporter(int module)
          Creates a new instance.
 
Method Summary
 void addMessage(java.lang.String message)
           
protected  void afterImport()
          Called after finishing the whole parsing process.
protected  void afterParse(DcObject dco)
          Called after parsing a single file.
 boolean allowDirectoryRegistration()
          Indicates if a directory can be used instead of a file.
 boolean allowReparsing()
          Indicates if files can be parsed again.
 void beforeParse()
          To be executed before a file is parsed.
 boolean canImportArt()
          Indicates if local art can be used.
 void enableActions(boolean b)
           
 IFileImportClient getClient()
           
 DcObject getContainer()
           
abstract  java.lang.String[] getDefaultSupportedFileTypes()
           
 int getItemPickMode()
           
 int getModule()
          The module to which this importer belongs.
protected  java.lang.String getName(java.lang.String file, int directoryUsage)
          Tries to create a name from the specified file.
 Region getRegion()
           
 SearchMode getSearchMode()
           
 IServer getServer()
           
 java.lang.String[] getSupportedFileTypes()
           
 void initialize()
           
 void initProgressBar(int max)
           
 boolean isCancelled()
           
 boolean isReparseFiles()
           
 void parse(java.util.Collection<java.lang.String> sources)
          Starts the parsing task.
protected  void parse(java.lang.String filename, boolean last)
          Parses a single file.
abstract  DcObject parse(java.lang.String filename, int directoryUsage)
          Parses a file and extracts its information.
 void setClient(IFileImportClient client)
           
protected  void setImages(java.lang.String filename, DcObject dco, int front, int back, int cd)
          Retrieve and use local art.
 void showUI()
          Opens the importer dialog.
 void updateProgressBar()
           
 boolean useOnlineService()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileImporter

public FileImporter(int module)
Creates a new instance.

Parameters:
module - The module to which this importer belongs.
Method Detail

setClient

public void setClient(IFileImportClient client)

getClient

public IFileImportClient getClient()

getModule

public int getModule()
The module to which this importer belongs.


showUI

public void showUI()
Opens the importer dialog.

See Also:
FileImportDialog

parse

public abstract DcObject parse(java.lang.String filename,
                               int directoryUsage)
Parses a file and extracts its information.

Parameters:
filename - The file to check.
directoryUsage - A free interpretation of the directory usage. Depends on a specific implementation.
Throws:
ParseException

getDefaultSupportedFileTypes

public abstract java.lang.String[] getDefaultSupportedFileTypes()

getSupportedFileTypes

public java.lang.String[] getSupportedFileTypes()

allowDirectoryRegistration

public boolean allowDirectoryRegistration()
Indicates if a directory can be used instead of a file.

Returns:
false

allowReparsing

public boolean allowReparsing()
Indicates if files can be parsed again. This useful when you know that the information of the file can be changed (such as the ID tag content of MP3 files).

Returns:
false

canImportArt

public boolean canImportArt()
Indicates if local art can be used.

Returns:
false

beforeParse

public void beforeParse()
To be executed before a file is parsed.


parse

public void parse(java.util.Collection<java.lang.String> sources)
           throws java.lang.Exception
Starts the parsing task.

Parameters:
sources - The files to check.
Throws:
java.lang.Exception

parse

protected void parse(java.lang.String filename,
                     boolean last)
Parses a single file. The process skips already imported files.

Parameters:
listener -
filename -

afterImport

protected void afterImport()
Called after finishing the whole parsing process.


afterParse

protected void afterParse(DcObject dco)
Called after parsing a single file.

Parameters:
listener -
dco -

getName

protected java.lang.String getName(java.lang.String file,
                                   int directoryUsage)
Tries to create a name from the specified file.

Parameters:
file -
directoryUsage - Either 1 (to use directory information) or 0.
Returns:
The name.

setImages

protected void setImages(java.lang.String filename,
                         DcObject dco,
                         int front,
                         int back,
                         int cd)
Retrieve and use local art.

Parameters:
filename - The file location for which art will be retrieved.
dco -
front - The front image field index.
back - The back image field index.
cd - The media image field index.
See Also:
DcRepository.ModuleSettings#stImportLocalArt, DcRepository.ModuleSettings#stImportLocalArtRecurse, DcRepository.ModuleSettings#stImportLocalArtFrontKeywords, DcRepository.ModuleSettings#stImportLocalArtBackKeywords, DcRepository.ModuleSettings#stImportLocalArtMediaKeywords

addMessage

public void addMessage(java.lang.String message)
Specified by:
addMessage in interface ISynchronizerClient

enableActions

public void enableActions(boolean b)
Specified by:
enableActions in interface ISynchronizerClient

getItemPickMode

public int getItemPickMode()
Specified by:
getItemPickMode in interface ISynchronizerClient

getRegion

public Region getRegion()
Specified by:
getRegion in interface ISynchronizerClient

getSearchMode

public SearchMode getSearchMode()
Specified by:
getSearchMode in interface ISynchronizerClient

getContainer

public DcObject getContainer()

getServer

public IServer getServer()
Specified by:
getServer in interface ISynchronizerClient

initialize

public void initialize()
Specified by:
initialize in interface ISynchronizerClient

initProgressBar

public void initProgressBar(int max)
Specified by:
initProgressBar in interface ISynchronizerClient

isCancelled

public boolean isCancelled()
Specified by:
isCancelled in interface ISynchronizerClient

isReparseFiles

public boolean isReparseFiles()
Specified by:
isReparseFiles in interface ISynchronizerClient

updateProgressBar

public void updateProgressBar()
Specified by:
updateProgressBar in interface ISynchronizerClient

useOnlineService

public boolean useOnlineService()
Specified by:
useOnlineService in interface ISynchronizerClient