KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > infoglue > cms > applications > workflowtool > function > SimpleCategoryProvider


1 /* ===============================================================================
2 *
3 * Part of the InfoGlue Content Management Platform (www.infoglue.org)
4 *
5 * ===============================================================================
6 *
7 * Copyright (C)
8 *
9 * This program is free software; you can redistribute it and/or modify it under
10 * the terms of the GNU General Public License version 2, as published by the
11 * Free Software Foundation. See the file LICENSE.html for more information.
12 *
13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY, including the implied warranty of MERCHANTABILITY or FITNESS
15 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along with
18 * this program; if not, write to the Free Software Foundation, Inc. / 59 Temple
19 * Place, Suite 330 / Boston, MA 02111-1307 / USA.
20 *
21 * ===============================================================================
22 */

23 package org.infoglue.cms.applications.workflowtool.function;
24
25 import java.util.ArrayList JavaDoc;
26 import java.util.Iterator JavaDoc;
27 import java.util.List JavaDoc;
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 /**
35  *
36  */

37 public class SimpleCategoryProvider extends CategoryProvider
38 {
39     /**
40      *
41      */

42     private static final String JavaDoc CATEGORY_PROPERTYSET_PREFIX = "category_";
43
44     /**
45      *
46      */

47     private static final String JavaDoc NAME_ARGUMENT = "attributeName";
48
49     /**
50      *
51      */

52     private static final String JavaDoc ROOT_ARGUMENT = "rootCategory";
53
54     /**
55      *
56      */

57     private CategoryVO rootCategory;
58
59     /**
60      *
61      */

62     private String JavaDoc attributeName;
63         
64     
65     
66     /**
67      *
68      */

69     public SimpleCategoryProvider()
70     {
71         super();
72     }
73
74     /**
75      *
76      */

77     protected void execute() throws WorkflowException
78     {
79         cleanPropertySet();
80         populate();
81     }
82     
83     /**
84      *
85      */

86     private void populate() throws WorkflowException
87     {
88         List JavaDoc result = new ArrayList JavaDoc();
89         for(Iterator JavaDoc i = rootCategory.getChildren().iterator(); i.hasNext();)
90         {
91             final CategoryVO categoryVO = (CategoryVO) i.next();
92             final String JavaDoc key = getCategoryKey(categoryVO);
93             final String JavaDoc 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     /**
104      *
105      */

106     private void cleanPropertySet() throws WorkflowException
107     {
108         removeFromPropertySet(getBaseKey(), true);
109     }
110     
111     /**
112      * Method used for initializing the function; will be called before <code>execute</code> is called.
113      * <p><strong>Note</strong>! You must call <code>super.initialize()</code> first.</p>
114      *
115      * @throws WorkflowException if an error occurs during the initialization.
116      */

117     protected void initialize() throws WorkflowException
118     {
119         super.initialize();
120         attributeName = getArgument(NAME_ARGUMENT);
121         rootCategory = getRootCategory(getArgument(ROOT_ARGUMENT));
122     }
123     
124     /**
125      *
126      */

127     private CategoryVO getRootCategory(final String JavaDoc 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 JavaDoc e)
135         {
136             e.printStackTrace();
137             throw new WorkflowException("SimpleCategoryProvider.getRootCategory() : " + e);
138         }
139     }
140
141     /**
142      *
143      */

144     private String JavaDoc getBaseKey()
145     {
146         return CATEGORY_PROPERTYSET_PREFIX + attributeName + "_";
147     }
148     
149     /**
150      *
151      */

152     private String JavaDoc getCategoryKey(final CategoryVO categoryVO)
153     {
154         return getBaseKey() + categoryVO.getName();
155     }
156 }
157
Popular Tags