1 23 package org.infoglue.cms.applications.workflowtool.function; 24 25 import java.util.ArrayList ; 26 import java.util.Iterator ; 27 import java.util.List ; 28 29 import org.infoglue.cms.controllers.kernel.impl.simple.CategoryController; 30 import org.infoglue.cms.entities.management.CategoryVO; 31 32 import com.opensymphony.workflow.WorkflowException; 33 34 37 public class SimpleCategoryProvider extends CategoryProvider 38 { 39 42 private static final String CATEGORY_PROPERTYSET_PREFIX = "category_"; 43 44 47 private static final String NAME_ARGUMENT = "attributeName"; 48 49 52 private static final String ROOT_ARGUMENT = "rootCategory"; 53 54 57 private CategoryVO rootCategory; 58 59 62 private String attributeName; 63 64 65 66 69 public SimpleCategoryProvider() 70 { 71 super(); 72 } 73 74 77 protected void execute() throws WorkflowException 78 { 79 cleanPropertySet(); 80 populate(); 81 } 82 83 86 private void populate() throws WorkflowException 87 { 88 List result = new ArrayList (); 89 for(Iterator i = rootCategory.getChildren().iterator(); i.hasNext();) 90 { 91 final CategoryVO categoryVO = (CategoryVO) i.next(); 92 final String key = getCategoryKey(categoryVO); 93 final String value = getRequestParameter(key); 94 if(parameterExists(key) && value != null && value.equals("1")) 95 { 96 setPropertySetDataString(getCategoryKey(categoryVO), "1"); 97 result.add(categoryVO); 98 } 99 } 100 getCategories().put(attributeName, result); 101 } 102 103 106 private void cleanPropertySet() throws WorkflowException 107 { 108 removeFromPropertySet(getBaseKey(), true); 109 } 110 111 117 protected void initialize() throws WorkflowException 118 { 119 super.initialize(); 120 attributeName = getArgument(NAME_ARGUMENT); 121 rootCategory = getRootCategory(getArgument(ROOT_ARGUMENT)); 122 } 123 124 127 private CategoryVO getRootCategory(final String path) throws WorkflowException 128 { 129 try 130 { 131 final CategoryVO categoryVO = CategoryController.getController().findByPath(path, getDatabase()); 132 return CategoryController.getController().findWithChildren(categoryVO.getId(), getDatabase()); 133 } 134 catch(Exception e) 135 { 136 e.printStackTrace(); 137 throw new WorkflowException("SimpleCategoryProvider.getRootCategory() : " + e); 138 } 139 } 140 141 144 private String getBaseKey() 145 { 146 return CATEGORY_PROPERTYSET_PREFIX + attributeName + "_"; 147 } 148 149 152 private String getCategoryKey(final CategoryVO categoryVO) 153 { 154 return getBaseKey() + categoryVO.getName(); 155 } 156 } 157 | Popular Tags |