KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > workplace > tools > database > CmsDatabaseExportDialog


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src-modules/org/opencms/workplace/tools/database/CmsDatabaseExportDialog.java,v $
3  * Date : $Date: 2006/03/28 13:10:02 $
4  * Version: $Revision: 1.16 $
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.database;
33
34 import org.opencms.importexport.CmsVfsImportExportHandler;
35 import org.opencms.jsp.CmsJspActionElement;
36 import org.opencms.main.OpenCms;
37 import org.opencms.util.CmsStringUtil;
38 import org.opencms.widgets.CmsCalendarWidget;
39 import org.opencms.widgets.CmsCheckboxWidget;
40 import org.opencms.widgets.CmsComboWidget;
41 import org.opencms.widgets.CmsInputWidget;
42 import org.opencms.widgets.CmsSelectWidgetOption;
43 import org.opencms.widgets.CmsVfsFileWidget;
44 import org.opencms.workplace.CmsWidgetDialog;
45 import org.opencms.workplace.CmsWidgetDialogParameter;
46 import org.opencms.workplace.CmsWorkplaceSettings;
47 import org.opencms.workplace.tools.CmsToolDialog;
48 import org.opencms.workplace.tools.CmsToolManager;
49
50 import java.io.File JavaDoc;
51 import java.io.IOException JavaDoc;
52 import java.util.ArrayList JavaDoc;
53 import java.util.HashMap JavaDoc;
54 import java.util.Iterator JavaDoc;
55 import java.util.List JavaDoc;
56 import java.util.Map JavaDoc;
57
58 import javax.servlet.ServletException JavaDoc;
59 import javax.servlet.http.HttpServletRequest JavaDoc;
60 import javax.servlet.http.HttpServletResponse JavaDoc;
61 import javax.servlet.jsp.PageContext JavaDoc;
62
63 /**
64  * Widget dialog that sets the export options to export VFS resources to the OpenCms server.<p>
65  *
66  * @author Andreas Zahner
67  *
68  * @version $Revision: 1.16 $
69  *
70  * @since 6.0.0
71  */

72 public class CmsDatabaseExportDialog extends CmsWidgetDialog {
73
74     /** Defines which pages are valid for this dialog. */
75     public static final String JavaDoc[] PAGES = {"page1"};
76
77     /** The import JSP report workplace URI. */
78     protected static final String JavaDoc EXPORT_ACTION_REPORT = PATH_WORKPLACE + "admin/database/reports/export.jsp";
79
80     /** The export handler object that is edited on this dialog. */
81     private CmsVfsImportExportHandler m_exportHandler;
82
83     /**
84      * Public constructor with JSP action element.<p>
85      *
86      * @param jsp an initialized JSP action element
87      */

88     public CmsDatabaseExportDialog(CmsJspActionElement jsp) {
89
90         super(jsp);
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 CmsDatabaseExportDialog(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() throws IOException JavaDoc, ServletException JavaDoc {
109
110         List JavaDoc errors = new ArrayList JavaDoc();
111         // create absolute RFS path and store it in dialog object
112
String JavaDoc exportFileName = OpenCms.getSystemInfo().getAbsoluteRfsPathRelativeToWebInf(
113             OpenCms.getSystemInfo().getPackagesRfsPath() + File.separator + m_exportHandler.getFileName());
114         m_exportHandler.setFileName(exportFileName);
115         setDialogObject(m_exportHandler);
116         Map JavaDoc params = new HashMap JavaDoc();
117         // set the name of this class to get dialog object in report
118
params.put(CmsDatabaseExportReport.PARAM_CLASSNAME, this.getClass().getName());
119         // set style to display report in correct layout
120
params.put(PARAM_STYLE, CmsToolDialog.STYLE_NEW);
121         // set close link to get back to overview after finishing the import
122
params.put(PARAM_CLOSELINK, CmsToolManager.linkForToolPath(getJsp(), "/database"));
123         // redirect to the report output JSP
124
getToolManager().jspForwardPage(this, EXPORT_ACTION_REPORT, params);
125         // set the list of errors to display when saving failed
126
setCommitErrors(errors);
127     }
128
129     /**
130      * @see org.opencms.workplace.CmsWidgetDialog#createDialogHtml(java.lang.String)
131      */

132     protected String JavaDoc createDialogHtml(String JavaDoc dialog) {
133
134         StringBuffer JavaDoc result = new StringBuffer JavaDoc(1024);
135
136         // create table
137
result.append(createWidgetTableStart());
138
139         // show error header once if there were validation errors
140
result.append(createWidgetErrorHeader());
141
142         // create export file name block
143
result.append(createWidgetBlockStart(key(Messages.GUI_DATABASE_EXPORT_FILE_BLOCK_0)));
144         result.append(createDialogRowsHtml(0, 0));
145         result.append(createWidgetBlockEnd());
146
147         // create export settings block
148
result.append(createWidgetBlockStart(key(Messages.GUI_DATABASE_EXPORT_SETTINGS_BLOCK_0)));
149         result.append(createDialogRowsHtml(1, 6));
150         result.append(createWidgetBlockEnd());
151
152         // create export resource(s) block
153
result.append(createWidgetBlockStart(key(Messages.GUI_DATABASE_EXPORT_RESOURCES_BLOCK_0)));
154         result.append(createDialogRowsHtml(7, 7));
155         result.append(createWidgetBlockEnd());
156
157         // close table
158
result.append(createWidgetTableEnd());
159
160         return result.toString();
161     }
162
163     /**
164      * @see org.opencms.workplace.CmsWidgetDialog#defineWidgets()
165      */

166     protected void defineWidgets() {
167
168         // initialize the sexport object to use for the dialog
169
initDatabaseExportObject();
170
171         List JavaDoc exportFiles = getComboExportFiles();
172         if (exportFiles.isEmpty()) {
173             // no export files available, display text input field
174
addWidget(new CmsWidgetDialogParameter(m_exportHandler, "fileName", PAGES[0], new CmsInputWidget()));
175         } else {
176             // one or more export files present, create combo widget
177
addWidget(new CmsWidgetDialogParameter(m_exportHandler, "fileName", PAGES[0], new CmsComboWidget(
178                 exportFiles)));
179         }
180
181         addWidget(new CmsWidgetDialogParameter(m_exportHandler, "includeUnchanged", PAGES[0], new CmsCheckboxWidget()));
182         addWidget(new CmsWidgetDialogParameter(m_exportHandler, "exportUserdata", PAGES[0], new CmsCheckboxWidget()));
183         addWidget(new CmsWidgetDialogParameter(m_exportHandler, "exportWebusers", PAGES[0], new CmsCheckboxWidget()));
184         addWidget(new CmsWidgetDialogParameter(m_exportHandler, "includeSystem", PAGES[0], new CmsCheckboxWidget()));
185         addWidget(new CmsWidgetDialogParameter(
186             m_exportHandler,
187             "contentAge",
188             "0",
189             PAGES[0],
190             new CmsCalendarWidget(),
191             0,
192             1));
193         addWidget(new CmsWidgetDialogParameter(m_exportHandler, "recursive", PAGES[0], new CmsCheckboxWidget()));
194
195         addWidget(new CmsWidgetDialogParameter(m_exportHandler, "exportPaths", "/", PAGES[0], new CmsVfsFileWidget(
196             false,
197             getCms().getRequestContext().getSiteRoot()), 1, CmsWidgetDialogParameter.MAX_OCCURENCES));
198     }
199
200     /**
201      * Returns the present export files on the server to show in the combo box.<p>
202      *
203      * The result list elements are of type <code>{@link org.opencms.widgets.CmsSelectWidgetOption}</code>.<p>
204      *
205      * @return the present export files on the server to show in the combo box
206      */

207     protected List JavaDoc getComboExportFiles() {
208
209         List JavaDoc result = new ArrayList JavaDoc(8);
210         Iterator JavaDoc i = CmsDatabaseImportFromServer.getFileListFromServer(false).iterator();
211         while (i.hasNext()) {
212             String JavaDoc fileName = (String JavaDoc)i.next();
213             String JavaDoc helpText = key(Messages.GUI_EDITOR_HELP_EXPORTFILE_1, new String JavaDoc[] {fileName});
214             result.add(new CmsSelectWidgetOption(fileName, false, null, helpText));
215         }
216         return result;
217     }
218
219     /**
220      * @see org.opencms.workplace.CmsWidgetDialog#getPageArray()
221      */

222     protected String JavaDoc[] getPageArray() {
223
224         return PAGES;
225     }
226
227     /**
228      * Initializes the import/export object to work with depending on the dialog state and request parameters.<p>
229      */

230     protected void initDatabaseExportObject() {
231
232         Object JavaDoc o;
233
234         if (CmsStringUtil.isEmpty(getParamAction())) {
235             o = new CmsVfsImportExportHandler();
236         } else {
237             // this is not the initial call, get the job object from session
238
o = getDialogObject();
239         }
240
241         if (!(o instanceof CmsVfsImportExportHandler)) {
242             // create a new export handler object
243
m_exportHandler = new CmsVfsImportExportHandler();
244         } else {
245             // reuse export handler object stored in session
246
m_exportHandler = (CmsVfsImportExportHandler)o;
247         }
248
249         if (CmsStringUtil.isEmpty(getParamAction()) && m_exportHandler.getExportPaths().size() < 1) {
250             // on initial call, at least on resource input field has to be present
251
List JavaDoc initialPaths = new ArrayList JavaDoc(1);
252             initialPaths.add("/");
253             m_exportHandler.setExportPaths(initialPaths);
254         }
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 default resource bundles
265
super.initMessages();
266     }
267
268     /**
269      * @see org.opencms.workplace.CmsWorkplace#initWorkplaceRequestValues(org.opencms.workplace.CmsWorkplaceSettings, javax.servlet.http.HttpServletRequest)
270      */

271     protected void initWorkplaceRequestValues(CmsWorkplaceSettings settings, HttpServletRequest JavaDoc request) {
272
273         // initialize parameters and dialog actions in super implementation
274
super.initWorkplaceRequestValues(settings, request);
275
276         // save the current state of the export handler (may be changed because of the widget values)
277
setDialogObject(m_exportHandler);
278     }
279 }
Popular Tags