Coverage Report - org.crosswire.jsword.bridge.ConfParser
 
Classes in this File Line Coverage Branch Coverage Complexity
ConfParser
0%
0/28
0%
0/8
2.75
 
 1  
 /**
 2  
  * Distribution License:
 3  
  * JSword is free software; you can redistribute it and/or modify it under
 4  
  * the terms of the GNU Lesser General Public License, version 2.1 or later
 5  
  * as published by the Free Software Foundation. This program is distributed
 6  
  * in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
 7  
  * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 8  
  * See the GNU Lesser General Public License for more details.
 9  
  *
 10  
  * The License is available on the internet at:
 11  
  *      http://www.gnu.org/copyleft/lgpl.html
 12  
  * or by writing to:
 13  
  *      Free Software Foundation, Inc.
 14  
  *      59 Temple Place - Suite 330
 15  
  *      Boston, MA 02111-1307, USA
 16  
  *
 17  
  * © CrossWire Bible Society, 2008 - 2016
 18  
  *
 19  
  */
 20  
 package org.crosswire.jsword.bridge;
 21  
 
 22  
 import java.io.File;
 23  
 import java.io.IOException;
 24  
 import java.io.PrintWriter;
 25  
 
 26  
 import org.crosswire.common.util.IniSection;
 27  
 import org.crosswire.jsword.book.BookMetaData;
 28  
 import org.crosswire.jsword.book.sword.SwordBookMetaData;
 29  
 
 30  
 /**
 31  
  * Parses the Sword conf and reports errors to the console.
 32  
  * Optionally will normalize the conf.
 33  
  * 
 34  
  * @see gnu.lgpl.License The GNU Lesser General Public License for details.
 35  
  * @author DM Smith
 36  
  */
 37  
 public class ConfParser {
 38  
 
 39  0
     public ConfParser(final String confFile) {
 40  0
         conf = confFile;
 41  0
     }
 42  
     public void parse() throws IOException {
 43  0
         File confFile = new File(conf);
 44  0
         if (!confFile.exists()) {
 45  0
             System.err.println("File does not exist: " + conf);
 46  0
             return;
 47  
         }
 48  0
         IniSection config = new IniSection();
 49  
 
 50  
         // So called Latin-1 is the default, but most are UTF-8
 51  0
         config.load(confFile, "UTF-8");
 52  0
         String encoding = config.get("Encoding");
 53  0
         if (encoding == null || "Latin-1".equalsIgnoreCase(encoding)) {
 54  0
             config.clear();
 55  0
             config.load(confFile, "WINDOWS-1252");
 56  
         }
 57  0
         SwordBookMetaData.report(config);
 58  0
         SwordBookMetaData.normalize(new PrintWriter(System.out), config, CANONICAL_ORDER);
 59  0
     }
 60  
 
 61  
     /**
 62  
      * 
 63  
      * 
 64  
      * @param args The list of conf files to check.
 65  
      */
 66  
     public static void main(String[] args) {
 67  0
         if (args.length != 1) {
 68  0
             usage();
 69  0
             return;
 70  
         }
 71  0
         ConfParser parser = new ConfParser(args[0]);
 72  
         try {
 73  0
             parser.parse();
 74  0
         } catch (IOException e) {
 75  
             // TODO Auto-generated catch block
 76  0
             e.printStackTrace();
 77  0
         }
 78  0
     }
 79  
 
 80  
     public static void usage() {
 81  0
         System.err.println("Usage: ConfParser /full/path/to/xyz.conf");
 82  0
     }
 83  
 
 84  
     private String conf;
 85  0
     private static final String[] CANONICAL_ORDER = {
 86  
             SwordBookMetaData.KEY_ABBREVIATION, // Uncommon, but renames [xyz] for non-latin languages
 87  
             SwordBookMetaData.KEY_DESCRIPTION, // Always
 88  
             SwordBookMetaData.KEY_DATA_PATH, // Always
 89  
             BookMetaData.KEY_CATEGORY, // Non-bibles
 90  
             SwordBookMetaData.KEY_MINIMUM_VERSION, // Should be the last released version of the SWORD engine
 91  
             BookMetaData.KEY_LANG, // Should always be used
 92  
             SwordBookMetaData.KEY_DIRECTION, // Defaults to ltor, here because of Lang
 93  
             SwordBookMetaData.KEY_ENCODING, // Default is Latin-1
 94  
             SwordBookMetaData.KEY_SOURCE_TYPE, // Always
 95  
             SwordBookMetaData.KEY_MOD_DRV, // Always
 96  
             SwordBookMetaData.KEY_COMPRESS_TYPE, // When compressed
 97  
             SwordBookMetaData.KEY_BLOCK_TYPE, // When compressed
 98  
             SwordBookMetaData.KEY_BLOCK_COUNT, // Compressed Dictionary, not common
 99  
             BookMetaData.KEY_VERSIFICATION, // Bibles and Commentaries, defaults to KJV
 100  
             SwordBookMetaData.KEY_OSIS_VERSION, // Informational, for SourceType=OSIS
 101  
             SwordBookMetaData.KEY_OSIS_Q_TO_TICK, // Bibles, obsolete, not common
 102  
             SwordBookMetaData.KEY_KEY_TYPE,      // For GenBook Bibles, not used
 103  
             SwordBookMetaData.KEY_DISPLAY_LEVEL, // GenBook, not common
 104  
             SwordBookMetaData.KEY_FEATURE, // SWORD Engine
 105  
             SwordBookMetaData.KEY_GLOBAL_OPTION_FILTER, // SWORD Engine toggles
 106  
             SwordBookMetaData.KEY_SIGLUM1, // For OSISGlosses
 107  
             SwordBookMetaData.KEY_SIGLUM2,
 108  
             SwordBookMetaData.KEY_SIGLUM3,
 109  
             SwordBookMetaData.KEY_SIGLUM4,
 110  
             SwordBookMetaData.KEY_SIGLUM5,
 111  
             SwordBookMetaData.KEY_GLOSSARY_FROM, // For Glossaries
 112  
             SwordBookMetaData.KEY_GLOSSARY_TO, // For Glossaries
 113  
             BookMetaData.KEY_FONT, // Rare
 114  
             BookMetaData.KEY_SCOPE, // Suggested, present in 1
 115  
             BookMetaData.KEY_BOOKLIST, // JSword only
 116  
             SwordBookMetaData.KEY_LCSH,
 117  
             SwordBookMetaData.KEY_SWORD_VERSION_DATE, // Date of last change
 118  
             SwordBookMetaData.KEY_VERSION, // Module version
 119  
             SwordBookMetaData.KEY_HISTORY, // Module history
 120  
             SwordBookMetaData.KEY_OBSOLETES,
 121  
             // General info
 122  
             SwordBookMetaData.KEY_DISTRIBUTION_LICENSE, // Always
 123  
             SwordBookMetaData.KEY_DISTRIBUTION_SOURCE,
 124  
             SwordBookMetaData.KEY_DISTRIBUTION_NOTES,
 125  
             SwordBookMetaData.KEY_TEXT_SOURCE,
 126  
             SwordBookMetaData.KEY_SHORT_PROMO,
 127  
             SwordBookMetaData.KEY_COPYRIGHT_DATE,
 128  
             SwordBookMetaData.KEY_SHORT_COPYRIGHT,
 129  
             SwordBookMetaData.KEY_ABOUT, // Always
 130  
             SwordBookMetaData.KEY_COPYRIGHT,
 131  
             SwordBookMetaData.KEY_COPYRIGHT_HOLDER,
 132  
             SwordBookMetaData.KEY_COPYRIGHT_CONTACT_NAME,
 133  
             SwordBookMetaData.KEY_COPYRIGHT_CONTACT_ADDRESS,
 134  
             SwordBookMetaData.KEY_COPYRIGHT_CONTACT_EMAIL,
 135  
             SwordBookMetaData.KEY_COPYRIGHT_CONTACT_NOTES,
 136  
             SwordBookMetaData.KEY_COPYRIGHT_NOTES,
 137  
             // Kept last as it is maintained there by external program
 138  
             SwordBookMetaData.KEY_INSTALL_SIZE
 139  
     };
 140  
 
 141  
 }