Source Code Cross Referenced for ISO8601DateConverter.java in  » Web-Services » Gomba » org » gomba » utils » convert » 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 Services » Gomba » org.gomba.utils.convert 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.gomba.utils.convert;
002:
003:        import java.util.Date;
004:
005:        import org.apache.commons.beanutils.ConversionException;
006:        import org.apache.commons.beanutils.Converter;
007:        import org.w3c.util.DateParser;
008:        import org.w3c.util.InvalidDateException;
009:
010:        /**
011:         * <p>
012:         * {@link Converter}implementation that converts an incoming String into a
013:         * <code>java.util.Date</code> object according to the ISO 8601 standard,
014:         * optionally using a default value or throwing a {@link ConversionException}if
015:         * a conversion error occurs.
016:         * </p>
017:         * 
018:         * <p>
019:         * Supported date formats:
020:         * <ul>
021:         * <li>1997-07-16T19:20:30.45-02:00</li>
022:         * <li>1997-07-16T19:20:30+01:00</li>
023:         * <li>1997-07-16T19:20:30</li>
024:         * <li>1997-07-16T19:20</li>
025:         * <li>1997-07-16</li>
026:         * <li>1997-07</li>
027:         * <li>1997</li>
028:         * </ul>
029:         * </p>
030:         * 
031:         * <p>
032:         * This class makes use of <code>org.w3c.util.DateParser</code> to parse
033:         * strings.
034:         * </p>
035:         * 
036:         * @author Flavio Tordini
037:         * @version $Id: ISO8601DateConverter.java,v 1.1.1.1 2004/06/16 13:15:12
038:         *                flaviotordini Exp $
039:         * @see <a
040:         *           href="http://www.w3.org/TR/NOTE-datetime">http://www.w3.org/TR/NOTE-datetime
041:         *           </a>
042:         * @see <a
043:         *           href="http://dev.w3.org/cvsweb/java/classes/org/w3c/util/">http://dev.w3.org/cvsweb/java/classes/org/w3c/util/
044:         *           </a>
045:         */
046:
047:        public final class ISO8601DateConverter implements  Converter {
048:
049:            /**
050:             * Create a {@link Converter}that will throw a {@link ConversionException}
051:             * if a conversion error occurs.
052:             */
053:            public ISO8601DateConverter() {
054:
055:                this .defaultValue = null;
056:                this .useDefault = false;
057:
058:            }
059:
060:            /**
061:             * Create a {@link Converter}that will return the specified default value
062:             * if a conversion error occurs.
063:             * 
064:             * @param defaultValue
065:             *                   The default value to be returned
066:             */
067:            public ISO8601DateConverter(Object defaultValue) {
068:
069:                this .defaultValue = defaultValue;
070:                this .useDefault = true;
071:
072:            }
073:
074:            /**
075:             * The default value specified to our Constructor, if any.
076:             */
077:            private Object defaultValue = null;
078:
079:            /**
080:             * Should we return the default value on conversion errors?
081:             */
082:            private boolean useDefault = true;
083:
084:            /**
085:             * Convert the specified input object into an output object of the specified
086:             * type.
087:             * 
088:             * @param type
089:             *                   Data type to which this value should be converted
090:             * @param value
091:             *                   The input value to be converted
092:             * 
093:             * @exception ConversionException
094:             *                        if conversion cannot be performed successfully
095:             */
096:            public Object convert(Class type, Object value) {
097:
098:                if (value == null) {
099:                    if (this .useDefault) {
100:                        return (this .defaultValue);
101:                    }
102:                    throw new ConversionException("No value specified");
103:                }
104:
105:                if (value instanceof  Date) {
106:                    return (value);
107:                } else if (value instanceof  java.lang.String) {
108:                    String valueStr = (String) value;
109:                    // w3c DateParser defaults to 1970 for an empty string
110:                    if (valueStr.length() == 0) {
111:                        throw new ConversionException(
112:                                "Cannot convert an empty string to "
113:                                        + Date.class);
114:                    }
115:                    try {
116:                        return DateParser.parse(valueStr);
117:                    } catch (InvalidDateException ide) {
118:                        throw new ConversionException(ide);
119:                    }
120:                }
121:
122:                if (this .useDefault) {
123:                    return (this .defaultValue);
124:                }
125:                throw new ConversionException("Cannot convert.");
126:
127:            }
128:
129:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.