KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > properties > PersistentSettings


1 package com.sslexplorer.properties;
2
3 import com.sslexplorer.boot.PropertyClassManager;
4 import com.sslexplorer.boot.PropertyDefinition;
5 import com.sslexplorer.properties.attributes.AttributeDefinition;
6 import com.sslexplorer.properties.attributes.DefaultAttributeDefinition;
7 import com.sslexplorer.properties.impl.userattributes.UserAttributeKey;
8 import com.sslexplorer.properties.impl.userattributes.UserAttributes;
9 import com.sslexplorer.security.SessionInfo;
10
11 public class PersistentSettings {
12
13     public static int getIntValue(SessionInfo session, String JavaDoc key, int defaultValue) {
14         
15         UserAttributeKey attr = new UserAttributeKey(session.getUser(), key);
16         
17         checkDefinition(attr, PropertyDefinition.TYPE_INTEGER, String.valueOf(defaultValue));
18         
19         return Property.getPropertyInt(new UserAttributeKey(session.getUser(), key));
20         
21     }
22
23     public static String JavaDoc getValue(SessionInfo session, String JavaDoc key, String JavaDoc defaultValue) {
24         
25         UserAttributeKey attr = new UserAttributeKey(session.getUser(), key);
26         
27         checkDefinition(attr, PropertyDefinition.TYPE_STRING, String.valueOf(defaultValue));
28         
29         return Property.getProperty(new UserAttributeKey(session.getUser(), key));
30         
31     }
32     private static void checkDefinition(UserAttributeKey attr, int type, String JavaDoc defaultValue) {
33         if(Property.getDefinition(attr)==null) {
34             
35             DefaultAttributeDefinition def = new DefaultAttributeDefinition(type,
36                     attr.getName(),
37                     "",
38                     90000,
39                     "",
40                     String.valueOf(defaultValue),
41                     AttributeDefinition.USER_OVERRIDABLE_ATTRIBUTE,
42                     10,
43                     "",
44                     true,
45                     "",
46                     "",
47                     true,
48                     false,
49                     null);
50
51             PropertyClassManager.getInstance().getPropertyClass(UserAttributes.NAME).registerPropertyDefinition(def);
52         }
53     }
54     
55     public static void setValue(SessionInfo session, String JavaDoc key, String JavaDoc actualValue, String JavaDoc defaultValue) {
56         
57         UserAttributeKey attr = new UserAttributeKey(session.getUser(), key);
58         
59         checkDefinition(attr, PropertyDefinition.TYPE_STRING, String.valueOf(defaultValue));
60         
61         Property.setProperty(new UserAttributeKey(session.getUser(), key), actualValue, session);
62     }
63
64
65     public static void setIntValue(SessionInfo session, String JavaDoc key, int actualValue, int defaultValue) {
66         
67         UserAttributeKey attr = new UserAttributeKey(session.getUser(), key);
68         
69         checkDefinition(attr, PropertyDefinition.TYPE_INTEGER, String.valueOf(defaultValue));
70         
71         Property.setProperty(new UserAttributeKey(session.getUser(), key), actualValue, session);
72     }
73 }
74
Popular Tags