KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.apache.log4j.Logger;
26 import org.infoglue.cms.controllers.kernel.impl.simple.ContentController;
27 import org.infoglue.cms.controllers.kernel.impl.simple.ContentVersionController;
28 import org.infoglue.cms.entities.content.ContentVO;
29 import org.infoglue.cms.entities.content.ContentVersionVO;
30 import org.infoglue.cms.entities.management.LanguageVO;
31
32 import com.opensymphony.workflow.WorkflowException;
33
34 /**
35  *
36  */

37 public class ContentProvider extends InfoglueFunction
38 {
39     private final static Logger logger = Logger.getLogger(ContentProvider.class.getName());
40
41     /**
42      *
43      */

44     public static final String JavaDoc CONTENT_ID_PROPERTYSET_KEY = ContentPopulator.CONTENT_PROPERTYSET_PREFIX + "contentID";
45     
46     /**
47      *
48      */

49     private LanguageVO languageVO;
50     
51     /**
52      *
53      */

54     private ContentVO contentVO;
55     
56     /**
57      *
58      */

59     private ContentVersionVO contentVersionVO;
60     
61     /**
62      *
63      */

64     protected void execute() throws WorkflowException
65     {
66         initializeContentVO();
67         initializeContentVersionVO();
68         if(getContentParameterName() != null && getContentParameterName().length() > 0)
69         {
70             setParameter(getContentParameterName(), contentVO);
71             
72         }
73         if(getContentVersionParameterName() != null && getContentVersionParameterName().length() > 0)
74         {
75             setParameter(getContentVersionParameterName(), contentVersionVO);
76         }
77     }
78
79     /**
80      *
81      */

82     protected void setContentVO(final ContentVO contentVO)
83     {
84         this.contentVO = contentVO;
85     }
86     
87     /**
88      *
89      */

90     protected void setContentVersionVO(final ContentVersionVO contentVersionVO)
91     {
92         this.contentVersionVO = contentVersionVO;
93     }
94     
95     /**
96      *
97      */

98     protected final LanguageVO getLanguageVO()
99     {
100         return this.languageVO;
101     }
102
103     /**
104      *
105      */

106     protected String JavaDoc getContentParameterName()
107     {
108         return ContentFunction.CONTENT_PARAMETER;
109     }
110     
111     /**
112      *
113      */

114     protected String JavaDoc getContentVersionParameterName()
115     {
116         return ContentFunction.CONTENT_VERSION_PARAMETER;
117     }
118     
119     /**
120      *
121      */

122     protected void initializeContentVO() throws WorkflowException
123     {
124         if(!propertySetContains(CONTENT_ID_PROPERTYSET_KEY))
125         {
126             return;
127         }
128         try
129         {
130             final Integer JavaDoc contentID = new Integer JavaDoc(getPropertySetString(CONTENT_ID_PROPERTYSET_KEY));
131             setContentVO(ContentController.getContentController().getContentVOWithId(contentID, getDatabase()));
132         }
133         catch(Exception JavaDoc e)
134         {
135             logger.warn("Non-existing contentId found; removing from the resultset.");
136             removeFromPropertySet(CONTENT_ID_PROPERTYSET_KEY);
137         }
138     }
139     
140     /**
141      *
142      */

143     protected void initializeContentVersionVO() throws WorkflowException
144     {
145         if(contentVO != null)
146         {
147             try
148             {
149                 final ContentVersionController controller = ContentVersionController.getContentVersionController();
150                 setContentVersionVO(controller.getLatestActiveContentVersionVO(contentVO.getId(), languageVO.getId(), getDatabase()));
151             }
152             catch(Exception JavaDoc e)
153             {
154                 throwException(e);
155             }
156         }
157     }
158     
159     /**
160      * Method used for initializing the function; will be called before <code>execute</code> is called.
161      * <p><strong>Note</strong>! You must call <code>super.initialize()</code> first.</p>
162      *
163      * @throws WorkflowException if an error occurs during the initialization.
164      */

165     protected void initialize() throws WorkflowException
166     {
167         super.initialize();
168         languageVO = (LanguageVO) getParameter(LanguageProvider.LANGUAGE_PARAMETER);
169     }
170 }
171
Popular Tags