KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > properties > impl > systemconfig > SystemConfiguration


1 /*
2  * SSL-Explorer
3  *
4  * Copyright (C) 2003-2006 3SP LTD. All Rights Reserved
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */

19             
20 package com.sslexplorer.properties.impl.systemconfig;
21
22 import java.io.IOException JavaDoc;
23
24 import org.apache.commons.logging.Log;
25 import org.apache.commons.logging.LogFactory;
26 import org.jdom.JDOMException;
27
28 import com.sslexplorer.boot.AbstractPropertyKey;
29 import com.sslexplorer.boot.AbstractXMLDefinedPropertyClass;
30 import com.sslexplorer.boot.ContextHolder;
31 import com.sslexplorer.boot.PropertyClass;
32 import com.sslexplorer.boot.PropertyDefinition;
33 import com.sslexplorer.core.CoreServlet;
34 import com.sslexplorer.properties.ProfilesFactory;
35
36 /**
37  * {@link PropertyClass} implementation suitable for system configuration
38  * properties
39  *
40  * @author Brett Smith <a HREF="mailto: brett@3sp.com">&lt;brett@3sp.com&gt;</a>
41  */

42 public class SystemConfiguration extends AbstractXMLDefinedPropertyClass {
43
44     final static Log log = LogFactory.getLog(SystemConfiguration.class);
45
46     /**
47      * Constant for name
48      */

49     public final static String JavaDoc NAME = "systemConfig";
50
51     /**
52      * Constructor.
53      *
54      * @throws IOException
55      * @throws JDOMException
56      */

57     public SystemConfiguration() throws IOException JavaDoc, JDOMException {
58         super(NAME, false);
59     }
60
61     /*
62      * (non-Javadoc)
63      *
64      * @see com.sslexplorer.properties.PropertyType#retrieve(com.sslexplorer.properties.PropertyKey)
65      */

66     public String JavaDoc retrievePropertyImpl(AbstractPropertyKey key) throws IllegalArgumentException JavaDoc {
67         PropertyDefinition def = getDefinition(key.getName());
68         try {
69             String JavaDoc val = ProfilesFactory.getInstance().retrieveGenericProperty(
70                 key.getName(), "", "0", "0", "");
71             if (val == null) {
72                 val = def.getDefaultValue();
73             } else {
74                 if (def.getType() == PropertyDefinition.TYPE_PASSWORD) {
75                     try {
76                         val = ContextHolder.getContext().deobfuscatePassword(val);
77                     } catch (Throwable JavaDoc t) {
78                         log.warn(
79                             "Password property " + def.getName() + " could not be decoded. It has been result to the default.", t);
80                     }
81                 }
82             }
83             return val;
84         } catch (Exception JavaDoc e) {
85             log.error("Failed to retrieve property.", e);
86         }
87         return null;
88     }
89
90     public String JavaDoc storePropertyImpl(AbstractPropertyKey key, String JavaDoc value) throws IllegalArgumentException JavaDoc {
91         PropertyDefinition def = getDefinition(key.getName());
92
93         String JavaDoc oldValue = retrieveProperty(key);
94
95         if (def.getType() == PropertyDefinition.TYPE_PASSWORD) {
96             try {
97                 value = ContextHolder.getContext().obfuscatePassword(value);
98             } catch (Throwable JavaDoc t) {
99                 log.warn("Password property " + def.getName() + " could not be encoded.", t);
100             }
101         }
102         try {
103             ProfilesFactory.getInstance().storeGenericProperty(
104                 key.getName(), "", "0", "0", "", value);
105         } catch (Exception JavaDoc e) {
106             log.error("Could not store properties in database.");
107         }
108         return oldValue;
109     }
110 }
111
Popular Tags