KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > workplace > tools > content > check > CmsContentCheckDialog


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src-modules/org/opencms/workplace/tools/content/check/CmsContentCheckDialog.java,v $
3  * Date : $Date: 2006/03/28 10:01:22 $
4  * Version: $Revision: 1.3 $
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.check;
33
34 import org.opencms.jsp.CmsJspActionElement;
35 import org.opencms.main.CmsIllegalArgumentException;
36 import org.opencms.util.CmsStringUtil;
37 import org.opencms.widgets.CmsCheckboxWidget;
38 import org.opencms.widgets.CmsVfsFileWidget;
39 import org.opencms.workplace.CmsDialog;
40 import org.opencms.workplace.CmsWidgetDialog;
41 import org.opencms.workplace.CmsWidgetDialogParameter;
42 import org.opencms.workplace.CmsWorkplaceSettings;
43 import org.opencms.workplace.tools.CmsToolDialog;
44 import org.opencms.workplace.tools.database.CmsDatabaseExportReport;
45
46 import java.util.ArrayList JavaDoc;
47 import java.util.HashMap JavaDoc;
48 import java.util.Iterator JavaDoc;
49 import java.util.List JavaDoc;
50 import java.util.Map JavaDoc;
51
52 import javax.servlet.http.HttpServletRequest JavaDoc;
53 import javax.servlet.http.HttpServletResponse JavaDoc;
54 import javax.servlet.jsp.PageContext JavaDoc;
55
56 /**
57  * Dialog for selecting the content checks.<p>
58  *
59  * @author Michael Emmerich
60  *
61  * @version $Revision: 1.3 $
62  *
63  * @since 6.1.2
64  */

65 public class CmsContentCheckDialog extends CmsWidgetDialog {
66
67     /** The dialog type. */
68     public static final String JavaDoc DIALOG_TYPE = "contentcheck";
69
70     /** Defines which pages are valid for this dialog. */
71     public static final String JavaDoc[] PAGES = {"page1"};
72
73     /** The content check JSP report workplace URI. */
74     protected static final String JavaDoc CONTENT_CHECK_REPORT = PATH_WORKPLACE + "admin/contenttools/check/report.jsp";
75
76     /** The content check JSP result workplace URI. */
77     protected static final String JavaDoc CONTENT_CHECK_RESULT = PATH_WORKPLACE + "admin/contenttools/check/result.jsp";
78
79     /** The Content Check object. */
80     private CmsContentCheck m_contentCheck;
81
82     /**
83      * Public constructor with JSP action element.<p>
84      *
85      * @param jsp an initialized JSP action element
86      */

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

100     public CmsContentCheckDialog(PageContext JavaDoc context, HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc res) {
101
102         this(new CmsJspActionElement(context, req, res));
103     }
104
105     /**
106      * @see org.opencms.workplace.CmsWidgetDialog#actionCommit()
107      */

108     public void actionCommit() {
109
110         List JavaDoc errors = new ArrayList JavaDoc();
111         try {
112             // check if there are any vfs paths entered
113
List JavaDoc paths = m_contentCheck.getPaths();
114             if (paths.size() == 0) {
115                 throw new CmsIllegalArgumentException(Messages.get().container(Messages.ERR_NO_VFSPATH_0));
116             } else {
117                 Iterator JavaDoc i = paths.iterator();
118                 while (i.hasNext()) {
119                     String JavaDoc path = (String JavaDoc)i.next();
120                     if (!getCms().existsResource(path)) {
121                         throw new CmsIllegalArgumentException(Messages.get().container(Messages.ERR_NO_VFSPATH_0));
122                     }
123                 }
124             }
125
126             // check if there is at least one test activated
127
boolean isActive = false;
128             List JavaDoc plugins = m_contentCheck.getPlugins();
129             Iterator JavaDoc i = plugins.iterator();
130             while (i.hasNext()) {
131                 I_CmsContentCheck plugin = (I_CmsContentCheck)i.next();
132                 if (plugin.isActive()) {
133                     isActive = true;
134                 }
135             }
136             if (!isActive) {
137                 throw new CmsIllegalArgumentException(Messages.get().container(Messages.ERR_NO_TEST_0));
138             }
139
140             // if there was no error, store the content check object in the session and forward it to the
141
// check thread
142
setDialogObject(m_contentCheck);
143             Map JavaDoc params = new HashMap JavaDoc();
144             // set the name of this class to get dialog object in report
145
params.put(CmsDatabaseExportReport.PARAM_CLASSNAME, this.getClass().getName());
146             // set style to display report in correct layout
147
params.put(PARAM_STYLE, CmsToolDialog.STYLE_NEW);
148             // set close link to get back to overview after finishing the import
149
params.put(PARAM_CLOSELINK, getJsp().link(CONTENT_CHECK_RESULT));
150             //params.put(PARAM_CLOSELINK, CmsToolManager.linkForToolPath(getJsp(), "/contenttools"));
151
getToolManager().jspForwardPage(this, CONTENT_CHECK_REPORT, params);
152
153         } catch (Throwable JavaDoc t) {
154             errors.add(t);
155         }
156         // set the list of errors to display when saving failed
157
setCommitErrors(errors);
158     }
159
160     /**
161      * Creates the dialog HTML for all defined widgets of the named dialog (page).<p>
162      *
163      * @param dialog the dialog (page) to get the HTML for
164      * @return the dialog HTML for all defined widgets of the named dialog (page)
165      */

166     protected String JavaDoc createDialogHtml(String JavaDoc dialog) {
167
168         StringBuffer JavaDoc result = new StringBuffer JavaDoc(1024);
169
170         // create table
171
result.append(createWidgetTableStart());
172
173         // show error header once if there were validation errors
174
result.append(createWidgetErrorHeader());
175
176         if (dialog.equals(PAGES[0])) {
177             result.append(dialogBlockStart(key("label.vfsresources")));
178             result.append(createWidgetTableStart());
179             result.append(createDialogRowsHtml(0, 0));
180             result.append(createWidgetTableEnd());
181             result.append(dialogBlockEnd());
182             result.append(dialogBlockStart(key("label.contentcheck")));
183             result.append(createWidgetTableStart());
184             result.append(createDialogRowsHtml(1, m_contentCheck.getPluginsCount()));
185             result.append(createWidgetTableEnd());
186             result.append(dialogBlockEnd());
187         }
188
189         // close table
190
result.append(createWidgetTableEnd());
191
192         return result.toString();
193     }
194
195     /**
196      * @see org.opencms.workplace.CmsWidgetDialog#defineWidgets()
197      */

198     protected void defineWidgets() {
199
200         initContentCheck();
201         addWidget(new CmsWidgetDialogParameter(m_contentCheck, "paths", PAGES[0], new CmsVfsFileWidget()));
202         // get a list of all plugins and build a widget for each plugin
203
List JavaDoc plugins = m_contentCheck.getPlugins();
204         for (int i = 0; i < plugins.size(); i++) {
205             I_CmsContentCheck plugin = (I_CmsContentCheck)plugins.get(i);
206             addWidget(new CmsWidgetDialogParameter(
207                 plugin,
208                 I_CmsContentCheck.PARAMETER,
209                 plugin.getDialogParameterName(),
210                 PAGES[0],
211                 new CmsCheckboxWidget()));
212         }
213
214     }
215
216     /**
217      * @see org.opencms.workplace.CmsWidgetDialog#getPageArray()
218      */

219     protected String JavaDoc[] getPageArray() {
220
221         return new String JavaDoc[] {"page1"};
222     }
223
224     /**
225      * Initializes the content check object or takes an exiting one which is stored in the sesstion.<p>
226      */

227     protected void initContentCheck() {
228
229         Object JavaDoc o;
230         if (CmsStringUtil.isEmpty(getParamAction()) || CmsDialog.DIALOG_INITIAL.equals(getParamAction())) {
231             // this is the initial dialog call
232
o = null;
233         } else {
234             // this is not the initial call, get module from session
235
o = getDialogObject();
236         }
237
238         if (!(o instanceof CmsContentCheck)) {
239             // create a new content check object
240
m_contentCheck = new CmsContentCheck(getCms());
241
242         } else {
243             // reuse content check object stored in session
244
m_contentCheck = (CmsContentCheck)o;
245         }
246     }
247
248     /**
249      * @see org.opencms.workplace.CmsWorkplace#initMessages()
250      */

251     protected void initMessages() {
252
253         // add specific dialog resource bundle
254
addMessages(org.opencms.workplace.tools.content.Messages.get().getBundleName());
255         addMessages("org.opencms.workplace.workplace");
256         addMessages(Messages.get().getBundleName());
257
258         // now add the additional message bundles for each plugin
259
CmsContentCheck dummy = new CmsContentCheck(getCms());
260         List JavaDoc plugins = dummy.getPlugins();
261         Iterator JavaDoc i = plugins.iterator();
262         while (i.hasNext()) {
263             I_CmsContentCheck plugin = (I_CmsContentCheck)i.next();
264             List JavaDoc bundles = plugin.getMessageBundles();
265             Iterator JavaDoc j = bundles.iterator();
266             while (j.hasNext()) {
267                 String JavaDoc bundle = (String JavaDoc)j.next();
268                 addMessages(bundle);
269             }
270         }
271
272         // add default resource bundles
273
super.initMessages();
274     }
275
276     /**
277      * @see org.opencms.workplace.CmsWorkplace#initWorkplaceRequestValues(org.opencms.workplace.CmsWorkplaceSettings, javax.servlet.http.HttpServletRequest)
278      */

279     protected void initWorkplaceRequestValues(CmsWorkplaceSettings settings, HttpServletRequest JavaDoc request) {
280
281         // set the dialog type
282
setParamDialogtype(DIALOG_TYPE);
283
284         super.initWorkplaceRequestValues(settings, request);
285
286         // save the current state of the content check object (may be changed because of the widget values)
287
setDialogObject(m_contentCheck);
288     }
289
290 }
291
Popular Tags