net.sf.dictccfe.and
Class IdxLoader

java.lang.Object
  extended by net.sf.dictccfe.and.Thr
      extended by net.sf.dictccfe.and.IdxLoader
All Implemented Interfaces:
java.lang.Runnable

public final class IdxLoader
extends Thr

Creates a dictionary index database. Creates an SQLite database from an index file in format for the C# version of dictccfe. Expected format of the index file:

From this index file the index loader creates the following SQLite database:

Version:
$Revision$
Author:
Damiel Stoinski

Nested Class Summary
private static class IdxLoader.DictDbFnFilter
          Filename filter for index database files.
private static class IdxLoader.DictIdxFnFilter
          Filename filter for dictionary index files.
 class IdxLoader.WrngIdxFileException
          Exception for a wrong index file format.
 
Field Summary
private static java.lang.String[] CREATE_SQLS
          SQL strings executed prior to inserting data into the table.
private static java.lang.String DB_SUFF
          File extension for database files.
static java.io.File DICT_DIR
          Directory where the files reside.
private static IdxLoader.DictDbFnFilter DICTDBFNFILTER
          Filename filter for index database files.
private static IdxLoader.DictIdxFnFilter DICTIDXFNFILTER
          Filename filter for dictionary index files.
private static java.lang.String IDX_SUFF
          File extension for dictionary index files.
private static java.lang.String[] INSERT_SQLS
          Insert statements.
private  java.io.File m_dbfile
          The name of the database file created.
private  java.io.File m_idxfile
          The name of the index file to import.
private  IProgress m_progress
          For showing the progress of the import process.
private static int NUMINSTRANS
          Number of inserts pro transaction.
 
Constructor Summary
IdxLoader(java.lang.CharSequence aDictionaryName, IProgress aProgress)
          Initializes the object for a creation of an index database for the given dictionary name.
 
Method Summary
private static boolean assureDir(java.io.File aFileName)
          Assures that parent directories for the given file will be created.
static java.lang.String[] getAvailableDictionaries()
          Returns a list of dictionary index files.
static java.lang.String getCharSet(int aDictType)
          Returns the character set name for the given dictionary type.
private  java.io.File getDbFile()
          Returns the name of the resulting database file.
private static java.io.File getDbFile(java.lang.CharSequence aDictName)
          Returns the name of the database file for the given dictionary name.
private static java.io.File getIdxFile(java.lang.CharSequence aDictName)
          Returns the name of the dictionary index file for the given dictionary name.
static java.lang.String[] getLoadedDictionaries()
          Returns a list of dictionary index databases.
static android.database.sqlite.SQLiteDatabase opendb(java.lang.CharSequence aDictionaryName)
          Opens a dictionary index database for the given dictionary name.
private static int readInt(java.io.InputStream aStream, byte[] aBuf)
          Reads an integer number from the given stream.
private static short readShort(java.io.InputStream aStream, byte[] aBuf)
          Reads a short integer number from the gven stream.
 void run()
          Does the whole import job.
 
Methods inherited from class net.sf.dictccfe.and.Thr
getGoon, start, stop
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DICT_DIR

public static final java.io.File DICT_DIR
Directory where the files reside. Directory for the dictionary, index and database files.


NUMINSTRANS

private static final int NUMINSTRANS
Number of inserts pro transaction.

See Also:
Constant Field Values

CREATE_SQLS

private static final java.lang.String[] CREATE_SQLS
SQL strings executed prior to inserting data into the table. Usually drops all tables and creates new ones.


INSERT_SQLS

private static final java.lang.String[] INSERT_SQLS
Insert statements. Prepared statements for inserting data into the following tables:
  1. config
  2. keys
  3. refs


IDX_SUFF

private static final java.lang.String IDX_SUFF
File extension for dictionary index files.

See Also:
Constant Field Values

DB_SUFF

private static final java.lang.String DB_SUFF
File extension for database files.

See Also:
Constant Field Values

DICTIDXFNFILTER

private static final IdxLoader.DictIdxFnFilter DICTIDXFNFILTER
Filename filter for dictionary index files.


DICTDBFNFILTER

private static final IdxLoader.DictDbFnFilter DICTDBFNFILTER
Filename filter for index database files.


m_idxfile

private final java.io.File m_idxfile
The name of the index file to import.


m_dbfile

private final java.io.File m_dbfile
The name of the database file created.


m_progress

private final IProgress m_progress
For showing the progress of the import process.

Constructor Detail

IdxLoader

public IdxLoader(java.lang.CharSequence aDictionaryName,
                 IProgress aProgress)
Initializes the object for a creation of an index database for the given dictionary name.

Parameters:
aDictionaryName - the dictionary name. The dictionary index file is expected in the place pointed by getIdxFile(). The database file will be created in the file pointed by getDbFile().
aProgress - for showing the progress of the import process.
Method Detail

getIdxFile

private static java.io.File getIdxFile(java.lang.CharSequence aDictName)
Returns the name of the dictionary index file for the given dictionary name.

Parameters:
aDictName - the dictionary name.
Returns:
the full path to the dictionary index file.

getDbFile

private static java.io.File getDbFile(java.lang.CharSequence aDictName)
Returns the name of the database file for the given dictionary name.

Parameters:
aDictName - the dictionary name.
Returns:
the full path to the database file.

opendb

public static android.database.sqlite.SQLiteDatabase opendb(java.lang.CharSequence aDictionaryName)
Opens a dictionary index database for the given dictionary name. In fact it opens a dictionary index database file with the name resulting from getDbFile(). The database is opened only for reading.

Parameters:
aDictionaryName - the name of the dictionary.
Returns:
the database object for the given dictionary file or null on error.

getCharSet

public static java.lang.String getCharSet(int aDictType)
Returns the character set name for the given dictionary type.

Parameters:
aDictType - the dictionary type, 0 for DICTCC, 1 for UDDL, 2 for thesaurus files.
Returns:
ISO-8859-1 for DICTCC, UTF-8 for UDDL and ISO-8859-2 for thesaurus. Else it returns UTF-8.

assureDir

private static boolean assureDir(java.io.File aFileName)
Assures that parent directories for the given file will be created.

Parameters:
aFileName - the name of the file.
Returns:
true if the parent directory exists or could be created.

getLoadedDictionaries

public static java.lang.String[] getLoadedDictionaries()
Returns a list of dictionary index databases.

Returns:
array of dictionary index databases.

getAvailableDictionaries

public static java.lang.String[] getAvailableDictionaries()
Returns a list of dictionary index files.

Returns:
array of dictionary index files.

readShort

private static short readShort(java.io.InputStream aStream,
                               byte[] aBuf)
                        throws java.io.IOException
Reads a short integer number from the gven stream. As written by the C# application dictccfe.
  1. low byte of the resulting word
  2. high byte of the resulting word

Parameters:
aStream - the stream to read from.
aBuf - help buffer for reading bytes, at least 2 bytes.
Returns:
the resulting short integer number or -1 if there is no more information to read, eof.
Throws:
java.io.IOException - exceptiona read errors.

readInt

private static int readInt(java.io.InputStream aStream,
                           byte[] aBuf)
                    throws java.io.IOException
Reads an integer number from the given stream. As written by the C# application dictccfe.
  1. low byte of the low word
  2. high byte of the low word
  3. low byte of the high word
  4. high byte of the high word

Parameters:
aStream - the stream to read from
aBuf - help buffer for reading bytes, at least 4 bytes.
Returns:
the resulting integer number or -1 if there is no more information to read, eof.
Throws:
java.io.IOException - exceptiona read errors.

getDbFile

private final java.io.File getDbFile()
Returns the name of the resulting database file.

Returns:
the name of the resulting database file.

run

public final void run()
Does the whole import job. Use rather start() in order to execute the import in the background.

Specified by:
run in interface java.lang.Runnable
Specified by:
run in class Thr