KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > workplace > tools > content > CmsElementChangeLocaleDialog


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src-modules/org/opencms/workplace/tools/content/CmsElementChangeLocaleDialog.java,v $
3  * Date : $Date: 2006/07/20 09:14:10 $
4  * Version: $Revision: 1.4 $
5  *
6  * This library is part of OpenCms -
7  * the Open Source Content Mananagement System
8  *
9  * Copyright (c) 2005 Alkacon Software GmbH (http://www.alkacon.com)
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public
13  * License as published by the Free Software Foundation; either
14  * version 2.1 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  * Lesser General Public License for more details.
20  *
21  * For further information about Alkacon Software GmbH, please see the
22  * company website: http://www.alkacon.com
23  *
24  * For further information about OpenCms, please see the
25  * project website: http://www.opencms.org
26  *
27  * You should have received a copy of the GNU Lesser General Public
28  * License along with this library; if not, write to the Free Software
29  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30  */

31
32 package org.opencms.workplace.tools.content;
33
34 import org.opencms.importexport.CmsVfsImportExportHandler;
35 import org.opencms.jsp.CmsJspActionElement;
36 import org.opencms.main.CmsException;
37 import org.opencms.main.CmsIllegalArgumentException;
38 import org.opencms.main.CmsLog;
39 import org.opencms.main.OpenCms;
40 import org.opencms.util.CmsStringUtil;
41 import org.opencms.widgets.CmsCheckboxWidget;
42 import org.opencms.widgets.CmsSelectWidget;
43 import org.opencms.widgets.CmsSelectWidgetOption;
44 import org.opencms.widgets.CmsVfsFileWidget;
45 import org.opencms.workplace.CmsWidgetDialog;
46 import org.opencms.workplace.CmsWidgetDialogParameter;
47 import org.opencms.workplace.CmsWorkplaceSettings;
48 import org.opencms.workplace.explorer.CmsNewResourceXmlPage;
49 import org.opencms.workplace.tools.CmsToolDialog;
50 import org.opencms.workplace.tools.CmsToolManager;
51
52 import java.io.IOException JavaDoc;
53 import java.util.ArrayList JavaDoc;
54 import java.util.HashMap JavaDoc;
55 import java.util.Iterator JavaDoc;
56 import java.util.List JavaDoc;
57 import java.util.Locale JavaDoc;
58 import java.util.Map JavaDoc;
59 import java.util.TreeMap JavaDoc;
60
61 import javax.servlet.ServletException JavaDoc;
62 import javax.servlet.http.HttpServletRequest JavaDoc;
63 import javax.servlet.http.HttpServletResponse JavaDoc;
64 import javax.servlet.jsp.PageContext JavaDoc;
65
66 import org.apache.commons.logging.Log;
67
68 /**
69  * Widget dialog that sets the settings to move page elements to another Locale.<p>
70  *
71  * @author Andreas Zahner
72  *
73  * @version $Revision: 1.4 $
74  *
75  * @since 6.0.1
76  */

77 public class CmsElementChangeLocaleDialog extends CmsWidgetDialog {
78     
79     /** Localized message keys prefix. */
80     public static final String JavaDoc KEY_PREFIX = "changelocale";
81
82     /** Defines which pages are valid for this dialog. */
83     public static final String JavaDoc[] PAGES = {"page1"};
84
85     /** The import JSP report workplace URI. */
86     protected static final String JavaDoc CHANGELOCALE_ACTION_REPORT = PATH_WORKPLACE + "admin/contenttools/reports/changelocale.jsp";
87     
88     /** The log object for this class. */
89     private static final Log LOG = CmsLog.getLog(CmsElementChangeLocaleDialog.class);
90
91     /** The settings object that is edited on this dialog. */
92     private CmsElementChangeLocaleSettings m_settings;
93
94     /**
95      * Public constructor with JSP action element.<p>
96      *
97      * @param jsp an initialized JSP action element
98      */

99     public CmsElementChangeLocaleDialog(CmsJspActionElement jsp) {
100
101         super(jsp);
102     }
103
104     /**
105      * Public constructor with JSP variables.<p>
106      *
107      * @param context the JSP page context
108      * @param req the JSP request
109      * @param res the JSP response
110      */

111     public CmsElementChangeLocaleDialog(PageContext JavaDoc context, HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc res) {
112
113         this(new CmsJspActionElement(context, req, res));
114     }
115
116     /**
117      * @see org.opencms.workplace.CmsWidgetDialog#actionCommit()
118      */

119     public void actionCommit() throws IOException JavaDoc, ServletException JavaDoc {
120
121         List JavaDoc errors = new ArrayList JavaDoc();
122         setDialogObject(m_settings);
123         
124         try {
125             
126             if (m_settings.getOldLocale().equals(m_settings.getNewLocale())) {
127                 // old Locale is equals to new one, show error
128
throw new CmsIllegalArgumentException(Messages.get().container(Messages.ERR_CHANGEELEMENTLOCALE_LOCALE_EQUAL_0));
129             }
130
131             Map JavaDoc params = new HashMap JavaDoc();
132             // set the name of this class to get dialog object in report
133
params.put(CmsElementChangeLocaleReport.PARAM_CLASSNAME, this.getClass().getName());
134             // set style to display report in correct layout
135
params.put(PARAM_STYLE, CmsToolDialog.STYLE_NEW);
136             // set close link to get back to overview after finishing the import
137
params.put(PARAM_CLOSELINK, CmsToolManager.linkForToolPath(getJsp(), "/contenttools"));
138             // redirect to the report output JSP
139
getToolManager().jspForwardPage(this, CHANGELOCALE_ACTION_REPORT, params);
140         
141         } catch (CmsIllegalArgumentException e) {
142             errors.add(e);
143         }
144         // set the list of errors to display when saving failed
145
setCommitErrors(errors);
146     }
147     
148     /**
149      * Returns the selector widget options to build a Locale selector widget.<p>
150      *
151      * @return the selector widget options to build a Locale selector widget
152      */

153     public List JavaDoc getLocaleConfigOptions() {
154         
155         List JavaDoc result = new ArrayList JavaDoc();
156         
157         List JavaDoc locales = OpenCms.getLocaleManager().getAvailableLocales();
158         Iterator JavaDoc i = locales.iterator();
159         while (i.hasNext()) {
160             Locale JavaDoc locale = (Locale JavaDoc)i.next();
161             String JavaDoc language = locale.toString();
162             String JavaDoc displayLanguage = locale.getDisplayLanguage(getLocale());
163             
164             result.add(new CmsSelectWidgetOption(language, false, displayLanguage));
165         }
166
167         return result;
168     }
169     
170     /**
171      * returns the selector widget options to build a template selector widget.<p>
172      *
173      * @return the selector widget options to build a template selector widget
174      */

175     public List JavaDoc getTemplateConfigOptions() {
176
177         List JavaDoc result = new ArrayList JavaDoc();
178         result.add(new CmsSelectWidgetOption("", true, key(Messages.GUI_CHANGEELEMENTLOCALE_DIALOG_TEMPLATE_ALL_0)));
179         
180         TreeMap JavaDoc templates = null;
181         try {
182             // get all available templates
183
templates = CmsNewResourceXmlPage.getTemplates(getCms(), null);
184         } catch (CmsException e) {
185             // can usually be ignored
186
if (LOG.isInfoEnabled()) {
187                 LOG.info(e);
188             }
189         }
190         if (templates != null) {
191             // templates found, create option and value lists
192
Iterator JavaDoc i = templates.keySet().iterator();
193             while (i.hasNext()) {
194                 String JavaDoc key = (String JavaDoc)i.next();
195                 String JavaDoc path = (String JavaDoc)templates.get(key);
196                 result.add(new CmsSelectWidgetOption(path, false, key));
197             }
198         }
199         return result;
200     }
201
202     /**
203      * @see org.opencms.workplace.CmsWidgetDialog#createDialogHtml(java.lang.String)
204      */

205     protected String JavaDoc createDialogHtml(String JavaDoc dialog) {
206
207         StringBuffer JavaDoc result = new StringBuffer JavaDoc(1024);
208
209         // create table
210
result.append(createWidgetTableStart());
211
212         // show error header once if there were validation errors
213
result.append(createWidgetErrorHeader());
214
215         // create export file name block
216
result.append(createWidgetBlockStart(key(Messages.GUI_CHANGEELEMENTLOCALE_DIALOG_BLOCK_SETTINGS_0)));
217         result.append(createDialogRowsHtml(0, 4));
218         result.append(createWidgetBlockEnd());
219
220         // close table
221
result.append(createWidgetTableEnd());
222
223         return result.toString();
224     }
225
226     /**
227      * @see org.opencms.workplace.CmsWidgetDialog#defineWidgets()
228      */

229     protected void defineWidgets() {
230
231         // initialize the export object to use for the dialog
232
initSettingsObject();
233         
234         // set localized key prefix
235
setKeyPrefix(KEY_PREFIX);
236
237         addWidget(new CmsWidgetDialogParameter(m_settings, "vfsFolder", "/", PAGES[0], new CmsVfsFileWidget(
238             false,
239             getCms().getRequestContext().getSiteRoot()), 1, 1));
240
241         addWidget(new CmsWidgetDialogParameter(m_settings, "includeSubFolders", PAGES[0], new CmsCheckboxWidget()));
242         addWidget(new CmsWidgetDialogParameter(m_settings, "template", PAGES[0], new CmsSelectWidget(getTemplateConfigOptions())));
243         
244         List JavaDoc localeSelections = getLocaleConfigOptions();
245         addWidget(new CmsWidgetDialogParameter(m_settings, "oldLocale", PAGES[0], new CmsSelectWidget(localeSelections)));
246         addWidget(new CmsWidgetDialogParameter(m_settings, "newLocale", PAGES[0], new CmsSelectWidget(localeSelections)));
247     }
248
249     /**
250      * @see org.opencms.workplace.CmsWidgetDialog#getPageArray()
251      */

252     protected String JavaDoc[] getPageArray() {
253
254         return PAGES;
255     }
256
257     /**
258      * @see org.opencms.workplace.CmsWorkplace#initMessages()
259      */

260     protected void initMessages() {
261
262         // add specific dialog resource bundle
263
addMessages(Messages.get().getBundleName());
264         // add workplace messages
265
addMessages("org.opencms.workplace.workplace");
266         // add default resource bundles
267
super.initMessages();
268     }
269
270     /**
271      * Initializes the settings object to work with depending on the dialog state and request parameters.<p>
272      */

273     protected void initSettingsObject() {
274
275         Object JavaDoc o;
276
277         if (CmsStringUtil.isEmpty(getParamAction())) {
278             o = new CmsVfsImportExportHandler();
279         } else {
280             // this is not the initial call, get the job object from session
281
o = getDialogObject();
282         }
283
284         if (!(o instanceof CmsElementChangeLocaleSettings)) {
285             // create a new export handler object
286
m_settings = new CmsElementChangeLocaleSettings();
287         } else {
288             // reuse export handler object stored in session
289
m_settings = (CmsElementChangeLocaleSettings)o;
290         }
291
292     }
293
294     /**
295      * @see org.opencms.workplace.CmsWorkplace#initWorkplaceRequestValues(org.opencms.workplace.CmsWorkplaceSettings, javax.servlet.http.HttpServletRequest)
296      */

297     protected void initWorkplaceRequestValues(CmsWorkplaceSettings settings, HttpServletRequest JavaDoc request) {
298
299         // initialize parameters and dialog actions in super implementation
300
super.initWorkplaceRequestValues(settings, request);
301
302         // save the current state of the export handler (may be changed because of the widget values)
303
setDialogObject(m_settings);
304     }
305 }
Popular Tags