KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2 * File : $Source: /usr/local/cvs/opencms/src-modules/com/opencms/workplace/CmsLock.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 lock screen of the OpenCms workplace.<p>
46  *
47  * Reads template files of the content type <code>CmsXmlWpTemplateFile</code>.
48  *
49  * @author Michael Emmerich
50  * @author Michaela Schleich
51  * @author Alexander Lucas
52  * @version $Revision: 1.5 $ $Date: 2005/06/27 23:22:07 $
53  *
54  * @deprecated Will not be supported past the OpenCms 6 release.
55  */

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

70     public byte[] getContent(CmsObject cms, String JavaDoc templateFile, String JavaDoc elementName,
71             Hashtable JavaDoc parameters, String JavaDoc templateSelector) throws CmsException {
72         I_CmsSession session = CmsXmlTemplateLoader.getSession(cms.getRequestContext(), true);
73
74         // the template to be displayed
75
String JavaDoc template = null;
76         CmsXmlWpTemplateFile xmlTemplateDocument = new CmsXmlWpTemplateFile(cms, templateFile);
77
78         // clear session values on first load
79
String JavaDoc initial = (String JavaDoc)parameters.get(CmsWorkplaceDefault.C_PARA_INITIAL);
80         if(initial != null) {
81
82             // remove all session values
83
session.removeValue(CmsWorkplaceDefault.C_PARA_RESOURCE);
84             session.removeValue("lasturl");
85         }
86
87         // get the lasturl parameter
88
String JavaDoc lasturl = getLastUrl(cms, parameters);
89         String JavaDoc lock = (String JavaDoc)parameters.get(CmsWorkplaceDefault.C_PARA_LOCK);
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
95         //check if the user wants the lock dialog
96
// if yes, the lock page is shown for the first time
97
filename = (String JavaDoc)session.getValue(CmsWorkplaceDefault.C_PARA_RESOURCE);
98         CmsResource file = cms.readResource(filename);
99
100         // select the template to be displayed
101
if(file.isFile()) {
102             template = "file";
103         }
104         else {
105             template = "folder";
106             if (! filename.endsWith("/")) {
107                 filename += "/";
108             }
109         }
110         Hashtable JavaDoc startSettings = (Hashtable JavaDoc)cms.getRequestContext().currentUser().getAdditionalInfo(CmsUserSettings.ADDITIONAL_INFO_STARTSETTINGS);
111         String JavaDoc showLockDialog = "off";
112         if(startSettings!=null){
113             showLockDialog = (String JavaDoc)startSettings.get(I_CmsConstants.C_START_LOCKDIALOG);
114         }
115         if(lock == null && !"on".equals(showLockDialog)) {
116             lock = "true";
117         }
118         if(lock != null) {
119             if(lock.equals("true")) {
120                 session.removeValue(CmsWorkplaceDefault.C_PARA_RESOURCE);
121                 try{
122                     cms.lockResource(filename);
123                 } catch(CmsException e){
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                 // return to filelist
138
try {
139                     if(lasturl == null || "".equals(lasturl)) {
140                         CmsXmlTemplateLoader.getResponse(cms.getRequestContext()).sendCmsRedirect(getConfigFile(cms).getWorkplaceActionPath()
141                                     + CmsWorkplaceAction.getExplorerFileUri(CmsXmlTemplateLoader.getRequest(cms.getRequestContext()).getOriginalRequest()));
142                     }
143                     else {
144                         CmsXmlTemplateLoader.getResponse(cms.getRequestContext()).sendRedirect(lasturl);
145                     }
146                 }
147                 catch(Exception JavaDoc e) {
148                         throw new CmsLegacyException("Redirect fails :"
149                                 + getConfigFile(cms).getWorkplaceActionPath()
150                                 + CmsWorkplaceAction.getExplorerFileUri(CmsXmlTemplateLoader.getRequest(cms.getRequestContext()).getOriginalRequest()), e);
151                 }
152                 return null;
153             }
154         }
155         xmlTemplateDocument.setData("FILENAME", file.getName());
156
157         // process the selected template
158
return startProcessing(cms, xmlTemplateDocument, "", parameters, template);
159     }
160
161     /**
162      * Indicates if the results of this class are cacheable.
163      *
164      * @param cms CmsObject Object for accessing system resources
165      * @param templateFile Filename of the template file
166      * @param elementName Element name of this template in our parent template.
167      * @param parameters Hashtable with all template class parameters.
168      * @param templateSelector template section that should be processed.
169      * @return <EM>true</EM> if cacheable, <EM>false</EM> otherwise.
170      */

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