Adding JMCR-Stable version
[Benchmarks_CSolver.git] / JMCR-Stable / real-world application / jigsaw / src / org / w3c / www / http / HttpDate.java
diff --git a/JMCR-Stable/real-world application/jigsaw/src/org/w3c/www/http/HttpDate.java b/JMCR-Stable/real-world application/jigsaw/src/org/w3c/www/http/HttpDate.java
new file mode 100644 (file)
index 0000000..9b45cd4
--- /dev/null
@@ -0,0 +1,154 @@
+// HttpDate.java\r
+// $Id: HttpDate.java,v 1.1 2010/06/15 12:19:51 smhuang Exp $$\r
+// (c) COPYRIGHT MIT and INRIA, 1996.\r
+// Please first read the full copyright statement in file COPYRIGHT.html\r
+\r
+package org.w3c.www.http;\r
+\r
+import java.util.Date;\r
+import java.util.Calendar;\r
+import java.util.TimeZone;\r
+\r
+public class HttpDate extends BasicValue {\r
+    \r
+    protected static byte bdays[][] = {{(byte)'P',(byte)'a',(byte)'d'},\r
+                                      {(byte)'S',(byte)'u',(byte)'n'}, \r
+                                      {(byte)'M',(byte)'o',(byte)'n'},\r
+                                      {(byte)'T',(byte)'u',(byte)'e'},\r
+                                      {(byte)'W',(byte)'e',(byte)'d'},\r
+                                      {(byte)'T',(byte)'h',(byte)'u'},\r
+                                      {(byte)'F',(byte)'r',(byte)'i'}, \r
+                                      {(byte)'S',(byte)'a',(byte)'t'}};\r
+    \r
+    protected static byte bmonthes[][] = {{(byte)'J',(byte)'a',(byte)'n'}, \r
+                                         {(byte)'F',(byte)'e',(byte)'b'}, \r
+                                         {(byte)'M',(byte)'a',(byte)'r'},\r
+                                         {(byte)'A',(byte)'p',(byte)'r'},\r
+                                         {(byte)'M',(byte)'a',(byte)'y'},\r
+                                         {(byte)'J',(byte)'u',(byte)'n'},\r
+                                         {(byte)'J',(byte)'u',(byte)'l'},\r
+                                         {(byte)'A',(byte)'u',(byte)'g'},\r
+                                         {(byte)'S',(byte)'e',(byte)'p'},\r
+                                         {(byte)'O',(byte)'c',(byte)'t'},\r
+                                         {(byte)'N',(byte)'o',(byte)'v'}, \r
+                                         {(byte)'D',(byte)'e',(byte)'c'}};\r
+    \r
+    protected Long date = null;\r
+\r
+    protected Calendar cal = null;\r
+    \r
+    protected void parse() {\r
+       ParseState ps = new ParseState();\r
+       ps.ioff   = roff;\r
+       ps.bufend = rlen;\r
+       date = new Long(HttpParser.parseDateOrDeltaSeconds(raw, ps));\r
+    }\r
+\r
+    protected void updateByteValue() {\r
+       if (cal == null) {\r
+           TimeZone tz = TimeZone.getTimeZone("UTC");\r
+           cal = Calendar.getInstance(tz);\r
+       }\r
+       Date now = new Date(date.longValue());\r
+       cal.setTime(now);\r
+       // Dump the date, according to HTTP/1.1 prefered format\r
+       byte buf[] = new byte[29];\r
+       int dayofweek = cal.get(Calendar.DAY_OF_WEEK);\r
+       int j = 0;\r
+       for (int i = 0; i< 3; i++) {\r
+           buf[j++] = bdays[dayofweek][i];\r
+       }\r
+       buf[j++] = (byte) ',';\r
+       buf[j++] = (byte) ' ';\r
+       int day = cal.get(Calendar.DAY_OF_MONTH);\r
+       if (day < 10) {\r
+           buf[j++] = 48;\r
+           buf[j++] = (byte)(48 + day);\r
+       } else {\r
+           buf[j++] = (byte) (48 + (day / 10));\r
+           buf[j++] = (byte) (48 + (day % 10));\r
+       }\r
+       buf[j++] = (byte) ' ';\r
+       int month = cal.get(Calendar.MONTH);\r
+       for (int i = 0; i< 3; i++) {\r
+           buf[j++] = bmonthes[month][i];\r
+       }\r
+       buf[j++] = (byte) ' ';\r
+       int year = cal.get(Calendar.YEAR);\r
+       // not y10k compliant\r
+       buf[j+3] = (byte) (48 + (year % 10));\r
+       year = year / 10;\r
+       buf[j+2] = (byte) (48 + (year % 10));\r
+       year = year / 10;\r
+       buf[j+1] = (byte) (48 + (year % 10));\r
+       year = year / 10;\r
+       buf[j] = (byte) (48 + year);\r
+       j += 4;\r
+       buf[j++] = (byte) ' ';\r
+       int hour = cal.get(Calendar.HOUR_OF_DAY);\r
+       if (hour < 10) {\r
+           buf[j++] = (byte) 48;\r
+           buf[j++] = (byte) (48 + hour);\r
+       } else {\r
+           buf[j++] = (byte) (48 + (hour / 10));\r
+           buf[j++] = (byte) (48 + (hour % 10));\r
+       }\r
+       buf[j++] = (byte) ':';\r
+       int minute = cal.get(Calendar.MINUTE);\r
+       if (minute < 10) {\r
+           buf[j++] = (byte) 48;\r
+           buf[j++] = (byte) (48 + minute);\r
+       } else {\r
+           buf[j++] = (byte) (48 + (minute / 10));\r
+           buf[j++] = (byte) (48 + (minute % 10));\r
+       }\r
+       buf[j++] = (byte) ':';\r
+       int second = cal.get(Calendar.SECOND);\r
+       if (second < 10) {\r
+           buf[j++] = (byte) 48;\r
+           buf[j++] = (byte) (48 + second);\r
+       } else {\r
+           buf[j++] = (byte) (48 + (second / 10));\r
+           buf[j++] = (byte) (48 + (second % 10));\r
+       } \r
+       buf[j++] = (byte) ' '; buf[j++] = (byte) 'G'; \r
+       buf[j++] = (byte) 'M'; buf[j++] = (byte) 'T';\r
+       raw = buf;\r
+       roff = 0;\r
+       rlen = raw.length;\r
+    }\r
+\r
+    /**\r
+     * Get the date value.\r
+     * @return A Long giving the date as a number of mmilliseconds since epoch.\r
+     */\r
+\r
+    public Object getValue() {\r
+       validate();\r
+       return date;\r
+    }\r
+\r
+    /**\r
+     * Set this date object value.\r
+     * @param date The new date value, as the number of milliseconds since\r
+     * epoch.\r
+     */\r
+\r
+    public void setValue(long date) {\r
+       if ( date == this.date.longValue() )\r
+           return ;\r
+       invalidateByteValue();\r
+       this.date = new Long(date);\r
+       this.isValid = true ;\r
+    }\r
+\r
+    HttpDate(boolean isValid, long date) {\r
+       this.isValid = isValid;\r
+       this.date    = new Long(date);\r
+    }\r
+\r
+    HttpDate() {\r
+       this.isValid = false;\r
+    }\r
+\r
+}\r