KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > wizard > actions > AbstractWizardPropertiesAction


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.wizard.actions;
21
22 import java.util.ArrayList JavaDoc;
23 import java.util.Collection JavaDoc;
24 import java.util.List JavaDoc;
25
26 import javax.servlet.http.HttpServletRequest JavaDoc;
27 import javax.servlet.http.HttpServletResponse JavaDoc;
28
29 import org.apache.struts.action.ActionForm;
30 import org.apache.struts.action.ActionForward;
31 import org.apache.struts.action.ActionMapping;
32
33 import com.sslexplorer.boot.AbstractPropertyKey;
34 import com.sslexplorer.boot.PropertyClass;
35 import com.sslexplorer.boot.PropertyDefinition;
36 import com.sslexplorer.boot.PropertyDefinitionCategory;
37 import com.sslexplorer.properties.Property;
38 import com.sslexplorer.properties.PropertyItem;
39 import com.sslexplorer.properties.forms.PropertiesForm;
40 import com.sslexplorer.wizard.forms.AbstractWizardPropertiesForm;
41
42 /**
43  * <p> Abstract properties action.
44  *
45  * @author James D Robinson <a HREF="mailto:james@3sp.com">&lt;james@3sp.com&gt;</a>
46  *
47  */

48 public abstract class AbstractWizardPropertiesAction extends AbstractWizardAction {
49
50
51     /* (non-Javadoc)
52      * @see com.sslexplorer.wizard.actions.AbstractWizardAction#unspecified(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
53      */

54     public ActionForward unspecified(ActionMapping mapping, ActionForm form, HttpServletRequest JavaDoc request,
55                                      HttpServletResponse JavaDoc response) throws Exception JavaDoc {
56         rebuildItems((PropertiesForm) form, request);
57         ActionForward fwd = super.unspecified(mapping, form, request, response);
58         return fwd;
59     }
60
61     protected void configureProperties() { }
62
63     
64     /**
65      * Rebuild items.
66      *
67      * @param form Properties form
68      * @param request request
69      * @throws Exception
70      */

71     protected void rebuildItems(PropertiesForm form, HttpServletRequest JavaDoc request) throws Exception JavaDoc {
72         configureProperties();
73         AbstractWizardPropertiesForm pf = (AbstractWizardPropertiesForm)form;
74         List JavaDoc<PropertyItem> propertyItems = new ArrayList JavaDoc<PropertyItem>();
75         List JavaDoc<PropertyDefinitionCategory> categoryDefinitions = new ArrayList JavaDoc<PropertyDefinitionCategory>();
76         Collection JavaDoc<PropertyDefinitionCategory> sourceCategories = null;
77         int parentCategory = pf.getParentCategory();
78         for (PropertyClass propertyClass : pf.getPropertyClasses()) {
79             /*
80              * If no parent category is supplied, then assume all categories in
81              * the class, otherwise get all the child categories of the supplied
82              * one
83              */

84             if (parentCategory == 0) {
85                 sourceCategories = propertyClass.getCategories();
86             } else {
87                 PropertyDefinitionCategory category = propertyClass.getPropertyDefinitionCategory(parentCategory);
88                 if (category != null) {
89                     sourceCategories = category.getCategories();
90                 }
91                 else {
92                     sourceCategories = null;
93                 }
94             }
95
96             if (sourceCategories != null) {
97                 for (PropertyDefinitionCategory def : sourceCategories) {
98                     if(def.isEnabled()) {
99                         categoryDefinitions.add(def);
100                         if (pf.getSelectedCategory() == -1) {
101                             pf.setSelectedCategory(def.getId());
102                             pf.setSelectedTab("category." + def.getId());
103                         }
104                         // TODO needs to more be efficient
105
for (PropertyDefinition propDef : propertyClass.getDefinitions()) {
106                             if (!propDef.isHidden() && propDef.getCategory() == def.getId()) {
107                                 propertyItems.add(new PropertyItem(this, request, propDef, Property
108                                                 .getProperty(createKey(propDef, pf))));
109                             }
110                         }
111                         
112                     }
113                 }
114             }
115         }
116         PropertyItem[] items = new PropertyItem[propertyItems.size()];
117         propertyItems.toArray(items);
118         pf.setPropertyItems(items);
119         pf.setCategoryDefinitions(categoryDefinitions);
120     }
121
122     /**
123      * Create a concrete implementation of an {@link AbstractPropertyKey} that
124      * should be used to retrieve the values of properties to be displayed
125      * on this form.
126      *
127      * @param definition definition
128      * @param propertiesForm form
129      * @return key
130      * @throws Exception if key cannot be created
131      */

132     public abstract AbstractPropertyKey createKey(PropertyDefinition definition, PropertiesForm propertiesForm) throws Exception JavaDoc;
133
134 }
135
Popular Tags