KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > opencms > workplace > CmsRestoreResource


1 /*
2 * File : $Source: /usr/local/cvs/opencms/src-modules/com/opencms/workplace/CmsRestoreResource.java,v $
3 * Date : $Date: 2005/06/27 23:22:07 $
4 * Version: $Revision: 1.4 $
5 *
6 * This library is part of OpenCms -
7 * the Open Source Content Mananagement System
8 *
9 * Copyright (C) 2001 The OpenCms Group
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 OpenCms, please see the
22 * OpenCms Website: http://www.opencms.org
23 *
24 * You should have received a copy of the GNU Lesser General Public
25 * License along with this library; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 */

28
29 package com.opencms.workplace;
30
31 import org.opencms.file.CmsObject;
32 import org.opencms.file.CmsResource;
33 import org.opencms.file.CmsResourceFilter;
34 import org.opencms.main.CmsException;
35 import org.opencms.main.OpenCms;
36 import org.opencms.util.CmsDateUtil;
37
38 import com.opencms.core.I_CmsSession;
39 import com.opencms.legacy.CmsLegacyException;
40 import com.opencms.legacy.CmsXmlTemplateLoader;
41
42 import java.util.Hashtable JavaDoc;
43
44 /**
45  * Template class for displaying the restore resource screen of the OpenCms workplace.<P>
46  * Reads template files of the content type <code>CmsXmlWpTemplateFile</code>.
47  *
48  * @author Edna Falkenhan
49  * @version $Revision: 1.4 $ $Date: 2005/06/27 23:22:07 $
50  *
51  * @deprecated Will not be supported past the OpenCms 6 release.
52  */

53
54 public class CmsRestoreResource extends CmsWorkplaceDefault {
55
56     /**
57      * Overwrites the getContent method of the CmsWorkplaceDefault.<br>
58      * Gets the content of the undelete template and processed the data input.
59      * @param cms The CmsObject.
60      * @param templateFile The undelete template file
61      * @param elementName not used
62      * @param parameters Parameters of the request and the template.
63      * @param templateSelector Selector of the template tag to be displayed.
64      * @return Bytearre containgine the processed data of the template.
65      * @throws CmsException if something goes wrong.
66      */

67
68     public byte[] getContent(CmsObject cms, String JavaDoc templateFile, String JavaDoc elementName,
69         Hashtable JavaDoc parameters, String JavaDoc templateSelector) throws CmsException {
70         I_CmsSession session = CmsXmlTemplateLoader.getSession(cms.getRequestContext(), true);
71         CmsXmlWpTemplateFile xmlTemplateDocument = new CmsXmlWpTemplateFile(cms, templateFile);
72         // the template to be displayed
73
String JavaDoc template = null;
74
75         // clear session values on first load
76
String JavaDoc initial = (String JavaDoc)parameters.get(CmsWorkplaceDefault.C_PARA_INITIAL);
77         if (initial != null) {
78             // remove all session values
79
session.removeValue(CmsWorkplaceDefault.C_PARA_RESOURCE);
80             //session.removeValue("versionid");
81
session.removeValue("restore");
82             session.removeValue("lasturl");
83         }
84
85         // get the lasturl parameter
86
String JavaDoc lasturl = getLastUrl(cms, parameters);
87         String JavaDoc restore = (String JavaDoc)parameters.get("restore");
88         if (restore != null) {
89             session.putValue("restore", restore);
90         }
91         restore = (String JavaDoc)session.getValue("restore");
92         String JavaDoc filename = (String JavaDoc)parameters.get(CmsWorkplaceDefault.C_PARA_RESOURCE);
93         if (filename != null) {
94             session.putValue(CmsWorkplaceDefault.C_PARA_RESOURCE, filename);
95         }
96         filename = (String JavaDoc)session.getValue(CmsWorkplaceDefault.C_PARA_RESOURCE);
97
98         String JavaDoc version = (String JavaDoc)session.getValue("version");
99         String JavaDoc action = (String JavaDoc)parameters.get("action");
100
101         CmsResource file = null;
102         if (filename.endsWith("/")) {
103             file = cms.readFolder(filename, CmsResourceFilter.IGNORE_EXPIRATION);
104         } else {
105             file = cms.readResource(filename, CmsResourceFilter.IGNORE_EXPIRATION);
106         }
107         //check if the name parameter was included in the request
108
// if not, the restoreresource page is shown for the first time
109
if (restore != null) {
110             if (action != null) {
111                 // restore the resource
112
try {
113                     // check the autolock resource setting and lock the resource if necessary
114
if (OpenCms.getWorkplaceManager().autoLockResources()) {
115                         if (cms.getLock(filename).isNullLock()) {
116                             // resource is not locked, lock it automatically
117
cms.lockResource(filename);
118                         }
119                     }
120                     cms.restoreResourceBackup(cms.getSitePath(file), Integer.parseInt(version));
121                     session.removeValue(CmsWorkplaceDefault.C_PARA_RESOURCE);
122                     //template = "done";
123
// return to filelist
124
try {
125                         if (lasturl == null || "".equals(lasturl)) {
126                             CmsXmlTemplateLoader.getResponse(cms.getRequestContext()).sendCmsRedirect(getConfigFile(cms).getWorkplaceActionPath()
127                                         + CmsWorkplaceAction.getExplorerFileUri(CmsXmlTemplateLoader.getRequest(cms.getRequestContext()).getOriginalRequest()));
128                         } else {
129                             CmsXmlTemplateLoader.getResponse(cms.getRequestContext()).sendRedirect(lasturl);
130                         }
131                     } catch (Exception JavaDoc e) {
132                             throw new CmsLegacyException("Redirect fails :"
133                                     + getConfigFile(cms).getWorkplaceActionPath()
134                                     + CmsWorkplaceAction.getExplorerFileUri(CmsXmlTemplateLoader.getRequest(cms.getRequestContext()).getOriginalRequest()), e);
135                     }
136                     return null;
137                 } catch (CmsException e) {
138                     session.removeValue(CmsWorkplaceDefault.C_PARA_RESOURCE);
139                     xmlTemplateDocument.setData("details", CmsException.getStackTraceAsString(e));
140                     xmlTemplateDocument.setData("lasturl", lasturl);
141                     return startProcessing(cms, xmlTemplateDocument, "", parameters, "error");
142                 }
143             } else {
144                 template = "wait";
145             }
146         }
147         // set the required datablocks
148
if (action == null) {
149             xmlTemplateDocument.setData("CHANGEDATE", CmsDateUtil.getDateTimeShort(file.getDateLastModified()));
150             xmlTemplateDocument.setData("USER", cms.readUser(file.getUserLastModified()).getName());
151             xmlTemplateDocument.setData("FILENAME", file.getName());
152         }
153
154         // process the selected template
155
return startProcessing(cms, xmlTemplateDocument, "", parameters, template);
156     }
157
158     /**
159      * Indicates if the results of this class are cacheable.
160      *
161      * @param cms CmsObject Object for accessing system resources
162      * @param templateFile Filename of the template file
163      * @param elementName Element name of this template in our parent template.
164      * @param parameters Hashtable with all template class parameters.
165      * @param templateSelector template section that should be processed.
166      * @return <EM>true</EM> if cacheable, <EM>false</EM> otherwise.
167      */

168
169     public boolean isCacheable(CmsObject cms, String JavaDoc templateFile, String JavaDoc elementName,
170             Hashtable JavaDoc parameters, String JavaDoc templateSelector) {
171         return false;
172     }
173 }
174
Popular Tags