Source Code Cross Referenced for CmsPasswordField.java in  » Content-Management-System » opencms » com » alkacon » opencms » registration » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Content Management System » opencms » com.alkacon.opencms.registration 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * File   : $Source: /usr/local/cvs/alkacon/com.alkacon.opencms.registration/src/com/alkacon/opencms/registration/CmsPasswordField.java,v $
003:         * Date   : $Date: 2008-02-19 13:22:30 $
004:         * Version: $Revision: 1.1 $
005:         *
006:         * This file is part of the Alkacon OpenCms Add-On Module Package
007:         *
008:         * Copyright (c) 2007 Alkacon Software GmbH (http://www.alkacon.com)
009:         *
010:         * The Alkacon OpenCms Add-On Module Package is free software: 
011:         * you can redistribute it and/or modify
012:         * it under the terms of the GNU General Public License as published by
013:         * the Free Software Foundation, either version 3 of the License, or
014:         * (at your option) any later version.
015:         * 
016:         * The Alkacon OpenCms Add-On Module Package is distributed 
017:         * in the hope that it will be useful,
018:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
019:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
020:         * GNU General Public License for more details.
021:         * 
022:         * You should have received a copy of the GNU General Public License
023:         * along with the Alkacon OpenCms Add-On Module Package.  
024:         * If not, see http://www.gnu.org/licenses/.
025:         *
026:         * For further information about Alkacon Software GmbH, please see the
027:         * company website: http://www.alkacon.com.
028:         *
029:         * For further information about OpenCms, please see the
030:         * project website: http://www.opencms.org.
031:         */
032:
033:        package com.alkacon.opencms.registration;
034:
035:        import com.alkacon.opencms.formgenerator.A_CmsField;
036:        import com.alkacon.opencms.formgenerator.CmsFormHandler;
037:
038:        import org.opencms.i18n.CmsMessages;
039:        import org.opencms.main.CmsException;
040:        import org.opencms.util.CmsStringUtil;
041:
042:        /**
043:         * Represents a password field.<p>
044:         * 
045:         * @author Michael Moossen 
046:         * 
047:         * @version $Revision: 1.1 $
048:         * 
049:         * @since 7.0.4 
050:         */
051:        public class CmsPasswordField extends A_CmsField {
052:
053:            /** Input field name prefix for the password confirmation. */
054:            private static final String PREFIX_CONFIRMATION = "cnf";
055:
056:            /** Input field name prefix for the old password. */
057:            private static final String PREFIX_PASSWORD = "old";
058:
059:            /** Password does not match. */
060:            public static final String ERROR_LOGIN = "login";
061:
062:            /** Confirmation does not match the password. */
063:            public static final String ERROR_CONFIRMATION = "confirmation";
064:
065:            /** HTML field type: hidden field. */
066:            private static final String TYPE = "password";
067:
068:            /**
069:             * Returns the type of the input field, e.g. "text" or "select".<p>
070:             * 
071:             * @return the type of the input field
072:             */
073:            public static String getStaticType() {
074:
075:                return TYPE;
076:            }
077:
078:            /**
079:             * @see com.alkacon.opencms.formgenerator.I_CmsField#buildHtml(CmsFormHandler, org.opencms.i18n.CmsMessages, String, boolean)
080:             */
081:            public String buildHtml(CmsFormHandler formHandler,
082:                    CmsMessages messages, String errorKey, boolean showMandatory) {
083:
084:                StringBuffer buf = new StringBuffer();
085:
086:                String fieldLabel = getLabel();
087:                String errorMessage = "";
088:                String mandatory = "";
089:
090:                if (CmsStringUtil.isNotEmpty(errorKey)) {
091:                    if (CmsFormHandler.ERROR_MANDATORY.equals(errorKey)) {
092:                        errorMessage = messages.key("form.error.mandatory");
093:                    } else if (ERROR_LOGIN.equals(errorKey)) {
094:                        errorMessage = ""; // will be show in the old password row
095:                    } else if (ERROR_CONFIRMATION.equals(errorKey)) {
096:                        errorMessage = ""; // will be show in the confirmation row
097:                    } else if (CmsStringUtil.isNotEmpty(getErrorMessage())) {
098:                        errorMessage = getErrorMessage();
099:                    } else {
100:                        errorMessage = messages.key("form.error.validation");
101:                    }
102:                    if (!ERROR_LOGIN.equals(errorKey)
103:                            && !ERROR_CONFIRMATION.equals(errorKey)) {
104:                        errorMessage = messages.key("form.html.error.start")
105:                                + errorMessage
106:                                + messages.key("form.html.error.end");
107:                        fieldLabel = messages
108:                                .key("form.html.label.error.start")
109:                                + fieldLabel
110:                                + messages.key("form.html.label.error.end");
111:                    }
112:                }
113:
114:                if (isMandatory() && showMandatory) {
115:                    mandatory = messages.key("form.html.mandatory");
116:                }
117:
118:                // zero row: confirmation, only if in profile mode
119:
120:                if (!formHandler.getCmsObject().getRequestContext()
121:                        .currentUser().isGuestUser()) {
122:                    // line #1
123:                    if (showRowStart(messages.key("form.html.col.two"))) {
124:                        buf.append(messages.key("form.html.row.start")).append(
125:                                "\n");
126:                    }
127:
128:                    // line #2
129:                    buf.append(messages.key("form.html.label.start"));
130:                    if (ERROR_LOGIN.equals(errorKey)) {
131:                        buf.append(messages.key("form.html.label.error.start"));
132:                    }
133:                    buf.append(messages.key("password.label.oldpwd"));
134:                    if (ERROR_LOGIN.equals(errorKey)) {
135:                        buf.append(messages.key("form.html.label.error.end"));
136:                    }
137:                    buf.append(mandatory).append(
138:                            messages.key("form.html.label.end")).append("\n");
139:
140:                    // line #3
141:                    buf.append(messages.key("form.html.field.start")).append(
142:                            "<input type=\"password\" name=\"").append(
143:                            PREFIX_PASSWORD).append(getName()).append(
144:                            "\" value=\"").append("\"").append(
145:                            formHandler.getFormConfiguration()
146:                                    .getFormFieldAttributes()).append("/>");
147:                    if (ERROR_LOGIN.equals(errorKey)) {
148:                        buf.append(messages.key("form.html.error.start"))
149:                                .append(messages.key("password.error.login"))
150:                                .append(messages.key("form.html.error.end"));
151:                    }
152:                    buf.append(messages.key("form.html.field.end"))
153:                            .append("\n");
154:
155:                    // line #4
156:                    if (showRowEnd(messages.key("form.html.col.two"))) {
157:                        buf.append(messages.key("form.html.row.end")).append(
158:                                "\n");
159:                    }
160:                }
161:
162:                // first row: password
163:
164:                // line #1
165:                if (showRowStart(messages.key("form.html.col.two"))) {
166:                    buf.append(messages.key("form.html.row.start"))
167:                            .append("\n");
168:                }
169:
170:                // line #2
171:                buf.append(messages.key("form.html.label.start")).append(
172:                        fieldLabel).append(mandatory).append(
173:                        messages.key("form.html.label.end")).append("\n");
174:
175:                // line #3
176:                buf.append(messages.key("form.html.field.start")).append(
177:                        "<input type=\"password\" name=\"").append(getName())
178:                        .append("\" value=\"").append("\"").append(
179:                                formHandler.getFormConfiguration()
180:                                        .getFormFieldAttributes()).append("/>")
181:                        .append(messages.key("form.html.field.end")).append(
182:                                "\n");
183:
184:                // line #4
185:                if (showRowEnd(messages.key("form.html.col.two"))) {
186:                    buf.append(messages.key("form.html.row.end")).append("\n");
187:                }
188:
189:                // second row: confirmation
190:
191:                // line #1
192:                if (showRowStart(messages.key("form.html.col.two"))) {
193:                    buf.append(messages.key("form.html.row.start"))
194:                            .append("\n");
195:                }
196:
197:                // line #2
198:                buf.append(messages.key("form.html.label.start"));
199:                if (ERROR_CONFIRMATION.equals(errorKey)) {
200:                    buf.append(messages.key("form.html.label.error.start"));
201:                }
202:                buf.append(messages.key("password.label.confirmation"));
203:                if (ERROR_CONFIRMATION.equals(errorKey)) {
204:                    buf.append(messages.key("form.html.label.error.end"));
205:                }
206:                buf.append(mandatory).append(
207:                        messages.key("form.html.label.end")).append("\n");
208:
209:                // line #3
210:                buf.append(messages.key("form.html.field.start")).append(
211:                        "<input type=\"password\" name=\"").append(
212:                        PREFIX_CONFIRMATION).append(getName()).append(
213:                        "\" value=\"").append("\"").append(
214:                        formHandler.getFormConfiguration()
215:                                .getFormFieldAttributes()).append("/>");
216:                if (ERROR_CONFIRMATION.equals(errorKey)) {
217:                    buf.append(messages.key("form.html.error.start")).append(
218:                            messages.key("password.error.login")).append(
219:                            messages.key("form.html.error.end"));
220:                }
221:                buf.append(messages.key("form.html.field.end")).append("\n");
222:
223:                // line #4
224:                if (showRowEnd(messages.key("form.html.col.two"))) {
225:                    buf.append(messages.key("form.html.row.end")).append("\n");
226:                }
227:
228:                return buf.toString();
229:            }
230:
231:            /**
232:             * @see com.alkacon.opencms.formgenerator.I_CmsField#getType()
233:             */
234:            public String getType() {
235:
236:                return TYPE;
237:            }
238:
239:            /**
240:             * @see com.alkacon.opencms.formgenerator.A_CmsField#validate(com.alkacon.opencms.formgenerator.CmsFormHandler)
241:             */
242:            public String validate(CmsFormHandler formHandler) {
243:
244:                String validationError = super .validate(formHandler);
245:                if (CmsStringUtil.isEmpty(validationError)) {
246:                    // old password, only if in profile mode
247:                    if (!formHandler.getCmsObject().getRequestContext()
248:                            .currentUser().isGuestUser()) {
249:                        // get old password value from request 
250:                        String[] parameterValues = (String[]) formHandler
251:                                .getParameterMap().get(
252:                                        PREFIX_PASSWORD + getName());
253:                        StringBuffer value = new StringBuffer();
254:                        if (parameterValues != null) {
255:                            for (int j = 0; j < parameterValues.length; j++) {
256:                                if (j != 0) {
257:                                    value.append(", ");
258:                                }
259:                                value.append(parameterValues[j]);
260:                            }
261:                        }
262:
263:                        // only if the user entered a password
264:                        if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(value
265:                                .toString())) {
266:                            try {
267:                                // check password
268:                                formHandler.getCmsObject().readUser(
269:                                        formHandler.getCmsObject()
270:                                                .getRequestContext()
271:                                                .currentUser().getName(),
272:                                        value.toString());
273:                                // password is ok
274:                            } catch (CmsException e) {
275:                                // wrong password
276:                                return ERROR_LOGIN;
277:                            }
278:                        }
279:                    }
280:                    // get confirmation value from request 
281:                    String[] parameterValues = (String[]) formHandler
282:                            .getParameterMap().get(
283:                                    PREFIX_CONFIRMATION + getName());
284:                    StringBuffer value = new StringBuffer();
285:                    if (parameterValues != null) {
286:                        for (int j = 0; j < parameterValues.length; j++) {
287:                            if (j != 0) {
288:                                value.append(", ");
289:                            }
290:                            value.append(parameterValues[j]);
291:                        }
292:                    }
293:
294:                    if (!getValue().equals(value.toString())) {
295:                        return ERROR_CONFIRMATION;
296:                    }
297:                }
298:                return validationError;
299:            }
300:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.