KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jmanage > core > util > JManageProperties


1 /**
2  * Copyright 2004-2005 jManage.org
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.jmanage.core.util;
17
18 import org.jmanage.core.util.Loggers;
19 import org.jmanage.core.util.CoreUtils;
20
21 import java.util.Properties JavaDoc;
22 import java.util.logging.Logger JavaDoc;
23 import java.util.logging.Level JavaDoc;
24 import java.io.*;
25
26 /**
27  * JManageProperties provides an interface to read configuration parameters from
28  * jmanage.properties file.
29  *
30  * Date: Dec 4, 2004 2:38:01 AM
31  * @author Shashank Bellary
32  * @author Rakesh Kalra
33  */

34 public class JManageProperties extends Properties JavaDoc{
35
36     private static final Logger JavaDoc logger =
37             Loggers.getLogger(JManageProperties.class);
38
39     private String JavaDoc JMANAGE_PROPERTY_FILE = CoreUtils.getConfigDir() +
40             "/jmanage.properties";
41
42     /* see jmanage.properties for documentation of these properties */
43     public static String JavaDoc LOGIN_MAX_ATTEMPTS = "login.maxAttempts";
44     private static String JavaDoc JMANAGE_HASH_ALGORITHM = "jmanage.hash.algorithm";
45
46     private static String JavaDoc JETTY_STOP_PORT = "STOP.PORT";
47
48     /* CLI properties */
49     private static String JavaDoc JMANAGE_URL = "jmanage.url";
50     private static String JavaDoc CLI_SSL_IGNORE_BAD_SSL_CERT =
51             "jmanage.cli.ssl.ignoreBadSSLCertificate";
52     private static String JavaDoc CLI_SSL_TRUST_STORE_PWD =
53             "jmanage.cli.ssl.trustStorePassword";
54
55     /*Email properties*/
56     private static String JavaDoc ALERT_EMAIL_FROM_NAME = "alert.email.from.name";
57     private static String JavaDoc EMAIL_HOST = "email.host";
58     private static String JavaDoc ALERT_EMAIL_FROM_EMAIL = "alert.email.from.email";
59
60     /* display properties */
61     private static String JavaDoc DISPLAY_MBEAN_CANONICAL_NAME =
62             "jmanage.objectName.displayCanonicalName";
63
64     /* HTML input type for boolean attributes */
65     private static String JavaDoc BOOLEAN_INPUT_TYPE = "jmanage.html.booleanInputType";
66
67     /* The only instance */
68     private static JManageProperties jManageProperties = new JManageProperties();
69
70     /**
71      * The only constructor, which is private.
72      *
73      * TODO: I think we should remove this ctor and initialize in static block.
74      * All get methods on this class can be static - rk
75      */

76     private JManageProperties(){
77       super();
78       try{
79         InputStream property =
80                 new FileInputStream(JMANAGE_PROPERTY_FILE);
81         load(property);
82       }catch(Throwable JavaDoc e){
83           logger.log(Level.WARNING, "Error reading " +
84                   JMANAGE_PROPERTY_FILE + ". error: " + e.getMessage());
85       }
86     }
87
88     /**
89      * Gets an instance of the JManageProperties class. This is the only way
90      * that any class can get and access a JManageProperties object, since the
91      * constructor is private
92      **/

93     public static JManageProperties getInstance() {
94       return jManageProperties;
95     }
96
97     public static String JavaDoc getJManageURL(){
98         return jManageProperties.getProperty(JMANAGE_URL);
99     }
100
101     public static String JavaDoc getHashAlgorithm(){
102         return jManageProperties.getProperty(JMANAGE_HASH_ALGORITHM, "SHA-1");
103     }
104
105     public static String JavaDoc getStopPort(){
106         return jManageProperties.getProperty(JETTY_STOP_PORT, "9099");
107     }
108
109     public static boolean isIgnoreBadSSLCertificate(){
110         String JavaDoc value =
111                 jManageProperties.getProperty(CLI_SSL_IGNORE_BAD_SSL_CERT, "false");
112         return value.equalsIgnoreCase("true");
113     }
114
115     public static String JavaDoc getSSLTrustStorePassword(){
116         return jManageProperties.getProperty(CLI_SSL_TRUST_STORE_PWD, "changeit");
117     }
118
119     public void storeMaxLoginAttempts(int maxLoginAttempt){
120                 this.setProperty(LOGIN_MAX_ATTEMPTS,
121                 Integer.toString(maxLoginAttempt));
122         try{
123            FileOutputStream fileOutputStream =
124                  new FileOutputStream(JMANAGE_PROPERTY_FILE);
125             this.store(fileOutputStream, null);
126         } catch( Exception JavaDoc e){
127             throw new RuntimeException JavaDoc(e);
128         }
129     }
130
131     public static String JavaDoc getAlertEmailFromName(){
132         return jManageProperties.getProperty(ALERT_EMAIL_FROM_NAME);
133     }
134     public static String JavaDoc getEmailHost(){
135         return jManageProperties.getProperty(EMAIL_HOST);
136     }
137     public static String JavaDoc getAlertEmailFrom(){
138         return jManageProperties.getProperty(ALERT_EMAIL_FROM_EMAIL);
139     }
140     public static boolean isBooleanInputTypeRadio(){
141         return "radio".equals(jManageProperties.getProperty(BOOLEAN_INPUT_TYPE));
142     }
143     public static boolean isBooleanInputTypeCheckbox(){
144         return "checkbox".equals(jManageProperties.getProperty(BOOLEAN_INPUT_TYPE));
145     }
146     public static boolean isBooleanInputTypeSelect() {
147         return "select".equals(jManageProperties.getProperty(BOOLEAN_INPUT_TYPE));
148     }
149
150     /**
151      * Indicates if the canonical name of the mbean should be displayed
152      * @return
153      */

154     public static boolean isDisplayCanonicalName(){
155         return "true".equals(
156                 jManageProperties.getProperty(DISPLAY_MBEAN_CANONICAL_NAME));
157     }
158 }
159
Popular Tags