KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > workplace > tools > modules > CmsExportpointsEdit


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src-modules/org/opencms/workplace/tools/modules/CmsExportpointsEdit.java,v $
3  * Date : $Date: 2005/06/23 11:11:38 $
4  * Version: $Revision: 1.9 $
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.modules;
33
34 import org.opencms.configuration.CmsConfigurationException;
35 import org.opencms.db.CmsExportPoint;
36 import org.opencms.jsp.CmsJspActionElement;
37 import org.opencms.main.OpenCms;
38 import org.opencms.module.CmsModule;
39 import org.opencms.security.CmsSecurityException;
40 import org.opencms.util.CmsStringUtil;
41 import org.opencms.widgets.CmsComboWidget;
42 import org.opencms.widgets.CmsDisplayWidget;
43 import org.opencms.widgets.CmsSelectWidgetOption;
44 import org.opencms.widgets.CmsVfsFileWidget;
45 import org.opencms.workplace.CmsDialog;
46 import org.opencms.workplace.CmsWidgetDialog;
47 import org.opencms.workplace.CmsWidgetDialogParameter;
48 import org.opencms.workplace.CmsWorkplaceSettings;
49
50 import java.util.ArrayList JavaDoc;
51 import java.util.Iterator JavaDoc;
52 import java.util.List JavaDoc;
53 import java.util.Map JavaDoc;
54
55 import javax.servlet.http.HttpServletRequest JavaDoc;
56 import javax.servlet.http.HttpServletResponse JavaDoc;
57 import javax.servlet.jsp.PageContext JavaDoc;
58
59 /**
60  * Class to edit a module dependencies.<p>
61  *
62  * @author Michael Emmerich
63  *
64  * @version $Revision: 1.9 $
65  *
66  * @since 6.0.0
67  */

68 public class CmsExportpointsEdit extends CmsWidgetDialog {
69
70     /** The dialog type. */
71     public static final String JavaDoc DIALOG_TYPE = "ExportpointsOverview";
72
73     /** Defines which pages are valid for this dialog. */
74     public static final String JavaDoc[] PAGES = {"page1"};
75
76     /** The module exportpoints object that is shown on this dialog. */
77     private CmsExportPoint m_exportpoint;
78
79     /** Exportpoint name. */
80     private String JavaDoc m_paramExportpoint;
81
82     /** Modulename. */
83     private String JavaDoc m_paramModule;
84
85     /**
86      * Public constructor with JSP action element.<p>
87      *
88      * @param jsp an initialized JSP action element
89      */

90     public CmsExportpointsEdit(CmsJspActionElement jsp) {
91
92         super(jsp);
93     }
94
95     /**
96      * Public constructor with JSP variables.<p>
97      *
98      * @param context the JSP page context
99      * @param req the JSP request
100      * @param res the JSP response
101      */

102     public CmsExportpointsEdit(PageContext JavaDoc context, HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc res) {
103
104         this(new CmsJspActionElement(context, req, res));
105     }
106
107     /**
108      * Commits the edited module.<p>
109      */

110     public void actionCommit() {
111
112         List JavaDoc errors = new ArrayList JavaDoc();
113
114         try {
115             // get the correct module
116
String JavaDoc moduleName = getParamModule();
117             CmsModule module = (CmsModule)OpenCms.getModuleManager().getModule(moduleName).clone();
118             // get the current exportpoints from the module
119
List JavaDoc oldExportpoints = module.getExportPoints();
120             // now loop through the exportpoints and create the new list of exportpoints
121
List JavaDoc newExportpoints = new ArrayList JavaDoc();
122             Iterator JavaDoc i = oldExportpoints.iterator();
123             while (i.hasNext()) {
124                 CmsExportPoint exp = (CmsExportPoint)i.next();
125                 if (!exp.getUri().equals(m_exportpoint.getUri())) {
126                     newExportpoints.add(exp);
127                 }
128             }
129             // update the exportpoints
130
newExportpoints.add(m_exportpoint);
131             module.setExportPoints(newExportpoints);
132             // update the module
133
OpenCms.getModuleManager().updateModule(getCms(), module);
134             // refresh the list
135
Map JavaDoc objects = (Map JavaDoc)getSettings().getListObject();
136             if (objects != null) {
137                 objects.remove(CmsModulesList.class.getName());
138                 objects.remove(CmsExportpointsList.class.getName());
139             }
140         } catch (CmsConfigurationException ce) {
141             errors.add(ce);
142         } catch (CmsSecurityException se) {
143             errors.add(se);
144         }
145
146         // set the list of errors to display when saving failed
147
setCommitErrors(errors);
148     }
149
150     /**
151      * Builds the HTML for the dialog form.<p>
152      *
153      * @return the HTML for the dialog form
154      */

155     public String JavaDoc buildDialogForm() {
156
157         StringBuffer JavaDoc result = new StringBuffer JavaDoc(1024);
158
159         try {
160
161             // create the dialog HTML
162
result.append(createDialogHtml(getParamPage()));
163
164         } catch (Throwable JavaDoc t) {
165             // TODO: Error handling
166
}
167         return result.toString();
168     }
169
170     /**
171      * @see org.opencms.workplace.CmsDialog#getCancelAction()
172      */

173     public String JavaDoc getCancelAction() {
174
175         // set the default action
176
setParamPage((String JavaDoc)getPages().get(0));
177
178         return DIALOG_SET;
179     }
180
181     /**
182      * Gets the module exportpoint parameter.<p>
183      *
184      * @return the module exportpoint parameter
185      */

186     public String JavaDoc getParamExportpoint() {
187
188         return m_paramExportpoint;
189     }
190
191     /**
192      * Gets the module parameter.<p>
193      *
194      * @return the module parameter
195      */

196     public String JavaDoc getParamModule() {
197
198         return m_paramModule;
199     }
200
201     /**
202      * Sets the module exportpoint parameter.<p>
203      * @param paramExportpoint the module exportpoint parameter
204      */

205     public void setParamExportpoint(String JavaDoc paramExportpoint) {
206
207         m_paramExportpoint = paramExportpoint;
208     }
209
210     /**
211      * Sets the module parameter.<p>
212      * @param paramModule the module parameter
213      */

214     public void setParamModule(String JavaDoc paramModule) {
215
216         m_paramModule = paramModule;
217     }
218
219     /**
220      * Creates the dialog HTML for all defined widgets of the named dialog (page).<p>
221      *
222      * @param dialog the dialog (page) to get the HTML for
223      * @return the dialog HTML for all defined widgets of the named dialog (page)
224      */

225     protected String JavaDoc createDialogHtml(String JavaDoc dialog) {
226
227         StringBuffer JavaDoc result = new StringBuffer JavaDoc(1024);
228
229         // create table
230
result.append(createWidgetTableStart());
231
232         // show error header once if there were validation errors
233
result.append(createWidgetErrorHeader());
234
235         if (dialog.equals(PAGES[0])) {
236             result.append(dialogBlockStart(key("label.exportpointinformation")));
237             result.append(createWidgetTableStart());
238             result.append(createDialogRowsHtml(0, 2));
239             result.append(createWidgetTableEnd());
240             result.append(dialogBlockEnd());
241         }
242
243         // close table
244
result.append(createWidgetTableEnd());
245
246         return result.toString();
247     }
248
249     /**
250      * Creates the list of widgets for this dialog.<p>
251      */

252     protected void defineWidgets() {
253
254         initModule();
255
256         List JavaDoc destinations = getDestinations();
257
258         addWidget(new CmsWidgetDialogParameter(m_exportpoint, "uri", PAGES[0], new CmsVfsFileWidget()));
259         addWidget(new CmsWidgetDialogParameter(m_exportpoint, "configuredDestination", PAGES[0], new CmsComboWidget(
260             destinations)));
261         addWidget(new CmsWidgetDialogParameter(m_exportpoint, "destinationPath", PAGES[0], new CmsDisplayWidget()));
262
263     }
264
265     /**
266      * @see org.opencms.workplace.CmsWidgetDialog#getPageArray()
267      */

268     protected String JavaDoc[] getPageArray() {
269
270         return PAGES;
271     }
272
273     /**
274      * @see org.opencms.workplace.CmsWorkplace#initMessages()
275      */

276     protected void initMessages() {
277
278         // add specific dialog resource bundle
279
addMessages(Messages.get().getBundleName());
280         // add default resource bundles
281
super.initMessages();
282     }
283
284     /**
285      * Initializes the module to work with depending on the dialog state and request parameters.<p>
286      */

287     protected void initModule() {
288
289         Object JavaDoc o;
290         CmsModule module;
291
292         if (CmsStringUtil.isEmpty(getParamAction()) || CmsDialog.DIALOG_INITIAL.equals(getParamAction())) {
293             // this is the initial dialog call
294
if (CmsStringUtil.isNotEmpty(m_paramModule)) {
295                 // edit an existing module, get it from manager
296
o = OpenCms.getModuleManager().getModule(m_paramModule);
297             } else {
298                 // create a new module
299
o = null;
300             }
301         } else {
302             // this is not the initial call, get module from session
303
o = getDialogObject();
304         }
305
306         if (!(o instanceof CmsModule)) {
307             // create a new module
308
module = new CmsModule();
309
310         } else {
311             // reuse module stored in session
312
module = (CmsModule)((CmsModule)o).clone();
313         }
314
315         List JavaDoc exportpoints = module.getExportPoints();
316         m_exportpoint = new CmsExportPoint();
317         if (exportpoints != null && exportpoints.size() > 0) {
318             Iterator JavaDoc i = exportpoints.iterator();
319             while (i.hasNext()) {
320                 CmsExportPoint exportpoint = (CmsExportPoint)i.next();
321                 if (exportpoint.getUri().equals(m_paramExportpoint)) {
322                     m_exportpoint = exportpoint;
323                 }
324             }
325         }
326
327     }
328
329     /**
330      * @see org.opencms.workplace.CmsWorkplace#initWorkplaceRequestValues(org.opencms.workplace.CmsWorkplaceSettings, javax.servlet.http.HttpServletRequest)
331      */

332     protected void initWorkplaceRequestValues(CmsWorkplaceSettings settings, HttpServletRequest JavaDoc request) {
333
334         // set the dialog type
335
setParamDialogtype(DIALOG_TYPE);
336
337         super.initWorkplaceRequestValues(settings, request);
338
339         // save the current state of the module (may be changed because of the widget values)
340
setDialogObject(m_exportpoint);
341
342     }
343
344     /**
345      * @see org.opencms.workplace.CmsWidgetDialog#validateParamaters()
346      */

347     protected void validateParamaters() throws Exception JavaDoc {
348
349         String JavaDoc moduleName = getParamModule();
350         // check module
351
CmsModule module = OpenCms.getModuleManager().getModule(moduleName);
352         if (module == null) {
353             throw new Exception JavaDoc();
354         }
355         // check export point
356
if (!isNewExportPoint()) {
357             Iterator JavaDoc it = module.getExportPoints().iterator();
358             while (it.hasNext()) {
359                 CmsExportPoint ep = (CmsExportPoint)it.next();
360                 if (ep.getUri().equals(getParamExportpoint())) {
361                     // export point found
362
return;
363                 }
364             }
365             throw new Exception JavaDoc();
366         }
367     }
368
369     /**
370      * Returns the list of default destinations for export points.<p>
371      *
372      * The result list elements are of type <code>{@link org.opencms.widgets.CmsSelectWidgetOption}</code>.<p>
373      *
374      * @return the list of default destinations for export points
375      */

376     private List JavaDoc getDestinations() {
377
378         List JavaDoc result = new ArrayList JavaDoc();
379         result.add(new CmsSelectWidgetOption("WEB-INF/classes/"));
380         result.add(new CmsSelectWidgetOption("WEB-INF/lib/"));
381         return result;
382     }
383
384     /**
385      * Checks if the new export point dialog has to be displayed.<p>
386      *
387      * @return <code>true</code> if the new export point dialog has to be displayed
388      */

389     private boolean isNewExportPoint() {
390
391         return getCurrentToolPath().equals("/modules/edit/exportpoints/new");
392     }
393 }
Popular Tags