001: /*
002: * File : $Source: /usr/local/cvs/opencms/src/org/opencms/workplace/commons/CmsDeletedResources.java,v $
003: * Date : $Date: 2008-02-27 12:05:25 $
004: * Version: $Revision: 1.4 $
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.commons;
033:
034: import org.opencms.jsp.CmsJspActionElement;
035: import org.opencms.main.CmsRuntimeException;
036: import org.opencms.util.CmsStringUtil;
037: import org.opencms.util.CmsUUID;
038: import org.opencms.workplace.CmsDialog;
039: import org.opencms.workplace.CmsWorkplace;
040: import org.opencms.workplace.CmsWorkplaceSettings;
041: import org.opencms.workplace.list.A_CmsListDialog;
042: import org.opencms.workplace.list.CmsHtmlList;
043:
044: import java.io.IOException;
045: import java.util.ArrayList;
046: import java.util.Iterator;
047: import java.util.List;
048:
049: import javax.servlet.ServletException;
050: import javax.servlet.http.HttpServletRequest;
051: import javax.servlet.http.HttpServletResponse;
052: import javax.servlet.jsp.JspException;
053: import javax.servlet.jsp.PageContext;
054:
055: /**
056: * Creates the dialogs for showing and restoring deleted resources.<p>
057: *
058: * The following files use this class:
059: * <ul>
060: * <li>/commons/show-deleted.jsp
061: * </ul>
062: * <p>
063: *
064: * @author Peter Bonrad
065: *
066: * @version $Revision: 1.4 $
067: *
068: * @since 6.9.1
069: */
070: public class CmsDeletedResources extends CmsDialog {
071:
072: /** Request parameter name for the relatedresources parameter. */
073: public static final String PARAM_READTREE = "readtree";
074:
075: /** The list action. */
076: private String m_paramListAction;
077:
078: /** Parameter value, if the deleted resources should be displayed for the subtree. */
079: private String m_paramReadtree;
080:
081: /** The selected items, comma separated list. */
082: private String m_paramSelItems;
083:
084: /**
085: * Public constructor with JSP action element.<p>
086: *
087: * @param jsp an initialized JSP action element
088: */
089: public CmsDeletedResources(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 CmsDeletedResources(PageContext context,
102: HttpServletRequest req, HttpServletResponse res) {
103:
104: this (new CmsJspActionElement(context, req, res));
105: }
106:
107: /**
108: * Returns the html code to include the needed js code.<p>
109: *
110: * @return html code
111: */
112: public String buildIncludeJs() {
113:
114: StringBuffer html = new StringBuffer(512);
115:
116: html.append("<script type='text/javascript' src='");
117: html.append(CmsWorkplace.getSkinUri());
118: html.append("commons/ajax.js'></script>\n");
119:
120: html.append("<script type='text/javascript' src='");
121: html.append(CmsWorkplace.getSkinUri());
122: html.append("editors/xmlcontent/help.js'></script>\n");
123:
124: html.append("<script type='text/javascript' src='");
125: html.append(CmsWorkplace.getSkinUri());
126: html.append("admin/javascript/general.js'></script>\n");
127:
128: html.append("<script type='text/javascript' src='");
129: html.append(CmsWorkplace.getSkinUri());
130: html.append("admin/javascript/list.js'></script>\n");
131:
132: html.append("<script type='text/javascript'><!--\n");
133:
134: html.append("\tvar ");
135: html.append(CmsHtmlList.NO_SELECTION_HELP_VAR);
136: html.append(" = '");
137: html
138: .append(CmsStringUtil
139: .escapeJavaScript(key(org.opencms.workplace.list.Messages.GUI_LIST_ACTION_NO_SELECTION_0)));
140: html.append("';\n");
141:
142: html.append("function doReportUpdate(msg, state) {\n");
143: html.append("\tvar img = state + '.png';\n");
144: html.append("\tvar txt = '';\n");
145: html
146: .append("\tvar elem = document.getElementById('ajaxreport');\n");
147: html.append("\tif (state != 'ok') {\n");
148: html.append("\t\tif (state == 'fatal') {\n");
149: html.append("\t\t\timg = 'error.png';\n");
150: html.append("\t\t\ttxt = '");
151: html
152: .append(key(org.opencms.workplace.Messages.GUI_AJAX_REPORT_GIVEUP_0));
153: html.append("';\n");
154: html.append("\t\t} else if (state == 'wait') {\n");
155: html.append("\t\t\timg = 'wait.gif';\n");
156: html.append("\t\t\ttxt = '");
157: html
158: .append(key(org.opencms.workplace.Messages.GUI_AJAX_REPORT_WAIT_0));
159: html.append("'\n");
160: html.append("\t\t} else if (state == 'error') {\n");
161: html.append("\t\t\ttxt = '");
162: html
163: .append(key(org.opencms.workplace.Messages.GUI_AJAX_REPORT_ERROR_0));
164: html.append("' + msg;\n");
165: html.append("\t\t}\n");
166: html.append("\t} else {");
167: html.append("\t\telem.innerHTML = msg;\n");
168: html.append("\t}\n");
169: html.append("\tif (txt != '') {\n");
170: html
171: .append("\t\tvar html = \"<table border='0' style='vertical-align:middle; height: 200px;'>\";");
172: html
173: .append("\t\thtml += \"<tr><td width='40' align='center' valign='middle'><img src='");
174: html.append(getSkinUri());
175: html.append("commons/\";");
176: html.append("\t\thtml += img;");
177: html
178: .append("\t\thtml += \"' width='32' height='32' alt=''></td>\";");
179: html
180: .append("\t\thtml += \"<td valign='middle'><span style='color: #000099; font-weight: bold;'>\";");
181: html.append("\t\thtml += txt;");
182: html.append("\t\thtml += \"</span><br></td></tr></table>\";");
183: html.append("\t\telem.innerHTML = html;");
184: html.append("\t}\n");
185: html.append("}\n");
186:
187: html.append("function reloadReport() {\n");
188: html.append("\tvar readtree = document.forms[\"");
189: html.append(CmsDeletedResourcesList.LIST_ID);
190: html.append("-form\"].");
191: html.append(PARAM_READTREE);
192: html.append(".checked;\n");
193: html.append("\tmakeRequest('");
194: html.append(getJsp().link(
195: "/system/workplace/commons/report-deleted.jsp"));
196: html.append("', '");
197: html.append(CmsDialog.PARAM_RESOURCE);
198: html.append("=");
199: html.append(getParamResource());
200: html.append("&");
201: html.append(PARAM_READTREE);
202: html.append("=");
203: html.append("' + readtree");
204: html.append(", 'doReportUpdate');\n");
205: html.append("}\n");
206:
207: html.append("// -->\n");
208: html.append("</script>\n");
209:
210: return html.toString();
211: }
212:
213: /**
214: * Override to display additional options in the dialog.<p>
215: *
216: * @return html code to display additional options
217: */
218: public String buildOptions() {
219:
220: StringBuffer result = new StringBuffer(128);
221:
222: result.append("<input type='checkbox' name='");
223: result.append(PARAM_READTREE);
224: result.append("' value='true' onclick=\"reloadReport();\"");
225: if (Boolean.valueOf(getParamReadtree()).booleanValue()) {
226: result.append(" checked='checked'");
227: }
228: result.append("> ");
229: result.append(key(Messages.GUI_DELETED_RESOURCES_READ_TREE_0));
230:
231: return result.toString();
232: }
233:
234: /**
235: * Builds the html code for the report with the list of deleted resources.<p>
236: *
237: * @return html code for the report with the list of deleted resources
238: *
239: * @throws JspException if dialog actions fail
240: * @throws IOException in case of errros forwarding to the required result page
241: * @throws ServletException in case of errros forwarding to the required result page
242: */
243: public String buildReport() throws JspException, ServletException,
244: IOException {
245:
246: CmsDeletedResourcesList list = new CmsDeletedResourcesList(
247: getJsp(), getParamResource(), Boolean.valueOf(
248: getParamReadtree()).booleanValue());
249:
250: list.actionDialog();
251: list.getList().setBoxed(false);
252:
253: StringBuffer result = new StringBuffer(512);
254: result.append("<div style='height:200px; overflow: auto;'>\n");
255: result.append(list.getList().listHtml());
256: result.append("</div>\n");
257: return result.toString();
258: }
259:
260: /**
261: * Builds the java script code to build the report.<p>
262: *
263: * @return html code with the java script to use ajax to create the report
264: */
265: public String buildReportRequest() {
266:
267: StringBuffer html = new StringBuffer(512);
268:
269: html.append("<script type='text/javascript'><!--\n");
270: html.append("makeRequest('");
271: html.append(getJsp().link(
272: "/system/workplace/commons/report-deleted.jsp"));
273: html.append("', '");
274: html.append(CmsDialog.PARAM_RESOURCE);
275: html.append("=");
276: html.append(getParamResource());
277: html.append("', 'doReportUpdate');\n");
278: html.append("// -->\n");
279: html.append("</script>\n");
280:
281: return html.toString();
282: }
283:
284: /**
285: * Builds the necessary button row.<p>
286: *
287: * @return the button row
288: */
289: public String dialogButtons() {
290:
291: return dialogButtonsOkCancel(" onclick=\"listMAction('"
292: + CmsDeletedResourcesList.LIST_ID + "','"
293: + CmsDeletedResourcesList.LIST_MACTION_RESTORE
294: + "', '', noSelHelp);\"", null);
295: }
296:
297: /**
298: * Executes the actions from the deleted resources list.<p>
299: *
300: * @see org.opencms.workplace.list.A_CmsListDialog#executeListMultiActions()
301: *
302: * @throws JspException if problems including sub-elements occur
303: */
304: public void executeListMultiActions() throws JspException {
305:
306: if (getParamListAction().equals(
307: CmsDeletedResourcesList.LIST_MACTION_RESTORE)) {
308:
309: StringBuffer errors = new StringBuffer();
310:
311: Iterator iter = getSelectedItems().iterator();
312: while (iter.hasNext()) {
313: CmsUUID id = new CmsUUID((String) iter.next());
314: try {
315: getCms().restoreDeletedResource(id);
316: } catch (Exception e) {
317: errors.append(e.getLocalizedMessage());
318: }
319: }
320:
321: if (errors.length() > 0) {
322: throw new CmsRuntimeException(Messages.get().container(
323: Messages.ERR_RESTORE_SELECTED_RESOURCES_1,
324: errors));
325: } else {
326: actionCloseDialog();
327: }
328: }
329: }
330:
331: /**
332: * Returns the paramListAction.<p>
333: *
334: * @return the paramListAction
335: */
336: public String getParamListAction() {
337:
338: return m_paramListAction;
339: }
340:
341: /**
342: * Returns the paramReadtree.<p>
343: *
344: * @return the paramReadtree
345: */
346: public String getParamReadtree() {
347:
348: if (CmsStringUtil.isEmptyOrWhitespaceOnly(m_paramReadtree)) {
349: return "false";
350: }
351:
352: return m_paramReadtree;
353: }
354:
355: /**
356: * Returns the paramSelItems.<p>
357: *
358: * @return the paramSelItems
359: */
360: public String getParamSelItems() {
361:
362: return m_paramSelItems;
363: }
364:
365: /**
366: * Returns a list of resource ids of the current selected items.<p>
367: *
368: * @return a list of resource ids of the current selected items
369: */
370: public List getSelectedItems() {
371:
372: Iterator it = CmsStringUtil.splitAsList(getParamSelItems(),
373: CmsHtmlList.ITEM_SEPARATOR, true).iterator();
374: List items = new ArrayList();
375: while (it.hasNext()) {
376: String id = (String) it.next();
377: items.add(id);
378: }
379: return items;
380: }
381:
382: /**
383: * @see org.opencms.workplace.CmsWorkplace#paramsAsHidden()
384: */
385: public String paramsAsHidden() {
386:
387: List excludes = new ArrayList();
388: excludes.add(PARAM_READTREE);
389: return paramsAsHidden(excludes);
390: }
391:
392: /**
393: * Sets the paramListAction.<p>
394: *
395: * @param paramListAction the paramListAction to set
396: */
397: public void setParamListAction(String paramListAction) {
398:
399: m_paramListAction = paramListAction;
400: }
401:
402: /**
403: * Sets the paramReadtree.<p>
404: *
405: * @param paramReadtree the paramReadtree to set
406: */
407: public void setParamReadtree(String paramReadtree) {
408:
409: m_paramReadtree = paramReadtree;
410: }
411:
412: /**
413: * Sets the paramSelItems.<p>
414: *
415: * @param paramSelItems the paramSelItems to set
416: */
417: public void setParamSelItems(String paramSelItems) {
418:
419: m_paramSelItems = paramSelItems;
420: }
421:
422: /**
423: * @see org.opencms.workplace.CmsDialog#initWorkplaceRequestValues(org.opencms.workplace.CmsWorkplaceSettings, javax.servlet.http.HttpServletRequest)
424: */
425: protected void initWorkplaceRequestValues(
426: CmsWorkplaceSettings settings, HttpServletRequest request) {
427:
428: super .initWorkplaceRequestValues(settings, request);
429:
430: // set title
431: setParamTitle(key(Messages.GUI_DELETED_RESOURCES_TITLE_1,
432: new Object[] { getParamResource() }));
433:
434: // init params to appear as hidden field
435: if (getParamListAction() == null) {
436: setParamListAction("");
437: }
438: if (getParamSelItems() == null) {
439: setParamSelItems("");
440: }
441:
442: if (A_CmsListDialog.LIST_MULTI_ACTION.equals(getParamAction())) {
443: setAction(A_CmsListDialog.ACTION_LIST_MULTI_ACTION);
444: }
445: }
446: }
|