KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > fr > jayasoft > ivy > util > EncrytedProperties


1 package fr.jayasoft.ivy.util;
2
3 import java.util.ArrayList JavaDoc;
4 import java.util.Collection JavaDoc;
5 import java.util.List JavaDoc;
6 import java.util.Properties JavaDoc;
7
8 /**
9  * An implementation of Properties which stores the values encrypted.
10  *
11  * The use is transparent from the user point of view (use as any Properties instance),
12  * except that get, put and putAll do not handle encryption/decryption.
13  *
14  * This means that get returns the encrypted value, while put and putAll
15  * puts given values without encrypting them.
16  *
17  * It this thus recommended to void using them, use setProperty and getProperty instead.
18  *
19  * @author Xavier Hanin
20  *
21  */

22 public class EncrytedProperties extends Properties JavaDoc {
23     
24     public EncrytedProperties() {
25         super();
26     }
27     
28     public synchronized Object JavaDoc setProperty(String JavaDoc key, String JavaDoc value) {
29         return StringUtils.decrypt((String JavaDoc)super.setProperty(key, StringUtils.encrypt(value)));
30     }
31     public String JavaDoc getProperty(String JavaDoc key) {
32         return StringUtils.decrypt(super.getProperty(key));
33     }
34     public String JavaDoc getProperty(String JavaDoc key, String JavaDoc defaultValue) {
35         return StringUtils.decrypt(super.getProperty(key, StringUtils.encrypt(defaultValue)));
36     }
37     public boolean containsValue(Object JavaDoc value) {
38         return super.containsValue(StringUtils.encrypt((String JavaDoc)value));
39     }
40     public synchronized boolean contains(Object JavaDoc value) {
41         return super.contains(StringUtils.encrypt((String JavaDoc)value));
42     }
43     public Collection JavaDoc values() {
44         List JavaDoc ret = new ArrayList JavaDoc(super.values());
45         for (int i=0; i<ret.size(); i++) {
46             ret.set(i, StringUtils.decrypt((String JavaDoc)ret.get(i)));
47         }
48         return ret;
49     }
50 }
51
Popular Tags