Subversion Repositories bacoAlunos

Rev

Rev 1306 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 fvelez 1
package openldap;
2
 
3
import jomm.utils.StringComparator;
4
import org.apache.log4j.Logger;
5
 
6
import java.util.*;
7
 
8
 
9
/**
10
 * Created by IntelliJ IDEA.
11
 * User: User
12
 * Date: 25/Jan/2005
13
 * Time: 12:43:54
14
 * To change this template use File | Settings | File Templates.
15
 */
16
 
17
public class LdapProperties{
18
 
19
    private static final 1.5.0/docs/api/java/util/logging/Logger.html">Logger logger = 1.5.0/docs/api/java/util/logging/Logger.html">Logger.getLogger(LdapProperties.class);
20
    private static 1.5.0/docs/api/java/util/Properties.html">Properties properties = new 1.5.0/docs/api/java/util/Properties.html">Properties();
21
 
22
    static {
23
 
24
        try {
25
            properties.load(LdapProperties.class.getResourceAsStream("/ldap.properties"));
26
        } catch (1.5.0/docs/api/java/lang/Exception.html">Exception ex) {
27
            throw new 1.5.0/docs/api/java/lang/ExceptionInInitializerError.html">ExceptionInInitializerError(ex);
28
        }
29
    }
30
 
31
    public static 5+0%2Fdocs%2Fapi+Object">Object getPlugin(1.5.0/docs/api/java/lang/Class.html">Class iface) {
32
 
33
        1.5.0/docs/api/java/lang/String.html">String implName = properties.getProperty(iface.getName());
34
        if (implName == null) {
35
            throw new 1.5.0/docs/api/java/lang/RuntimeException.html">RuntimeException("implementation not specified for " +
36
                    iface.getName() + " in AuthenticationPluginFactory propeties.");
37
        }
38
        try {
39
            return 1.5.0/docs/api/java/lang/Class.html">Class.forName(implName).newInstance();
40
        } catch (1.5.0/docs/api/java/lang/Exception.html">Exception ex) {
41
            throw new 1.5.0/docs/api/java/lang/RuntimeException.html">RuntimeException("factory unable to construct instance of " +
42
                    iface.getName());
43
        }
44
    }
45
 
46
    public static 5+0%2Fdocs%2Fapi+Object">Object getPlugin(1.5.0/docs/api/java/lang/String.html">String plugin) {
47
 
48
        1.5.0/docs/api/java/lang/String.html">String implName = properties.getProperty(plugin);
49
        if (implName == null) {
50
            throw new 1.5.0/docs/api/java/lang/RuntimeException.html">RuntimeException("implementation not specified for " +
51
                    plugin + " in AuthenticationPluginFactory propeties.");
52
        }
53
        try {
54
            return 1.5.0/docs/api/java/lang/Class.html">Class.forName(implName).newInstance();
55
        } catch (1.5.0/docs/api/java/lang/Exception.html">Exception ex) {
56
            throw new 1.5.0/docs/api/java/lang/RuntimeException.html">RuntimeException("factory unable to construct instance of " +
57
                    plugin);
58
        }
59
    }
60
 
61
    public static 1.5.0/docs/api/java/lang/String.html">String getProperty(1.5.0/docs/api/java/lang/String.html">String key){return properties.getProperty(key);}
62
 
63
    public static int getIntProperty(1.5.0/docs/api/java/lang/String.html">String property)
64
    {
65
 
66
        1.5.0/docs/api/java/lang/String.html">String stringValue = properties.getProperty(property);
67
        int intValue = 0;
68
 
69
        if (stringValue != null)
70
        {
71
            try
72
            {
73
                intValue = new 1.5.0/docs/api/java/lang/Integer.html">Integer(stringValue).intValue();
74
            }
75
            catch (1.5.0/docs/api/java/lang/NumberFormatException.html">NumberFormatException e)
76
            {
77
                logger.warn("Warning: Number format exception in property: " + property);
78
            }
79
        }
80
 
81
        return intValue;
82
    }
83
    public static long getLongProperty(1.5.0/docs/api/java/lang/String.html">String property)
84
    {
85
 
86
        1.5.0/docs/api/java/lang/String.html">String stringValue = properties.getProperty(property);
87
        long longValue = 0;
88
 
89
        if (stringValue != null)
90
        {
91
            try
92
            {
93
                longValue = new 1.5.0/docs/api/java/lang/Long.html">Long(stringValue).intValue();
94
            }
95
            catch (1.5.0/docs/api/java/lang/NumberFormatException.html">NumberFormatException e)
96
            {
97
                logger.warn("Warning: Number format exception in property: " + property);
98
            }
99
        }
100
 
101
        return longValue;
102
    }
103
 
104
    public static float getFloatProperty(1.5.0/docs/api/java/lang/String.html">String property)
105
    {
106
 
107
        1.5.0/docs/api/java/lang/String.html">String stringValue = properties.getProperty(property);
108
        float floatValue = 0;
109
 
110
        if (stringValue != null)
111
        {
112
            try
113
            {
114
                floatValue = new 1.5.0/docs/api/java/lang/Float.html">Float(stringValue).floatValue();
115
            }
116
            catch (1.5.0/docs/api/java/lang/NumberFormatException.html">NumberFormatException e)
117
            {
118
                logger.warn("Warning: Number format exception in property: " + property);
119
            }
120
        }
121
 
122
        return floatValue;
123
    }
124
 
125
    public static double getDoubleProperty(1.5.0/docs/api/java/lang/String.html">String property)
126
    {
127
 
128
        1.5.0/docs/api/java/lang/String.html">String stringValue = properties.getProperty(property);
129
        double doubleValue = 0;
130
 
131
        if (stringValue != null)
132
        {
133
            try
134
            {
135
                doubleValue = new 1.5.0/docs/api/java/lang/Float.html">Float(stringValue).doubleValue();
136
            }
137
            catch (1.5.0/docs/api/java/lang/NumberFormatException.html">NumberFormatException e)
138
            {
139
                logger.warn("Warning: Number format exception in property: " + property);
140
            }
141
        }
142
 
143
        return doubleValue;
144
    }
145
    public static boolean getBooleanProperty(1.5.0/docs/api/java/lang/String.html">String property)
146
    {
147
 
148
        1.5.0/docs/api/java/lang/String.html">String stringValue = properties.getProperty(property);
149
        boolean boolValue = false;
150
 
151
        if (stringValue != null)
152
        {
153
            if (stringValue.equalsIgnoreCase("true"))
154
            {
155
                boolValue = true;
156
            }
157
            else if (stringValue.equalsIgnoreCase("yes"))
158
            {
159
                boolValue = true;
160
            }
161
        }
162
 
163
        return boolValue;
164
    }
165
 
166
 
167
       /***********************************************************
168
      * Returns a list of all property names hat starts with the given
169
      * prefix
170
      *
171
      ************************************************************/
172
     public static 5+0%2Fdocs%2Fapi+List">List getListProperties(1.5.0/docs/api/java/lang/String.html">String propertyPrefix){
173
 
174
        5+0%2Fdocs%2Fapi+List">List props = new 1.5.0/docs/api/java/util/ArrayList.html">ArrayList();
175
         1.5.0/docs/api/java/util/Enumeration.html">Enumeration enumE;
176
         try{
177
             enumE = properties.propertyNames();
178
         }
179
         catch(1.5.0/docs/api/java/lang/Exception.html">Exception e){
180
             logger.fatal("cant load properties");
181
             return null;
182
         }
183
 
184
         while (enumE.hasMoreElements()) {
185
            1.5.0/docs/api/java/lang/String.html">String propertyName = (1.5.0/docs/api/java/lang/String.html">String)enumE.nextElement();
186
            if (propertyName.startsWith(propertyPrefix)) {
187
                props.add(propertyName);
188
            }
189
         }
190
         1.5.0/docs/api/java/util/Collections.html">Collections.sort(props,StringComparator.getInstance());
191
         return props;
192
     }
193
 
194
     public static 5+0%2Fdocs%2Fapi+List">List getListValuesProperties(1.5.0/docs/api/java/lang/String.html">String propertyPrefix){
195
 
196
        5+0%2Fdocs%2Fapi+List">List props = new 1.5.0/docs/api/java/util/ArrayList.html">ArrayList();
197
         1.5.0/docs/api/java/util/Enumeration.html">Enumeration enumE;
198
         try{
199
             enumE = properties.propertyNames();
200
         }
201
         catch(1.5.0/docs/api/java/lang/Exception.html">Exception e){
202
             logger.fatal("cant load properties");
203
             return null;
204
         }
205
         while (enumE.hasMoreElements()) {
206
            1.5.0/docs/api/java/lang/String.html">String propertyName = (1.5.0/docs/api/java/lang/String.html">String)enumE.nextElement();
207
            if (propertyName.startsWith(propertyPrefix)) {
208
                props.add(getProperty(propertyName));
209
            }
210
         }
211
         1.5.0/docs/api/java/util/Collections.html">Collections.sort(props,StringComparator.getInstance());
212
         return props;
213
     }
214
 
215
}