KickJava   Java API By Example, From Geeks To Geeks.

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


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.HashMap JavaDoc;
26 import java.util.Map JavaDoc;
27
28 import org.apache.log4j.Logger;
29 import org.infoglue.cms.applications.workflowtool.util.ContentFactory;
30 import org.infoglue.cms.applications.workflowtool.util.ContentValues;
31 import org.infoglue.cms.applications.workflowtool.util.ContentVersionValues;
32 import org.infoglue.cms.entities.content.ContentVO;
33 import org.infoglue.cms.entities.management.ContentTypeDefinitionVO;
34 import org.infoglue.cms.entities.management.LanguageVO;
35 import org.infoglue.cms.exception.ConstraintException;
36
37 import com.opensymphony.workflow.WorkflowException;
38
39 /**
40  *
41  */

42 public class ContentCreator extends ContentFunction
43 {
44     private final static Logger logger = Logger.getLogger(ContentCreator.class.getName());
45
46     /**
47      *
48      */

49     public static final String JavaDoc FOLDER_PARAMETER = "create_folder";
50     
51     /**
52      *
53      */

54     private static final String JavaDoc STATUS_OK = "status.content.ok";
55     
56     /**
57      *
58      */

59     private static final String JavaDoc STATUS_NOK = "status.content.nok";
60     
61     /**
62      *
63      */

64     private LanguageVO languageVO;
65     
66     /**
67      *
68      */

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

74     private Map JavaDoc categories;
75     
76     /**
77      * The content bean.
78      */

79     private ContentValues contentValues;
80     
81     /**
82      * The content version bean.
83      */

84     private ContentVersionValues contentVersionValues;
85     
86     /**
87      * The parent content to use when creating new content.
88      */

89     private ContentVO parentFontentVO;
90     
91     
92     /**
93      *
94      */

95     protected void execute() throws WorkflowException
96     {
97         setFunctionStatus(STATUS_NOK);
98         try
99         {
100             final ContentFactory factory = new ContentFactory(contentTypeDefinitionVO, contentValues, contentVersionValues, getPrincipal(), languageVO);
101             ContentVO newContentVO = null;
102             if(getContentVO() == null)
103             {
104                 parentFontentVO = (ContentVO) getParameter(FOLDER_PARAMETER);
105                 newContentVO = factory.create(parentFontentVO, categories, getDatabase());
106             }
107             else
108             {
109                 newContentVO = factory.update(getContentVO(), categories, getDatabase());
110             }
111             if(newContentVO != null)
112             {
113                 setPropertySetString(ContentProvider.CONTENT_ID_PROPERTYSET_KEY, newContentVO.getContentId().toString());
114             }
115             setFunctionStatus((newContentVO != null) ? STATUS_OK : STATUS_NOK);
116         }
117         catch(ConstraintException e)
118         {
119             logger.debug(e.toString());
120         }
121         catch(Exception JavaDoc e)
122         {
123             throwException(e);
124         }
125     }
126
127     /**
128      * Method used for initializing the function; will be called before <code>execute</code> is called.
129      * <p><strong>Note</strong>! You must call <code>super.initialize()</code> first.</p>
130      *
131      * @throws WorkflowException if an error occurs during the initialization.
132      */

133     protected void initialize() throws WorkflowException
134     {
135         super.initialize();
136         contentTypeDefinitionVO = (ContentTypeDefinitionVO) getParameter(ContentTypeDefinitionProvider.CONTENT_TYPE_DEFINITION_PARAMETER);
137         languageVO = (LanguageVO) getParameter(LanguageProvider.LANGUAGE_PARAMETER);
138         categories = (Map JavaDoc) getParameter(CategoryProvider.CATEGORIES_PARAMETER, new HashMap JavaDoc());
139         contentValues = (ContentValues) getParameter(ContentPopulator.CONTENT_VALUES_PARAMETER);
140         contentVersionValues = (ContentVersionValues) getParameter(ContentPopulator.CONTENT_VERSION_VALUES_PARAMETER);
141     }
142 }
143
Popular Tags