org.crosswire.jsword.book.sword
Class ConfigEntryTable

java.lang.Object
  extended by org.crosswire.jsword.book.sword.ConfigEntryTable

public final class ConfigEntryTable
extends Object

A utility class for loading the entries in a Sword book's conf file. Since the conf files are manually maintained, there can be all sorts of errors in them. This class does robust checking and reporting.

Config file format. See also: http://sword.sourceforge.net/cgi-bin/twiki/view/Swordapi/ConfFileLayout

The contents of the About field are in rtf.

\ is used as a continuation line.

Author:
Mark Goodwin [mark at thorubio dot org], Joe Walker [joe at eireneh dot com], Jacky Cheung, DM Smith [dmsmith555 at yahoo dot com]
See Also:
for license details. The copyright to this program is held by it's authors.

Field Summary
private static ConfigEntryType[] BASIC_INFO
          These are the elements that JSword requires.
private  BookType bookType
          The BookType for this ConfigEntry
private  File configFile
          If the module's config is tied to a file remember it so that it can be updated.
private static ConfigEntryType[] COPYRIGHT_INFO
           
private static String ENCODING_LATIN1
           
private static String ENCODING_UTF8
          Sword only recognizes two encodings for its modules: UTF-8 and LATIN1 Sword uses MS Windows cp1252 for Latin 1 not the standard.
private static ConfigEntryType[] FEATURE_INFO
           
private static ConfigEntryType[] HIDDEN
           
private  String internal
          The original name of this config file from mods.d.
private static Pattern KEY_VALUE_PATTERN
          Pattern that matches a key=value.
private static ConfigEntryType[] LANG_INFO
           
private static Logger log
          The log stream
private  boolean questionable
          True if this book is considered questionable.
private  String readahead
          A helper for the reading of the conf file.
private  boolean supported
          True if this book's config type can be used by JSword.
private static ConfigEntryType[] SYSTEM_INFO
           
private  Map table
          A map of lists of known config entries.
 
Constructor Summary
ConfigEntryTable(String bookName)
          Create an empty Sword config for the named book.
 
Method Summary
 void add(ConfigEntryType type, String aValue)
          A helper to create/replace a value for a given type.
private  void adjustBookType()
           
private  void adjustDataPath()
           
private  void adjustLanguage()
           
private  void adjustName()
           
private  String advance(BufferedReader bin)
          Get the next line from the input
private  void backup(String oops)
          Read too far ahead and need to return a line.
 BookType getBookType()
          Returns an Enumeration of all the keys found in the config file.
private  void getContinuation(ConfigEntry configEntry, BufferedReader bin, StringBuffer buf)
          Get continuation lines, if any.
 Set getKeys()
          Returns an Enumeration of all the keys found in the config file.
 String getUnlockKey()
          Gets the unlock key for the module.
 Object getValue(ConfigEntryType type)
          Gets a particular ConfigEntry's value by its type
 boolean isEnciphered()
          Determines whether the Sword Book is enciphered.
private  boolean isKeyLine(String line)
          Does this line of text represent a key/value pair?
 boolean isLocked()
          Determines whether the Sword Book is enciphered and without a key.
 boolean isQuestionable()
          Determines whether the Sword Book's conf is supported by JSword.
 boolean isSupported()
          Determines whether the Sword Book's conf is supported by JSword.
 void load(byte[] buffer)
          Load the conf from a buffer.
 void load(File file)
          Load the conf from a file.
private  void loadContents(BufferedReader in)
           
private  void loadInitials(BufferedReader in)
           
 boolean match(ConfigEntryType type, Object search)
          Determine whether this ConfigEntryTable has the ConfigEntry and it matches the value.
private  String report(String issue, String confEntryName, String line)
           
 void save()
           
private  void testLanguage(String initials, Language lang)
           
 String toConf()
          Build's a SWORD conf file as a string.
private  void toConf(StringBuffer buf, ConfigEntryType[] category)
           
 org.jdom.Element toOSIS()
          Sort the keys for a more meaningful presentation order.
private  void toOSIS(OSISUtil.OSISFactory factory, org.jdom.Element ele, String aTitle, ConfigEntryType[] category)
          Build an ordered map so that it displays in a consistent order.
 boolean unlock(String unlockKey)
          Unlocks a book with the given key.
private  void validate()
          Determine which books are not supported.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ENCODING_UTF8

private static final String ENCODING_UTF8
Sword only recognizes two encodings for its modules: UTF-8 and LATIN1 Sword uses MS Windows cp1252 for Latin 1 not the standard. Arrgh!

See Also:
Constant Field Values

ENCODING_LATIN1

private static final String ENCODING_LATIN1
See Also:
Constant Field Values

BASIC_INFO

private static final ConfigEntryType[] BASIC_INFO
These are the elements that JSword requires. They are a superset of those that Sword requires.


LANG_INFO

private static final ConfigEntryType[] LANG_INFO

COPYRIGHT_INFO

private static final ConfigEntryType[] COPYRIGHT_INFO

FEATURE_INFO

private static final ConfigEntryType[] FEATURE_INFO

SYSTEM_INFO

private static final ConfigEntryType[] SYSTEM_INFO

HIDDEN

private static final ConfigEntryType[] HIDDEN

log

private static final Logger log
The log stream


internal

private String internal
The original name of this config file from mods.d. This is only used for managing warnings and errors


table

private Map table
A map of lists of known config entries.


bookType

private BookType bookType
The BookType for this ConfigEntry


supported

private boolean supported
True if this book's config type can be used by JSword.


questionable

private boolean questionable
True if this book is considered questionable.


readahead

private String readahead
A helper for the reading of the conf file.


configFile

private File configFile
If the module's config is tied to a file remember it so that it can be updated.


KEY_VALUE_PATTERN

private static final Pattern KEY_VALUE_PATTERN
Pattern that matches a key=value. The key can contain ascii letters, numbers, underscore and period. The key must begin at the beginning of the line. The = sign following the key may be surrounded by whitespace. The value may contain anything, including an = sign.

Constructor Detail

ConfigEntryTable

public ConfigEntryTable(String bookName)
Create an empty Sword config for the named book.

Parameters:
bookName - the name of the book
Method Detail

load

public void load(File file)
          throws IOException
Load the conf from a file.

Parameters:
file - the file to load
Throws:
IOException

load

public void load(byte[] buffer)
          throws IOException
Load the conf from a buffer. This is used to load conf entries from the mods.d.tar.gz file.

Parameters:
buffer - the buffer to load
Throws:
IOException

isQuestionable

public boolean isQuestionable()
Determines whether the Sword Book's conf is supported by JSword.


isSupported

public boolean isSupported()
Determines whether the Sword Book's conf is supported by JSword.


isEnciphered

public boolean isEnciphered()
Determines whether the Sword Book is enciphered.

Returns:
true if enciphered

isLocked

public boolean isLocked()
Determines whether the Sword Book is enciphered and without a key.

Returns:
true if enciphered

unlock

public boolean unlock(String unlockKey)
Unlocks a book with the given key. The key is trimmed of any leading or trailing whitespace.

Parameters:
unlockKey - the key to try
Returns:
true if the unlock key worked.

getUnlockKey

public String getUnlockKey()
Gets the unlock key for the module.

Returns:
the unlock key, if any, null otherwise.

getKeys

public Set getKeys()
Returns an Enumeration of all the keys found in the config file.


getBookType

public BookType getBookType()
Returns an Enumeration of all the keys found in the config file.


getValue

public Object getValue(ConfigEntryType type)
Gets a particular ConfigEntry's value by its type

Parameters:
type - of the ConfigEntry
Returns:
the requested value, the default (if there is no entry) or null (if there is no default)

match

public boolean match(ConfigEntryType type,
                     Object search)
Determine whether this ConfigEntryTable has the ConfigEntry and it matches the value.

Parameters:
type - The kind of ConfigEntry to look for
search - the value to match against
Returns:
true if there is a matching ConfigEntry matching the value

toOSIS

public org.jdom.Element toOSIS()
Sort the keys for a more meaningful presentation order.


toConf

public String toConf()
Build's a SWORD conf file as a string. The result is not identical to the original, cleaning up problems in the original and re-arranging the entries into a predictable order.

Returns:
the well-formed conf.

save

public void save()
          throws IOException
Throws:
IOException

loadContents

private void loadContents(BufferedReader in)
                   throws IOException
Throws:
IOException

loadInitials

private void loadInitials(BufferedReader in)
                   throws IOException
Throws:
IOException

getContinuation

private void getContinuation(ConfigEntry configEntry,
                             BufferedReader bin,
                             StringBuffer buf)
                      throws IOException
Get continuation lines, if any.

Throws:
IOException

advance

private String advance(BufferedReader bin)
                throws IOException
Get the next line from the input

Parameters:
bin - The reader to get data from
Returns:
the next line
Throws:
IOException

backup

private void backup(String oops)
Read too far ahead and need to return a line.


isKeyLine

private boolean isKeyLine(String line)
Does this line of text represent a key/value pair?


add

public void add(ConfigEntryType type,
                String aValue)
A helper to create/replace a value for a given type.

Parameters:
type -
aValue -

adjustDataPath

private void adjustDataPath()

adjustLanguage

private void adjustLanguage()

adjustBookType

private void adjustBookType()

adjustName

private void adjustName()

validate

private void validate()
Determine which books are not supported. Also, report on problems.


testLanguage

private void testLanguage(String initials,
                          Language lang)

toOSIS

private void toOSIS(OSISUtil.OSISFactory factory,
                    org.jdom.Element ele,
                    String aTitle,
                    ConfigEntryType[] category)
Build an ordered map so that it displays in a consistent order.


toConf

private void toConf(StringBuffer buf,
                    ConfigEntryType[] category)

report

private String report(String issue,
                      String confEntryName,
                      String line)

Copyright ยจ 2003-2007