KickJava   Java API By Example, From Geeks To Geeks.

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


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.infoglue.cms.controllers.kernel.impl.simple.ContentController;
26 import org.infoglue.cms.controllers.kernel.impl.simple.ContentVersionController;
27 import org.infoglue.cms.entities.content.Content;
28 import org.infoglue.cms.entities.content.ContentVO;
29 import org.infoglue.cms.entities.content.ContentVersion;
30 import org.infoglue.cms.entities.content.ContentVersionVO;
31
32 import com.opensymphony.workflow.WorkflowException;
33
34 /**
35  * Base class for all functions operating on <code>ContentVO</code> objects.
36  */

37 public abstract class ContentFunction extends InfoglueFunction
38 {
39     /**
40      *
41      */

42     public static final String JavaDoc CONTENT_PARAMETER = "content";
43     
44     /**
45      *
46      */

47     public static final String JavaDoc CONTENT_VERSION_PARAMETER = "contentVersion";
48     
49     /**
50      *
51      */

52     private static final String JavaDoc CONTENT_PARAMETER_NAME_ARGUMENT = "contentParameterName";
53     
54     /**
55      *
56      */

57     private static final String JavaDoc CONTENT_VERSION_PARAMETER_NAME_ARGUMENT = "contentVersionParameterName";
58     
59     /**
60      *
61      */

62     private Content content;
63     
64     /**
65      *
66      */

67     private ContentVO contentVO;
68
69     /**
70      *
71      */

72     private ContentVersion contentVersion;
73     
74     /**
75      *
76      */

77     private ContentVersionVO contentVersionVO;
78     
79     /**
80      * Default constructor.
81      */

82     protected ContentFunction()
83     {
84         super();
85     }
86     
87     /**
88      *
89      */

90     protected ContentVO getContentVO()
91     {
92         return contentVO;
93     }
94     
95     /**
96      *
97      */

98     protected ContentVersionVO getContentVersionVO()
99     {
100         return contentVersionVO;
101     }
102     
103     /**
104      *
105      */

106     protected Content getContent()
107     {
108         if(contentVO != null && content == null)
109         {
110             try
111             {
112                 content = ContentController.getContentController().getContentWithId(contentVO.getContentId(), getDatabase());
113             }
114             catch(Exception JavaDoc e)
115             {
116                 // shouldn't happen; just return null...
117
}
118         }
119         return content;
120     }
121     
122     /**
123      *
124      */

125     protected ContentVersion getContentVersion()
126     {
127         if(contentVersionVO != null && contentVersion == null)
128         {
129             try
130             {
131                 contentVersion = ContentVersionController.getContentVersionController().getContentVersionWithId(contentVersionVO.getContentVersionId(), getDatabase());
132             }
133             catch(Exception JavaDoc e)
134             {
135                 // shouldn't happen; just return null...
136
}
137         }
138         return contentVersion;
139     }
140     
141     /**
142      *
143      */

144     protected String JavaDoc getAttribute(final String JavaDoc name, final boolean escapeHTML) throws WorkflowException
145     {
146         if(contentVersionVO == null)
147         {
148             throwException("No content version.");
149         }
150         String JavaDoc value = "";
151         try
152         {
153             value = ContentVersionController.getContentVersionController().getAttributeValue(contentVersionVO, name, escapeHTML);
154         }
155         catch(Exception JavaDoc e)
156         {
157             throwException(e);
158         }
159         return value;
160     }
161     
162     /**
163      * Method used for initializing the function; will be called before <code>execute</code> is called.
164      * <p><strong>Note</strong>! You must call <code>super.initialize()</code> first.</p>
165      *
166      * @throws WorkflowException if an error occurs during the initialization.
167      */

168     protected void initialize() throws WorkflowException
169     {
170         super.initialize();
171         contentVO = (ContentVO) getParameter(getArgument(CONTENT_PARAMETER_NAME_ARGUMENT, CONTENT_PARAMETER), false);
172         contentVersionVO = (ContentVersionVO) getParameter(getArgument(CONTENT_VERSION_PARAMETER_NAME_ARGUMENT, CONTENT_VERSION_PARAMETER), false);
173     }
174 }
175
Popular Tags