KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src-modules/com/opencms/workplace/CmsChpwd.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 Management 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 package com.opencms.workplace;
29
30 import org.opencms.file.CmsObject;
31 import org.opencms.file.CmsRequestContext;
32 import org.opencms.main.CmsException;
33
34 import com.opencms.legacy.CmsLegacyException;
35 import com.opencms.legacy.CmsXmlTemplateLoader;
36
37 import java.util.Hashtable JavaDoc;
38
39 /**
40  * Template class for displaying the chpwd screen of the OpenCms workplace.<p>
41  *
42  * @author Michael Emmerich
43  * @version $Revision: 1.5 $ $Date: 2005/06/27 23:22:07 $
44  *
45  * @deprecated Will not be supported past the OpenCms 6 release.
46  */

47
48 public class CmsChpwd extends CmsWorkplaceDefault {
49
50     /**
51      * Gets the content of the chpwd template and processes the data input.<p>
52      *
53      * @param cms The CmsObject.
54      * @param templateFile The chpwd template file
55      * @param elementName not used
56      * @param parameters Parameters of the request and the template.
57      * @param templateSelector Selector of the template tag to be displayed.
58      * @return Bytearray containing the processed data of the template.
59      * @throws CmsException if something goes wrong.
60      */

61     public byte[] getContent(CmsObject cms, String JavaDoc templateFile, String JavaDoc elementName,
62        Hashtable JavaDoc parameters, String JavaDoc templateSelector)
63     throws CmsException {
64         // the template to be displayed
65
String JavaDoc template = null;
66         CmsXmlWpTemplateFile xmlTemplateDocument = new CmsXmlWpTemplateFile(cms, templateFile);
67         String JavaDoc oldpwd = (String JavaDoc)parameters.get(CmsWorkplaceDefault.C_PARA_OLDPWD);
68         String JavaDoc newpwd = (String JavaDoc)parameters.get(CmsWorkplaceDefault.C_PARA_NEWPWD);
69         String JavaDoc newpwdrepeat = (String JavaDoc)parameters.get(CmsWorkplaceDefault.C_PARA_NEWPWDREPEAT);
70         // a password was given in the request so try to change it
71
if(oldpwd != null && newpwd != null && newpwdrepeat != null) {
72             if("".equals(oldpwd) || "".equals(newpwd) || "".equals(newpwdrepeat)) {
73                 xmlTemplateDocument.setData("details", "All fields must be filled.");
74                 template = "error";
75             } else {
76                 // check if the new password and its repetition are identical
77
if(newpwd.equals(newpwdrepeat)) {
78                     // change the password
79
try {
80                         CmsRequestContext requestContext = cms.getRequestContext();
81                         cms.setPassword(requestContext.currentUser().getName(),
82                         oldpwd, newpwd);
83                         // return to the parameter dialog
84
try {
85                             CmsXmlTemplateLoader.getResponse(requestContext).sendCmsRedirect(getConfigFile(cms).getWorkplaceActionPath() + CmsWorkplaceDefault.C_WP_EXPLORER_PREFERENCES);
86                         }
87                         catch(Exception JavaDoc e) {
88                             throw new CmsLegacyException("Redirect fails :" + getConfigFile(cms).getWorkplaceActionPath()
89                             + CmsWorkplaceDefault.C_WP_EXPLORER_PREFERENCES, e);
90                         }
91
92                         // an error was thrown while setting the new password
93
}
94                     catch(CmsException exp) {
95                         // check if the old password was not correct
96
if ((exp instanceof CmsLegacyException) && (((CmsLegacyException)exp).getType() == CmsLegacyException.C_NO_USER)) {
97                             xmlTemplateDocument.setData("details", CmsException.getStackTraceAsString(exp));
98                             template = "error2";
99                         }
100                         else {
101                             if ((exp instanceof CmsLegacyException) && (((CmsLegacyException)exp).getType() == 1)) {
102                                 xmlTemplateDocument.setData("details", CmsException.getStackTraceAsString(exp));
103                                 template = "error2";
104                             } else {
105                                 throw exp;
106                             }
107                         }
108                     }
109                 }
110                 else {
111                     // the new passwords do not match
112
xmlTemplateDocument.setData("details", "The new passwords do not match.");
113                     template = "error";
114                 }
115             }
116         }
117
118         // process the selected template
119
return startProcessing(cms, xmlTemplateDocument, "", parameters, template);
120     }
121
122     /**
123      * Indicates if the results of this class are cacheable,
124      * which is not the case for this class.<p>
125      *
126      * @param cms CmsObject Object for accessing system resources
127      * @param templateFile Filename of the template file
128      * @param elementName Element name of this template in our parent template.
129      * @param parameters Hashtable with all template class parameters.
130      * @param templateSelector template section that should be processed.
131      * @return <code>false</code>
132      */

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