01: /*************************************************************************
02: * *
03: * EJBCA: The OpenSource Certificate Authority *
04: * *
05: * This software is free software; you can redistribute it and/or *
06: * modify it under the terms of the GNU Lesser General Public *
07: * License as published by the Free Software Foundation; either *
08: * version 2.1 of the License, or any later version. *
09: * *
10: * See terms of license at gnu.org. *
11: * *
12: *************************************************************************/package org.ejbca.ui.cli.batch;
13:
14: import java.io.File;
15: import java.io.FileInputStream;
16: import java.io.FileNotFoundException;
17: import java.io.IOException;
18: import java.util.Properties;
19:
20: import org.apache.log4j.Logger;
21:
22: /**
23: * Class used to manage the batch tool property file.
24: *
25: * @author Philip Vendil 2006 sep 19
26: *
27: * @version $Id: BatchToolProperties.java,v 1.4 2006/12/13 09:49:04 anatom Exp $
28: */
29: public class BatchToolProperties {
30:
31: private static final String PROPERTY_KEYSPEC = "keys.spec";
32: private static final String PROPERTY_KEYALG = "keys.alg";
33:
34: Properties batchToolProperties = new Properties();
35: private static final Logger log = Logger
36: .getLogger(BatchToolProperties.class);
37:
38: BatchToolProperties() {
39: load();
40: }
41:
42: /**
43: * Returns the configured keysize
44: * Default is 1024
45: */
46: public String getKeySpec() {
47: return batchToolProperties
48: .getProperty(PROPERTY_KEYSPEC, "1024");
49: }
50:
51: /**
52: * Returns the configured key algorithm
53: * Default is RSA, can be ECDSA
54: */
55: public String getKeyAlg() {
56: return batchToolProperties.getProperty(PROPERTY_KEYALG, "RSA");
57: }
58:
59: /**
60: * Method that tries to read the property file 'batchtool.properties'
61: * in the home directory then in the current directory and finally
62: * in the bin\batchtool.properties
63: *
64: */
65: private void load() {
66: File file = new File(System.getProperty("user.home"),
67: "batchtool.properties");
68: try {
69: try {
70: FileInputStream fis = new FileInputStream(file);
71: batchToolProperties.load(fis);
72: } catch (FileNotFoundException e) {
73: try {
74: FileInputStream fis = new FileInputStream(
75: "batchtool.properties");
76: batchToolProperties.load(fis);
77: } catch (FileNotFoundException e1) {
78: try {
79: FileInputStream fis = new FileInputStream(
80: "bin/batchtool.properties");
81: batchToolProperties.load(fis);
82: } catch (FileNotFoundException e2) {
83: log
84: .info("Could not find any batchtool property file, default values will be used.");
85: log.debug(e);
86: }
87: }
88: }
89: } catch (IOException e) {
90: log.error("Error reading batchtool property file ");
91: log.debug(e);
92: }
93: }
94:
95: }
|