KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2 * File : $Source: /usr/local/cvs/opencms/src-modules/com/opencms/workplace/CmsUndochanges.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.main.CmsException;
35 import org.opencms.util.CmsDateUtil;
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 undo 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 CmsUndochanges 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         // 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("undochanges");
81             session.removeValue("lasturl");
82         }
83         // get the lasturl parameter
84
String JavaDoc lasturl = getLastUrl(cms, parameters);
85         String JavaDoc undochanges = (String JavaDoc)parameters.get("undochanges");
86         if(undochanges != null) {
87             session.putValue("undochanges", undochanges);
88         }
89         undochanges = (String JavaDoc)session.getValue("undochanges");
90         String JavaDoc filename = (String JavaDoc)parameters.get(CmsWorkplaceDefault.C_PARA_RESOURCE);
91         if(filename != null) {
92             session.putValue(CmsWorkplaceDefault.C_PARA_RESOURCE, filename);
93         }
94         filename = (String JavaDoc)session.getValue(CmsWorkplaceDefault.C_PARA_RESOURCE);
95         String JavaDoc action = (String JavaDoc)parameters.get("action");
96
97         CmsResource file = null;
98         if(filename.endsWith("/")){
99             file = cms.readFolder(filename);
100         } else {
101             file = cms.readResource(filename);
102         }
103         //check if the name parameter was included in the request
104
// if not, the undoChanges page is shown for the first time
105
if(undochanges != null){
106             if(action != null) {
107                 // undo changes of the resource
108
try{
109                     cms.undoChanges(cms.getSitePath(file), true);
110                     session.removeValue(CmsWorkplaceDefault.C_PARA_RESOURCE);
111                     //template = "done";
112
// return to filelist
113
try {
114                         if(lasturl == null || "".equals(lasturl)) {
115                             CmsXmlTemplateLoader.getResponse(cms.getRequestContext()).sendCmsRedirect(getConfigFile(cms).getWorkplaceActionPath()
116                                         + CmsWorkplaceAction.getExplorerFileUri(CmsXmlTemplateLoader.getRequest(cms.getRequestContext()).getOriginalRequest()));
117                         }else {
118                             CmsXmlTemplateLoader.getResponse(cms.getRequestContext()).sendRedirect(lasturl);
119                         }
120                     }catch(Exception JavaDoc e) {
121                         throw new CmsLegacyException("Redirect fails :"
122                             + getConfigFile(cms).getWorkplaceActionPath()
123                             + CmsWorkplaceAction.getExplorerFileUri(CmsXmlTemplateLoader.getRequest(cms.getRequestContext()).getOriginalRequest()), e);
124                     }
125                     return null;
126                 } catch(CmsException e){
127                     session.removeValue(CmsWorkplaceDefault.C_PARA_RESOURCE);
128                     xmlTemplateDocument.setData("details", CmsException.getStackTraceAsString(e));
129                     xmlTemplateDocument.setData("lasturl", lasturl);
130                     return startProcessing(cms, xmlTemplateDocument, "", parameters, "error");
131                 }
132             } else {
133                 template = "wait";
134             }
135         }
136         // set the required datablocks
137
if(action == null) {
138             xmlTemplateDocument.setData("CHANGEDATE", CmsDateUtil.getDateTimeShort(file.getDateLastModified()));
139             xmlTemplateDocument.setData("USER", cms.readUser(file.getUserLastModified()).getName());
140             xmlTemplateDocument.setData("FILENAME", file.getName());
141         }
142
143         // process the selected template
144
return startProcessing(cms, xmlTemplateDocument, "", parameters, template);
145     }
146
147     /**
148      * Indicates if the results of this class are cacheable.
149      *
150      * @param cms CmsObject Object for accessing system resources
151      * @param templateFile Filename of the template file
152      * @param elementName Element name of this template in our parent template.
153      * @param parameters Hashtable with all template class parameters.
154      * @param templateSelector template section that should be processed.
155      * @return <EM>true</EM> if cacheable, <EM>false</EM> otherwise.
156      */

157
158     public boolean isCacheable(CmsObject cms, String JavaDoc templateFile, String JavaDoc elementName,
159             Hashtable JavaDoc parameters, String JavaDoc templateSelector) {
160         return false;
161     }
162 }
163
Popular Tags