001: /*
002: * Created on 29-Oct-2004
003: *
004: * TODO To change the template for this generated file go to
005: * Window - Preferences - Java - Code Style - Code Templates
006: */
007: package org.jical;
008:
009: import java.util.Date;
010:
011: /**
012: * @author sfg
013: *
014: * TODO To change the template for this generated type comment go to
015: * Window - Preferences - Java - Code Style - Code Templates
016: */
017: public class ICalUtil {
018:
019: public static String makeVEventLines(String type, String text) {
020: if (text == null)
021: return "";
022: StringBuffer textLine = new StringBuffer();
023: textLine.append(type).append(text).append("\n");
024:
025: // Now check for the fold over effect.
026: //DESCRIPTION:This is a really big event line. I need to make this as I'm testing
027: // this stuff.
028:
029: if (textLine.length() <= 75)
030: return textLine.toString();
031:
032: StringBuffer newLines = new StringBuffer();
033: while (textLine.length() > 75) {
034: newLines.append(textLine.substring(0, 75)).append("\n");
035: // Make text line from 78th char on.
036: String newTextLine = " " + textLine.substring(75);
037: textLine = new StringBuffer().append(newTextLine);
038: }
039:
040: return newLines.toString() + textLine;
041: }
042:
043: /*
044: * TODO, all these renderings should be here in a util class.
045: */
046: public String getJiCaldisplayXML(ICalendar icalendar,
047: Date dateFrom, Date dateTo, String timeRange) {
048: // if (icalendar.getOrganizerEmail() == null
049: // || icalendar.getOrganizer() == null) {
050: // //logger.severe("Cannot create XML unless OrganizerEmail are Organizer provided to ICalendar");
051: // return "";
052: // }
053: //
054: // /*
055: // * This is more useful for rendering as HTML or PDF an
056: // * Evolution Calendar.
057: // *
058: // */
059: //
060: // StringBuffer XMLString = new StringBuffer("<jicaldisplay>\n");
061: // XMLString.append("\t<organizer>").append( icalendar.getOrganizer()).append("</organizer>\n");
062: // XMLString.append("\t<organizeremail>").append(icalendar.getOrganizerEmail()).append("</organizeremail>\n");
063: // XMLString.append("\t<datestart>").append(dateFormatter.format(dateFrom)).append("</datestart>\n");
064: // XMLString.append("\t<dateend>").append(dateFormatter.format(dateTo)).append("</dateend>\n");
065: //
066: // // Hmmm... If we truely want to represent this date range, we must get all dates from .
067: // // to the To range. Reason being that some might start before this date and repeat in
068: // // this range....
069: //
070: // // Make starting date really old!!
071: //
072: // Date trueStartDate = new Date(0);
073: // getIcalExpandedEvents(trueStartDate, dateTo, timeRange);
074: //
075: // /*
076: // * This is the tricky bit, iterate from the datefrom date, through the
077: // * days to the dateto date. All days in between get some XML.
078: // */
079: //
080: // //int dateRepeatUnit = Calendar.HOUR_OF_DAY;
081: //
082: // Calendar repeatXMLDateStart = new GregorianCalendar();
083: // repeatXMLDateStart.setTime(dateFrom);
084: //
085: // XMLString.append("<days>\n");
086: //
087: // while (repeatXMLDateStart != null
088: // && ! repeatXMLDateStart.getTime().after(dateTo))
089: // {
090: // XMLString.append("\t\t<day>\n");
091: // XMLString.append("\t\t\t<dayofweek>").append(dayOfWeek.format(repeatXMLDateStart.getTime())).append("</dayofweek>\n");
092: // XMLString.append("\t\t\t<monthofyear>").append(monthOfYear.format(repeatXMLDateStart.getTime())).append("</monthofyear>\n");
093: // XMLString.append("\t\t\t<weeknumber>").append(weekNumber.format(repeatXMLDateStart.getTime())).append("</weeknumber>\n");
094: // XMLString.append("\t\t\t<date>").append(dateOnlyFormat.format(repeatXMLDateStart.getTime())).append("</date>\n");
095: // XMLString.append("\t\t\t<vevents>\n");
096: // // Now find all events that match this date.
097: // Calendar thisDateFrom = new GregorianCalendar();
098: // thisDateFrom.setTime(repeatXMLDateStart.getTime());
099: // thisDateFrom.set(Calendar.HOUR_OF_DAY, 0);
100: // thisDateFrom.set(Calendar.MINUTE, 0);
101: // thisDateFrom.set(Calendar.SECOND, 0);
102: //
103: // Date thisTimeFrom = thisDateFrom.getTime();
104: // // Altered as was excluding all day events which END at 00:00 on the next day..
105: // Calendar thisDateTo = new GregorianCalendar();
106: // thisDateTo.setTime(repeatXMLDateStart.getTime());
107: // thisDateTo.set(Calendar.HOUR_OF_DAY,24);
108: // thisDateTo.set(java.util.Calendar.MINUTE,0);
109: // thisDateTo.set(java.util.Calendar.SECOND,0);
110: // Date thisTimeTo = thisDateTo.getTime();
111: //
112: // Iterator eeIterator = sortedExpandedEvents.iterator();
113: // while (eeIterator.hasNext())
114: // {
115: // ICalendarVEvent icalEvent = (ICalendarVEvent) eeIterator.next();
116: // /* There are four conditions for inclusion of this event
117: // in this day.
118: // 1) Runs right across this date and others.
119: // * ie day 23/2/2004. Event goes 22/2/2004 to 25/2/2004
120: // 2) Falls within the day
121: // ** ie day 23/2/2004. Event goes 23/2/2004 to 23/2/2004
122: // 3) End period falls within the start day point or
123: // * ie day 23/2/2004. Event goes 22/2/2004 to 23/2/2004 5am
124: // 4) Start period falls within the end day point.
125: // * ie day 23/2/2004. Event goes 23/2/2004 12 noon to 25/2/2004
126: // */
127: // Date icalDateStart = icalEvent.getDateStart();
128: // Date icalDateEnd = icalEvent.getDateEnd();
129: //
130: // /*
131: // * Whole day events are not handled well with this method as they run
132: // * exactly on the 24hr time line. We need to recognise them and
133: // * for the purposes of testing conditions, reduce the seconds so
134: // * that they fit within a day.
135: // */
136: // thisDateFrom.setTime(icalDateStart);
137: // thisDateTo.setTime(icalDateEnd);
138: //
139: // // Condition 1.
140: // if ((thisTimeFrom.after(icalDateStart)
141: // || thisTimeFrom.equals(icalDateStart))
142: // && (thisTimeTo.before(icalDateEnd)
143: // || thisTimeTo.equals(icalDateEnd)))
144: // {
145: // // Create an all day event as this event wraps this day and others.
146: // icalEvent.setDateStart(thisTimeFrom);
147: // icalEvent.setDateEnd(thisTimeTo);
148: // XMLString.append("\t\t");
149: // XMLString.append(icalEvent.toXML());
150: // XMLString.append("\n");
151: // }
152: // // Condition 2.
153: // else if (thisTimeFrom.before(icalDateStart)
154: // && thisTimeTo.after(icalDateEnd))
155: // {
156: // // Create event as is.
157: //// XMLString.append("Cond2");
158: // XMLString.append("\t\t");
159: // XMLString.append(icalEvent.toXML());
160: // XMLString.append("\n");
161: // }
162: // // Condition 3.
163: // else if (thisTimeFrom.before(icalDateEnd)
164: // && thisTimeTo.after(icalDateEnd))
165: // {
166: // // Create event with end time as thisTimeTo, start time as speced.
167: //// XMLString.append("Cond3" + thisTimeFrom + thisTimeTo);
168: // icalEvent.setDateStart(thisTimeFrom);
169: // icalEvent.setDateEnd(icalDateEnd);
170: // XMLString.append("\t\t");
171: // XMLString.append(icalEvent.toXML());
172: // XMLString.append("\n");
173: // }
174: // // Condition 4.
175: // else if (thisTimeFrom.before(icalDateStart)
176: // && thisTimeTo.after(icalDateStart))
177: // {
178: // // Create event with starttime time as thisTimeFrom, end time as speced.
179: //// XMLString.append("Cond4");
180: // icalEvent.setDateStart(icalDateStart);
181: // icalEvent.setDateEnd(thisTimeTo);
182: // XMLString.append("\t\t");
183: // XMLString.append(icalEvent.toXML());
184: // XMLString.append("\n");
185: // }
186: // else {
187: // //Event rejected for this date
188: // }
189: // }
190: //
191: // XMLString.append("\t\t\t</vevents>");
192: // XMLString.append("\t\t</day>\n");
193: //
194: // // On to the next day..
195: // repeatXMLDateStart.add(Calendar.HOUR_OF_DAY, 24);
196: //
197: // }
198: //
199: // XMLString.append("\t</days>\n");
200: // XMLString.append("</jicaldisplay>\n");
201: // return XMLString.toString();
202: return "";
203: }
204: }
|