KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2 * File : $Source: /usr/local/cvs/opencms/src-modules/com/opencms/workplace/CmsUndelete.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
30 package com.opencms.workplace;
31
32 import org.opencms.file.CmsObject;
33 import org.opencms.file.CmsResource;
34 import org.opencms.file.CmsResourceFilter;
35 import org.opencms.main.CmsException;
36
37 import com.opencms.core.I_CmsSession;
38 import com.opencms.legacy.CmsLegacyException;
39 import com.opencms.legacy.CmsXmlTemplateLoader;
40
41 import java.util.Hashtable JavaDoc;
42
43 /**
44  * Template class for displaying the undelete screen of the OpenCms workplace.<P>
45  * Reads template files of the content type <code>CmsXmlWpTemplateFile</code>.
46  *
47  * @author Edna Falkenhan
48  * @version $Revision: 1.4 $ $Date: 2005/06/27 23:22:07 $
49  *
50  * @deprecated Will not be supported past the OpenCms 6 release.
51  */

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

66
67     public byte[] getContent(CmsObject cms, String JavaDoc templateFile, String JavaDoc elementName,
68             Hashtable JavaDoc parameters, String JavaDoc templateSelector) throws CmsException {
69         I_CmsSession session = CmsXmlTemplateLoader.getSession(cms.getRequestContext(), true);
70         CmsXmlWpTemplateFile xmlTemplateDocument = new CmsXmlWpTemplateFile(cms, templateFile);
71
72         // clear session values on first load
73
String JavaDoc initial = (String JavaDoc)parameters.get(CmsWorkplaceDefault.C_PARA_INITIAL);
74         if(initial != null) {
75             // remove all session values
76
session.removeValue(CmsWorkplaceDefault.C_PARA_RESOURCE);
77             session.removeValue("lasturl");
78         }
79
80         String JavaDoc lasturl = getLastUrl(cms, parameters);
81         String JavaDoc filename = (String JavaDoc)parameters.get(CmsWorkplaceDefault.C_PARA_RESOURCE);
82         if(filename != null) {
83             session.putValue(CmsWorkplaceDefault.C_PARA_RESOURCE, filename);
84         }
85         filename = (String JavaDoc)session.getValue(CmsWorkplaceDefault.C_PARA_RESOURCE);
86         CmsResource file = null;
87         if (filename.endsWith("/")){
88             file = cms.readFolder(filename, CmsResourceFilter.ALL);
89         } else {
90             file = cms.readResource(filename, CmsResourceFilter.ALL);
91         }
92         try{
93             cms.undeleteResource(cms.getSitePath(file));
94             session.removeValue(CmsWorkplaceDefault.C_PARA_RESOURCE);
95             //template = "done";
96
// return to filelist
97
try {
98                 if(lasturl == null || "".equals(lasturl)) {
99                     CmsXmlTemplateLoader.getResponse(cms.getRequestContext()).sendCmsRedirect(getConfigFile(cms).getWorkplaceActionPath()
100                                         + CmsWorkplaceAction.getExplorerFileUri(CmsXmlTemplateLoader.getRequest(cms.getRequestContext()).getOriginalRequest()));
101                 }else {
102                     CmsXmlTemplateLoader.getResponse(cms.getRequestContext()).sendRedirect(lasturl);
103                 }
104             }catch(Exception JavaDoc e) {
105                 throw new CmsLegacyException("Redirect fails :"
106                     + getConfigFile(cms).getWorkplaceActionPath()
107                     + CmsWorkplaceAction.getExplorerFileUri(CmsXmlTemplateLoader.getRequest(cms.getRequestContext()).getOriginalRequest()), e);
108             }
109             return null;
110         } catch(CmsException e){
111             session.removeValue(CmsWorkplaceDefault.C_PARA_RESOURCE);
112             xmlTemplateDocument.setData("details", CmsException.getStackTraceAsString(e));
113             xmlTemplateDocument.setData("lasturl", lasturl);
114             return startProcessing(cms, xmlTemplateDocument, "", parameters, "error");
115         }
116         // process the selected template
117
//return startProcessing(cms, xmlTemplateDocument, "", parameters, template);
118
}
119
120     /**
121      * Indicates if the results of this class are cacheable.
122      *
123      * @param cms CmsObject Object for accessing system resources
124      * @param templateFile Filename of the template file
125      * @param elementName Element name of this template in our parent template.
126      * @param parameters Hashtable with all template class parameters.
127      * @param templateSelector template section that should be processed.
128      * @return <EM>true</EM> if cacheable, <EM>false</EM> otherwise.
129      */

130
131     public boolean isCacheable(CmsObject cms, String JavaDoc templateFile, String JavaDoc elementName,
132             Hashtable JavaDoc parameters, String JavaDoc templateSelector) {
133         return false;
134     }
135 }
136
Popular Tags