KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > input > validators > ThemeValidator


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.input.validators;
21
22 import java.io.File JavaDoc;
23 import java.util.Properties JavaDoc;
24
25 import org.apache.commons.logging.Log;
26 import org.apache.commons.logging.LogFactory;
27
28 import com.sslexplorer.boot.CodedException;
29 import com.sslexplorer.boot.PropertyClassManager;
30 import com.sslexplorer.boot.PropertyDefinition;
31 import com.sslexplorer.boot.PropertyValidator;
32 import com.sslexplorer.core.CoreException;
33 import com.sslexplorer.properties.impl.profile.ProfileProperties;
34
35 /**
36  * {@link PropertyValidator} implementation that excepts two <i>Validator
37  * properties</i>.
38  *
39  * @author Brett Smith <a HREF="mailto: brett@3sp.com">&lt;brett@3sp.com&gt;</a>
40  */

41 public class ThemeValidator extends NonBlankStringValidator {
42
43     final static Log log = LogFactory.getLog(ThemeValidator.class);
44
45     /**
46      * Constructor.
47      *
48      */

49     public ThemeValidator() {
50         super();
51     }
52
53     /*
54      * (non-Javadoc)
55      *
56      * @see com.sslexplorer.boot.PropertyValidator#validate(com.sslexplorer.boot.PropertyDefinition,
57      * java.lang.String, java.util.Properties)
58      */

59     public void validate(PropertyDefinition definition, String JavaDoc value, Properties JavaDoc properties) throws CodedException {
60         try {
61             super.validate(definition, value, properties);
62         } catch (CoreException ce) {
63             throw new CoreException(ErrorConstants.ERR_EMPTY_THEME,
64                             ErrorConstants.CATEGORY_NAME,
65                             ErrorConstants.BUNDLE_NAME,
66                             null,
67                             value,
68                             PropertyClassManager.getInstance()
69                                             .getPropertyClass(ProfileProperties.NAME)
70                                             .getDefinition("ui.theme")
71                                             .getDefaultValue(),
72                             null,
73                             null);
74         }
75         File JavaDoc themeDirectory = new File JavaDoc(new File JavaDoc("webapp"), value.replace('/', File.separatorChar).replace('\\', File.separatorChar));
76         if (!themeDirectory.isDirectory()) {
77             throw new CoreException(ErrorConstants.ERR_INVALID_THEME,
78                             ErrorConstants.CATEGORY_NAME,
79                             ErrorConstants.BUNDLE_NAME,
80                             null,
81                             value);
82         }
83     }
84
85 }
86
Popular Tags