KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ejbca > core > model > ca > catoken > KeyStrings


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
14 package org.ejbca.core.model.ca.catoken;
15
16 import java.util.HashSet JavaDoc;
17 import java.util.Hashtable JavaDoc;
18 import java.util.Map JavaDoc;
19 import java.util.Properties JavaDoc;
20 import java.util.Set JavaDoc;
21
22 import org.ejbca.core.model.SecConst;
23
24
25 /**
26  *
27  * @version $Id: KeyStrings.java,v 1.2.6.1 2007/02/13 13:11:56 primelars Exp $
28 */

29 public class KeyStrings {
30     
31     final static public String JavaDoc CAKEYPURPOSE_CERTSIGN_STRING = "certSignKey";
32     final static public String JavaDoc CAKEYPURPOSE_CRLSIGN_STRING = "crlSignKey";
33     final static public String JavaDoc CAKEYPURPOSE_KEYENCRYPT_STRING = "keyEncryptKey";
34     final static public String JavaDoc CAKEYPURPOSE_TESTKEY_STRING = "testKey";
35     final static public String JavaDoc CAKEYPURPOSE_DEFAULT_STRING = "defaultKey";
36     final private Map JavaDoc map;
37     final String JavaDoc defaultKeyS;
38     public KeyStrings(Properties JavaDoc properties) {
39         {
40             String JavaDoc tmpS = properties.getProperty(CAKEYPURPOSE_DEFAULT_STRING);
41             defaultKeyS = tmpS!=null ? tmpS.trim() : null;
42         }
43         map = new Hashtable JavaDoc();
44         addKey(CAKEYPURPOSE_CERTSIGN_STRING,
45                SecConst.CAKEYPURPOSE_CERTSIGN,
46                properties);
47         addKey(CAKEYPURPOSE_CRLSIGN_STRING,
48                SecConst.CAKEYPURPOSE_CRLSIGN,
49                properties);
50         addKey(CAKEYPURPOSE_KEYENCRYPT_STRING,
51                SecConst.CAKEYPURPOSE_KEYENCRYPT,
52                properties);
53         addKey(CAKEYPURPOSE_TESTKEY_STRING,
54                 SecConst.CAKEYPURPOSE_KEYTEST,
55                 properties);
56     }
57     private void addKey(String JavaDoc keyS, int keyI,
58                         Properties JavaDoc properties) {
59         String JavaDoc value = properties.getProperty(keyS);
60         if ( value!=null && value.length()>0 ) {
61             value = value.trim();
62             map.put(new Integer JavaDoc(keyI), value);
63         }
64     }
65     public String JavaDoc getString(int key) {
66         String JavaDoc s;
67         try {
68             s = (String JavaDoc)map.get(new Integer JavaDoc(key));
69         } catch(Exception JavaDoc e) {
70             s = null;
71         }
72         if ( s!=null && s.length()>0 )
73             return s;
74         return defaultKeyS;
75     }
76     public String JavaDoc[] getAllStrings() {
77         Set JavaDoc set = new HashSet JavaDoc();
78         set.addAll(map.values());
79         if(defaultKeyS != null){
80           set.add(defaultKeyS);
81         }
82         return (String JavaDoc[])set.toArray(new String JavaDoc[0]);
83     }
84 }
85
Popular Tags