org.crosswire.jsword.book.sword
Class SwordBookMetaData

java.lang.Object
  extended by org.crosswire.jsword.book.basic.AbstractBookMetaData
      extended by org.crosswire.jsword.book.sword.SwordBookMetaData
All Implemented Interfaces:
Comparable<BookMetaData>, BookMetaData

public final class SwordBookMetaData
extends AbstractBookMetaData

A utility class for loading and representing Sword book configs.

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

In addition, the SwordBookMetaData is hierarchical. The Level indicates where the file originates from. The full hierarchy could be laid out as followed:

     - sword
         - jsword
            - front-end
 
Various rules govern where attributes are read from. The general rule is that the highest level (front-end write) will override values from the lowest common denominator (sword). Various parts of the tree may be missing as the files may not exist on disk. There are exceptions however and each method in this file documents its behavior.

The contents of the About field are in RTF.

\ is used as a continuation line.

Author:
Mark Goodwin, Joe Walker, Jacky Cheung, DM Smith
See Also:
The GNU Lesser General Public License for details.

Field Summary
private  BookCategory bookCat
          The BookCategory for this Book
private  String bookConf
          The name of the conf file, such as kjv.conf.
private  BookType bookType
          The BookType for this Book
private  IniSection configAll
          The configAll IniSection holds the merged view of configSword, configJSword, and configFrontend.
private  File configFile
          If the module's config is tied to a file remember it so that it can be updated.
private  IniSection configFrontend
          configFrontend contains the configuration for the current front-end.
private  IniSection configJSword
          configJSword holds shared configuration for all front-ends.
private  IniSection configSword
          configSword holds the pristine conf for the Book.
static Map<String,String> DEFAULTS
           
private static PropertyMap ENCODING_JAVA
           
private static String ENCODING_LATIN1
           
private static String ENCODING_UTF8
          Sword only recognizes two encodings for its modules: UTF-8 and Latin-1 Sword uses MS Windows cp1252 for Latin 1 not the standard.
private static String[] HIDDEN
           
static String KEY_ABBREVIATION
           
static String KEY_ABOUT
           
static String KEY_BLOCK_COUNT
           
static String KEY_BLOCK_TYPE
           
static String KEY_CIPHER_KEY
           
static String KEY_COMPRESS_TYPE
           
static String KEY_COPYRIGHT
           
static String KEY_COPYRIGHT_CONTACT_ADDRESS
           
static String KEY_COPYRIGHT_CONTACT_EMAIL
           
static String KEY_COPYRIGHT_CONTACT_NAME
           
static String KEY_COPYRIGHT_CONTACT_NOTES
           
static String KEY_COPYRIGHT_DATE
           
static String KEY_COPYRIGHT_HOLDER
           
static String KEY_COPYRIGHT_NOTES
           
static String KEY_DATA_PATH
           
static String KEY_DESCRIPTION
           
static String KEY_DIRECTION
           
static String KEY_DISPLAY_LEVEL
           
static String KEY_DISTRIBUTION_LICENSE
           
static String KEY_DISTRIBUTION_NOTES
           
static String KEY_DISTRIBUTION_SOURCE
           
static String KEY_ENCODING
           
static String KEY_FEATURE
           
static String KEY_GLOBAL_OPTION_FILTER
           
static String KEY_GLOSSARY_FROM
           
static String KEY_GLOSSARY_TO
           
static String KEY_HISTORY
           
static String KEY_INSTALL_SIZE
           
static String KEY_KEY_TYPE
           
static String KEY_LCSH
           
static String KEY_LOCAL_STRIP_FILTER
           
static String KEY_MINIMUM_VERSION
           
static String KEY_MOD_DRV
           
static String KEY_OBSOLETES
           
static String KEY_OSIS_Q_TO_TICK
           
static String KEY_OSIS_VERSION
           
static String KEY_PREFERRED_CSS_XHTML
           
static String KEY_SEARCH_OPTION
           
static String KEY_SHORT_COPYRIGHT
           
static String KEY_SHORT_PROMO
           
static String KEY_SOURCE_TYPE
           
static String KEY_STRONGS_PADDING
           
static String KEY_SWORD_VERSION_DATE
           
static String KEY_TEXT_SOURCE
           
static String KEY_UNLOCK_URL
           
static String KEY_VERSION
           
private static org.slf4j.Logger log
          The log stream
private static String[] OSIS_INFO
          These are the elements that JSword requires.
private  boolean questionable
          True if this book is considered questionable.
private static Pattern RTF_PATTERN
           
private  boolean supported
          True if this book's config type can be used by JSword.
 
Fields inherited from interface org.crosswire.jsword.book.BookMetaData
KEY_BOOK, KEY_BOOKLIST, KEY_CATEGORY, KEY_DRIVER, KEY_FONT, KEY_LANG, KEY_LANGUAGE, KEY_NAME, KEY_SCOPE, KEY_VERSIFICATION
 
Constructor Summary
SwordBookMetaData(byte[] buffer, String bookConf)
          Loads a sword config from a buffer.
SwordBookMetaData(File file, URI bookRootPath)
          Loads a sword config from a given File.
 
Method Summary
private  IniSection addConfig(MetaDataLocator locator)
           
private  void adjustBookType()
           
private  void adjustConfig()
           
private  void adjustHistory()
           
private  void adjustLanguage()
           
private  void adjustName()
           
 BookCategory getBookCategory()
          What category of content is this, a Bible or a reference work like a Dictionary or Commentary.
 String getBookCharset()
          Returns the Charset of the book based on the encoding attribute.
 BookType getBookType()
           
 File getConfigFile()
          To maintain backwards compatibility, this always returns the Sword conf file Get the conf file for this SwordMetaData.
(package private)  IniSection getConfiguration()
          Exposed as package private for testing purposes.
 Filter getFilter()
           
 String getInitials()
          The initials of this book - how people familiar with this book will know it, for example "NIV", "KJV".
 String getInternalName()
          The internal name of this book.
 KeyType getKeyType()
          How this Book organizes it's keys.
 String getName()
          The name of the book, for example "King James Version" or "Bible in Basic English" or "Greek".
 String getProperty(String key)
          Get the property or null.
 Set<String> getPropertyKeys()
          Get a list of all the properties available to do with this Book.
 String getUnlockKey()
          Gets the unlock key for the module.
private  Object getValue(String key)
          Gets a particular entry value by its type
 boolean hasFeature(FeatureType feature)
          Return whether the feature is supported by the book.
 boolean isEnciphered()
          Indicate whether this book is enciphered.
 boolean isLeftToRight()
          Return the orientation of the script of the Book.
 boolean isLocked()
          Indicate whether this book is enciphered and without a key.
 boolean isQuestionable()
          Indicate whether this book is questionable.
 boolean isSupported()
          Indicate whether this book is supported by JSword.
private  IniSection load(byte[] buffer)
          Load the conf from a buffer.
private  IniSection load(File file)
          Load the conf from a file.
private  void mergeConfig(IniSection config)
           
 void putProperty(String key, String value, boolean forFrontend)
          Saves an entry to a particular configuration file.
protected  void report()
           
 void setLibrary(URI library)
          Set the base URI for library of this module.
private  void testLanguage(String key, String lang)
           
private  org.jdom2.Element toKeyCell(OSISUtil.OSISFactory factory, String key)
           
 org.jdom2.Document toOSIS()
          Get an OSIS representation of information concerning this Book.
private  org.jdom2.Element toRow(OSISUtil.OSISFactory factory, String key)
           
private  org.jdom2.Element toRow(OSISUtil.OSISFactory factory, String key, String value)
           
 boolean unlock(String unlockKey)
          Unlocks a book with the given key.
 
Methods inherited from class org.crosswire.jsword.book.basic.AbstractBookMetaData
compareTo, equals, getDriver, getDriverName, getIndexStatus, getLanguage, getLibrary, getLocation, getOsisID, hashCode, putProperty, setDriver, setIndexStatus, setLanguage, setLocation, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

KEY_ABBREVIATION

public static final String KEY_ABBREVIATION
See Also:
Constant Field Values

KEY_ABOUT

public static final String KEY_ABOUT
See Also:
Constant Field Values

KEY_BLOCK_COUNT

public static final String KEY_BLOCK_COUNT
See Also:
Constant Field Values

KEY_BLOCK_TYPE

public static final String KEY_BLOCK_TYPE
See Also:
Constant Field Values

KEY_CIPHER_KEY

public static final String KEY_CIPHER_KEY
See Also:
Constant Field Values

KEY_COMPRESS_TYPE

public static final String KEY_COMPRESS_TYPE
See Also:
Constant Field Values

KEY_COPYRIGHT

public static final String KEY_COPYRIGHT
See Also:
Constant Field Values

KEY_COPYRIGHT_CONTACT_ADDRESS

public static final String KEY_COPYRIGHT_CONTACT_ADDRESS
See Also:
Constant Field Values

KEY_COPYRIGHT_CONTACT_EMAIL

public static final String KEY_COPYRIGHT_CONTACT_EMAIL
See Also:
Constant Field Values

KEY_COPYRIGHT_CONTACT_NAME

public static final String KEY_COPYRIGHT_CONTACT_NAME
See Also:
Constant Field Values

KEY_COPYRIGHT_CONTACT_NOTES

public static final String KEY_COPYRIGHT_CONTACT_NOTES
See Also:
Constant Field Values

KEY_COPYRIGHT_DATE

public static final String KEY_COPYRIGHT_DATE
See Also:
Constant Field Values

KEY_COPYRIGHT_HOLDER

public static final String KEY_COPYRIGHT_HOLDER
See Also:
Constant Field Values

KEY_COPYRIGHT_NOTES

public static final String KEY_COPYRIGHT_NOTES
See Also:
Constant Field Values

KEY_DATA_PATH

public static final String KEY_DATA_PATH
See Also:
Constant Field Values

KEY_DESCRIPTION

public static final String KEY_DESCRIPTION
See Also:
Constant Field Values

KEY_DIRECTION

public static final String KEY_DIRECTION
See Also:
Constant Field Values

KEY_DISPLAY_LEVEL

public static final String KEY_DISPLAY_LEVEL
See Also:
Constant Field Values

KEY_DISTRIBUTION_LICENSE

public static final String KEY_DISTRIBUTION_LICENSE
See Also:
Constant Field Values

KEY_DISTRIBUTION_NOTES

public static final String KEY_DISTRIBUTION_NOTES
See Also:
Constant Field Values

KEY_DISTRIBUTION_SOURCE

public static final String KEY_DISTRIBUTION_SOURCE
See Also:
Constant Field Values

KEY_ENCODING

public static final String KEY_ENCODING
See Also:
Constant Field Values

KEY_FEATURE

public static final String KEY_FEATURE
See Also:
Constant Field Values

KEY_GLOBAL_OPTION_FILTER

public static final String KEY_GLOBAL_OPTION_FILTER
See Also:
Constant Field Values

KEY_GLOSSARY_FROM

public static final String KEY_GLOSSARY_FROM
See Also:
Constant Field Values

KEY_GLOSSARY_TO

public static final String KEY_GLOSSARY_TO
See Also:
Constant Field Values

KEY_HISTORY

public static final String KEY_HISTORY
See Also:
Constant Field Values

KEY_INSTALL_SIZE

public static final String KEY_INSTALL_SIZE
See Also:
Constant Field Values

KEY_KEY_TYPE

public static final String KEY_KEY_TYPE
See Also:
Constant Field Values

KEY_LCSH

public static final String KEY_LCSH
See Also:
Constant Field Values

KEY_LOCAL_STRIP_FILTER

public static final String KEY_LOCAL_STRIP_FILTER
See Also:
Constant Field Values

KEY_MINIMUM_VERSION

public static final String KEY_MINIMUM_VERSION
See Also:
Constant Field Values

KEY_MOD_DRV

public static final String KEY_MOD_DRV
See Also:
Constant Field Values

KEY_OBSOLETES

public static final String KEY_OBSOLETES
See Also:
Constant Field Values

KEY_OSIS_Q_TO_TICK

public static final String KEY_OSIS_Q_TO_TICK
See Also:
Constant Field Values

KEY_OSIS_VERSION

public static final String KEY_OSIS_VERSION
See Also:
Constant Field Values

KEY_PREFERRED_CSS_XHTML

public static final String KEY_PREFERRED_CSS_XHTML
See Also:
Constant Field Values

KEY_SEARCH_OPTION

public static final String KEY_SEARCH_OPTION
See Also:
Constant Field Values

KEY_SHORT_COPYRIGHT

public static final String KEY_SHORT_COPYRIGHT
See Also:
Constant Field Values

KEY_SHORT_PROMO

public static final String KEY_SHORT_PROMO
See Also:
Constant Field Values

KEY_SOURCE_TYPE

public static final String KEY_SOURCE_TYPE
See Also:
Constant Field Values

KEY_STRONGS_PADDING

public static final String KEY_STRONGS_PADDING
See Also:
Constant Field Values

KEY_SWORD_VERSION_DATE

public static final String KEY_SWORD_VERSION_DATE
See Also:
Constant Field Values

KEY_TEXT_SOURCE

public static final String KEY_TEXT_SOURCE
See Also:
Constant Field Values

KEY_UNLOCK_URL

public static final String KEY_UNLOCK_URL
See Also:
Constant Field Values

KEY_VERSION

public static final String KEY_VERSION
See Also:
Constant Field Values

DEFAULTS

public static final Map<String,String> DEFAULTS

bookConf

private String bookConf
The name of the conf file, such as kjv.conf.


configAll

private IniSection configAll
The configAll IniSection holds the merged view of configSword, configJSword, and configFrontend.


configSword

private IniSection configSword
configSword holds the pristine conf for the Book.


configJSword

private IniSection configJSword
configJSword holds shared configuration for all front-ends.


configFrontend

private IniSection configFrontend
configFrontend contains the configuration for the current front-end.


supported

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


bookCat

private BookCategory bookCat
The BookCategory for this Book


bookType

private BookType bookType
The BookType for this Book


questionable

private boolean questionable
True if this book is considered questionable.


configFile

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


OSIS_INFO

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


HIDDEN

private static final String[] HIDDEN

RTF_PATTERN

private static final Pattern RTF_PATTERN

ENCODING_UTF8

private static final String ENCODING_UTF8
Sword only recognizes two encodings for its modules: UTF-8 and Latin-1 Sword uses MS Windows cp1252 for Latin 1 not the standard. Arrgh! The encoding strings need to be converted to Java charsets

See Also:
Constant Field Values

ENCODING_LATIN1

private static final String ENCODING_LATIN1
See Also:
Constant Field Values

ENCODING_JAVA

private static final PropertyMap ENCODING_JAVA

log

private static final org.slf4j.Logger log
The log stream

Constructor Detail

SwordBookMetaData

public SwordBookMetaData(File file,
                         URI bookRootPath)
                  throws IOException,
                         BookException
Loads a sword config from a given File.

Parameters:
file - the config file
bookRootPath - the root path for the book
Throws:
IOException
BookException - indicates missing data files

SwordBookMetaData

public SwordBookMetaData(byte[] buffer,
                         String bookConf)
                  throws IOException
Loads a sword config from a buffer.

Parameters:
buffer -
bookConf -
Throws:
IOException
Method Detail

isQuestionable

public boolean isQuestionable()
Description copied from interface: BookMetaData
Indicate whether this book is questionable. A book may be deemed questionable if it's quality or content has not been confirmed. Since the expectation is that all books are not questionable, abstract implementations should return false and let specific implementations return true if the book is questionable.

Specified by:
isQuestionable in interface BookMetaData
Overrides:
isQuestionable in class AbstractBookMetaData
Returns:
true if the book is questionable

isSupported

public boolean isSupported()
Description copied from interface: BookMetaData
Indicate whether this book is supported by JSword. Since the expectation is that all books are supported, abstract implementations should return true and let specific implementations return false if they cannot support the book.

Specified by:
isSupported in interface BookMetaData
Overrides:
isSupported in class AbstractBookMetaData
Returns:
true if the book is supported

isEnciphered

public boolean isEnciphered()
Description copied from interface: BookMetaData
Indicate whether this book is enciphered. Since the expectation is that most books are unenciphered, abstract implementations should return false and let specific implementations return true otherwise.

Specified by:
isEnciphered in interface BookMetaData
Overrides:
isEnciphered in class AbstractBookMetaData
Returns:
true if the book is enciphered

isLocked

public boolean isLocked()
Description copied from interface: BookMetaData
Indicate whether this book is enciphered and without a key. Since the expectation is that most books are unenciphered, abstract implementations should return false and let specific implementations return true otherwise.

Specified by:
isLocked in interface BookMetaData
Overrides:
isLocked in class AbstractBookMetaData
Returns:
true if the book is locked

unlock

public boolean unlock(String unlockKey)
Description copied from interface: BookMetaData
Unlocks a book with the given key.

Specified by:
unlock in interface BookMetaData
Overrides:
unlock in class AbstractBookMetaData
Parameters:
unlockKey - the key to try
Returns:
true if the unlock key worked.

getUnlockKey

public String getUnlockKey()
Description copied from interface: BookMetaData
Gets the unlock key for the module.

Specified by:
getUnlockKey in interface BookMetaData
Overrides:
getUnlockKey in class AbstractBookMetaData
Returns:
the unlock key, if any, null otherwise.

getName

public String getName()
Description copied from interface: BookMetaData
The name of the book, for example "King James Version" or "Bible in Basic English" or "Greek". This method should not return null or a blank string.

Returns:
The name of this book

getBookCharset

public String getBookCharset()
Returns the Charset of the book based on the encoding attribute. This cannot be override

Returns:
the charset of the book.

getKeyType

public KeyType getKeyType()
Description copied from interface: BookMetaData
How this Book organizes it's keys.

Specified by:
getKeyType in interface BookMetaData
Overrides:
getKeyType in class AbstractBookMetaData
Returns:
the organization of keys of this Book

getBookType

public BookType getBookType()
Returns:
the book type

getFilter

public Filter getFilter()
Returns:
the Filter based upon the SourceType.

getConfigFile

public File getConfigFile()
To maintain backwards compatibility, this always returns the Sword conf file Get the conf file for this SwordMetaData.

Returns:
Returns the conf file or null if loaded from a byte buffer.

setLibrary

public void setLibrary(URI library)
                throws BookException
Description copied from interface: BookMetaData
Set the base URI for library of this module.

Specified by:
setLibrary in interface BookMetaData
Overrides:
setLibrary in class AbstractBookMetaData
Parameters:
library - the base URI or null if there is none
Throws:
BookException - indicates missing data files

getBookCategory

public BookCategory getBookCategory()
Description copied from interface: BookMetaData
What category of content is this, a Bible or a reference work like a Dictionary or Commentary.

Returns:
The category of book

toOSIS

public org.jdom2.Document toOSIS()
Description copied from interface: BookMetaData
Get an OSIS representation of information concerning this Book.

Specified by:
toOSIS in interface BookMetaData
Overrides:
toOSIS in class AbstractBookMetaData
Returns:
the OSIS representation of information about this book.

getInitials

public String getInitials()
Description copied from interface: BookMetaData
The initials of this book - how people familiar with this book will know it, for example "NIV", "KJV".

Returns:
The book's initials

getInternalName

public String getInternalName()
Description copied from interface: BookMetaData
The internal name of this book.

Returns:
the internal name of the module, useful when re-constructing all the meta-information, after installation for example

isLeftToRight

public boolean isLeftToRight()
Description copied from interface: BookMetaData
Return the orientation of the script of the Book. If a book contains more than one script, it refers to the dominate script of the book. This will be used to present Arabic and Hebrew in their proper orientation. Note: some languages have multiple scripts which don't have the same directionality.

Returns:
true if the orientation for the dominate script is LeftToRight.

hasFeature

public boolean hasFeature(FeatureType feature)
Description copied from interface: BookMetaData
Return whether the feature is supported by the book.

Specified by:
hasFeature in interface BookMetaData
Overrides:
hasFeature in class AbstractBookMetaData
Parameters:
feature - the feature in question
Returns:
true if the book supports the feature

getPropertyKeys

public Set<String> getPropertyKeys()
Description copied from interface: BookMetaData
Get a list of all the properties available to do with this Book. The returned Properties will be read-only so any attempts to alter it will fail.

Returns:
the read-only properties for this book

getProperty

public String getProperty(String key)
Description copied from interface: BookMetaData
Get the property or null.

Parameters:
key - the key of the property.
Returns:
the value of the property

putProperty

public void putProperty(String key,
                        String value,
                        boolean forFrontend)
Description copied from interface: BookMetaData
Saves an entry to a particular configuration file.

Parameters:
key - the entry that we are saving
value - the value of the entry
forFrontend - when true save to front end storage, else in shared storage

load

private IniSection load(File file)
                 throws IOException
Load the conf from a file.

Parameters:
file - the file to load
Throws:
IOException

load

private IniSection 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

addConfig

private IniSection addConfig(MetaDataLocator locator)

mergeConfig

private void mergeConfig(IniSection config)

getValue

private Object getValue(String key)
Gets a particular entry value by its type

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

toRow

private org.jdom2.Element toRow(OSISUtil.OSISFactory factory,
                                String key,
                                String value)

toRow

private org.jdom2.Element toRow(OSISUtil.OSISFactory factory,
                                String key)

toKeyCell

private org.jdom2.Element toKeyCell(OSISUtil.OSISFactory factory,
                                    String key)

getConfiguration

IniSection getConfiguration()
Exposed as package private for testing purposes.

Returns:
the config entry table

adjustConfig

private void adjustConfig()

adjustLanguage

private void adjustLanguage()

testLanguage

private void testLanguage(String key,
                          String lang)

adjustBookType

private void adjustBookType()

adjustName

private void adjustName()

adjustHistory

private void adjustHistory()

report

protected void report()

Copyright ยจ 2003-2015