// // ThmlConverter.java // GoBibleCreator // // Created by Jolon Faichney on Sat Oct 30 2004. // For the glory of our Lord Jesus Christ and the furtherance of His Kingdom. // This file is placed into the public domain. // import java.io.*; import java.util.*; import java.util.jar.*; import jolon.xml.*; public class ThmlConverter extends XMLConverter { public ThmlConverter (//File collectionsFile, XMLObject xml) { super(xml); } /** Tag to identify ThML XML data. **/ public final static String THML_TAG = "ThML"; /** ThML tag that contains all of the testaments. **/ public final static String THML_BODY_TAG = "ThML.body"; /** ThML tag that contains a testament (New Testament, Old Testament, Aprocrypha, etc). **/ public final static String TESTAMENT_TAG[] = {"div1"}; /** ThML tag that contains a book (Psalms, Mark, etc). **/ public final static String BOOK_TAG = "div2"; /** ThML attribute within the BOOK_TAG that contains the book name. **/ public final static String BOOK_NAME_ATTRIBUTE = "title"; /** ThML attribute within the BOOK_TAG that contains the short book name. It is assumed that the contents of this attribute will be Latin and will be converted to US-ASCII. **/ public final static String BOOK_SHORT_NAME_ATTRIBUTE = "id"; /** ThML tag that contains one chapter. **/ public final static String CHAPTER_TAG = "div3"; /** ThML attribute within the CHAPTER_TAG that contains the chapter number (eg "Chapter 1"). **/ public final static String CHAPTER_NUMBER_ATTRIBUTE = "title"; /** All verses appear within the paragraph tag and are separated by the VERSE_TAG. **/ public final static String PARAGRAPH_TAG = "p"; /** ThML tag that separates two scriptures. **/ public final static String VERSE_TAG = "scripture"; /** ThML tag used to change the colour of the text to red. **/ public final static String RED_TAG = "span"; /** Attribute of ThML tag used to change the colour of the text to red. **/ public final static String RED_TAG_ATTRIBUTE = "class"; /** Value of attribute of ThML tag used to change the colour of the text to red. **/ public final static String RED_TAG_VALUE = "red"; /** Style changes are written out as flags in a single byte. **/ public final static char STYLE_RED = 1; public HashMap parse(XMLObject thml) { // Call the GoBibleCreator parseBooks method with the // ThML specific tags // Extract the books from the ThML indexed by book name return parseBooks(thml, THML_BODY_TAG, TESTAMENT_TAG, BOOK_TAG, BOOK_NAME_ATTRIBUTE, BOOK_SHORT_NAME_ATTRIBUTE); } public boolean isChapter(XMLObject xml) { return xml.getTag().equals(CHAPTER_TAG); } /** * ThML chapter titles are assumed to end with a space then the chapter number. **/ public int getChapterNumber(XMLObject xml) { String title = xml.getAttribute(CHAPTER_NUMBER_ATTRIBUTE, "*Error no " + CHAPTER_NUMBER_ATTRIBUTE + " attribute*"); // Find the last space int spaceIndex = title.lastIndexOf(' '); return Integer.parseInt(title.substring(spaceIndex + 1)); } /** * A chapter consists of paragraphs (
tags). Somewhere within
* those paragraphs exists