KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src-modules/org/opencms/workplace/tools/modules/CmsDependenciesOverview.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.jsp.CmsJspActionElement;
35 import org.opencms.main.OpenCms;
36 import org.opencms.module.CmsModule;
37 import org.opencms.module.CmsModuleDependency;
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 dependencies overview.<p>
54  *
55  * @author Michael Emmerich
56  *
57  * @version $Revision: 1.6 $
58  *
59  * @version $Revision: 1.6 $
60  *
61  * @since 6.0.0
62  */

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

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

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

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

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

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

146     public String JavaDoc getParamDependency() {
147
148         return m_paramDependency;
149     }
150
151     /**
152      * Gets the module parameter.<p>
153      *
154      * @return the module parameter
155      */

156     public String JavaDoc getParamModule() {
157
158         return m_paramModule;
159     }
160
161     /**
162      * Sets the module dependency parameter.<p>
163      * @param paramDependency the module dependency parameter
164      */

165     public void setParamDependency(String JavaDoc paramDependency) {
166
167         m_paramDependency = paramDependency;
168     }
169
170     /**
171      * Sets the module parameter.<p>
172      * @param paramModule the module parameter
173      */

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

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

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

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

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

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

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

303     protected void validateParamaters() throws Exception JavaDoc {
304
305         String JavaDoc moduleName = getParamModule();
306         // check module
307
CmsModule module = OpenCms.getModuleManager().getModule(moduleName);
308         if (module == null) {
309             throw new Exception JavaDoc();
310         }
311         // check dependency
312
Iterator JavaDoc it = module.getDependencies().iterator();
313         while (it.hasNext()) {
314             CmsModuleDependency dep = (CmsModuleDependency)it.next();
315             if (dep.getName().equals(getParamDependency())) {
316                 // dependency found
317
return;
318             }
319         }
320         throw new Exception JavaDoc();
321     }
322
323 }
324
Popular Tags