KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ejbca > ui > cli > batch > BatchToolProperties


1 /*************************************************************************
2  * *
3  * EJBCA: The OpenSource Certificate Authority *
4  * *
5  * This software is free software; you can redistribute it and/or *
6  * modify it under the terms of the GNU Lesser General Public *
7  * License as published by the Free Software Foundation; either *
8  * version 2.1 of the License, or any later version. *
9  * *
10  * See terms of license at gnu.org. *
11  * *
12  *************************************************************************/

13 package org.ejbca.ui.cli.batch;
14
15 import java.io.File JavaDoc;
16 import java.io.FileInputStream JavaDoc;
17 import java.io.FileNotFoundException JavaDoc;
18 import java.io.IOException JavaDoc;
19 import java.util.Properties JavaDoc;
20
21 import org.apache.log4j.Logger;
22
23 /**
24  * Class used to manage the batch tool property file.
25  *
26  * @author Philip Vendil 2006 sep 19
27  *
28  * @version $Id: BatchToolProperties.java,v 1.4 2006/12/13 09:49:04 anatom Exp $
29  */

30 public class BatchToolProperties {
31     
32     private static final String JavaDoc PROPERTY_KEYSPEC = "keys.spec";
33     private static final String JavaDoc PROPERTY_KEYALG = "keys.alg";
34     
35
36     Properties JavaDoc batchToolProperties = new Properties JavaDoc();
37     private static final Logger log = Logger.getLogger(BatchToolProperties.class);
38     
39     BatchToolProperties(){
40         load();
41     }
42     
43     /**
44      * Returns the configured keysize
45      * Default is 1024
46      */

47     public String JavaDoc getKeySpec(){
48         return batchToolProperties.getProperty(PROPERTY_KEYSPEC,"1024");
49     }
50     
51     /**
52      * Returns the configured key algorithm
53      * Default is RSA, can be ECDSA
54      */

55     public String JavaDoc getKeyAlg(){
56         return batchToolProperties.getProperty(PROPERTY_KEYALG,"RSA");
57     }
58
59     
60     
61     
62     /**
63      * Method that tries to read the property file 'batchtool.properties'
64      * in the home directory then in the current directory and finally
65      * in the bin\batchtool.properties
66      *
67      */

68     private void load(){
69         File JavaDoc file = new File JavaDoc( System.getProperty("user.home"),
70                 "batchtool.properties");
71         try {
72             try{
73             FileInputStream JavaDoc fis = new FileInputStream JavaDoc(file);
74             batchToolProperties.load(fis);
75             } catch (FileNotFoundException JavaDoc e) {
76                 try{
77                     FileInputStream JavaDoc fis = new FileInputStream JavaDoc("batchtool.properties");
78                     batchToolProperties.load(fis);
79                 }catch (FileNotFoundException JavaDoc e1) {
80                     try{
81                         FileInputStream JavaDoc fis = new FileInputStream JavaDoc("bin/batchtool.properties");
82                         batchToolProperties.load(fis);
83                     }catch (FileNotFoundException JavaDoc e2) {
84                         log.info("Could not find any batchtool property file, default values will be used.");
85                         log.debug(e);
86                     }
87                 }
88             }
89         } catch (IOException JavaDoc e) {
90             log.error("Error reading batchtool property file ");
91             log.debug(e);
92         }
93     }
94     
95     
96     
97 }
98
Popular Tags