Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: jgift/ConfigReader.java


1   /*
2    * This file is part of jgiFT.
3    * Copyright (C) 2003, Jason Shobe
4    *
5    * jgiFT is free software; you can redistribute it and/or modify
6    * it under the terms of the GNU General Public License as published by
7    * the Free Software Foundation; either version 2 of the License, or
8    * (at your option) any later version.
9    *
10   * jgiFT is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   * GNU General Public License for more details.
14   *
15   * You should have received a copy of the GNU General Public License
16   * along with jgiFT; if not, write to the Free Software
17   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18   */
19  package jgift;
20  
21  import java.io.BufferedReader;
22  import java.io.File;
23  import java.io.FileReader;
24  import java.io.IOException;
25  import java.util.Properties;
26  
27  /**
28   * ConfigParser handles the parsing of the giFT configuration files.
29   *
30   * @author  Jason Shobe
31   * @version $Revision: 1.2 $
32   */
33  public class ConfigReader {
34     /**
35      * Creates a new instance of ConfigParser.
36      *
37      * @param properties the map of properties.
38      */
39     public ConfigReader(Properties properties) {
40        this.properties = properties;
41     }
42     
43     /**
44      * Reads in the configuration settings.
45      *
46      * @throws IOException if an I/O error occurs while reading the configuration
47      *                     file(s).
48      */
49     public void read() throws IOException {
50        File file = new File(System.getProperty("user.home") + File.separator +
51                             ".giFT" + File.separator + "gift.conf");
52        BufferedReader reader = new BufferedReader(new FileReader(file));
53        String line = null;
54        String group = null;
55        
56        while((line = reader.readLine()) != null) {
57           line = line.trim();
58           
59           if(line.startsWith("#") || line.length() == 0) {
60              continue;
61           }
62           
63           if(line.startsWith("[")) {
64              group = line.substring(1, line.length() - 1);
65              continue;
66           }
67           
68           if(line.indexOf('=') < 0) {
69              // illegal line, ignore
70              continue;
71           }
72           
73           String key = group + "." + line.substring(0, line.indexOf('=')).trim();
74           String value = line.substring(line.indexOf('=') + 1).trim();
75           properties.setProperty(key, value);
76        }
77        
78        reader.close();
79     }
80     
81     private Properties properties = null;
82  }
83