KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src-modules/org/opencms/workplace/tools/modules/CmsExportpointsOverview.java,v $
3  * Date : $Date: 2005/06/23 11:11:38 $
4  * Version: $Revision: 1.6 $
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.db.CmsExportPoint;
35 import org.opencms.jsp.CmsJspActionElement;
36 import org.opencms.main.OpenCms;
37 import org.opencms.module.CmsModule;
38 import org.opencms.util.CmsStringUtil;
39 import org.opencms.widgets.CmsDisplayWidget;
40 import org.opencms.workplace.CmsDialog;
41 import org.opencms.workplace.CmsWidgetDialog;
42 import org.opencms.workplace.CmsWidgetDialogParameter;
43 import org.opencms.workplace.CmsWorkplaceSettings;
44
45 import java.util.Iterator JavaDoc;
46 import java.util.List JavaDoc;
47
48 import javax.servlet.http.HttpServletRequest JavaDoc;
49 import javax.servlet.http.HttpServletResponse JavaDoc;
50 import javax.servlet.jsp.PageContext JavaDoc;
51
52 /**
53  * Class to show the module exportpoint overview.<p>
54  *
55  * @author Michael Emmerich
56  *
57  * @version $Revision: 1.6 $
58  *
59  * @since 6.0.0
60  */

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

83     public CmsExportpointsOverview(CmsJspActionElement jsp) {
84
85         super(jsp);
86     }
87
88     /**
89      * Public constructor with JSP variables.<p>
90      *
91      * @param context the JSP page context
92      * @param req the JSP request
93      * @param res the JSP response
94      */

95     public CmsExportpointsOverview(PageContext JavaDoc context, HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc res) {
96
97         this(new CmsJspActionElement(context, req, res));
98     }
99
100     /**
101      * Commits the edited module.<p>
102      */

103     public void actionCommit() {
104
105         // noop
106
}
107
108     /**
109      * Builds the HTML for the dialog form.<p>
110      *
111      * @return the HTML for the dialog form
112      */

113     public String JavaDoc buildDialogForm() {
114
115         StringBuffer JavaDoc result = new StringBuffer JavaDoc(1024);
116
117         try {
118
119             // create the dialog HTML
120
result.append(createDialogHtml(getParamPage()));
121
122         } catch (Throwable JavaDoc t) {
123             // TODO: Error handling
124
}
125         return result.toString();
126     }
127
128     /**
129      * @see org.opencms.workplace.CmsDialog#getCancelAction()
130      */

131     public String JavaDoc getCancelAction() {
132
133         // set the default action
134
setParamPage((String JavaDoc)getPages().get(0));
135
136         return DIALOG_SET;
137     }
138
139     /**
140      * Gets the module exportpoint parameter.<p>
141      *
142      * @return the module exportpoint parameter
143      */

144     public String JavaDoc getParamExportpoint() {
145
146         return m_paramExportpoint;
147     }
148
149     /**
150      * Gets the module parameter.<p>
151      *
152      * @return the module parameter
153      */

154     public String JavaDoc getParamModule() {
155
156         return m_paramModule;
157     }
158
159     /**
160      * Sets the module exportpoint parameter.<p>
161      * @param paramExportpoint the module exportpoint parameter
162      */

163     public void setParamExportpoint(String JavaDoc paramExportpoint) {
164
165         m_paramExportpoint = paramExportpoint;
166     }
167
168     /**
169      * Sets the module parameter.<p>
170      * @param paramModule the module parameter
171      */

172     public void setParamModule(String JavaDoc paramModule) {
173
174         m_paramModule = paramModule;
175     }
176
177     /**
178      * Creates the dialog HTML for all defined widgets of the named dialog (page).<p>
179      *
180      * @param dialog the dialog (page) to get the HTML for
181      * @return the dialog HTML for all defined widgets of the named dialog (page)
182      */

183     protected String JavaDoc createDialogHtml(String JavaDoc dialog) {
184
185         StringBuffer JavaDoc result = new StringBuffer JavaDoc(1024);
186
187         // create table
188
result.append(createWidgetTableStart());
189
190         // show error header once if there were validation errors
191
result.append(createWidgetErrorHeader());
192
193         if (dialog.equals(PAGES[0])) {
194             result.append(dialogBlockStart(key("label.exportpointinformation")));
195             result.append(createWidgetTableStart());
196             result.append(createDialogRowsHtml(0, 2));
197             result.append(createWidgetTableEnd());
198             result.append(dialogBlockEnd());
199         }
200
201         // close table
202
result.append(createWidgetTableEnd());
203
204         return result.toString();
205     }
206
207     /**
208      * Creates the list of widgets for this dialog.<p>
209      */

210     protected void defineWidgets() {
211
212         initModule();
213
214         addWidget(new CmsWidgetDialogParameter(m_exportpoint, "uri", PAGES[0], new CmsDisplayWidget()));
215         addWidget(new CmsWidgetDialogParameter(m_exportpoint, "configuredDestination", PAGES[0], new CmsDisplayWidget()));
216         addWidget(new CmsWidgetDialogParameter(m_exportpoint, "destinationPath", PAGES[0], new CmsDisplayWidget()));
217
218     }
219
220     /**
221      * @see org.opencms.workplace.CmsWidgetDialog#getPageArray()
222      */

223     protected String JavaDoc[] getPageArray() {
224
225         return PAGES;
226     }
227
228     /**
229      * @see org.opencms.workplace.CmsWorkplace#initMessages()
230      */

231     protected void initMessages() {
232
233         // add specific dialog resource bundle
234
addMessages(Messages.get().getBundleName());
235         // add default resource bundles
236
super.initMessages();
237     }
238
239     /**
240      * Initializes the module to work with depending on the dialog state and request parameters.<p>
241      */

242     protected void initModule() {
243
244         Object JavaDoc o;
245         CmsModule module;
246
247         if (CmsStringUtil.isEmpty(getParamAction()) || CmsDialog.DIALOG_INITIAL.equals(getParamAction())) {
248             // this is the initial dialog call
249
if (CmsStringUtil.isNotEmpty(m_paramModule)) {
250                 // edit an existing module, get it from manager
251
o = OpenCms.getModuleManager().getModule(m_paramModule);
252             } else {
253                 // create a new module
254
o = null;
255             }
256         } else {
257             // this is not the initial call, get module from session
258
o = getDialogObject();
259         }
260
261         if (!(o instanceof CmsModule)) {
262             // create a new module
263
module = new CmsModule();
264
265         } else {
266             // reuse module stored in session
267
module = (CmsModule)((CmsModule)o).clone();
268         }
269
270         List JavaDoc exportpoints = module.getExportPoints();
271         m_exportpoint = new CmsExportPoint();
272         if (exportpoints != null && exportpoints.size() > 0) {
273             Iterator JavaDoc i = exportpoints.iterator();
274             while (i.hasNext()) {
275                 CmsExportPoint exportpoint = (CmsExportPoint)i.next();
276                 if (exportpoint.getUri().equals(m_paramExportpoint)) {
277                     m_exportpoint = exportpoint;
278                 }
279             }
280         }
281
282     }
283
284     /**
285      * @see org.opencms.workplace.CmsWorkplace#initWorkplaceRequestValues(org.opencms.workplace.CmsWorkplaceSettings, javax.servlet.http.HttpServletRequest)
286      */

287     protected void initWorkplaceRequestValues(CmsWorkplaceSettings settings, HttpServletRequest JavaDoc request) {
288
289         // set the dialog type
290
setParamDialogtype(DIALOG_TYPE);
291
292         super.initWorkplaceRequestValues(settings, request);
293
294         // save the current state of the module (may be changed because of the widget values)
295
setDialogObject(m_exportpoint);
296
297     }
298
299     /**
300      * @see org.opencms.workplace.CmsWidgetDialog#validateParamaters()
301      */

302     protected void validateParamaters() throws Exception JavaDoc {
303
304         String JavaDoc moduleName = getParamModule();
305         // check module
306
CmsModule module = OpenCms.getModuleManager().getModule(moduleName);
307         if (module == null) {
308             throw new Exception JavaDoc();
309         }
310         // check export point
311
Iterator JavaDoc it = module.getExportPoints().iterator();
312         while (it.hasNext()) {
313             CmsExportPoint ep = (CmsExportPoint)it.next();
314             if (ep.getUri().equals(getParamExportpoint())) {
315                 // export point found
316
return;
317             }
318         }
319         throw new Exception JavaDoc();
320     }
321 }
322
Popular Tags