KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jical > ICalUtil


1 /*
2  * Created on 29-Oct-2004
3  *
4  * TODO To change the template for this generated file go to
5  * Window - Preferences - Java - Code Style - Code Templates
6  */

7 package org.jical;
8
9 import java.util.Date JavaDoc;
10
11 /**
12  * @author sfg
13  *
14  * TODO To change the template for this generated type comment go to
15  * Window - Preferences - Java - Code Style - Code Templates
16  */

17 public class ICalUtil {
18     
19     public static String JavaDoc makeVEventLines(String JavaDoc type, String JavaDoc text)
20     {
21         if (text == null)
22             return "";
23         StringBuffer JavaDoc textLine = new StringBuffer JavaDoc();
24         textLine.append(type).append(text).append("\n");
25         
26         // Now check for the fold over effect.
27
//DESCRIPTION:This is a really big event line. I need to make this as I'm testing
28
// this stuff.
29

30         
31         if (textLine.length() <= 75)
32             return textLine.toString();
33         
34         StringBuffer JavaDoc newLines = new StringBuffer JavaDoc();
35         while (textLine.length() > 75)
36         {
37             newLines.append(textLine.substring(0,75)).append("\n");
38             // Make text line from 78th char on.
39
String JavaDoc newTextLine = " "+textLine.substring(75);
40             textLine = new StringBuffer JavaDoc().append(newTextLine);
41         }
42             
43         return newLines.toString()+textLine;
44     }
45
46     /*
47      * TODO, all these renderings should be here in a util class.
48      */

49     public String JavaDoc getJiCaldisplayXML(ICalendar icalendar, Date JavaDoc dateFrom, Date JavaDoc dateTo, String JavaDoc timeRange)
50     {
51 // if (icalendar.getOrganizerEmail() == null
52
// || icalendar.getOrganizer() == null) {
53
// //logger.severe("Cannot create XML unless OrganizerEmail are Organizer provided to ICalendar");
54
// return "";
55
// }
56
//
57
// /*
58
// * This is more useful for rendering as HTML or PDF an
59
// * Evolution Calendar.
60
// *
61
// */
62
//
63
// StringBuffer XMLString = new StringBuffer("<jicaldisplay>\n");
64
// XMLString.append("\t<organizer>").append( icalendar.getOrganizer()).append("</organizer>\n");
65
// XMLString.append("\t<organizeremail>").append(icalendar.getOrganizerEmail()).append("</organizeremail>\n");
66
// XMLString.append("\t<datestart>").append(dateFormatter.format(dateFrom)).append("</datestart>\n");
67
// XMLString.append("\t<dateend>").append(dateFormatter.format(dateTo)).append("</dateend>\n");
68
//
69
// // Hmmm... If we truely want to represent this date range, we must get all dates from .
70
// // to the To range. Reason being that some might start before this date and repeat in
71
// // this range....
72
//
73
// // Make starting date really old!!
74
//
75
// Date trueStartDate = new Date(0);
76
// getIcalExpandedEvents(trueStartDate, dateTo, timeRange);
77
//
78
// /*
79
// * This is the tricky bit, iterate from the datefrom date, through the
80
// * days to the dateto date. All days in between get some XML.
81
// */
82
//
83
// //int dateRepeatUnit = Calendar.HOUR_OF_DAY;
84
//
85
// Calendar repeatXMLDateStart = new GregorianCalendar();
86
// repeatXMLDateStart.setTime(dateFrom);
87
//
88
// XMLString.append("<days>\n");
89
//
90
// while (repeatXMLDateStart != null
91
// && ! repeatXMLDateStart.getTime().after(dateTo))
92
// {
93
// XMLString.append("\t\t<day>\n");
94
// XMLString.append("\t\t\t<dayofweek>").append(dayOfWeek.format(repeatXMLDateStart.getTime())).append("</dayofweek>\n");
95
// XMLString.append("\t\t\t<monthofyear>").append(monthOfYear.format(repeatXMLDateStart.getTime())).append("</monthofyear>\n");
96
// XMLString.append("\t\t\t<weeknumber>").append(weekNumber.format(repeatXMLDateStart.getTime())).append("</weeknumber>\n");
97
// XMLString.append("\t\t\t<date>").append(dateOnlyFormat.format(repeatXMLDateStart.getTime())).append("</date>\n");
98
// XMLString.append("\t\t\t<vevents>\n");
99
// // Now find all events that match this date.
100
// Calendar thisDateFrom = new GregorianCalendar();
101
// thisDateFrom.setTime(repeatXMLDateStart.getTime());
102
// thisDateFrom.set(Calendar.HOUR_OF_DAY, 0);
103
// thisDateFrom.set(Calendar.MINUTE, 0);
104
// thisDateFrom.set(Calendar.SECOND, 0);
105
//
106
// Date thisTimeFrom = thisDateFrom.getTime();
107
// // Altered as was excluding all day events which END at 00:00 on the next day..
108
// Calendar thisDateTo = new GregorianCalendar();
109
// thisDateTo.setTime(repeatXMLDateStart.getTime());
110
// thisDateTo.set(Calendar.HOUR_OF_DAY,24);
111
// thisDateTo.set(java.util.Calendar.MINUTE,0);
112
// thisDateTo.set(java.util.Calendar.SECOND,0);
113
// Date thisTimeTo = thisDateTo.getTime();
114
//
115
// Iterator eeIterator = sortedExpandedEvents.iterator();
116
// while (eeIterator.hasNext())
117
// {
118
// ICalendarVEvent icalEvent = (ICalendarVEvent) eeIterator.next();
119
// /* There are four conditions for inclusion of this event
120
// in this day.
121
// 1) Runs right across this date and others.
122
// * ie day 23/2/2004. Event goes 22/2/2004 to 25/2/2004
123
// 2) Falls within the day
124
// ** ie day 23/2/2004. Event goes 23/2/2004 to 23/2/2004
125
// 3) End period falls within the start day point or
126
// * ie day 23/2/2004. Event goes 22/2/2004 to 23/2/2004 5am
127
// 4) Start period falls within the end day point.
128
// * ie day 23/2/2004. Event goes 23/2/2004 12 noon to 25/2/2004
129
// */
130
// Date icalDateStart = icalEvent.getDateStart();
131
// Date icalDateEnd = icalEvent.getDateEnd();
132
//
133
// /*
134
// * Whole day events are not handled well with this method as they run
135
// * exactly on the 24hr time line. We need to recognise them and
136
// * for the purposes of testing conditions, reduce the seconds so
137
// * that they fit within a day.
138
// */
139
// thisDateFrom.setTime(icalDateStart);
140
// thisDateTo.setTime(icalDateEnd);
141
//
142
// // Condition 1.
143
// if ((thisTimeFrom.after(icalDateStart)
144
// || thisTimeFrom.equals(icalDateStart))
145
// && (thisTimeTo.before(icalDateEnd)
146
// || thisTimeTo.equals(icalDateEnd)))
147
// {
148
// // Create an all day event as this event wraps this day and others.
149
// icalEvent.setDateStart(thisTimeFrom);
150
// icalEvent.setDateEnd(thisTimeTo);
151
// XMLString.append("\t\t");
152
// XMLString.append(icalEvent.toXML());
153
// XMLString.append("\n");
154
// }
155
// // Condition 2.
156
// else if (thisTimeFrom.before(icalDateStart)
157
// && thisTimeTo.after(icalDateEnd))
158
// {
159
// // Create event as is.
160
//// XMLString.append("Cond2");
161
// XMLString.append("\t\t");
162
// XMLString.append(icalEvent.toXML());
163
// XMLString.append("\n");
164
// }
165
// // Condition 3.
166
// else if (thisTimeFrom.before(icalDateEnd)
167
// && thisTimeTo.after(icalDateEnd))
168
// {
169
// // Create event with end time as thisTimeTo, start time as speced.
170
//// XMLString.append("Cond3" + thisTimeFrom + thisTimeTo);
171
// icalEvent.setDateStart(thisTimeFrom);
172
// icalEvent.setDateEnd(icalDateEnd);
173
// XMLString.append("\t\t");
174
// XMLString.append(icalEvent.toXML());
175
// XMLString.append("\n");
176
// }
177
// // Condition 4.
178
// else if (thisTimeFrom.before(icalDateStart)
179
// && thisTimeTo.after(icalDateStart))
180
// {
181
// // Create event with starttime time as thisTimeFrom, end time as speced.
182
//// XMLString.append("Cond4");
183
// icalEvent.setDateStart(icalDateStart);
184
// icalEvent.setDateEnd(thisTimeTo);
185
// XMLString.append("\t\t");
186
// XMLString.append(icalEvent.toXML());
187
// XMLString.append("\n");
188
// }
189
// else {
190
// //Event rejected for this date
191
// }
192
// }
193
//
194
// XMLString.append("\t\t\t</vevents>");
195
// XMLString.append("\t\t</day>\n");
196
//
197
// // On to the next day..
198
// repeatXMLDateStart.add(Calendar.HOUR_OF_DAY, 24);
199
//
200
// }
201
//
202
// XMLString.append("\t</days>\n");
203
// XMLString.append("</jicaldisplay>\n");
204
// return XMLString.toString();
205
return "";
206     }
207 }
208
Popular Tags