Source Code Cross Referenced for DateTool.java in  » Sevlet-Container » tomcat-connectors » org » apache » tomcat » util » buf » 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 » Sevlet Container » tomcat connectors » org.apache.tomcat.util.buf 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  Copyright 1999-2004 The Apache Software Foundation
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:         */
016:
017:        package org.apache.tomcat.util.buf;
018:
019:        import java.text.DateFormat;
020:        import java.text.FieldPosition;
021:        import java.text.ParseException;
022:        import java.text.SimpleDateFormat;
023:        import java.util.Date;
024:        import java.util.Locale;
025:        import java.util.TimeZone;
026:
027:        import org.apache.tomcat.util.res.StringManager;
028:
029:        /**
030:         *  Common place for date utils.
031:         *
032:         * @deprecated Will be replaced with a more efficient impl, based on
033:         * FastDateFormat, with an API using less objects.
034:         * @author dac@eng.sun.com
035:         * @author Jason Hunter [jch@eng.sun.com]
036:         * @author James Todd [gonzo@eng.sun.com]
037:         * @author Costin Manolache
038:         */
039:        public class DateTool {
040:
041:            /** US locale - all HTTP dates are in english
042:             */
043:            private final static Locale LOCALE_US = Locale.US;
044:
045:            /** GMT timezone - all HTTP dates are on GMT
046:             */
047:            public final static TimeZone GMT_ZONE = TimeZone.getTimeZone("GMT");
048:
049:            /** format for RFC 1123 date string -- "Sun, 06 Nov 1994 08:49:37 GMT"
050:             */
051:            public final static String RFC1123_PATTERN = "EEE, dd MMM yyyy HH:mm:ss z";
052:
053:            // format for RFC 1036 date string -- "Sunday, 06-Nov-94 08:49:37 GMT"
054:            public final static String rfc1036Pattern = "EEEEEEEEE, dd-MMM-yy HH:mm:ss z";
055:
056:            // format for C asctime() date string -- "Sun Nov  6 08:49:37 1994"
057:            public final static String asctimePattern = "EEE MMM d HH:mm:ss yyyy";
058:
059:            /** Pattern used for old cookies
060:             */
061:            private final static String OLD_COOKIE_PATTERN = "EEE, dd-MMM-yyyy HH:mm:ss z";
062:
063:            /** DateFormat to be used to format dates. Called from MessageBytes
064:             */
065:            private final static DateFormat rfc1123Format = new SimpleDateFormat(
066:                    RFC1123_PATTERN, LOCALE_US);
067:
068:            /** DateFormat to be used to format old netscape cookies
069:            Called from ServerCookie
070:             */
071:            private final static DateFormat oldCookieFormat = new SimpleDateFormat(
072:                    OLD_COOKIE_PATTERN, LOCALE_US);
073:
074:            private final static DateFormat rfc1036Format = new SimpleDateFormat(
075:                    rfc1036Pattern, LOCALE_US);
076:
077:            private final static DateFormat asctimeFormat = new SimpleDateFormat(
078:                    asctimePattern, LOCALE_US);
079:
080:            static {
081:                rfc1123Format.setTimeZone(GMT_ZONE);
082:                oldCookieFormat.setTimeZone(GMT_ZONE);
083:                rfc1036Format.setTimeZone(GMT_ZONE);
084:                asctimeFormat.setTimeZone(GMT_ZONE);
085:            }
086:
087:            private static String rfc1123DS;
088:            private static long rfc1123Sec;
089:
090:            private static StringManager sm = StringManager
091:                    .getManager("org.apache.tomcat.util.buf.res");
092:
093:            // Called from MessageBytes.getTime()
094:            static long parseDate(MessageBytes value) {
095:                return parseDate(value.toString());
096:            }
097:
098:            // Called from MessageBytes.setTime
099:            /** 
100:             */
101:            public static String format1123(Date d) {
102:                String dstr = null;
103:                synchronized (rfc1123Format) {
104:                    dstr = format1123(d, rfc1123Format);
105:                }
106:                return dstr;
107:            }
108:
109:            public static String format1123(Date d, DateFormat df) {
110:                long dt = d.getTime() / 1000;
111:                if ((rfc1123DS != null) && (dt == rfc1123Sec))
112:                    return rfc1123DS;
113:                rfc1123DS = df.format(d);
114:                rfc1123Sec = dt;
115:                return rfc1123DS;
116:            }
117:
118:            // Called from ServerCookie
119:            /** 
120:             */
121:            public static void formatOldCookie(Date d, StringBuffer sb,
122:                    FieldPosition fp) {
123:                synchronized (oldCookieFormat) {
124:                    oldCookieFormat.format(d, sb, fp);
125:                }
126:            }
127:
128:            // Called from ServerCookie
129:            public static String formatOldCookie(Date d) {
130:                String ocf = null;
131:                synchronized (oldCookieFormat) {
132:                    ocf = oldCookieFormat.format(d);
133:                }
134:                return ocf;
135:            }
136:
137:            /** Called from HttpServletRequest.getDateHeader().
138:            Not efficient - but not very used.
139:             */
140:            public static long parseDate(String dateString) {
141:                DateFormat[] format = { rfc1123Format, rfc1036Format,
142:                        asctimeFormat };
143:                return parseDate(dateString, format);
144:            }
145:
146:            public static long parseDate(String dateString, DateFormat[] format) {
147:                Date date = null;
148:                for (int i = 0; i < format.length; i++) {
149:                    try {
150:                        date = format[i].parse(dateString);
151:                        return date.getTime();
152:                    } catch (ParseException e) {
153:                    } catch (StringIndexOutOfBoundsException e) {
154:                    }
155:                }
156:                String msg = sm.getString("httpDate.pe", dateString);
157:                throw new IllegalArgumentException(msg);
158:            }
159:
160:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.