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 as published by
5    * the Free Software Foundation. This program is distributed in the hope
6    * that it will be useful, but WITHOUT ANY WARRANTY; without even the
7    * 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   * Copyright: 2007
18   *     The copyright to this program is held by it's authors.
19   *
20   * ID: $Id: KeyAnalyzer.java 1376 2007-06-01 18:27:01Z dmsmith $
21   */
22  package org.crosswire.jsword.index.lucene;
23  
24  import java.io.IOException;
25  
26  import org.crosswire.common.util.Logger;
27  import org.crosswire.common.util.PropertyMap;
28  import org.crosswire.common.util.ResourceUtil;
29  
30  /**
31   * A singleton that Reads and Maintains IndexMetadata from properties file All
32   * version number in the properties file must be float.
33   * 
34   * @see gnu.lgpl.License for license details.<br>
35   *      The copyright to this program is held by it's authors.
36   * @author Sijo Cherian [sijocherian at yahoo dot com]
37   */
38  public class IndexMetadata {
39      private IndexMetadata() {
40          try {
41              props = ResourceUtil.getProperties(getClass());
42  
43          } catch (IOException e) {
44              log.error("Property file read error", e);
45          }
46      }
47  
48      /**
49       * All access to IndexMetadata is through this single instance.
50       * 
51       * @return the singleton instance
52       */
53      public static IndexMetadata instance() {
54          return myInstance;
55      }
56  
57      public float getInstalledIndexVersion() {
58          String value = props.get(INDEX_VERSION, "1.1");
59          return Float.parseFloat(value);
60      }
61  
62      public float getLuceneVersion() {
63          return Float.parseFloat(props.get(LUCENE_VERSION));
64      }
65  
66      public float getLatestIndexVersion() {
67          String value = props.get(INDEX_VERSION, "1.1");
68          return Float.parseFloat(value);
69      }
70  
71      public static final String INDEX_VERSION = "Installed.Index.Version";
72      public static final String LATEST_INDEX_VERSION = "Latest.Index.Version";
73      public static final String LUCENE_VERSION = "Lucene.Version";
74      public static final float INDEX_VERSION_1_1 = 1.1f;
75      public static final float INDEX_VERSION_1_2 = 1.2f;
76  
77      private static final Logger log = Logger.getLogger(IndexMetadata.class);
78      private static IndexMetadata myInstance = new IndexMetadata();
79      private PropertyMap props;
80  }
81