public abstract class DocumentFileImporter extends Object
GeneiousPlugin.getDocumentFileImporters().
PluginDocument, it may be desirable to have a constructor that takes a file, and constructs the document from it, e.g. callback.add(new SomethingDocument(file));DocumentFileExporter.
new DocumentFileImporter(){
public String[] getPermissibleExtensions(){
return new String[] {".txt"};
}
public String getFileTypeDescription(){
return "sequence txt file";
}
//this method returns an DocumentFileImporter.AutoDetectStatus showing whether it can import the file.
//REJECT_FILE means that the importer will definately not import the file, ACCEPT_FILE means that it definately will, and MAYBE means that we're not sure yet.
public AutoDetectStatus tentativeAutoDetect(File f, String fileContentsStart){
//if the beginning of the file contains a character that is not a valid protein character, reject the file
for(int i=0; i < fileContentsStart.length(); i++){
char c = fileContentsStart.charAt(i);
if (AminoAcids.getState(c) == null && c != '\n'){
return AutoDetectStatus.REJECT_FILE;
}
}
//otherwise we are unsure.
return AutoDetectStatus.MAYBE;
}
//When importing documents, the documents are added to an DocumentFileImporter.ImportCallback
//instead of the importer returning them in a list or directly adding them to a repository.
//The callback adds the documents to the local repository while the file is still being read.
public void importDocuments(File f, ImportCallback callback, ProgressListener progress) throws DocumentImportException, IOException{
try{
//First we need to create a reader from the file that Geneious gives us.
BufferedReader br = new BufferedReader(new FileReader(f));
//we'll use these two numbers to calculate the progress.
long fileSize = f.length();
long count = 0;
//give the ProgressListener a descriptive message
progress.setMessage("Importing sequence data");
//we need to loop through all lines in the file, and create a sequence from each file
String residues = "";
//We need to check whether the user has pressed cancel on the ProgressListener, and stop reading the file if they have.
while((residues = br.readLine()) != null && !progress.isCanceled()){
progress.setProgress(((double)count)/fileSize);
try{
//create a new sequence from the line
DefaultAminoAcidSequence seq = new DefaultAminoAcidSequence("New Sequence", "",residues,new Date(f.lastModified()));
//increase the count for the ProgressListener
count += residues.length();
//add the document to the callback
callback.addDocument(seq);
}
catch(IllegalArgumentException ex){
//the document was invalid, so we won't add it.
//in a more robust implementation we would do something here...
}
}
//housekeeping...
br.close();
}
catch(FileNotFoundException ex){
throw new DocumentImportException("File not found: "+ f.getName(),ex);
}
}
}| Modifier and Type | Class and Description |
|---|---|
static class |
DocumentFileImporter.AutoDetectStatus
Possible results of file type auto detection.
|
static class |
DocumentFileImporter.ImportCallback |
| Constructor and Description |
|---|
DocumentFileImporter() |
| Modifier and Type | Method and Description |
|---|---|
boolean |
arePermissibleExtensionsCaseSensitive()
Specifies whether the extensions returned by getPermissibleExtensions() should be regarded
case sensitive.
|
abstract String |
getFileTypeDescription() |
double |
getFractionOfTimeToSaveResults()
Returns an approximate fraction of the total operation time which will probably be required to save the imported document(s).
|
Options |
getOptions(List<File> filesToImport,
ProgressListener progressListener)
Provides some options applicable to this importer to the user.
|
abstract String[] |
getPermissibleExtensions()
Standard file name extensions for this document type.
|
File |
getPrimaryFileForMultipleFileImporter(List<File> files)
Determines if this importer supports importing from a list of multiple files.
|
String |
getUniqueId()
Get a unique identifier for this DocumentFileImporter.
|
abstract void |
importDocuments(File file,
DocumentFileImporter.ImportCallback callback,
ProgressListener progressListener)
Import document(s) from file into a callback
|
void |
importDocuments(Options options,
File file,
DocumentFileImporter.ImportCallback callback,
ProgressListener progressListener)
Import document(s) from file into a callback.
|
void |
importDocumentsFromMultipleFiles(List<File> filesToImport,
DocumentFileImporter.ImportCallback callback,
ProgressListener progressListener)
|
List<File> |
importDocumentsFromMultipleFilesReturningUnimported(Options options,
List<File> filesToImport,
DocumentFileImporter.ImportCallback callback,
ProgressListener progressListener)
An alternative to
importDocuments(java.io.File, com.biomatters.geneious.publicapi.plugin.DocumentFileImporter.ImportCallback, jebl.util.ProgressListener) that
importers which import multiple files may implement. |
boolean |
isProOnly()
Deprecated.
Importers and exporters should not be restricted, all though this method still functions.
|
boolean |
supportsCompression(CompressionUtilities.CompressionMethod method)
Returns true if this DocumentFileImporter is able to handle a specified type of compression.
|
abstract DocumentFileImporter.AutoDetectStatus |
tentativeAutoDetect(File file,
String fileContentsStart)
Attempts to detect whether a file is of the right type for this importer,
based purely on the first up to 512 (this number may change in the
future) characters of the file.
|
public abstract String[] getPermissibleExtensions()
new String[] { ".txt", ".xml" }
By default, these extensions are case insensitive, i.e. the
filename filter would also allow extensions like ".tXt", ".TXT" etc.
If you want case sensitive behaviour, you should override
arePermissibleExtensionsCaseSensitive().public abstract String getFileTypeDescription()
public abstract DocumentFileImporter.AutoDetectStatus tentativeAutoDetect(File file, String fileContentsStart)
file - to checkfileContentsStart - first characters (say up to 512 chars) in file.public Options getOptions(List<File> filesToImport, ProgressListener progressListener) throws DocumentImportException
importDocuments(java.io.File, com.biomatters.geneious.publicapi.plugin.DocumentFileImporter.ImportCallback, jebl.util.ProgressListener) or importDocumentsFromMultipleFilesReturningUnimported(com.biomatters.geneious.publicapi.plugin.Options, java.util.List<java.io.File>, com.biomatters.geneious.publicapi.plugin.DocumentFileImporter.ImportCallback, jebl.util.ProgressListener) will not be called
The same Options object will be passed to performOperation if the user clicks "Ok". The necessary values
can then be extracted from it.filesToImport - files we are importing. This will include all the files being imported, if this importer overrides getPrimaryFileForMultipleFileImporter(java.util.List<java.io.File>),
or all the files being imported which will use this importer, if it does not. An importer that provides Options should also handle an empty list of files in order to provide general options which will work on any filesprogressListener - for reporting progress while creating the options and allowing creation to be cancelled.DocumentImportException - if the options can't be generatedpublic abstract void importDocuments(File file, DocumentFileImporter.ImportCallback callback, ProgressListener progressListener) throws IOException, DocumentImportException
file - to import from.callback - use callback.add () for each document importedprogressListener - call setProgress or similar to report progress for the import.
This may be ignored but is not recommended if the import may
take more than a second or so.IOException - when unable to read the full contents of the file for any reasonDocumentImportException - when unable to generate document(s) from contents of file.public void importDocuments(Options options, File file, DocumentFileImporter.ImportCallback callback, ProgressListener progressListener) throws IOException, DocumentImportException
getOptions(java.util.List, jebl.util.ProgressListener)
it should override this to receive the options as input. The default implementation calls
importDocuments(java.io.File, com.biomatters.geneious.publicapi.plugin.DocumentFileImporter.ImportCallback, jebl.util.ProgressListener).file - to import from.options - options to use for import (from getOptions(java.util.List, jebl.util.ProgressListener) or null for no optionscallback - use callback.add () for each document importedprogressListener - call setProgress or similar to report progress for the import.
This may be ignored but is not recommended if the import may
take more than a second or so.IOException - when unable to read the full contents of the file for any reasonDocumentImportException - when unable to generate document(s) from contents of file.public File getPrimaryFileForMultipleFileImporter(List<File> files)
importDocumentsFromMultipleFilesReturningUnimported(Options options, java.util.List, com.biomatters.geneious.publicapi.plugin.DocumentFileImporter.ImportCallback, jebl.util.ProgressListener)}.files - all the files to be imported.public void importDocumentsFromMultipleFiles(List<File> filesToImport, DocumentFileImporter.ImportCallback callback, ProgressListener progressListener) throws IOException, DocumentImportException
importDocumentsFromMultipleFilesReturningUnimported(Options, java.util.List, com.biomatters.geneious.publicapi.plugin.DocumentFileImporter.ImportCallback, jebl.util.ProgressListener) insteadimportDocuments(java.io.File, com.biomatters.geneious.publicapi.plugin.DocumentFileImporter.ImportCallback, jebl.util.ProgressListener) that
importers which import multiple files may implement. An implementation must also implement getPrimaryFileForMultipleFileImporter(java.util.List).
The default implementation of this method throws an UnsupportedOperationExceptionfilesToImport - the files to importcallback - use callback.add () for each document importedprogressListener - call setProgress or similar to report progress for the import.
This may be ignored but is not recommended if the import may
take more than a second or so.IOException - when unable to read the full contents of the files for any reasonDocumentImportException - when unable to generate document(s) from contents of files.public List<File> importDocumentsFromMultipleFilesReturningUnimported(Options options, List<File> filesToImport, DocumentFileImporter.ImportCallback callback, ProgressListener progressListener) throws IOException, DocumentImportException
importDocuments(java.io.File, com.biomatters.geneious.publicapi.plugin.DocumentFileImporter.ImportCallback, jebl.util.ProgressListener) that
importers which import multiple files may implement. An implementation must also implement getPrimaryFileForMultipleFileImporter(java.util.List).
The default implementation of this method throws an UnsupportedOperationExceptionoptions - options to use for import from getOptions(java.util.List, jebl.util.ProgressListener). If null is passed in the importer must proceed with reasonable default settings. The default implementation of this method does not pass on the options.filesToImport - the files to importcallback - use callback.add () for each document importedprogressListener - call setProgress or similar to report progress for the import.
This may be ignored but is not recommended if the import may
take more than a second or so.IOException - when unable to read the full contents of the files for any reasonDocumentImportException - when unable to generate document(s) from contents of files.public boolean arePermissibleExtensionsCaseSensitive()
@Deprecated public boolean isProOnly()
public String getUniqueId()
PluginUtilities.getDocumentFileImporter(String)
can be used to find this DocumentFileImporter.
A unique identifier may consist of any valid Java indentifier characters (see Character.isJavaIdentifierPart(char) as well as to the space character.public double getFractionOfTimeToSaveResults()
importDocuments
and related methods will take the progress bar up to 50% and then Geneious will fill in the remaining 50% as the documents is saved to the user's local database.public boolean supportsCompression(CompressionUtilities.CompressionMethod method)
CompressionUtilities. If an importer
returns false then Geneious will decompress the file before passing it to the importer.
A DocumentFileImporter should return true if it wishes to handle the compressed file itself. For example if
files are typically large and the importer makes use of streams to avoid using the extra disk space
required to decompress the file.
Note: If an importer returns true then it may find methods in
CompressionUtilities helpful.method - The compression method