001: /*
002: * File : $Source: /usr/local/cvs/opencms/src-modules/org/opencms/workplace/tools/database/CmsDatabaseExportDialog.java,v $
003: * Date : $Date: 2008-02-27 12:05:51 $
004: * Version: $Revision: 1.21 $
005: *
006: * This library is part of OpenCms -
007: * the Open Source Content Management System
008: *
009: * Copyright (c) 2002 - 2008 Alkacon Software GmbH (http://www.alkacon.com)
010: *
011: * This library is free software; you can redistribute it and/or
012: * modify it under the terms of the GNU Lesser General Public
013: * License as published by the Free Software Foundation; either
014: * version 2.1 of the License, or (at your option) any later version.
015: *
016: * This library is distributed in the hope that it will be useful,
017: * but WITHOUT ANY WARRANTY; without even the implied warranty of
018: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
019: * Lesser General Public License for more details.
020: *
021: * For further information about Alkacon Software GmbH, please see the
022: * company website: http://www.alkacon.com
023: *
024: * For further information about OpenCms, please see the
025: * project website: http://www.opencms.org
026: *
027: * You should have received a copy of the GNU Lesser General Public
028: * License along with this library; if not, write to the Free Software
029: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
030: */
031:
032: package org.opencms.workplace.tools.database;
033:
034: import org.opencms.importexport.CmsExportParameters;
035: import org.opencms.jsp.CmsJspActionElement;
036: import org.opencms.main.OpenCms;
037: import org.opencms.util.CmsStringUtil;
038: import org.opencms.widgets.CmsCalendarWidget;
039: import org.opencms.widgets.CmsCheckboxWidget;
040: import org.opencms.widgets.CmsComboWidget;
041: import org.opencms.widgets.CmsInputWidget;
042: import org.opencms.widgets.CmsSelectWidgetOption;
043: import org.opencms.widgets.CmsVfsFileWidget;
044: import org.opencms.workplace.CmsWidgetDialog;
045: import org.opencms.workplace.CmsWidgetDialogParameter;
046: import org.opencms.workplace.CmsWorkplaceSettings;
047: import org.opencms.workplace.tools.CmsToolDialog;
048: import org.opencms.workplace.tools.CmsToolManager;
049:
050: import java.io.File;
051: import java.io.IOException;
052: import java.util.ArrayList;
053: import java.util.HashMap;
054: import java.util.Iterator;
055: import java.util.List;
056: import java.util.Map;
057:
058: import javax.servlet.ServletException;
059: import javax.servlet.http.HttpServletRequest;
060: import javax.servlet.http.HttpServletResponse;
061: import javax.servlet.jsp.PageContext;
062:
063: /**
064: * Widget dialog that sets the export options to export VFS resources to the OpenCms server.<p>
065: *
066: * @author Andreas Zahner
067: *
068: * @version $Revision: 1.21 $
069: *
070: * @since 6.0.0
071: */
072: public class CmsDatabaseExportDialog extends CmsWidgetDialog {
073:
074: /** Defines which pages are valid for this dialog. */
075: public static final String[] PAGES = { "page1" };
076:
077: /** The import JSP report workplace URI. */
078: protected static final String EXPORT_ACTION_REPORT = PATH_WORKPLACE
079: + "admin/database/reports/export.jsp";
080:
081: /** The export parameters object that is edited on this dialog. */
082: private CmsExportParameters m_exportParams;
083:
084: /**
085: * Public constructor with JSP action element.<p>
086: *
087: * @param jsp an initialized JSP action element
088: */
089: public CmsDatabaseExportDialog(CmsJspActionElement jsp) {
090:
091: super (jsp);
092: }
093:
094: /**
095: * Public constructor with JSP variables.<p>
096: *
097: * @param context the JSP page context
098: * @param req the JSP request
099: * @param res the JSP response
100: */
101: public CmsDatabaseExportDialog(PageContext context,
102: HttpServletRequest req, HttpServletResponse res) {
103:
104: this (new CmsJspActionElement(context, req, res));
105: }
106:
107: /**
108: * @see org.opencms.workplace.CmsWidgetDialog#actionCommit()
109: */
110: public void actionCommit() throws IOException, ServletException {
111:
112: List errors = new ArrayList();
113: // create absolute RFS path and store it in dialog object
114: String exportFileName = OpenCms.getSystemInfo()
115: .getAbsoluteRfsPathRelativeToWebInf(
116: OpenCms.getSystemInfo().getPackagesRfsPath()
117: + File.separator
118: + m_exportParams.getPath());
119: m_exportParams.setPath(exportFileName);
120: setDialogObject(m_exportParams);
121: Map params = new HashMap();
122: // set the name of this class to get dialog object in report
123: params.put(CmsDatabaseExportReport.PARAM_CLASSNAME, this
124: .getClass().getName());
125: // set style to display report in correct layout
126: params.put(PARAM_STYLE, CmsToolDialog.STYLE_NEW);
127: // set close link to get back to overview after finishing the import
128: params.put(PARAM_CLOSELINK, CmsToolManager.linkForToolPath(
129: getJsp(), "/database"));
130: // redirect to the report output JSP
131: getToolManager().jspForwardPage(this , EXPORT_ACTION_REPORT,
132: params);
133: // set the list of errors to display when saving failed
134: setCommitErrors(errors);
135: }
136:
137: /**
138: * @see org.opencms.workplace.CmsWidgetDialog#createDialogHtml(java.lang.String)
139: */
140: protected String createDialogHtml(String dialog) {
141:
142: StringBuffer result = new StringBuffer(1024);
143:
144: // create table
145: result.append(createWidgetTableStart());
146:
147: // show error header once if there were validation errors
148: result.append(createWidgetErrorHeader());
149:
150: // create export file name block
151: result
152: .append(createWidgetBlockStart(key(Messages.GUI_DATABASE_EXPORT_FILE_BLOCK_0)));
153: result.append(createDialogRowsHtml(0, 0));
154: result.append(createWidgetBlockEnd());
155:
156: // create export data type block
157: result
158: .append(createWidgetBlockStart(key(Messages.GUI_DATABASE_EXPORT_TYPES_BLOCK_0)));
159: result.append(createDialogRowsHtml(1, 3));
160: result.append(createWidgetBlockEnd());
161:
162: // create export settings block
163: result
164: .append(createWidgetBlockStart(key(Messages.GUI_DATABASE_EXPORT_SETTINGS_BLOCK_0)));
165: result.append(createDialogRowsHtml(4, 8));
166: result.append(createWidgetBlockEnd());
167:
168: // create export resource(s) block
169: result
170: .append(createWidgetBlockStart(key(Messages.GUI_DATABASE_EXPORT_RESOURCES_BLOCK_0)));
171: result.append(createDialogRowsHtml(9, 9));
172: result.append(createWidgetBlockEnd());
173:
174: // close table
175: result.append(createWidgetTableEnd());
176:
177: return result.toString();
178: }
179:
180: /**
181: * @see org.opencms.workplace.CmsWidgetDialog#defineWidgets()
182: */
183: protected void defineWidgets() {
184:
185: // initialize the sexport object to use for the dialog
186: initDatabaseExportObject();
187:
188: List exportFiles = getComboExportFiles();
189: if (exportFiles.isEmpty()) {
190: // no export files available, display text input field
191: addWidget(new CmsWidgetDialogParameter(m_exportParams,
192: "path", PAGES[0], new CmsInputWidget()));
193: } else {
194: // one or more export files present, create combo widget
195: addWidget(new CmsWidgetDialogParameter(m_exportParams,
196: "path", PAGES[0], new CmsComboWidget(exportFiles)));
197: }
198:
199: addWidget(new CmsWidgetDialogParameter(m_exportParams,
200: "exportResourceData", PAGES[0], new CmsCheckboxWidget()));
201: addWidget(new CmsWidgetDialogParameter(m_exportParams,
202: "exportAccountData", PAGES[0], new CmsCheckboxWidget()));
203: addWidget(new CmsWidgetDialogParameter(m_exportParams,
204: "exportProjectData", PAGES[0], new CmsCheckboxWidget()));
205:
206: addWidget(new CmsWidgetDialogParameter(m_exportParams,
207: "includeUnchangedResources", PAGES[0],
208: new CmsCheckboxWidget()));
209: addWidget(new CmsWidgetDialogParameter(m_exportParams,
210: "includeSystemFolder", PAGES[0],
211: new CmsCheckboxWidget()));
212: addWidget(new CmsWidgetDialogParameter(m_exportParams,
213: "contentAge", "0", PAGES[0], new CmsCalendarWidget(),
214: 0, 1));
215: addWidget(new CmsWidgetDialogParameter(m_exportParams,
216: "recursive", PAGES[0], new CmsCheckboxWidget()));
217: addWidget(new CmsWidgetDialogParameter(m_exportParams,
218: "inProject", PAGES[0], new CmsCheckboxWidget()));
219:
220: addWidget(new CmsWidgetDialogParameter(m_exportParams,
221: "resources", "/", PAGES[0], new CmsVfsFileWidget(false,
222: getCms().getRequestContext().getSiteRoot()), 1,
223: CmsWidgetDialogParameter.MAX_OCCURENCES));
224:
225: }
226:
227: /**
228: * Returns the present export files on the server to show in the combo box.<p>
229: *
230: * The result list elements are of type <code>{@link org.opencms.widgets.CmsSelectWidgetOption}</code>.<p>
231: *
232: * @return the present export files on the server to show in the combo box
233: */
234: protected List getComboExportFiles() {
235:
236: List result = new ArrayList(8);
237: Iterator i = CmsDatabaseImportFromServer.getFileListFromServer(
238: false).iterator();
239: while (i.hasNext()) {
240: String fileName = (String) i.next();
241: String helpText = key(
242: Messages.GUI_EDITOR_HELP_EXPORTFILE_1,
243: new String[] { fileName });
244: result.add(new CmsSelectWidgetOption(fileName, false, null,
245: helpText));
246: }
247: return result;
248: }
249:
250: /**
251: * @see org.opencms.workplace.CmsWidgetDialog#getPageArray()
252: */
253: protected String[] getPageArray() {
254:
255: return PAGES;
256: }
257:
258: /**
259: * Initializes the import/export object to work with depending on the dialog state and request parameters.<p>
260: */
261: protected void initDatabaseExportObject() {
262:
263: Object o;
264:
265: if (CmsStringUtil.isEmpty(getParamAction())) {
266: o = new CmsExportParameters();
267: } else {
268: // this is not the initial call, get the job object from session
269: o = getDialogObject();
270: }
271:
272: if (!(o instanceof CmsExportParameters)) {
273: // create a new export parameters object
274: m_exportParams = new CmsExportParameters();
275: } else {
276: // reuse export parameters object stored in session
277: m_exportParams = (CmsExportParameters) o;
278: }
279:
280: if (CmsStringUtil.isEmpty(getParamAction())
281: && (m_exportParams.getResources().size() < 1)) {
282: // on initial call, at least on resource input field has to be present
283: List initialPaths = new ArrayList(1);
284: initialPaths.add("/");
285: m_exportParams.setResources(initialPaths);
286: }
287: }
288:
289: /**
290: * @see org.opencms.workplace.CmsWorkplace#initMessages()
291: */
292: protected void initMessages() {
293:
294: // add specific dialog resource bundle
295: addMessages(Messages.get().getBundleName());
296: // add default resource bundles
297: super .initMessages();
298: }
299:
300: /**
301: * @see org.opencms.workplace.CmsWorkplace#initWorkplaceRequestValues(org.opencms.workplace.CmsWorkplaceSettings, javax.servlet.http.HttpServletRequest)
302: */
303: protected void initWorkplaceRequestValues(
304: CmsWorkplaceSettings settings, HttpServletRequest request) {
305:
306: // initialize parameters and dialog actions in super implementation
307: super .initWorkplaceRequestValues(settings, request);
308:
309: // save the current state of the export parameters (may be changed because of the widget values)
310: setDialogObject(m_exportParams);
311: }
312: }
|