KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > core > tags > CheckPropertyNotEqualsTag


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.core.tags;
21
22 import javax.servlet.jsp.tagext.TagSupport JavaDoc;
23
24 import org.apache.commons.logging.Log;
25 import org.apache.commons.logging.LogFactory;
26
27 import com.sslexplorer.core.CoreUtil;
28 import com.sslexplorer.properties.Property;
29 import com.sslexplorer.properties.impl.systemconfig.SystemConfigKey;
30 import com.sslexplorer.security.LogonControllerFactory;
31 import com.sslexplorer.security.SecurityErrorException;
32 import com.sslexplorer.security.User;
33
34 public class CheckPropertyNotEqualsTag extends TagSupport JavaDoc {
35
36     final static Log log = LogFactory.getLog(CheckPropertyNotEqualsTag.class);
37
38     String JavaDoc propertyName;
39     String JavaDoc propertyValue;
40     boolean regExp;
41     boolean userProfile;
42
43     public CheckPropertyNotEqualsTag() {
44     }
45
46     public int doStartTag() {
47
48         User user = null;
49         try {
50             user = LogonControllerFactory.getInstance().getUser(pageContext.getSession(), null);
51         } catch (SecurityErrorException ex) {
52         }
53         String JavaDoc val;
54         try {
55             if(userProfile) {
56                 val = CoreUtil.getUsersProfileProperty(pageContext.getSession(), propertyName, user);
57             }
58             else {
59                 val = Property.getProperty(new SystemConfigKey(propertyName));
60             }
61             if (regExp) {
62                 if (!val.matches(propertyValue)) {
63                     return EVAL_BODY_INCLUDE;
64                 } else {
65                     return SKIP_BODY;
66                 }
67             } else {
68                 if (!propertyValue.equals(val)) {
69                     return EVAL_BODY_INCLUDE;
70                 } else {
71                     return SKIP_BODY;
72                 }
73             }
74         } catch (Exception JavaDoc e) {
75             log.error("Could not determine property value.", e);
76             return SKIP_BODY;
77         }
78     }
79
80     public void setUserProfile(boolean userProfile) {
81         this.userProfile = userProfile;
82     }
83
84     public void setRegExp(boolean regExp) {
85         this.regExp = regExp;
86     }
87
88     public void setPropertyName(String JavaDoc propertyName) {
89         this.propertyName = propertyName;
90     }
91
92     public void setPropertyValue(String JavaDoc propertyValue) {
93         this.propertyValue = propertyValue;
94     }
95
96     public void release() {
97         super.release();
98         userProfile = false;
99         regExp = false;
100         propertyName = null;
101         propertyValue = null;
102     }
103
104 }
Popular Tags