KickJava   Java API By Example, From Geeks To Geeks.

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


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.Iterator JavaDoc;
26 import java.util.List JavaDoc;
27
28 import org.apache.log4j.Logger;
29 import org.infoglue.cms.applications.workflowtool.util.ContentValues;
30 import org.infoglue.cms.applications.workflowtool.util.ContentVersionValues;
31 import org.infoglue.cms.controllers.kernel.impl.simple.ContentTypeDefinitionController;
32 import org.infoglue.cms.entities.management.ContentTypeAttribute;
33 import org.infoglue.cms.entities.management.ContentTypeDefinitionVO;
34
35 import com.opensymphony.workflow.WorkflowException;
36
37 /**
38  *
39  */

40 public class ContentPopulator extends InfoglueFunction
41 {
42     private final static Logger logger = Logger.getLogger(ContentPopulator.class.getName());
43
44     /**
45      *
46      */

47     public static final String JavaDoc CONTENT_PROPERTYSET_PREFIX = "content_";
48
49     /**
50      *
51      */

52     public static final String JavaDoc CONTENT_VERSION_PROPERTYSET_PREFIX = "contentversion_";
53     
54     /**
55      *
56      */

57     public static final String JavaDoc CONTENT_VALUES_PARAMETER = "contentValues";
58
59     /**
60      *
61      */

62     public static final String JavaDoc CONTENT_VERSION_VALUES_PARAMETER = "contentVersionValues";
63     
64     /**
65      *
66      */

67     private ContentTypeDefinitionVO contentTypeDefinitionVO;
68
69     
70     
71     /**
72      *
73      */

74     protected void execute() throws WorkflowException
75     {
76         populateContentValues();
77         populateContentVersionValues();
78     }
79
80     /**
81      *
82      */

83     protected void initialize() throws WorkflowException
84     {
85         super.initialize();
86         contentTypeDefinitionVO = (ContentTypeDefinitionVO) getParameter(ContentTypeDefinitionProvider.CONTENT_TYPE_DEFINITION_PARAMETER);
87     }
88     
89     /**
90      *
91      */

92     protected void populateContentValues() throws WorkflowException
93     {
94         final ContentValues result = new ContentValues();
95         
96         result.setName(populate(CONTENT_PROPERTYSET_PREFIX + ContentValues.NAME));
97         result.setPublishDateTime(populate(CONTENT_PROPERTYSET_PREFIX + ContentValues.PUBLISH_DATE_TIME));
98         result.setExpireDateTime(populate(CONTENT_PROPERTYSET_PREFIX + ContentValues.EXPIRE_DATE_TIME));
99
100         setParameter(CONTENT_VALUES_PARAMETER, result);
101     }
102     
103     /**
104      *
105      */

106     protected void populateContentVersionValues() throws WorkflowException
107     {
108         final ContentVersionValues result = new ContentVersionValues();
109         final List JavaDoc contentTypeAttributes = getContentTypeAttributes();
110         for(Iterator JavaDoc i=contentTypeAttributes.iterator(); i.hasNext(); )
111         {
112             final ContentTypeAttribute attribute = (ContentTypeAttribute) i.next();
113             result.set(attribute.getName(), populate(CONTENT_VERSION_PROPERTYSET_PREFIX + attribute.getName()));
114         }
115         setParameter(CONTENT_VERSION_VALUES_PARAMETER, result);
116     }
117     
118     /**
119      *
120      */

121     private String JavaDoc populate(final String JavaDoc name) throws WorkflowException
122     {
123         if(parameterExists(name))
124         {
125             setPropertySetDataString(name, getRequestParameter(name));
126             logger.debug(name + " is found in the request; propertyset updated.");
127         }
128         else
129         {
130             logger.debug(name + " is not found in the request; propertyset not updated.");
131         }
132         return propertySetContains(name) ? getPropertySetDataString(name) : "";
133     }
134     /**
135      *
136      */

137     private List JavaDoc getContentTypeAttributes()
138     {
139         return ContentTypeDefinitionController.getController().getContentTypeAttributes(contentTypeDefinitionVO.getSchemaValue());
140     }
141 }
142
Popular Tags