KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > workplace > commons > CmsUndelete


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src/org/opencms/workplace/commons/CmsUndelete.java,v $
3  * Date : $Date: 2006/03/27 14:52:18 $
4  * Version: $Revision: 1.15 $
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.commons;
33
34 import org.opencms.jsp.CmsJspActionElement;
35 import org.opencms.main.CmsException;
36 import org.opencms.security.CmsPermissionSet;
37 import org.opencms.workplace.CmsMultiDialog;
38 import org.opencms.workplace.CmsWorkplaceSettings;
39
40 import java.util.Iterator JavaDoc;
41
42 import javax.servlet.http.HttpServletRequest JavaDoc;
43 import javax.servlet.http.HttpServletResponse JavaDoc;
44 import javax.servlet.jsp.JspException JavaDoc;
45 import javax.servlet.jsp.PageContext JavaDoc;
46
47 /**
48  * Provides methods for the undelete resources dialog.<p>
49  *
50  * The following files use this class:
51  * <ul>
52  * <li>/commons/undelete.jsp
53  * </ul>
54  * <p>
55  *
56  * @author Andreas Zahner
57  *
58  * @version $Revision: 1.15 $
59  *
60  * @since 6.0.0
61  */

62 public class CmsUndelete extends CmsMultiDialog {
63
64     /** Value for the action: undelete resource. */
65     public static final int ACTION_UNDELETE = 100;
66
67     /** The dialog type. */
68     public static final String JavaDoc DIALOG_TYPE = "undelete";
69
70     /**
71      * Public constructor with JSP action element.<p>
72      *
73      * @param jsp an initialized JSP action element
74      */

75     public CmsUndelete(CmsJspActionElement jsp) {
76
77         super(jsp);
78     }
79
80     /**
81      * Public constructor with JSP variables.<p>
82      *
83      * @param context the JSP page context
84      * @param req the JSP request
85      * @param res the JSP response
86      */

87     public CmsUndelete(PageContext JavaDoc context, HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc res) {
88
89         this(new CmsJspActionElement(context, req, res));
90     }
91
92     /**
93      * Performs the undelete action, will be called by the JSP page.<p>
94      *
95      * @throws JspException if problems including sub-elements occur
96      */

97     public void actionUndelete() throws JspException JavaDoc {
98
99         // save initialized instance of this class in request attribute for included sub-elements
100
getJsp().getRequest().setAttribute(SESSION_WORKPLACE_CLASS, this);
101         try {
102             if (performDialogOperation()) {
103                 // if no exception is caused and "true" is returned delete operation was successful
104
actionCloseDialog();
105             } else {
106                 // "false" returned, display "please wait" screen
107
getJsp().include(FILE_DIALOG_SCREEN_WAIT);
108             }
109         } catch (Throwable JavaDoc e) {
110             // error during deletion, show error dialog
111
includeErrorpage(this, e);
112         }
113     }
114     
115     /**
116      * Returns the HTML for the localized undelete confirmation message depending on single or multi operation.<p>
117      *
118      * @return the HTML for the localized undelete confirmation message
119      */

120     public String JavaDoc buildConfirmationMessage() {
121         
122         if (isMultiOperation()) {
123             return key(Messages.GUI_UNDELETE_MULTI_CONFIRMATION_0);
124         } else {
125             return key(Messages.GUI_UNDELETE_CONFIRMATION_0);
126         }
127     }
128
129     /**
130      * @see org.opencms.workplace.CmsWorkplace#initWorkplaceRequestValues(org.opencms.workplace.CmsWorkplaceSettings, javax.servlet.http.HttpServletRequest)
131      */

132     protected void initWorkplaceRequestValues(CmsWorkplaceSettings settings, HttpServletRequest JavaDoc request) {
133
134         // fill the parameter values in the get/set methods
135
fillParamValues(request);
136         
137         // check the required permissions to undelete the resource
138
if (! checkResourcePermissions(CmsPermissionSet.ACCESS_WRITE, false)) {
139             // no write permissions for the resource, set cancel action to close dialog
140
setParamAction(DIALOG_CANCEL);
141         }
142         
143         // set the dialog type
144
setParamDialogtype(DIALOG_TYPE);
145         // set the action for the JSP switch
146
if (DIALOG_TYPE.equals(getParamAction())) {
147             setAction(ACTION_UNDELETE);
148         } else if (DIALOG_WAIT.equals(getParamAction())) {
149             setAction(ACTION_WAIT);
150         } else if (DIALOG_CANCEL.equals(getParamAction())) {
151             setAction(ACTION_CANCEL);
152         } else {
153             setAction(ACTION_DEFAULT);
154             // build title for delete dialog
155
setDialogTitle(Messages.GUI_UNDELETE_RESOURCE_1, Messages.GUI_UNDELETE_MULTI_2);
156         }
157     }
158
159     /**
160      * Performs the resource undeletion.<p>
161      *
162      * @return true, if the undelete operation is successful, otherwise false
163      * @throws CmsException if undeletion is not successful
164      */

165     protected boolean performDialogOperation() throws CmsException {
166
167         // check if the current resource is a folder for single operation
168
boolean isFolder = isOperationOnFolder();
169         // on folder undelete or multi operation display "please wait" screen, not for simple file undeletion
170
if ((isMultiOperation() || isFolder) && !DIALOG_WAIT.equals(getParamAction())) {
171             // return false, this will trigger the "please wait" screen
172
return false;
173         }
174         
175         Iterator JavaDoc i = getResourceList().iterator();
176         // iterate the resources to undelete
177
while (i.hasNext()) {
178             String JavaDoc resName = (String JavaDoc)i.next();
179             try {
180                 // lock resource if autolock is enabled
181
checkLock(resName);
182                 // undelete the resource
183
getCms().undeleteResource(resName);
184             } catch (CmsException e) {
185                 if (isMultiOperation()) {
186                     // collect exceptions to create a detailed output
187
addMultiOperationException(e);
188                 } else {
189                     // for single operation, throw the exception immediately
190
throw e;
191                 }
192             }
193         }
194         // check if exceptions occured
195
checkMultiOperationException(Messages.get(), Messages.ERR_UNDELETE_MULTI_0);
196         return true;
197     }
198 }
199
Popular Tags