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


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