1 13 14 package org.ejbca.core.model.ca.catoken; 15 16 import java.util.HashSet ; 17 import java.util.Hashtable ; 18 import java.util.Map ; 19 import java.util.Properties ; 20 import java.util.Set ; 21 22 import org.ejbca.core.model.SecConst; 23 24 25 29 public class KeyStrings { 30 31 final static public String CAKEYPURPOSE_CERTSIGN_STRING = "certSignKey"; 32 final static public String CAKEYPURPOSE_CRLSIGN_STRING = "crlSignKey"; 33 final static public String CAKEYPURPOSE_KEYENCRYPT_STRING = "keyEncryptKey"; 34 final static public String CAKEYPURPOSE_TESTKEY_STRING = "testKey"; 35 final static public String CAKEYPURPOSE_DEFAULT_STRING = "defaultKey"; 36 final private Map map; 37 final String defaultKeyS; 38 public KeyStrings(Properties properties) { 39 { 40 String tmpS = properties.getProperty(CAKEYPURPOSE_DEFAULT_STRING); 41 defaultKeyS = tmpS!=null ? tmpS.trim() : null; 42 } 43 map = new Hashtable (); 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 keyS, int keyI, 58 Properties properties) { 59 String value = properties.getProperty(keyS); 60 if ( value!=null && value.length()>0 ) { 61 value = value.trim(); 62 map.put(new Integer (keyI), value); 63 } 64 } 65 public String getString(int key) { 66 String s; 67 try { 68 s = (String )map.get(new Integer (key)); 69 } catch(Exception e) { 70 s = null; 71 } 72 if ( s!=null && s.length()>0 ) 73 return s; 74 return defaultKeyS; 75 } 76 public String [] getAllStrings() { 77 Set set = new HashSet (); 78 set.addAll(map.values()); 79 if(defaultKeyS != null){ 80 set.add(defaultKeyS); 81 } 82 return (String [])set.toArray(new String [0]); 83 } 84 } 85 | Popular Tags |