Issue 489 update the port
[zxing.git] / csharp / client / result / CalendarParsedResult.cs
1 /*\r
2 * Copyright 2008 ZXing authors\r
3 *\r
4 * Licensed under the Apache License, Version 2.0 (the "License");\r
5 * you may not use this file except in compliance with the License.\r
6 * You may obtain a copy of the License at\r
7 *\r
8 *      http://www.apache.org/licenses/LICENSE-2.0\r
9 *\r
10 * Unless required by applicable law or agreed to in writing, software\r
11 * distributed under the License is distributed on an "AS IS" BASIS,\r
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
13 * See the License for the specific language governing permissions and\r
14 * limitations under the License.\r
15 */\r
16 using System;\r
17 namespace com.google.zxing.client.result\r
18 {\r
19         \r
20         /// <author>  Sean Owen\r
21         /// </author>\r
22         /// <author>www.Redivivus.in (suraj.supekar@redivivus.in) - Ported from ZXING Java Source \r
23         /// </author>\r
24         public sealed class CalendarParsedResult:ParsedResult\r
25         {\r
26                 public System.String Summary\r
27                 {\r
28                         get\r
29                         {\r
30                                 return summary;\r
31                         }\r
32                         \r
33                 }\r
34                 /// <summary> <p>We would return the start and end date as a {@link java.util.Date} except that this code\r
35                 /// needs to work under JavaME / MIDP and there is no date parsing library available there, such\r
36                 /// as <code>java.text.SimpleDateFormat</code>.</p> See validateDate() for the return format.\r
37                 /// \r
38                 /// </summary>\r
39                 /// <returns> start time formatted as a RFC 2445 DATE or DATE-TIME.</p>\r
40                 /// </returns>\r
41                 public System.String Start\r
42                 {\r
43                         get\r
44                         {\r
45                                 return start;\r
46                         }\r
47                         \r
48                 }\r
49                 /// <seealso cref="getStart(). May return null if the event has no duration.">\r
50                 /// </seealso>\r
51                 public System.String End\r
52                 {\r
53                         get\r
54                         {\r
55                                 return end;\r
56                         }\r
57                         \r
58                 }\r
59                 public System.String Location\r
60                 {\r
61                         get\r
62                         {\r
63                                 return location;\r
64                         }\r
65                         \r
66                 }\r
67                 public System.String Attendee\r
68                 {\r
69                         get\r
70                         {\r
71                                 return attendee;\r
72                         }\r
73                         \r
74                 }\r
75                 public System.String Title\r
76                 {\r
77                         get\r
78                         {\r
79                                 return title;\r
80                         }\r
81                         \r
82                 }\r
83                 override public System.String DisplayResult\r
84                 {\r
85                         get\r
86                         {\r
87                                 System.Text.StringBuilder result = new System.Text.StringBuilder(100);\r
88                                 maybeAppend(summary, result);\r
89                                 maybeAppend(start, result);\r
90                                 maybeAppend(end, result);\r
91                                 maybeAppend(location, result);\r
92                                 maybeAppend(attendee, result);\r
93                                 maybeAppend(title, result);\r
94                                 return result.ToString();\r
95                         }\r
96                         \r
97                 }\r
98                 \r
99                 //UPGRADE_NOTE: Final was removed from the declaration of 'summary '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'"\r
100                 private System.String summary;\r
101                 //UPGRADE_NOTE: Final was removed from the declaration of 'start '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'"\r
102                 private System.String start;\r
103                 //UPGRADE_NOTE: Final was removed from the declaration of 'end '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'"\r
104                 private System.String end;\r
105                 //UPGRADE_NOTE: Final was removed from the declaration of 'location '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'"\r
106                 private System.String location;\r
107                 //UPGRADE_NOTE: Final was removed from the declaration of 'attendee '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'"\r
108                 private System.String attendee;\r
109                 //UPGRADE_NOTE: Final was removed from the declaration of 'title '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'"\r
110                 private System.String title;\r
111                 \r
112                 public CalendarParsedResult(System.String summary, System.String start, System.String end, System.String location, System.String attendee, System.String title):base(ParsedResultType.CALENDAR)\r
113                 {\r
114                         // Start is required, end is not\r
115                         if (start == null)\r
116                         {\r
117                                 throw new System.ArgumentException();\r
118                         }\r
119                         validateDate(start);\r
120                         validateDate(end);\r
121                         this.summary = summary;\r
122                         this.start = start;\r
123                         this.end = end;\r
124                         this.location = location;\r
125                         this.attendee = attendee;\r
126                         this.title = title;\r
127                 }\r
128                 \r
129                 /// <summary> RFC 2445 allows the start and end fields to be of type DATE (e.g. 20081021) or DATE-TIME\r
130                 /// (e.g. 20081021T123000 for local time, or 20081021T123000Z for UTC).\r
131                 /// \r
132                 /// </summary>\r
133                 /// <param name="date">The string to validate\r
134                 /// </param>\r
135                 private static void  validateDate(System.String date)\r
136                 {\r
137                         if (date != null)\r
138                         {\r
139                                 int length = date.Length;\r
140                                 if (length != 8 && length != 15 && length != 16)\r
141                                 {\r
142                                         throw new System.ArgumentException();\r
143                                 }\r
144                                 for (int i = 0; i < 8; i++)\r
145                                 {\r
146                                         if (!System.Char.IsDigit(date[i]))\r
147                                         {\r
148                                                 throw new System.ArgumentException();\r
149                                         }\r
150                                 }\r
151                                 if (length > 8)\r
152                                 {\r
153                                         if (date[8] != 'T')\r
154                                         {\r
155                                                 throw new System.ArgumentException();\r
156                                         }\r
157                                         for (int i = 9; i < 15; i++)\r
158                                         {\r
159                                                 if (!System.Char.IsDigit(date[i]))\r
160                                                 {\r
161                                                         throw new System.ArgumentException();\r
162                                                 }\r
163                                         }\r
164                                         if (length == 16 && date[15] != 'Z')\r
165                                         {\r
166                                                 throw new System.ArgumentException();\r
167                                         }\r
168                                 }\r
169                         }\r
170                 }\r
171         }\r
172 }