KickJava   Java API By Example, From Geeks To Geeks.

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


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.List JavaDoc;
26
27 import org.infoglue.cms.controllers.kernel.impl.simple.LanguageController;
28 import org.infoglue.cms.entities.management.LanguageVO;
29
30 import com.opensymphony.workflow.WorkflowException;
31
32 /**
33  *
34  */

35 public class LanguageProvider extends InfoglueFunction
36 {
37     /**
38      *
39      */

40     public static final String JavaDoc LANGUAGE_PARAMETER = "language";
41
42     /**
43      *
44      */

45     private static final String JavaDoc LANGUAGE_PROPERTYSET_KEY = "languageId";
46
47     /**
48      *
49      */

50     private static final String JavaDoc LANGUAGE_CODE_ARGUMENT = "code";
51
52     /**
53      *
54      */

55     private static final String JavaDoc LANGUAGE_ID_IDENTIFIER = "languageId";
56
57     
58     
59     /**
60      *
61      */

62     protected void execute() throws WorkflowException
63     {
64         LanguageVO languageVO = null;
65
66         if(propertySetContains(LANGUAGE_PROPERTYSET_KEY))
67         {
68             languageVO = getLanguageWithID(getPropertySetString(LANGUAGE_PROPERTYSET_KEY));
69         }
70         if(languageVO == null && parameterExists(LANGUAGE_ID_IDENTIFIER))
71         {
72             languageVO = getLanguageWithID(getParameter(LANGUAGE_ID_IDENTIFIER).toString());
73         }
74         if(languageVO == null && argumentExists(LANGUAGE_CODE_ARGUMENT))
75         {
76             languageVO = getLanguageWithCode(getArgument(LANGUAGE_CODE_ARGUMENT));
77         }
78
79         if(languageVO == null)
80         {
81             languageVO = getAnyLanguage();
82         }
83         
84         populate(languageVO);
85     }
86     
87     /**
88      *
89      */

90     private void populate(final LanguageVO languageVO) throws WorkflowException
91     {
92         if(languageVO == null && propertySetContains(LANGUAGE_PROPERTYSET_KEY))
93         {
94             removeFromPropertySet(LANGUAGE_PROPERTYSET_KEY);
95         }
96         if(languageVO != null)
97         {
98             setParameter(LANGUAGE_PARAMETER, languageVO);
99             setPropertySetString(LANGUAGE_PROPERTYSET_KEY, languageVO.getId().toString());
100         }
101     }
102     
103     /**
104      *
105      */

106     public LanguageVO getAnyLanguage() throws WorkflowException
107     {
108         LanguageVO languageVO = null;
109         try
110         {
111             final List JavaDoc languages = LanguageController.getController().getLanguageVOList(getDatabase());
112             if(!languages.isEmpty())
113             {
114                 languageVO = (LanguageVO) languages.get(0);
115             }
116             throwException("No languages found...");
117         }
118         catch (Exception JavaDoc e)
119         {
120             throwException("Language.getAnyLanguage() : " + e);
121         }
122         return languageVO;
123     }
124
125     /**
126      *
127      */

128     public LanguageVO getLanguageWithID(final String JavaDoc languageId) throws WorkflowException
129     {
130         LanguageVO languageVO = null;
131         try
132         {
133             languageVO = LanguageController.getController().getLanguageVOWithId(new Integer JavaDoc(languageId), getDatabase());
134         }
135         catch (Exception JavaDoc e)
136         {
137             throw new WorkflowException("Language.getLanguageWithID() : " + e);
138         }
139         return languageVO;
140     }
141
142     /**
143      *
144      */

145     public LanguageVO getLanguageWithCode(final String JavaDoc code) throws WorkflowException
146     {
147         LanguageVO languageVO = null;
148         try
149         {
150             languageVO = LanguageController.getController().getLanguageVOWithCode(code, getDatabase());
151         }
152         catch (Exception JavaDoc e)
153         {
154             throwException("Language.getLanguageWithCode() : " + e);
155         }
156         return languageVO;
157     }
158 }
Popular Tags