KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2 * File : $Source: /usr/local/cvs/opencms/src-modules/com/opencms/workplace/CmsLockChange.java,v $
3 * Date : $Date: 2005/06/27 23:22:07 $
4 * Version: $Revision: 1.5 $
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.db.CmsUserSettings;
32 import org.opencms.file.CmsObject;
33 import org.opencms.file.CmsResource;
34 import org.opencms.main.CmsException;
35 import org.opencms.security.CmsSecurityException;
36
37 import com.opencms.core.I_CmsConstants;
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 lockchange screen of the OpenCms workplace.<P>
46  * Reads template files of the content type <code>CmsXmlWpTemplateFile</code>.
47  *
48  * @author Michael Emmerich
49  * @author Michaela Schleich
50  * @version $Revision: 1.5 $ $Date: 2005/06/27 23:22:07 $
51  *
52  * @deprecated Will not be supported past the OpenCms 6 release.
53  */

54
55 public class CmsLockChange extends CmsWorkplaceDefault {
56
57     /**
58      * Overwrites the getContent method of the CmsWorkplaceDefault.<br>
59      * Gets the content of the lockchange template and processed the data input.
60      * @param cms The CmsObject.
61      * @param templateFile The lockchange template file
62      * @param elementName not used
63      * @param parameters Parameters of the request and the template.
64      * @param templateSelector Selector of the template tag to be displayed.
65      * @return Bytearre containgine the processed data of the template.
66      * @throws Throws CmsException if something goes wrong.
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
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
79             // remove all session values
80
session.removeValue(CmsWorkplaceDefault.C_PARA_RESOURCE);
81             session.removeValue("lasturl");
82         }
83
84         // get the lasturl parameter
85
String JavaDoc lasturl = getLastUrl(cms, parameters);
86         String JavaDoc lock = (String JavaDoc)parameters.get(CmsWorkplaceDefault.C_PARA_LOCK);
87         String JavaDoc filename = (String JavaDoc)parameters.get(CmsWorkplaceDefault.C_PARA_RESOURCE);
88         if(filename != null) {
89             session.putValue(CmsWorkplaceDefault.C_PARA_RESOURCE, filename);
90         }
91
92         //check if the user wants the lock dialog
93
// if yes, the lock page is shown for the first time
94
filename = (String JavaDoc)session.getValue(CmsWorkplaceDefault.C_PARA_RESOURCE);
95         CmsResource file = cms.readResource(filename);
96
97         // select the template to be displayed
98
if(file.isFile()) {
99             template = "file";
100         }
101         else {
102             template = "folder";
103             if (! filename.endsWith("/")) {
104                 filename += "/";
105             }
106         }
107         Hashtable JavaDoc startSettings = (Hashtable JavaDoc)cms.getRequestContext().currentUser().getAdditionalInfo(CmsUserSettings.ADDITIONAL_INFO_STARTSETTINGS);
108         String JavaDoc showLockDialog = "off";
109         if(startSettings!=null){
110             showLockDialog = (String JavaDoc)startSettings.get(I_CmsConstants.C_START_LOCKDIALOG);
111         }
112         if(lock == null && !"on".equals(showLockDialog)) {
113             lock = "true";
114         }
115         if(lock != null) {
116             if(lock.equals("true")) {
117                 session.removeValue(CmsWorkplaceDefault.C_PARA_RESOURCE);
118                 try{
119                     //cms.unlockResource(filename, false);
120
//cms.lockResource(filename, true);
121
cms.changeLock(filename);
122                 } catch (CmsException e){
123                     CmsXmlWpTemplateFile xmlTemplateDocument = new CmsXmlWpTemplateFile(cms, templateFile);
124                     if (e instanceof CmsSecurityException) {
125                         template = "erroraccessdenied";
126                         xmlTemplateDocument.setData("details", file.getName());
127                     } else {
128                         xmlTemplateDocument.setData("details", e.toString());
129                         template = "error";
130                     }
131                     xmlTemplateDocument.setData("lasturl", lasturl);
132                     xmlTemplateDocument.setData("FILENAME", file.getName());
133                     // process the selected template
134
return startProcessing(cms, xmlTemplateDocument, "", parameters, template);
135                 }
136             }
137
138             // return to filelist
139
try {
140                 if(lasturl == null || "".equals(lasturl)) {
141                     CmsXmlTemplateLoader.getResponse(cms.getRequestContext()).sendCmsRedirect(getConfigFile(cms).getWorkplaceActionPath()
142                             + CmsWorkplaceAction.getExplorerFileUri(CmsXmlTemplateLoader.getRequest(cms.getRequestContext()).getOriginalRequest()));
143                 }
144                 else {
145                     CmsXmlTemplateLoader.getResponse(cms.getRequestContext()).sendRedirect(lasturl);
146                 }
147             }
148             catch(Exception JavaDoc e) {
149                 throw new CmsLegacyException("Redirect fails :"
150                         + getConfigFile(cms).getWorkplaceActionPath()
151                         + CmsWorkplaceAction.getExplorerFileUri(CmsXmlTemplateLoader.getRequest(cms.getRequestContext()).getOriginalRequest()), e);
152             }
153             return null;
154         }
155         CmsXmlWpTemplateFile xmlTemplateDocument = new CmsXmlWpTemplateFile(cms,
156                 templateFile);
157         xmlTemplateDocument.setData("FILENAME", file.getName());
158
159         // process the selected template
160
return startProcessing(cms, xmlTemplateDocument, "", parameters, template);
161     }
162
163     /**
164      * Indicates if the results of this class are cacheable.
165      *
166      * @param cms CmsObject Object for accessing system resources
167      * @param templateFile Filename of the template file
168      * @param elementName Element name of this template in our parent template.
169      * @param parameters Hashtable with all template class parameters.
170      * @param templateSelector template section that should be processed.
171      * @return <EM>true</EM> if cacheable, <EM>false</EM> otherwise.
172      */

173
174     public boolean isCacheable(CmsObject cms, String JavaDoc templateFile, String JavaDoc elementName,
175             Hashtable JavaDoc parameters, String JavaDoc templateSelector) {
176         return false;
177     }
178 }
179
180
Popular Tags