Source Code Cross Referenced for TimestampControl.java in  » Web-Framework » aranea-mvc-1.1.1 » org » araneaframework » uilib » form » control » 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 » Web Framework » aranea mvc 1.1.1 » org.araneaframework.uilib.form.control 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * Copyright 2006 Webmedia Group Ltd.
003:         *
004:         * Licensed under the Apache License, Version 2.0 (the "License");
005:         * you may not use this file except in compliance with the License.
006:         * You may obtain a copy of the License at
007:         *
008:         *  http://www.apache.org/licenses/LICENSE-2.0
009:         *
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS,
012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         * See the License for the specific language governing permissions and
014:         * limitations under the License.
015:         **/package org.araneaframework.uilib.form.control;
016:
017:        import java.sql.Timestamp;
018:        import java.text.SimpleDateFormat;
019:        import org.apache.commons.lang.StringUtils;
020:        import org.araneaframework.uilib.form.FilteredInputControl;
021:        import org.araneaframework.uilib.form.control.inputfilter.InputFilter;
022:        import org.araneaframework.uilib.support.UiLibMessages;
023:        import org.araneaframework.uilib.util.MessageUtil;
024:        import org.araneaframework.uilib.util.ValidationUtil;
025:        import org.araneaframework.uilib.util.ValidationUtil.ParsedDate;
026:
027:        /**
028:         * This class represents a generalization of controls that have a value
029:         * of type <code>Timestamp</code>. 
030:         * 
031:         * @author Jevgeni Kabanov (ekabanov <i>at</i> araneaframework <i>dot</i> org)
032:         */
033:        public abstract class TimestampControl extends
034:                EmptyStringNullableControl implements  FilteredInputControl {
035:
036:            //*********************************************************************
037:            // FIELDS
038:            //*********************************************************************    
039:
040:            /**
041:             * The date-time format used by the element for parsing.
042:             */
043:            protected String dateTimeInputPattern;
044:            protected String dateTimeOutputPattern;
045:
046:            protected boolean confOverridden = false;
047:
048:            private InputFilter inputFilter;
049:
050:            //*********************************************************************
051:            // CONSTRUCTORS
052:            //*********************************************************************     
053:
054:            /**
055:             * Creates the control setting it's date format pattern to the one provided.
056:             * 
057:             * @param dateTimeFormat date format pattern for {@link SimpleDateFormat}.
058:             */
059:            public TimestampControl(String dateTimeFormat,
060:                    String defaultOutputFormat) {
061:                this .dateTimeInputPattern = dateTimeFormat;
062:                this .dateTimeOutputPattern = defaultOutputFormat;
063:            }
064:
065:            /** @since 1.0.11 */
066:            public InputFilter getInputFilter() {
067:                return inputFilter;
068:            }
069:
070:            /** @since 1.0.11 */
071:            public void setInputFilter(InputFilter inputFilter) {
072:                this .inputFilter = inputFilter;
073:            }
074:
075:            //*********************************************************************
076:            //* INTERNAL METHODS
077:            //*********************************************************************  	
078:
079:            /**
080:             * Parses the parameter using the <code>dateTimeFormat</code>, 
081:             * trying to get <code>Timestamp</code>. Adds a 
082:             * <code>error.form.date.wrongformat</code> error message if
083:             * it fails.
084:             */
085:            protected Object fromRequest(String parameterValue) {
086:                ValidationUtil.ParsedDate result = parseDate(parameterValue);
087:
088:                if (result != null) {
089:                    dateTimeOutputPattern = result.getOutputPattern();
090:                    return new Timestamp(result.getDate().getTime());
091:                }
092:
093:                addWrongTimeFormatError();
094:
095:                if (parameterValue != null
096:                        && getInputFilter() != null
097:                        && !StringUtils.containsOnly(parameterValue,
098:                                getInputFilter().getCharacterFilter())) {
099:                    addError(MessageUtil.localizeAndFormat(getInputFilter()
100:                            .getInvalidInputMessage(), MessageUtil.localize(
101:                            getLabel(), getEnvironment()), getInputFilter()
102:                            .getCharacterFilter(), getEnvironment()));
103:                }
104:
105:                return null;
106:            }
107:
108:            /** @since 1.1 */
109:            protected void addWrongTimeFormatError() {
110:                addError(MessageUtil.localizeAndFormat(
111:                        UiLibMessages.WRONG_DATE_FORMAT, MessageUtil.localize(
112:                                getLabel(), getEnvironment()),
113:                        dateTimeInputPattern, getEnvironment()));
114:            }
115:
116:            /**
117:             * Used by {@link TimestampControl#fromRequest(String)} to convert value
118:             * read from request to a <code>Date</code> in default <code>TimeZone</code>
119:             * and <code>Locale</code>.
120:             * 
121:             * @since 1.0.3
122:             */
123:            protected ParsedDate parseDate(String parameterValue) {
124:                return ValidationUtil.parseDate(parameterValue,
125:                        dateTimeInputPattern);
126:            }
127:
128:            /**
129:             * Formats the value using <code>dateTimeFormat</code>.
130:             */
131:            protected String toResponse(Object controlValue) {
132:                return new SimpleDateFormat(dateTimeOutputPattern)
133:                        .format((Timestamp) controlValue);
134:            }
135:
136:            //*********************************************************************
137:            //* PUBLIC METHODS
138:            //*********************************************************************  	
139:
140:            /**
141:             * Returns {@link ViewModel}.
142:             * @return {@link ViewModel}.
143:             */
144:            public Object getViewModel() {
145:                return new ViewModel();
146:            }
147:
148:            //*********************************************************************
149:            //* VIEWMODEL
150:            //*********************************************************************  	
151:
152:            public class ViewModel extends EmptyStringNullableControl.ViewModel {
153:                private String dateTimeOutputPattern;
154:                private InputFilter inputFilter;
155:
156:                /**
157:                 * Takes an outer class snapshot.     
158:                 */
159:                public ViewModel() {
160:                    this .dateTimeOutputPattern = TimestampControl.this .dateTimeOutputPattern;
161:                    this .inputFilter = TimestampControl.this .getInputFilter();
162:                }
163:
164:                public SimpleDateFormat getCurrentSimpleDateTimeFormat() {
165:                    return new SimpleDateFormat(dateTimeOutputPattern);
166:                }
167:
168:                public InputFilter getInputFilter() {
169:                    return this.inputFilter;
170:                }
171:            }
172:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.