1 19 20 package com.sslexplorer.wizard.actions; 21 22 import java.util.ArrayList ; 23 import java.util.Collection ; 24 import java.util.List ; 25 26 import javax.servlet.http.HttpServletRequest ; 27 import javax.servlet.http.HttpServletResponse ; 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 48 public abstract class AbstractWizardPropertiesAction extends AbstractWizardAction { 49 50 51 54 public ActionForward unspecified(ActionMapping mapping, ActionForm form, HttpServletRequest request, 55 HttpServletResponse response) throws Exception { 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 71 protected void rebuildItems(PropertiesForm form, HttpServletRequest request) throws Exception { 72 configureProperties(); 73 AbstractWizardPropertiesForm pf = (AbstractWizardPropertiesForm)form; 74 List <PropertyItem> propertyItems = new ArrayList <PropertyItem>(); 75 List <PropertyDefinitionCategory> categoryDefinitions = new ArrayList <PropertyDefinitionCategory>(); 76 Collection <PropertyDefinitionCategory> sourceCategories = null; 77 int parentCategory = pf.getParentCategory(); 78 for (PropertyClass propertyClass : pf.getPropertyClasses()) { 79 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 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 132 public abstract AbstractPropertyKey createKey(PropertyDefinition definition, PropertiesForm propertiesForm) throws Exception ; 133 134 } 135 | Popular Tags |