Coverage Report - org.crosswire.jsword.versification.FileVersificationMapping
 
Classes in this File Line Coverage Branch Coverage Complexity
FileVersificationMapping
0%
0/18
0%
0/8
2
 
 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, 2013 - 2016
 18  
  *
 19  
  */
 20  
 package org.crosswire.jsword.versification;
 21  
 
 22  
 import org.crosswire.common.config.ConfigException;
 23  
 import org.crosswire.common.util.KeyValuePair;
 24  
 import org.crosswire.common.util.ResourceUtil;
 25  
 
 26  
 import java.io.BufferedReader;
 27  
 import java.io.IOException;
 28  
 import java.io.InputStream;
 29  
 import java.io.InputStreamReader;
 30  
 import java.util.ArrayList;
 31  
 import java.util.List;
 32  
 
 33  
 /**
 34  
  * This reads a file up front and creates the key value pairs. Because
 35  
  * we're not quite using the 'properties' file definition because we allow
 36  
  * duplicate keys on either side of the '=' sign, we need to do the processing ourselves.
 37  
  *
 38  
  * @see gnu.lgpl.License The GNU Lesser General Public License for details.
 39  
  * @author Chris Burrell
 40  
  */
 41  
 public class FileVersificationMapping {
 42  
     //unsure what a typical value would be, so leaving at 16 - best to optimize for memory,
 43  
     //than speed upon reading the first time.
 44  0
     private List<KeyValuePair> pairs = new ArrayList<KeyValuePair>(16);
 45  
 
 46  
     /**
 47  
      * Allow a default initialising if someone wants to create a mapping file dynamically.
 48  
      */
 49  0
     public FileVersificationMapping() {
 50  
         //no work to do.
 51  0
     }
 52  
 
 53  
     /**
 54  
      * @param versification the name of the versification maps to the expected .properties file
 55  
      * @throws IOException     error reading the mapping files
 56  
      * @throws ConfigException error parsing the contents of the file
 57  
      */
 58  0
     public FileVersificationMapping(Versification versification) throws IOException, ConfigException {
 59  
         //TODO(CJB): deal with Missing Resource Exceptions
 60  0
         InputStream s = ResourceUtil.getResourceAsStream(getClass(), versification.getName() + ".properties");
 61  0
         BufferedReader lineReader = new BufferedReader(new InputStreamReader(s));
 62  
         String line;
 63  0
         while ((line = lineReader.readLine()) != null) {
 64  0
             if (line.length() == 0 || line.charAt(0) == '#') {
 65  0
                 continue;
 66  
             }
 67  
 
 68  0
             int firstEqual = line.indexOf('=');
 69  0
             if (firstEqual == -1) {
 70  0
                 this.addProperty(line, null);
 71  
             } else {
 72  0
                 this.addProperty(line.substring(0, firstEqual), line.substring(firstEqual + 1));
 73  
             }
 74  0
         }
 75  0
     }
 76  
 
 77  
     /**
 78  
      * @param key   the key
 79  
      * @param value the value
 80  
      */
 81  
     public void addProperty(String key, String value) {
 82  0
         pairs.add(new KeyValuePair(key, value));
 83  0
     }
 84  
 
 85  
     public List<KeyValuePair> getMappings() {
 86  0
         return this.pairs;
 87  
     }
 88  
 }