KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > properties > attributes > wizards > actions > AttributeDefinitionOptionsAction


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.attributes.wizards.actions;
21
22 import javax.servlet.http.HttpServletRequest JavaDoc;
23 import javax.servlet.http.HttpServletResponse JavaDoc;
24
25 import org.apache.struts.action.ActionForm;
26 import org.apache.struts.action.ActionForward;
27 import org.apache.struts.action.ActionMapping;
28
29 import com.sslexplorer.boot.PropertyDefinition;
30 import com.sslexplorer.properties.attributes.AttributeDefinition;
31 import com.sslexplorer.properties.attributes.wizards.forms.AttributeDefinitionOptionsForm;
32 import com.sslexplorer.security.SessionInfo;
33 import com.sslexplorer.wizard.actions.AbstractWizardAction;
34
35 /**
36  * Additional attribute definition options. These may be edited after
37  * the attribute definition has been created.
38  *
39  * @author brett
40  */

41 public class AttributeDefinitionOptionsAction extends AbstractWizardAction {
42
43     /**
44      * Label. See {@link AttributeDefinition#getLabel()}.
45      */

46     public final static String JavaDoc ATTR_LABEL = "label";
47     
48     /**
49      * Category. See {@link PropertyDefinition#getCategory()}.
50      */

51     public final static String JavaDoc ATTR_CATEGORY = "category";
52     
53     /**
54      * Type meta data. See {@link PropertyDefinition#getTypeMeta()}.
55      */

56     public final static String JavaDoc ATTR_TYPE_META = "typeMeta";
57     
58     /**
59      * Type. See {@link AttributeDefinition#getType()}.
60      */

61     public final static String JavaDoc ATTR_TYPE = "type";
62     
63     /**
64      * Validation string. See {@link AttributeDefinition#getValidationString()}
65      */

66     public final static String JavaDoc ATTR_VALIDATION_STRING = "validationString";
67     
68     /**
69      * Default value. Category. See {@link PropertyDefinition#getDefaultValue()}.
70      */

71     public final static String JavaDoc ATTR_DEFAULT_VALUE = "defaultValue";
72     
73     /**
74      * Visibility. See {@link AttributeDefinition#getVisibility()}.
75      */

76     public final static String JavaDoc ATTR_VISIBILITY = "visibility";
77     
78     /**
79      * Sort order. See {@link PropertyDefinition#getSortOrder()}.
80      */

81     public final static String JavaDoc ATTR_SORT_ORDER = "sortOrder";
82
83     /**
84      * Constructor
85      */

86     public AttributeDefinitionOptionsAction() {
87         super();
88     }
89
90     public int getNavigationContext(ActionMapping mapping, ActionForm form, HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) {
91         return SessionInfo.MANAGEMENT_CONSOLE_CONTEXT;
92     }
93
94     /**
95      * Type of attribute has changed, so choose a default validator
96      *
97      * @param mapping mapping
98      * @param form form
99      * @param request request
100      * @param response response
101      * @return forward forward
102      * @throws Exception on any error
103      */

104     public ActionForward typeChanged(ActionMapping mapping, ActionForm form, HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) throws Exception JavaDoc {
105         
106         // Set a default validator when type changes
107
AttributeDefinitionOptionsForm adof = (AttributeDefinitionOptionsForm)form;
108         if(adof.getType() == PropertyDefinition.TYPE_COLOR ||
109                         adof.getType() == PropertyDefinition.TYPE_LIST ||
110                         adof.getType() == PropertyDefinition.TYPE_MULTI_ENTRY_LIST ||
111                         adof.getType() == PropertyDefinition.TYPE_MULTI_SELECT_LIST ||
112                         adof.getType() == PropertyDefinition.TYPE_TIME_IN_MS) {
113             getWizardSequence(request).putAttribute(AttributeDefinitionOptionsAction.ATTR_VALIDATION_STRING, "");
114         }
115         else if(adof.getType() == PropertyDefinition.TYPE_BOOLEAN ) {
116             getWizardSequence(request).putAttribute(AttributeDefinitionOptionsAction.ATTR_VALIDATION_STRING, "com.sslexplorer.input.validators.BooleanValidator");
117         }
118         else if(adof.getType() == PropertyDefinition.TYPE_INTEGER) {
119             getWizardSequence(request).putAttribute(AttributeDefinitionOptionsAction.ATTR_VALIDATION_STRING, "com.sslexplorer.input.validators.IntegerValidator(minValue=0,maxValue=9999999)");
120         }
121         else if(adof.getType() == PropertyDefinition.TYPE_STRING) {
122             getWizardSequence(request).putAttribute(AttributeDefinitionOptionsAction.ATTR_VALIDATION_STRING, "com.sslexplorer.input.validators.StringValidator(minLength=0,maxLength=30,trim=true,regExp=,pattern=)");
123         }
124         else if(adof.getType() == PropertyDefinition.TYPE_TEXT_AREA) {
125             getWizardSequence(request).putAttribute(AttributeDefinitionOptionsAction.ATTR_VALIDATION_STRING, "com.sslexplorer.input.validators.StringValidator(minLength=0,maxLength=255,trim=true,regExp=,pattern=)");
126         }
127         
128         getWizardSequence(request).putAttribute(AttributeDefinitionOptionsAction.ATTR_TYPE, new Integer JavaDoc(adof.getType()));
129         
130         return super.unspecified(mapping, form, request, response);
131     }
132 }
133
Popular Tags