KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > tasklist > usertasks > translators > ICalExportFormat


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.tasklist.usertasks.translators;
21
22 import java.io.BufferedOutputStream JavaDoc;
23 import java.io.BufferedReader JavaDoc;
24 import java.io.File JavaDoc;
25 import java.io.FileOutputStream JavaDoc;
26 import java.io.IOException JavaDoc;
27 import java.io.OutputStreamWriter JavaDoc;
28 import java.io.Reader JavaDoc;
29 import java.io.StringReader JavaDoc;
30 import java.io.StringWriter JavaDoc;
31 import java.io.Writer JavaDoc;
32 import java.net.URISyntaxException JavaDoc;
33 import java.net.URL JavaDoc;
34 import java.text.ParseException JavaDoc;
35 import java.text.SimpleDateFormat JavaDoc;
36 import java.util.ArrayList JavaDoc;
37 import java.util.Iterator JavaDoc;
38 import java.util.List JavaDoc;
39 import java.util.logging.Level JavaDoc;
40 import net.fortuna.ical4j.data.CalendarOutputter;
41 import net.fortuna.ical4j.model.Calendar;
42 import net.fortuna.ical4j.model.Component;
43 import net.fortuna.ical4j.model.ComponentList;
44 import net.fortuna.ical4j.model.Date;
45 import net.fortuna.ical4j.model.DateTime;
46 import net.fortuna.ical4j.model.Property;
47 import net.fortuna.ical4j.model.PropertyList;
48 import net.fortuna.ical4j.model.ValidationException;
49 import net.fortuna.ical4j.model.component.VToDo;
50 import net.fortuna.ical4j.model.parameter.XParameter;
51 import net.fortuna.ical4j.model.property.Categories;
52 import net.fortuna.ical4j.model.property.Completed;
53 import net.fortuna.ical4j.model.property.Created;
54 import net.fortuna.ical4j.model.property.Description;
55 import net.fortuna.ical4j.model.property.DtStamp;
56 import net.fortuna.ical4j.model.property.DtStart;
57 import net.fortuna.ical4j.model.property.LastModified;
58 import net.fortuna.ical4j.model.property.PercentComplete;
59 import net.fortuna.ical4j.model.property.Priority;
60 import net.fortuna.ical4j.model.property.ProdId;
61 import net.fortuna.ical4j.model.property.RelatedTo;
62 import net.fortuna.ical4j.model.property.Summary;
63 import net.fortuna.ical4j.model.property.Uid;
64 import net.fortuna.ical4j.model.property.Url;
65 import net.fortuna.ical4j.model.property.Version;
66 import net.fortuna.ical4j.model.property.XProperty;
67
68 import org.netbeans.modules.tasklist.core.export.ExportImportFormat;
69 import org.netbeans.modules.tasklist.core.export.ExportImportProvider;
70 import org.netbeans.modules.tasklist.core.export.SaveFilePanel;
71 import org.netbeans.modules.tasklist.core.util.ExtensionFileFilter;
72 import org.netbeans.modules.tasklist.core.util.ObjectList;
73 import org.netbeans.modules.tasklist.core.util.SimpleWizardPanel;
74 import org.netbeans.modules.tasklist.usertasks.options.Settings;
75 import org.netbeans.modules.tasklist.usertasks.UserTaskViewRegistry;
76 import org.netbeans.modules.tasklist.usertasks.model.UserTask;
77 import org.netbeans.modules.tasklist.usertasks.model.UserTaskList;
78 import org.netbeans.modules.tasklist.usertasks.model.Dependency;
79 import org.netbeans.modules.tasklist.usertasks.util.UTUtils;
80 import org.openide.WizardDescriptor;
81 import org.openide.util.NbBundle;
82
83 /**
84  * This class provides import/export capabilities for the iCalendar calendar
85  * format (used by for example KDE's Konqueror calendar/todoitem tool)
86  * as specified in RFC 2445 with the following exceptions:
87  *
88  * @todo Store the alarm-part of the associated time as an VALARM field (but
89  * I guess I must hardcode some of the fields (the alarm action etc);)
90  *
91  * @todo Trond: I have left traces after a class named AssociatedTime in this
92  * file. I might need some of it again when we decide we want to
93  * event support.
94  *
95  * @author Tor Norbye
96  * @author Trond Norbye
97  * @author tl
98  */

99 public class ICalExportFormat implements ExportImportFormat {
100     private final static String JavaDoc PRODID =
101         "-//NetBeans User Tasks//NONSGML 1.0//EN"; // NOI18N
102
protected final static String JavaDoc
103         CHOOSE_FILE_PANEL_PROP = "ChooseFilePanel"; // NOI18N
104

105     // Format which includes the timezone at the end. This is the format
106
// used by the tasklist's own written files for example.
107
private static final String JavaDoc DATEFORMATZ = "yyyyMMdd'T'HHmmss'Z'"; // NOI18N
108
private static final SimpleDateFormat JavaDoc DATEFORMAT =
109         new SimpleDateFormat JavaDoc(DATEFORMATZ);
110     
111     /**
112      * Converts a stream to default system line endings.
113      *
114      * @param r \r\n terminated strings
115      * @param w default system line endings
116      */

117     private static void convertToSystem(Reader JavaDoc r, Writer JavaDoc w) throws
118     IOException JavaDoc {
119         BufferedReader JavaDoc br = new BufferedReader JavaDoc(r);
120         final String JavaDoc EOL = System.getProperty("line.separator"); // NOI18N
121
String JavaDoc line;
122         while ((line = br.readLine()) != null) {
123             w.write(line);
124             w.write(EOL);
125         }
126     }
127     
128     /**
129      * Constructor
130      */

131     public ICalExportFormat() {
132     }
133     
134     public void doExportImport(ExportImportProvider provider, WizardDescriptor wd) {
135         SaveFilePanel panel =
136             (SaveFilePanel) wd.getProperty(CHOOSE_FILE_PANEL_PROP);
137         try {
138             UserTaskList list = UserTaskViewRegistry.getInstance().
139                     getCurrent().getUserTaskList();
140             Writer JavaDoc w = new OutputStreamWriter JavaDoc(
141                     new BufferedOutputStream JavaDoc(
142                     new FileOutputStream JavaDoc(panel.getFile())), "UTF-8");
143             try {
144                 writeList(list, w, true);
145                 Settings.getDefault().setLastUsedExportFolder(
146                         panel.getFile().getParentFile());
147             } finally {
148                 try {
149                     w.close();
150                 } catch (IOException JavaDoc e) {
151                     UTUtils.LOGGER.log(Level.WARNING,
152                             "Error closing file", e); // NOI18N
153
}
154             }
155         } catch (ParseException JavaDoc e) {
156             UTUtils.LOGGER.log(Level.SEVERE, "", e); // NOI18N
157
} catch (URISyntaxException JavaDoc e) {
158             UTUtils.LOGGER.log(Level.SEVERE, "", e); // NOI18N
159
} catch (ValidationException e) {
160             UTUtils.LOGGER.log(Level.SEVERE, "", e); // NOI18N
161
} catch (IOException JavaDoc e) {
162             UTUtils.LOGGER.log(Level.SEVERE, "", e); // NOI18N
163
}
164     }
165     
166     public String JavaDoc getName() {
167         return NbBundle.getMessage(ICalExportFormat.class, "iCalExp"); // NOI18N
168
}
169     
170     // Extends AbstractTranslator
171

172     public org.openide.WizardDescriptor getWizard() {
173         SaveFilePanel chooseFilePanel = new SaveFilePanel();
174         SimpleWizardPanel chooseFileWP = new SimpleWizardPanel(chooseFilePanel);
175         chooseFilePanel.setWizardPanel(chooseFileWP);
176         chooseFilePanel.getFileChooser().addChoosableFileFilter(
177             new ExtensionFileFilter(
178                 NbBundle.getMessage(XmlExportFormat.class,
179                     "IcsFilter"), // NOI18N
180
new String JavaDoc[] {".ics"})); // NOI18N
181
chooseFilePanel.setFile(new File JavaDoc(
182                 Settings.getDefault().getLastUsedExportFolder(),
183                 "tasklist.ics")); // NOI18N
184

185         // create the wizard
186
WizardDescriptor.Iterator iterator =
187             new WizardDescriptor.ArrayIterator(new WizardDescriptor.Panel[] {
188                 chooseFileWP
189         });
190         WizardDescriptor d = new WizardDescriptor(iterator);
191         d.putProperty("WizardPanel_contentData", // NOI18N
192
new String JavaDoc[] {
193                 NbBundle.getMessage(
194                     XmlExportFormat.class, "ChooseDestination"), // NOI18N
195
}
196         ); // NOI18N
197
String JavaDoc title;
198         title = NbBundle.getMessage(ICalExportFormat.class, "ExportICAL"); // NOI18N
199
d.setTitle(title); // NOI18N
200
d.putProperty(CHOOSE_FILE_PANEL_PROP, chooseFilePanel);
201         d.putProperty("WizardPanel_autoWizardStyle", Boolean.TRUE); // NOI18N
202
d.putProperty("WizardPanel_contentDisplayed", Boolean.TRUE); // NOI18N
203
d.putProperty("WizardPanel_contentNumbered", Boolean.TRUE); // NOI18N
204
d.setTitleFormat(new java.text.MessageFormat JavaDoc("{0}")); // NOI18N todo
205
return d;
206     }
207
208     /**
209      * Do the actual export of the list into the stream
210      *
211      * @param list The tasklist to store
212      * @param out The output stream object to use
213      * @param std true = use RFC 2445 line endings, false = system default
214      * line ending
215      */

216     public void writeList(UserTaskList list, Writer JavaDoc out, boolean std)
217     throws IOException JavaDoc, ValidationException, URISyntaxException JavaDoc, ParseException JavaDoc {
218         Calendar cal = (Calendar) list.userObject;
219         if (cal == null)
220             cal = new Calendar();
221         
222         Property prop = cal.getProperties().getProperty(Property.PRODID);
223         if (prop == null) {
224             prop = new ProdId(PRODID);
225             cal.getProperties().add(prop);
226         } else {
227             prop.setValue(PRODID);
228         }
229
230         prop = cal.getProperties().getProperty(Property.VERSION);
231         if (prop != null)
232             cal.getProperties().remove(prop);
233         cal.getProperties().add(Version.VERSION_2_0);
234         
235         Iterator JavaDoc it = list.getSubtasks().iterator();
236         int[] p = new int[1];
237         while (it.hasNext()) {
238             UserTask item = (UserTask) it.next();
239             writeTask(cal, item, p);
240         }
241         
242         final List JavaDoc<String JavaDoc> uids = new ArrayList JavaDoc<String JavaDoc>();
243         UserTaskList.processDepthFirst(
244             new UserTaskList.UserTaskProcessor() {
245                 public void process(UserTask ut) {
246                     uids.add(ut.getUID());
247                 }
248             }, list.getSubtasks()
249         );
250         removeUnusedVToDos(cal, uids);
251
252         // an .ics file cannot be empty
253
if (cal.getComponents().size() == 0) {
254             VToDo td = new VToDo();
255             td.getProperties().add(new Summary(
256                     NbBundle.getMessage(ICalExportFormat.class,
257                     "Welcome"))); // NOI18N
258

259             cal.getComponents().add(td);
260         }
261
262         CalendarOutputter co = new CalendarOutputter();
263         if (std) {
264             co.output(cal, out);
265         } else {
266             StringWriter JavaDoc sw = new StringWriter JavaDoc();
267             co.output(cal, sw);
268             StringReader JavaDoc sr = new StringReader JavaDoc(sw.getBuffer().toString());
269             convertToSystem(sr, out);
270         }
271     }
272     
273     /**
274      * Removes all VTODOs from the calendar if their IDs are not in the list.
275      *
276      * @param cal a calendar
277      * @param uids &lt;String&gt; list of used uids.
278      */

279     private static void removeUnusedVToDos(Calendar cal, List JavaDoc uids) {
280         ComponentList cl = cal.getComponents();
281         Iterator JavaDoc it = cl.iterator();
282         while (it.hasNext()) {
283             Component c = (Component) it.next();
284             if (c.getName().equals(Component.VTODO)) {
285                 Uid p = (Uid) c.getProperties().getProperty(Property.UID);
286                 if (p == null || uids.indexOf(p.getValue()) < 0)
287                     it.remove();
288             }
289         }
290     }
291     
292     /**
293      * Searches for a VTODO with the given uid.
294      *
295      * @param cal a calendar object
296      * @param uid searching for this uid.
297      * @return found component or null
298      */

299     private static VToDo find(Calendar cal, String JavaDoc uid) {
300         ComponentList cl = cal.getComponents().getComponents(Component.VTODO);
301         for (int i = 0; i < cl.size(); i++) {
302             VToDo c = (VToDo) cl.get(i);
303             Uid p = (Uid) c.getProperties().getProperty(Property.UID);
304             if (p != null && p.getValue().equals(uid))
305                 return c;
306         }
307         return null;
308     }
309     
310     /**
311      * Write out the given todo item to the given writer.
312      *
313      * @param cal calendar object
314      * @param task The task/todo item to use
315      * @param position position of the VTODO-element in cal.getComponents()
316      * Length of the array should be 1 (in/out argument).
317      */

318     @SuppressWarnings JavaDoc("unchecked")
319     private void writeTask(Calendar cal, UserTask task, int[] position)
320     throws IOException JavaDoc, URISyntaxException JavaDoc, ParseException JavaDoc, ValidationException {
321         VToDo vtodo = find(cal, task.getUID());
322         if (vtodo == null) {
323             vtodo = new VToDo();
324             vtodo.getProperties().add(new Uid(task.getUID()));
325             cal.getComponents().add(position[0], vtodo);
326         } else {
327             cal.getComponents().remove(vtodo);
328             cal.getComponents().add(position[0], vtodo);
329         }
330         position[0]++;
331
332         PropertyList pl = vtodo.getProperties();
333         Property prop = pl.getProperty(Property.CREATED);
334         if (prop == null) {
335             prop = new Created();
336             pl.add(prop);
337         }
338         long created = task.getCreatedDate();
339         DateTime dt = new DateTime(created);
340         dt.setUtc(true);
341         ((Created) prop).setDate(dt);
342         prop.validate();
343             
344         // DTSTAMP
345
prop = pl.getProperty(Property.DTSTAMP);
346         if (prop == null) {
347             prop = new DtStamp();
348             pl.add(prop);
349         }
350         ((DtStamp) prop).setDate(dt);
351         
352         prop = pl.getProperty(Property.DTSTART);
353         if (task.getStart() != -1) {
354             if (prop == null) {
355                 prop = new DtStart();
356                 pl.add(prop);
357             }
358             dt = new DateTime(task.getStart());
359             dt.setUtc(true);
360             ((DtStart) prop).setDate(dt);
361             prop.validate();
362         } else {
363             if (prop != null)
364                 pl.remove(prop);
365         }
366
367         // summary: (Description)
368
String JavaDoc desc = task.getSummary();
369         prop = pl.getProperty(Property.SUMMARY);
370         if (desc != null && desc.length() > 0) {
371             if (prop == null) {
372                 prop = new Summary();
373                 pl.add(prop);
374             }
375             prop.setValue(desc);
376         } else {
377             if (prop != null)
378                 pl.remove(prop);
379         }
380
381         // description (details)
382
String JavaDoc details = task.getDetails();
383         prop = pl.getProperty(Property.DESCRIPTION);
384         if (details != null && details.length() > 0) {
385             if (prop == null) {
386                 prop = new Description();
387                 pl.add(prop);
388             }
389             prop.setValue(details);
390         } else {
391             if (prop != null)
392                 pl.remove(prop);
393         }
394
395         // Priority
396
prop = pl.getProperty(Property.PRIORITY);
397         if (prop != null)
398             pl.remove(prop);
399         if (task.getPriority() != UserTask.MEDIUM) {
400             prop = new Priority(task.getPriority());
401             pl.add(prop);
402         }
403
404         // Class -- not implemented (always PRIVATE, right?) Also allowed:
405
// PRIVATE, CONFIDENTIAL
406
/* Don't bother with this yet... waste of diskspace
407            and parsing time -- only needed when we either export
408            to XCS, or directly interoperate. There's too much
409            missing yet to add partial support
410         // For now, hardcode to private such that others don't get access
411         writer.write("CLASS:PRIVATE\r\n"); // NOI18N
412          */

413
414         // attendee -- not implemented
415

416         // Others not implemented:
417
// geo, location, organizer, percent, recurid, seq, status,
418
// due, duration (both cannot occur)
419

420         // Optional ones not implemented:
421
// attach, attendee, categories, comment, contact, exdate, exrule,
422
// rstatus, related, resources, rdate, rrule, x-prop (actually,
423
// xprop is special, we will have those)
424

425
426         prop = pl.getProperty(Property.PERCENT_COMPLETE);
427         if (prop == null) {
428             prop = new PercentComplete();
429             pl.add(prop);
430         }
431         ((PercentComplete) prop).setPercentage(task.getPercentComplete());
432
433         setXProperty(pl, "X-NETBEANS-VALUES-COMPUTED", "yes", // NOI18N
434
task.isValuesComputed());
435         
436         
437         // these 3 will be set for backwards compatibility only
438
setXProperty(pl, "X-NETBEANS-PROGRESS-COMPUTED", "yes", // NOI18N
439
task.isValuesComputed());
440         setXProperty(pl, "X-NETBEANS-EFFORT-COMPUTED", "yes", // NOI18N
441
task.isValuesComputed());
442         setXProperty(pl, "X-NETBEANS-SPENT-TIME-COMPUTED", "yes", // NOI18N
443
task.isValuesComputed());
444         
445         setXProperty(pl, "X-NETBEANS-EFFORT", // NOI18N
446
Integer.toString(task.getEffort()), true);
447
448         setXProperty(pl, "X-NETBEANS-SPENT-TIME", // NOI18N
449
Integer.toString(task.getSpentTime()), true);
450
451         // Category (XXX standard allows MULTIPLE categories, I must handle
452
// that when I parse back)
453
String JavaDoc category = task.getCategory();
454         prop = pl.getProperty(Property.CATEGORIES);
455         if (category != null && category.length() > 0) {
456             // TODO Write out multiple CATEGORIES lines instead
457
// of a combined comma separated list which is what we're
458
// doing here
459
if (prop == null) {
460                 prop = new Categories();
461                 pl.add(prop);
462             }
463             ((Categories) prop).setValue(category); // NOI18N
464
} else {
465             if (prop != null)
466                 pl.remove(prop);
467         }
468
469         // Last modified
470
// Last Edited Date, if different than created
471
long edited = task.getLastEditedDate();
472         prop = pl.getProperty(Property.LAST_MODIFIED);
473         if (edited != created) {
474             // They differ
475
if (prop == null) {
476                 prop = new LastModified();
477                 pl.add(prop);
478             }
479             dt = new DateTime(edited);
480             dt.setUtc(true);
481             ((LastModified) prop).setDate(dt);
482             prop.validate();
483         } else {
484             if (prop != null)
485                 pl.remove(pl);
486         }
487
488         // completion date
489
long completed = task.getCompletedDate();
490         prop = pl.getProperty(Property.COMPLETED);
491         if (completed != 0) {
492             if (prop == null) {
493                 prop = new Completed();
494                 pl.add(prop);
495             }
496             dt = new DateTime(task.getCompletedDate());
497             dt.setUtc(true);
498             ((Completed) prop).setDate(dt);
499             prop.validate();
500         } else {
501             if (prop != null)
502                 pl.remove(prop);
503         }
504
505         // URL
506
URL JavaDoc url = task.getUrl();
507         prop = pl.getProperty(Property.URL);
508         if (url != null) {
509             if (prop == null) {
510                 prop = new Url();
511                 pl.add(prop);
512             }
513             prop.setValue(url.toExternalForm());
514         } else {
515             if (prop != null)
516                 pl.remove(pl);
517         }
518         
519         // Line number
520
int lineno = task.getLineNumber();
521         setXProperty(pl, "X-NETBEANS-LINE", // NOI18N
522
Integer.toString(lineno + 1), lineno >= 0);
523         
524         setXProperty(pl, "X-NETBEANS-OWNER", task.getOwner(), // NOI18N
525
task.getOwner().length() != 0);
526
527         // Parent item
528
// attribute reltype for related-to defaults to "PARENT" so we
529
// don't need to specify it
530
prop = pl.getProperty(Property.RELATED_TO);
531         if (task.getParent() != null) {
532             if (prop == null) {
533                 prop = new RelatedTo();
534                 pl.add(prop);
535             }
536             String JavaDoc parentuid = ((UserTask)task.getParent()).getUID();
537             prop.setValue(parentuid);
538         } else {
539             if (prop != null)
540                 pl.remove(prop);
541         }
542         
543         List JavaDoc dep = task.getDependencies();
544         pl.removeAll(pl.getProperties("X-NETBEANS-DEPENDENCY")); // NOI18N
545
for (int i = 0; i < dep.size(); i++) {
546             Dependency d = (Dependency) dep.get(i);
547             prop = new XProperty("X-NETBEANS-DEPENDENCY"); // NOI18N
548
prop.setValue(d.getDependsOn().getUID());
549             String JavaDoc t = (d.getType() == Dependency.BEGIN_BEGIN) ?
550                 "BEGIN_BEGIN" : "END_BEGIN"; // NOI18N
551
prop.getParameters().add(new XParameter("X-NETBEANS-TYPE", t)); // NOI18N
552
pl.add(prop);
553         }
554
555         ObjectList wks = task.getWorkPeriods();
556         pl.removeAll(pl.getProperties("X-NETBEANS-WORK-PERIOD")); // NOI18N
557
for (int i = 0; i < wks.size(); i++) {
558             UserTask.WorkPeriod wk = (UserTask.WorkPeriod) wks.get(i);
559             prop = new XProperty("X-NETBEANS-WORK-PERIOD"); // NOI18N
560
String JavaDoc v = DATEFORMAT.format(new java.util.Date JavaDoc(wk.getStart()));
561             prop.getParameters().add(new XParameter(
562                     "X-NETBEANS-START", // NOI18N
563
v));
564             prop.setValue(Integer.toString(wk.getDuration()));
565             pl.add(prop);
566         }
567         
568         java.util.Date JavaDoc d = task.getDueDate();
569         if (d != null)
570             setXProperty(pl, "X-NETBEANS-DUETIME", Long.toString(d.getTime()), // NOI18N
571
true);
572         else
573             setXProperty(pl, "X-NETBEANS-DUETIME", "", // NOI18N
574
false);
575         
576         setXProperty(pl, "X-NETBEANS-DUE-SIGNALED", "yes", // NOI18N
577
task.isDueAlarmSent());
578         
579 // AssociatedTime associatedTime = task.getAssociatedTime();
580
// if (associatedTime != null) {
581
// Date d = associatedTime.getStartTime();
582
// if (d != null) {
583
// writer.write("X-NETBEANS-STARTTIME:"); // NOI18N
584
// writer.write(Long.toString(d.getTime()));
585
// writer.write("\r\n"); // NOI18N
586
// }
587
// d = associatedTime.getEndTime();
588
// if (d != null) {
589
// writer.write("X-NETBEANS-ENDTIME:"); // NOI18N
590
// writer.write(Long.toString(d.getTime()));
591
// writer.write("\r\n"); // NOI18N
592
// }
593
// d = associatedTime.getDueDate();
594
// if (d != null) {
595
// writer.write("X-NETBEANS-DUETIME:"); // NOI18N
596
// writer.write(Long.toString(d.getTime()));
597
// writer.write("\r\n"); // NOI18N
598
// }
599
//
600
// if (associatedTime.isRecurrent()) {
601
// writer.write("X-NETBEANS-DUERECURRENT-INTERVAL:"); // NOI18N
602
// writer.write(Integer.toString(associatedTime.getInterval()));
603
// writer.write("\r\nX-NETBEANS-DUERECURRENT-MEASUREMENT:"); // NOI18N
604
// switch (associatedTime.getMeasurement()) {
605
// case AssociatedTime.DAY :
606
// writer.write("DAY\r\n"); // NOI18N
607
// break;
608
// case AssociatedTime.WEEK :
609
// writer.write("WEEK\r\n"); // NOI18N
610
// break;
611
// case AssociatedTime.MONTH :
612
// writer.write("MONTH\r\n"); // NOI18N
613
// break;
614
// case AssociatedTime.YEAR :
615
// writer.write("YEAR\r\n"); // NOI18N
616
// break;
617
// default :
618
// System.err.println("EINVAL"); //NOI18N
619
// }
620
// }
621
// }
622

623         // Recurse over subtasks
624
Iterator JavaDoc it = task.getSubtasks().iterator();
625         while (it.hasNext()) {
626             UserTask subtask = (UserTask)it.next();
627             writeTask(cal, subtask, position);
628         }
629     }
630     
631     /**
632      * Changes value of an X-property.
633      *
634      * @param pl a list of properties
635      * @param name name for a X-property
636      * @param value new value for the property
637      * @param set true = the property will be created, false = the property
638      * will be deleted
639      */

640     private static void setXProperty(PropertyList pl,
641         String JavaDoc name, String JavaDoc value, boolean set) throws IOException JavaDoc,
642         URISyntaxException JavaDoc, ParseException JavaDoc {
643         Property prop = pl.getProperty(name);
644         if (set) {
645             if (prop == null) {
646                 prop = new XProperty(name);
647                 pl.add(prop);
648             }
649             prop.setValue(value);
650         } else {
651             if (prop != null)
652                 pl.remove(prop);
653         }
654     }
655 }
656
Popular Tags