-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added strategy implementations for populating iCalendar and vCard obj…
…ects
- Loading branch information
1 parent
85f54e4
commit 7f9a803
Showing
29 changed files
with
1,322 additions
and
0 deletions.
There are no files selected for viewing
61 changes: 61 additions & 0 deletions
61
src/main/java/net/fortuna/ical4j/extensions/strategy/vcard/Individual.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package net.fortuna.ical4j.extensions.strategy.vcard; | ||
|
||
import net.fortuna.ical4j.vcard.GeneralPropertyModifiers; | ||
import net.fortuna.ical4j.vcard.IdentificationPropertyModifiers; | ||
import net.fortuna.ical4j.vcard.VCard; | ||
import net.fortuna.ical4j.vcard.property.N; | ||
import net.fortuna.ical4j.vcard.property.immutable.ImmutableKind; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
/** | ||
* A strategy used to populate a {@link VCard} to represent an individual. | ||
*/ | ||
public class Individual { | ||
|
||
private String familyName; | ||
|
||
private String givenName; | ||
|
||
private final List<String> additionalNames = new ArrayList<>(); | ||
|
||
private final List<String> prefixes = new ArrayList<>(); | ||
|
||
private final List<String> suffixes = new ArrayList<>(); | ||
|
||
public Individual familyName(String familyName) { | ||
this.familyName = familyName; | ||
return this; | ||
} | ||
|
||
public Individual givenName(String givenName) { | ||
this.givenName = givenName; | ||
return this; | ||
} | ||
|
||
public Individual additionalName(String... additionalName) { | ||
this.additionalNames.addAll(Arrays.asList(additionalName)); | ||
return this; | ||
} | ||
|
||
public Individual prefix(String... prefix) { | ||
this.prefixes.addAll(Arrays.asList(prefix)); | ||
return this; | ||
} | ||
|
||
public Individual suffix(String... suffix) { | ||
this.suffixes.addAll(Arrays.asList(suffix)); | ||
return this; | ||
} | ||
|
||
public VCard apply(VCard vCard) { | ||
|
||
vCard.with(GeneralPropertyModifiers.KIND, ImmutableKind.INDIVIDUAL); | ||
vCard.with(IdentificationPropertyModifiers.N, new N(familyName, givenName, | ||
additionalNames.toArray(new String[0]), prefixes.toArray(new String[0]), | ||
suffixes.toArray(new String[0]))); | ||
return vCard; | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/main/java/net/fortuna/ical4j/extensions/strategy/vcard/Organization.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package net.fortuna.ical4j.extensions.strategy.vcard; | ||
|
||
import net.fortuna.ical4j.vcard.GeneralPropertyModifiers; | ||
import net.fortuna.ical4j.vcard.IdentificationPropertyModifiers; | ||
import net.fortuna.ical4j.vcard.VCard; | ||
import net.fortuna.ical4j.vcard.property.Fn; | ||
import net.fortuna.ical4j.vcard.property.immutable.ImmutableKind; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
public class Organization { | ||
|
||
private final List<String> names = new ArrayList<>(); | ||
|
||
public Organization name(String... name) { | ||
names.addAll(Arrays.asList(name)); | ||
return this; | ||
} | ||
|
||
public VCard apply(VCard vCard) { | ||
vCard.with(GeneralPropertyModifiers.KIND, ImmutableKind.ORG); | ||
names.forEach(name -> vCard.with(IdentificationPropertyModifiers.FN, new Fn(name))); | ||
return vCard; | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
src/main/java/net/fortuna/ical4j/extensions/strategy/vcard/Team.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package net.fortuna.ical4j.extensions.strategy.vcard; | ||
|
||
import net.fortuna.ical4j.vcard.GeneralPropertyModifiers; | ||
import net.fortuna.ical4j.vcard.IdentificationPropertyModifiers; | ||
import net.fortuna.ical4j.vcard.OrganizationalPropertyModifiers; | ||
import net.fortuna.ical4j.vcard.VCard; | ||
import net.fortuna.ical4j.vcard.property.Fn; | ||
import net.fortuna.ical4j.vcard.property.Member; | ||
import net.fortuna.ical4j.vcard.property.immutable.ImmutableKind; | ||
|
||
import java.net.URI; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
public class Team { | ||
|
||
private final List<String> names = new ArrayList<>(); | ||
|
||
private final List<URI> members = new ArrayList<>(); | ||
|
||
public Team name(String... name) { | ||
names.addAll(Arrays.asList(name)); | ||
return this; | ||
} | ||
|
||
public Team member(URI... member) { | ||
members.addAll(Arrays.asList(member)); | ||
return this; | ||
} | ||
|
||
public VCard apply(VCard vCard) { | ||
vCard.with(GeneralPropertyModifiers.KIND, ImmutableKind.GROUP); | ||
names.forEach(name -> vCard.with(IdentificationPropertyModifiers.FN, new Fn(name))); | ||
members.forEach(member -> vCard.with(OrganizationalPropertyModifiers.MEMBER, new Member(member))); | ||
return vCard; | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
src/main/java/net/fortuna/ical4j/extensions/strategy/vevent/Anniversary.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package net.fortuna.ical4j.extensions.strategy.vevent; | ||
|
||
import net.fortuna.ical4j.extensions.model.property.Repeats; | ||
import net.fortuna.ical4j.model.component.VEvent; | ||
|
||
import java.time.LocalDate; | ||
|
||
import static net.fortuna.ical4j.model.DateTimePropertyModifiers.DTSTART; | ||
import static net.fortuna.ical4j.model.RecurrencePropertyModifiers.RRULE; | ||
|
||
/** | ||
* Creates a recurring {@link VEvent} representing a birthday/anniversary, etc. | ||
*/ | ||
public class Anniversary { | ||
|
||
private Repeats<?> schedule; | ||
|
||
private LocalDate date; | ||
|
||
public Anniversary withRepeats(Repeats<?> schedule) { | ||
this.schedule = schedule; | ||
return this; | ||
} | ||
|
||
public Anniversary withDate(LocalDate date) { | ||
this.date = date; | ||
return this; | ||
} | ||
|
||
public VEvent apply(VEvent vEvent) { | ||
vEvent.with(DTSTART, date); | ||
vEvent.with(RRULE, schedule); | ||
return vEvent; | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/net/fortuna/ical4j/extensions/strategy/vevent/Appointment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package net.fortuna.ical4j.extensions.strategy.vevent; | ||
|
||
import net.fortuna.ical4j.model.component.VEvent; | ||
|
||
import java.time.ZonedDateTime; | ||
|
||
import static net.fortuna.ical4j.model.DateTimePropertyModifiers.DTSTART; | ||
|
||
public class Appointment { | ||
|
||
private ZonedDateTime start; | ||
|
||
public Appointment start(ZonedDateTime start) { | ||
this.start = start; | ||
return this; | ||
} | ||
|
||
public VEvent apply(VEvent vEvent) { | ||
vEvent.with(DTSTART, start); | ||
return vEvent; | ||
} | ||
} |
136 changes: 136 additions & 0 deletions
136
src/main/java/net/fortuna/ical4j/extensions/strategy/vevent/Meeting.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
package net.fortuna.ical4j.extensions.strategy.vevent; | ||
|
||
import net.fortuna.ical4j.extensions.model.concept.EventType; | ||
import net.fortuna.ical4j.extensions.model.property.Repeats; | ||
import net.fortuna.ical4j.model.component.*; | ||
import net.fortuna.ical4j.model.property.Uid; | ||
import net.fortuna.ical4j.vcard.VCard; | ||
|
||
import java.time.Instant; | ||
import java.time.ZonedDateTime; | ||
import java.time.temporal.TemporalAmount; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import static net.fortuna.ical4j.extensions.strategy.vevent.VEventPropertyModifiers.*; | ||
import static net.fortuna.ical4j.model.ChangeManagementPropertyModifiers.DTSTAMP; | ||
import static net.fortuna.ical4j.model.DateTimePropertyModifiers.DTSTART; | ||
import static net.fortuna.ical4j.model.DateTimePropertyModifiers.DURATION; | ||
import static net.fortuna.ical4j.model.DescriptivePropertyModifiers.SUMMARY; | ||
import static net.fortuna.ical4j.model.RecurrencePropertyModifiers.RRULE; | ||
import static net.fortuna.ical4j.model.RelationshipPropertyModifiers.UID; | ||
|
||
/** | ||
* Creates a {@link VEvent} representing a meeting of one or more attendees. | ||
*/ | ||
public class Meeting { | ||
|
||
private ZonedDateTime start; | ||
|
||
private TemporalAmount duration; | ||
|
||
private VCard organizer; | ||
|
||
private Uid uid; | ||
|
||
private String summary; | ||
|
||
private String description; | ||
|
||
private Participant chair; | ||
|
||
private final List<Participant> required = new ArrayList<>(); | ||
|
||
private final List<Participant> optional = new ArrayList<>(); | ||
|
||
private Repeats<ZonedDateTime> repeats; | ||
|
||
private VLocation location; | ||
|
||
private List<VAlarm> notifications = new ArrayList<>(); | ||
|
||
private VToDo agenda; | ||
|
||
private VResource conference; | ||
|
||
private VResource recording; | ||
|
||
private VResource transcript; | ||
|
||
public Meeting organizer(VCard card) { | ||
this.organizer = card; | ||
return this; | ||
} | ||
|
||
public Meeting start(ZonedDateTime start) { | ||
this.start = start; | ||
return this; | ||
} | ||
|
||
public Meeting duration(TemporalAmount duration) { | ||
this.duration = duration; | ||
return this; | ||
} | ||
|
||
public Meeting required(Participant participant) { | ||
required.add(participant); | ||
return this; | ||
} | ||
|
||
public Meeting optional(Participant participant) { | ||
optional.add(participant); | ||
return this; | ||
} | ||
|
||
public Meeting chair(Participant participant) { | ||
this.chair = participant; | ||
return this; | ||
} | ||
|
||
public Meeting repeats(Repeats<ZonedDateTime> repeats) { | ||
this.repeats = repeats; | ||
return this; | ||
} | ||
|
||
public Meeting location(VLocation location) { | ||
this.location = location; | ||
return this; | ||
} | ||
|
||
public Meeting notification(VAlarm notification) { | ||
this.notifications.add(notification); | ||
return this; | ||
} | ||
|
||
public Meeting agenda(VToDo agenda) { | ||
this.agenda = agenda; | ||
return this; | ||
} | ||
|
||
public VEvent apply(VEvent vEvent) { | ||
vEvent.with(DTSTAMP, Instant.now()); | ||
// apply mandatory properties.. | ||
vEvent.replace(EventType.MEETING); | ||
|
||
vEvent.with(UID, uid); | ||
vEvent.with(RRULE, repeats); | ||
vEvent.with(SUMMARY, summary); | ||
vEvent.with(DTSTART, start); | ||
vEvent.with(DURATION, duration); | ||
vEvent.with(ORGANIZER, organizer); | ||
vEvent.with(CHAIR, chair); | ||
required.forEach(p -> vEvent.with(REQUIRED_ATTENDEE, p)); | ||
optional.forEach(p -> vEvent.with(OPTIONAL_ATTENDEE, p)); | ||
|
||
// if (location != null) { | ||
// vEvent.add(location); | ||
// } | ||
// resources.forEach(vEvent::add); | ||
// if (agenda != null) { | ||
// vEvent.add(new Link(agenda)); | ||
// } | ||
notifications.forEach(vEvent::add); | ||
//todo: for each existing attendee add corresponding participant component.. | ||
return vEvent; | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
src/main/java/net/fortuna/ical4j/extensions/strategy/vevent/Observance.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package net.fortuna.ical4j.extensions.strategy.vevent; | ||
|
||
import net.fortuna.ical4j.extensions.model.property.Repeats; | ||
import net.fortuna.ical4j.model.DateList; | ||
import net.fortuna.ical4j.model.DateTimePropertyModifiers; | ||
import net.fortuna.ical4j.model.DescriptivePropertyModifiers; | ||
import net.fortuna.ical4j.model.RecurrencePropertyModifiers; | ||
import net.fortuna.ical4j.model.component.VEvent; | ||
import net.fortuna.ical4j.model.property.immutable.ImmutableTransp; | ||
|
||
import java.time.LocalDate; | ||
import java.time.temporal.Temporal; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* Creates an (optionally recurring) date-based {@link VEvent} representing a public holiday or | ||
* other observance. | ||
* <p> | ||
* Includes observances from <a href="https://www.un.org/en/observances/list-days-weeks"> UN International Days</a>. | ||
*/ | ||
public class Observance { | ||
|
||
private String title; | ||
|
||
private Temporal start; | ||
|
||
private Temporal end; | ||
|
||
private List<LocalDate> dates = new ArrayList<>(); | ||
|
||
private Repeats<LocalDate> schedule; | ||
|
||
public Observance title(String title) { | ||
this.title = title; | ||
return this; | ||
} | ||
|
||
public Observance start(Temporal date) { | ||
this.start = date; | ||
return this; | ||
} | ||
|
||
public Observance end(Temporal date) { | ||
this.end = date; | ||
return this; | ||
} | ||
|
||
public Observance date(LocalDate date) { | ||
dates.add(date); | ||
return this; | ||
} | ||
|
||
public Observance repeats(Repeats<LocalDate> schedule) { | ||
this.schedule = schedule; | ||
return this; | ||
} | ||
|
||
public VEvent apply(VEvent vEvent) { | ||
vEvent.replace(ImmutableTransp.TRANSPARENT); | ||
vEvent.with(DescriptivePropertyModifiers.SUMMARY, title); | ||
vEvent.with(DateTimePropertyModifiers.DTSTART, start); | ||
vEvent.with(DateTimePropertyModifiers.DTEND, end); | ||
vEvent.with(RecurrencePropertyModifiers.RRULE, schedule); | ||
vEvent.with(RecurrencePropertyModifiers.RDATE, new DateList<>(dates)); | ||
return vEvent; | ||
} | ||
} |
Oops, something went wrong.