KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2 * File : $Source: /usr/local/cvs/opencms/src-modules/com/opencms/workplace/CmsUnlock.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 unlock 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 CmsUnlock extends CmsWorkplaceDefault {
58
59     /**
60      * Overwrties the getContent method of the CmsWorkplaceDefault.<br>
61      * Gets the content of the unlock templated and processed the data input.
62      * @param cms The CmsObject.
63      * @param templateFile The unlock 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
71     public byte[] getContent(CmsObject cms, String JavaDoc templateFile, String JavaDoc elementName,
72             Hashtable JavaDoc parameters, String JavaDoc templateSelector) throws CmsException {
73                                   
74         I_CmsSession session = CmsXmlTemplateLoader.getSession(cms.getRequestContext(), true);
75
76         // the template to be displayed
77
String JavaDoc template = null;
78
79         // clear session values on first load
80
String JavaDoc initial = (String JavaDoc)parameters.get(CmsWorkplaceDefault.C_PARA_INITIAL);
81         if(initial != null) {
82
83             // remove all session values
84
session.removeValue(CmsWorkplaceDefault.C_PARA_RESOURCE);
85             session.removeValue("lasturl");
86         }
87
88         // get the lasturl parameter
89
String JavaDoc lasturl = getLastUrl(cms, parameters);
90         String JavaDoc unlock = (String JavaDoc)parameters.get(CmsWorkplaceDefault.C_PARA_UNLOCK);
91         String JavaDoc filename = (String JavaDoc)parameters.get(CmsWorkplaceDefault.C_PARA_RESOURCE);
92         if(filename != null) {
93             session.putValue(CmsWorkplaceDefault.C_PARA_RESOURCE, filename);
94         }
95
96         //check if the user wants the lock dialog
97
// if yes, the lock page is shown for the first time
98
filename = (String JavaDoc)session.getValue(CmsWorkplaceDefault.C_PARA_RESOURCE);
99         CmsResource file = cms.readResource(filename);
100
101         // select the template to be displayed
102
if(file.isFile()) {
103             template = "file";
104         }
105         else {
106             template = "folder";
107             if (! filename.endsWith("/")) {
108                 filename += "/";
109             }
110         }
111         Hashtable JavaDoc startSettings = (Hashtable JavaDoc)cms.getRequestContext().currentUser().getAdditionalInfo(CmsUserSettings.ADDITIONAL_INFO_STARTSETTINGS);
112         String JavaDoc showLockDialog = "off";
113         if(startSettings!=null){
114             showLockDialog = (String JavaDoc)startSettings.get(I_CmsConstants.C_START_LOCKDIALOG);
115         }
116         if (unlock == null && !"on".equals(showLockDialog)) {
117             unlock = "true";
118         }
119         if (unlock != null) {
120             if (unlock.equals("true")) {
121                 try {
122                     cms.unlockResource(filename);
123                     session.removeValue(CmsWorkplaceDefault.C_PARA_RESOURCE);
124                 } catch (CmsException e) {
125                     CmsXmlWpTemplateFile xmlTemplateDocument = new CmsXmlWpTemplateFile(cms, templateFile);
126                     if (e instanceof CmsSecurityException) {
127                         template = "erroraccessdenied";
128                         xmlTemplateDocument.setData("details", file.getName());
129                     } else {
130                         template = "error";
131                         xmlTemplateDocument.setData("details", e.toString());
132                     }
133                     xmlTemplateDocument.setData("lasturl", lasturl);
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                 } else {
144                     CmsXmlTemplateLoader.getResponse(cms.getRequestContext()).sendRedirect(lasturl);
145                 }
146             } catch (Exception JavaDoc e) {
147                 throw new CmsLegacyException("Redirect fails :" + getConfigFile(cms).getWorkplaceActionPath()
148                         + CmsWorkplaceAction.getExplorerFileUri(CmsXmlTemplateLoader.getRequest(cms.getRequestContext()).getOriginalRequest()), e);
149             }
150             return null;
151         }
152         CmsXmlWpTemplateFile xmlTemplateDocument = new CmsXmlWpTemplateFile(cms, templateFile);
153         xmlTemplateDocument.setData("FILENAME", file.getName());
154
155         // process the selected template
156
return startProcessing(cms, xmlTemplateDocument, "", parameters, template);
157     }
158
159
160     /**
161      * Indicates if the results of this class are cacheable.
162      *
163      * @param cms CmsObject Object for accessing system resources
164      * @param templateFile Filename of the template file
165      * @param elementName Element name of this template in our parent template.
166      * @param parameters Hashtable with all template class parameters.
167      * @param templateSelector template section that should be processed.
168      * @return <EM>true</EM> if cacheable, <EM>false</EM> otherwise.
169      */

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