public class ICalendar extends ICalComponent
Represents an iCalendar object.
Examples:
ICalendar ical = new ICalendar(); VEvent event = new VEvent(); event.setSummary("Team Meeting"); Date start = ...; event.setDateStart(start); Date end = ...; event.setDateEnd(end); ical.addEvent(event);
Getting timezone information from parsed iCalendar objects:
//The timezone information associated with an ICalendar object is stored in its TimezoneInfo object. ICalReader reader = ... ICalendar ical = reader.readNext(); TimezoneInfo tzinfo = ical.getTimezoneInfo(); //You can use this object to get the VTIMEZONE components that were parsed from the input stream. //Note that the VTIMEZONE components will NOT be in the ICalendar object itself Collection<VTimezone> vtimezones = tzinfo.getComponents(); //You can also get the timezone that a specific property was originally formatted in. DateStart dtstart = ical.getEvents().get(0).getDateStart(); TimeZone tz = tzinfo.getTimezone(dtstart).getTimeZone(); //This is useful for calculating recurrence rule dates. RecurrenceRule rrule = ical.getEvents(0).getRecurrenceRule(); DateIterator it = rrule.getDateIterator(dtstart.getValue(), tz);
Setting timezone information when writing iCalendar objects:
//The TimezoneInfo field is used to determine what timezone to format each date-time value in when the ICalendar object is written. //Appropriate VTIMEZONE components are automatically added to the written iCalendar object. ICalendar ical = ... TimezoneInfo tzinfo = ical.getTimezoneInfo(); //biweekly uses the TimezoneAssignment class to define timezones. //This class groups together a Java TimeZone object, which is used to format/parse the date-time values, and its equivalent VTIMEZONE component definition. //biweekly can auto-generate the VTIMEZONE definitions by downloading them from tzurl.org. //If you want the generated VTIMEZONE components to be tailored for Microsoft Outlook email clients, pass "true" into this method. TimezoneAssignment timezone = TimezoneAssignment.download(TimeZone.getTimeZone("America/New_York"), true); //Using the TimezoneAssignment class, you can specify what timezone you'd like to format all date-time values in. tzinfo.setDefaultTimezone(timezone); //You can also specify what timezone to use for individual properties if you want. DateStart dtstart = ical.getEvents(0).getDateStart(); TimezoneAssignment losAngeles = TimezoneAssignment.download(TimeZone.getTimeZone("America/Los_Angeles"), true); tzinfo.setTimezone(dtstart, losAngeles); //The writer object will use this information to determine what timezone to format each date-time value in. //Date-time values are formatted in UTC by default. ICalWriter writer = ... writer.write(ical);
For more information on working with timezones, see this page: https://github. com/mangstadt/biweekly/wiki/Timezones
components, properties
Constructor and Description |
---|
ICalendar()
Creates a new iCalendar object.
|
ICalendar(ICalendar original)
Copy constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
addCategories(Categories categories)
Adds a list of keywords that describe the calendar.
|
Categories |
addCategories(String... categories)
Adds a list of keywords that describe the calendar.
|
void |
addDescription(Description description)
Assigns a human-readable description to the calendar as a whole.
|
Description |
addDescription(String description)
Assigns a human-readable description to the calendar as a whole.
|
void |
addEvent(VEvent event)
Adds an event to the calendar.
|
void |
addFreeBusy(VFreeBusy freeBusy)
Adds a free/busy entry to the calendar.
|
void |
addImage(Image image)
Adds an image that is associated with the calendar.
|
void |
addJournal(VJournal journal)
Adds a journal entry to the calendar.
|
void |
addName(Name name)
Assigns a human-readable name to the calendar as a whole.
|
Name |
addName(String name)
Assigns a human-readable name to the calendar as a whole.
|
void |
addTodo(VTodo todo)
Adds a to-do task to the calendar.
|
boolean |
equals(Object obj) |
CalendarScale |
getCalendarScale()
Gets the calendar system that this iCalendar object uses.
|
List<Categories> |
getCategories()
Gets the keywords that describe the calendar.
|
Color |
getColor()
Gets the color that clients may use when displaying the calendar (for
example, a background color).
|
List<Description> |
getDescriptions()
Gets the human-readable description of the calendar as a whole.
|
List<VEvent> |
getEvents()
Gets the calendar's events.
|
List<VFreeBusy> |
getFreeBusies()
Gets the calendar's free/busy entries.
|
List<Image> |
getImages()
Gets the images that are associated with the calendar.
|
List<VJournal> |
getJournals()
Gets the calendar's journal entries.
|
LastModified |
getLastModified()
Gets the date and time that the information in this calendar object was
last revised.
|
Method |
getMethod()
Gets the type of iTIP
request that this iCalendar object represents, or the value of the
"Content-Type" header's "method" parameter if the iCalendar object is
defined as a MIME message entity.
|
List<Name> |
getNames()
Gets the human-readable name of the calendar as a whole.
|
ProductId |
getProductId()
Gets the name of the application that created the iCalendar object.
|
RefreshInterval |
getRefreshInterval()
Gets the suggested minimum polling interval for checking for updates to
the calendar data.
|
Source |
getSource()
Gets the location that the calendar data can be refreshed from.
|
TimezoneInfo |
getTimezoneInfo()
Gets the timezone information associated with this iCalendar object.
|
List<VTodo> |
getTodos()
Gets the calendar's to-do tasks.
|
Uid |
getUid()
Gets the calendar's unique identifier.
|
Url |
getUrl()
Gets the location of a more dynamic, alternate representation of the
calendar (such as a website that allows you to interact with the calendar
data).
|
ICalVersion |
getVersion()
Gets the version of this iCalendar object.
|
int |
hashCode() |
void |
setCalendarScale(CalendarScale calendarScale)
Sets the calendar system that this iCalendar object uses.
|
void |
setColor(Color color)
Sets the color that clients may use when displaying the calendar (for
example, a background color).
|
Color |
setColor(String color)
Sets the color that clients may use when displaying the calendar (for
example, a background color).
|
void |
setDescription(Description description)
Sets the human-readable description of the calendar as a whole.
|
Description |
setDescription(String description)
Sets the human-readable description of the calendar as a whole.
|
LastModified |
setLastModified(Date lastModified)
Sets the date and time that the information in this calendar object was
last revised.
|
void |
setLastModified(LastModified lastModified)
Sets the date and time that the information in this calendar object was
last revised.
|
void |
setMethod(Method method)
Sets the type of iTIP
request that this iCalendar object represents, or the value of the
"Content-Type" header's "method" parameter if the iCalendar object is
defined as a MIME message entity.
|
Method |
setMethod(String method)
Sets the type of iTIP
request that this iCalendar object represents, or the value of the
"Content-Type" header's "method" parameter if the iCalendar object is
defined as a MIME message entity.
|
void |
setName(Name name)
Sets the human-readable name of the calendar as a whole.
|
Name |
setName(String name)
Sets the human-readable name of the calendar as a whole.
|
void |
setProductId(ProductId prodId)
Sets the name of the application that created the iCalendar object.
|
ProductId |
setProductId(String prodId)
Sets the application that created the iCalendar object.
|
RefreshInterval |
setRefreshInterval(Duration refreshInterval)
Sets the suggested minimum polling interval for checking for updates to
the calendar data.
|
void |
setRefreshInterval(RefreshInterval refreshInterval)
Sets the suggested minimum polling interval for checking for updates to
the calendar data.
|
void |
setSource(Source source)
Sets the location that the calendar data can be refreshed from.
|
Source |
setSource(String url)
Sets the location that the calendar data can be refreshed from.
|
void |
setTimezoneInfo(TimezoneInfo tzinfo)
Sets the timezone information associated with this iCalendar object.
|
Uid |
setUid(String uid)
Sets the calendar's unique identifier.
|
void |
setUid(Uid uid)
Sets the calendar's unique identifier.
|
Url |
setUrl(String url)
Sets the location of a more dynamic, alternate representation of the
calendar (such as a website that allows you to interact with the calendar
data).
|
void |
setUrl(Url url)
Sets the location of a more dynamic, alternate representation of the
calendar (such as a website that allows you to interact with the calendar
data).
|
void |
setVersion(ICalVersion version)
Sets the version of this iCalendar object.
|
protected Map<String,Object> |
toStringValues()
Gets string representations of any additional fields the component has
(other than sub-components and properties) for the
ICalComponent.toString()
method. |
ValidationWarnings |
validate(ICalVersion version)
Checks this iCalendar object for data consistency problems or deviations
from the specifications.
|
protected void |
validate(List<ICalComponent> components,
ICalVersion version,
List<ValidationWarning> warnings)
Checks the component for data consistency problems or deviations from the
spec.
|
String |
write()
Marshals this iCalendar object to its traditional, plain-text
representation.
|
void |
write(File file)
Marshals this iCalendar object to its traditional, plain-text
representation.
|
void |
write(OutputStream out)
Marshals this iCalendar object to its traditional, plain-text
representation.
|
void |
write(Writer writer)
Marshals this iCalendar object to its traditional, plain-text
representation.
|
String |
writeJson()
Marshals this iCalendar object to its JSON representation (jCal).
|
void |
writeJson(File file)
Marshals this iCalendar object to its JSON representation (jCal).
|
void |
writeJson(OutputStream out)
Marshals this iCalendar object to its JSON representation (jCal).
|
void |
writeJson(Writer writer)
Marshals this iCalendar object to its JSON representation (jCal).
|
String |
writeXml()
Marshals this iCalendar object to its XML representation (xCal).
|
void |
writeXml(File file)
Marshals this iCalendar object to its XML representation (xCal).
|
void |
writeXml(OutputStream out)
Marshals this iCalendar object to its XML representation (xCal).
|
void |
writeXml(Writer writer)
Marshals this iCalendar object to its XML representation (xCal).
|
addComponent, addExperimentalComponent, addExperimentalProperty, addExperimentalProperty, addProperty, checkOptionalCardinality, checkRequiredCardinality, checkStatus, copy, getComponent, getComponents, getComponents, getExperimentalComponent, getExperimentalComponents, getExperimentalComponents, getExperimentalProperties, getExperimentalProperties, getExperimentalProperty, getProperties, getProperties, getProperty, removeComponent, removeComponents, removeExperimentalComponents, removeExperimentalProperties, removeProperties, removeProperty, setComponent, setComponent, setExperimentalComponent, setExperimentalProperty, setExperimentalProperty, setProperty, setProperty, toString, validate
public ICalendar()
Creates a new iCalendar object.
The following properties are added to the component when it is created:
ProductId
: Set to a value that represents this library.public ICalVersion getVersion()
public void setVersion(ICalVersion version)
version
- the versionpublic TimezoneInfo getTimezoneInfo()
Gets the timezone information associated with this iCalendar object.
When an iCalendar object is parsed from an input stream, the
TimezoneInfo
object remembers the original timezone definitions
that each property was associated with. One use for this is when you want
to calculate the dates in a recurrence rule. The recurrence rule needs to
know what timezone its associated date values were originally formatted
in in order to work correctly.
When an ICalendar
object is written to an output stream, its
TimezoneInfo
object tells the writer what timezone to format each
property in.
public void setTimezoneInfo(TimezoneInfo tzinfo)
Sets the timezone information associated with this iCalendar object.
When an iCalendar object is parsed from an input stream, the
TimezoneInfo
object remembers the original timezone definitions
that each property was associated with. One use for this is when you want
to calculate the dates in a recurrence rule. The recurrence rule needs to
know what timezone its associated date values were originally formatted
in in order to work correctly.
When an ICalendar
object is written to an output stream, its
TimezoneInfo
object tells the writer what timezone to format each
property in.
tzinfo
- the timezone info (cannot be null)NullPointerException
- if the timezone info object is nullpublic ProductId getProductId()
ICalendar
objects are initialized with a product ID representing
this library.public void setProductId(ProductId prodId)
ICalendar
objects are initialized with a product ID representing
this library.prodId
- the property instance or null to removepublic ProductId setProductId(String prodId)
ICalendar
objects are initialized with a product ID representing
this library.prodId
- a unique string representing the application (e.g.
"-//Company//Application//EN") or null to removepublic CalendarScale getCalendarScale()
public void setCalendarScale(CalendarScale calendarScale)
calendarScale
- the calendar system or null to removepublic Method getMethod()
public void setMethod(Method method)
method
- the property or null to removepublic Method setMethod(String method)
method
- the method or null to removepublic List<Name> getNames()
Gets the human-readable name of the calendar as a whole.
An iCalendar object can only have one name, but multiple Name
properties can exist in order to specify the name in multiple languages.
In this case, each property instance must be assigned a LANGUAGE
parameter.
public void setName(Name name)
name
- the name or null to removepublic Name setName(String name)
name
- the name or null to removepublic void addName(Name name)
Assigns a human-readable name to the calendar as a whole.
An iCalendar object can only have one name, but multiple Name
properties can exist in order to specify the name in multiple languages.
In this case, each property instance must be assigned a LANGUAGE
parameter.
name
- the namepublic Name addName(String name)
Assigns a human-readable name to the calendar as a whole.
An iCalendar object can only have one name, but multiple Name
properties can exist in order to specify the name in multiple languages.
In this case, each property instance must be assigned a LANGUAGE
parameter.
name
- the name (e.g. "Company Vacation Days")public List<Description> getDescriptions()
Gets the human-readable description of the calendar as a whole.
An iCalendar object can only have one description, but multiple
Description
properties can exist in order to specify the
description in multiple languages. In this case, each property instance
must be assigned a LANGUAGE parameter.
public void setDescription(Description description)
description
- the description or null to removepublic Description setDescription(String description)
description
- the description or null to removepublic void addDescription(Description description)
Assigns a human-readable description to the calendar as a whole.
An iCalendar object can only have one description, but multiple
Description
properties can exist in order to specify the
description in multiple languages. In this case, each property instance
must be assigned a LANGUAGE parameter.
description
- the descriptionpublic Description addDescription(String description)
Assigns a human-readable description to the calendar as a whole.
An iCalendar object can only have one description, but multiple
Description
properties can exist in order to specify the
description in multiple languages. In this case, each property instance
must be assigned a LANGUAGE parameter.
description
- the descriptionpublic Uid getUid()
public void setUid(Uid uid)
uid
- the unique identifier or null to removepublic Uid setUid(String uid)
uid
- the unique identifier or null to removepublic LastModified getLastModified()
public void setLastModified(LastModified lastModified)
lastModified
- the last modified time or null to removepublic LastModified setLastModified(Date lastModified)
lastModified
- the date and time or null to removepublic Url getUrl()
public void setUrl(Url url)
url
- the URL or null to removepublic Url setUrl(String url)
url
- the URL or null to removepublic List<Categories> getCategories()
public void addCategories(Categories categories)
categories
- the categories to addpublic Categories addCategories(String... categories)
categories
- the categories to addpublic RefreshInterval getRefreshInterval()
public void setRefreshInterval(RefreshInterval refreshInterval)
refreshInterval
- the refresh interval or null to removepublic RefreshInterval setRefreshInterval(Duration refreshInterval)
refreshInterval
- the refresh interval or null to removepublic Source getSource()
public void setSource(Source source)
source
- the source or null to removepublic Source setSource(String url)
url
- the source or null to removepublic Color getColor()
public void setColor(Color color)
color
- the color or null to removepublic Color setColor(String color)
color
- the color name (case insensitive) or null to remove.
Acceptable values are defined in Section 4.3 of the CSS Color Module Level 3 Recommendation. For
example, "aliceblue", "green", "navy".public List<Image> getImages()
public void addImage(Image image)
image
- the imagepublic List<VEvent> getEvents()
public void addEvent(VEvent event)
event
- the eventpublic List<VTodo> getTodos()
public void addTodo(VTodo todo)
todo
- the to-do taskpublic List<VJournal> getJournals()
public void addJournal(VJournal journal)
journal
- the journal entrypublic List<VFreeBusy> getFreeBusies()
public void addFreeBusy(VFreeBusy freeBusy)
freeBusy
- the free/busy entrypublic ValidationWarnings validate(ICalVersion version)
Checks this iCalendar object for data consistency problems or deviations from the specifications.
The existence of validation warnings will not prevent the iCalendar object from being written to a data stream. Syntactically-correct output will still be produced. However, the consuming application may have trouble interpreting some of the data due to the presence of these warnings.
These problems can largely be avoided by reading the Javadocs of the component and property classes, or by being familiar with the iCalendar standard.
version
- the version to validate againstprotected void validate(List<ICalComponent> components, ICalVersion version, List<ValidationWarning> warnings)
ICalComponent
Checks the component for data consistency problems or deviations from the spec.
This method should be overridden by child classes that wish to provide validation logic. The default implementation of this method does nothing.
validate
in class ICalComponent
components
- the hierarchy of components that the component belongs
toversion
- the version to validate againstwarnings
- the list to add the warnings topublic String write()
Marshals this iCalendar object to its traditional, plain-text representation.
If this iCalendar object contains user-defined property or component
objects, you must use the Biweekly
or ICalWriter
classes
instead in order to register the scribe classes.
IllegalArgumentException
- if this iCalendar object contains
user-defined property or component objectspublic void write(File file) throws IOException
Marshals this iCalendar object to its traditional, plain-text representation.
If this iCalendar object contains user-defined property or component
objects, you must use the Biweekly
or ICalWriter
classes
instead in order to register the scribe classes.
file
- the file to write toIllegalArgumentException
- if this iCalendar object contains
user-defined property or component objectsIOException
- if there's an problem writing to the filepublic void write(OutputStream out) throws IOException
Marshals this iCalendar object to its traditional, plain-text representation.
If this iCalendar object contains user-defined property or component
objects, you must use the Biweekly
or ICalWriter
classes
instead in order to register the scribe classes.
out
- the output stream to write toIllegalArgumentException
- if this iCalendar object contains
user-defined property or component objectsIOException
- if there's a problem writing to the output streampublic void write(Writer writer) throws IOException
Marshals this iCalendar object to its traditional, plain-text representation.
If this iCalendar object contains user-defined property or component
objects, you must use the Biweekly
or ICalWriter
classes
instead in order to register the scribe classes.
writer
- the writer to write toIllegalArgumentException
- if this iCalendar object contains
user-defined property or component objectsIOException
- if there's a problem writing to the writerpublic String writeXml()
Marshals this iCalendar object to its XML representation (xCal).
If this iCalendar object contains user-defined property or component
objects, you must use the Biweekly
, XCalWriter
, or
XCalDocument
classes instead in order to register the scribe
classes.
IllegalArgumentException
- if this iCalendar object contains
user-defined property or component objectspublic void writeXml(File file) throws TransformerException, IOException
Marshals this iCalendar object to its XML representation (xCal).
If this iCalendar object contains user-defined property or component
objects, you must use the Biweekly
, XCalWriter
, or
XCalDocument
classes instead in order to register the scribe
classes.
file
- the file to write toIllegalArgumentException
- if this iCalendar object contains
user-defined property or component objectsTransformerException
- if there's a problem writing to the fileIOException
- if there's a problem opening the filepublic void writeXml(OutputStream out) throws TransformerException
Marshals this iCalendar object to its XML representation (xCal).
If this iCalendar object contains user-defined property or component
objects, you must use the Biweekly
, XCalWriter
, or
XCalDocument
classes instead in order to register the scribe
classes.
out
- the output stream to write toIllegalArgumentException
- if this iCalendar object contains
user-defined property or component objectsTransformerException
- if there's a problem writing to the output
streampublic void writeXml(Writer writer) throws TransformerException
Marshals this iCalendar object to its XML representation (xCal).
If this iCalendar object contains user-defined property or component
objects, you must use the Biweekly
, XCalWriter
, or
XCalDocument
classes instead in order to register the scribe
classes.
writer
- the writer to write toIllegalArgumentException
- if this iCalendar object contains
user-defined property or component objectsTransformerException
- if there's a problem writing to the writerpublic String writeJson()
Marshals this iCalendar object to its JSON representation (jCal).
If this iCalendar object contains user-defined property or component
objects, you must use the Biweekly
or JCalWriter
classes
instead in order to register the scribe classes.
IllegalArgumentException
- if this iCalendar object contains
user-defined property or component objectspublic void writeJson(File file) throws IOException
Marshals this iCalendar object to its JSON representation (jCal).
If this iCalendar object contains user-defined property or component
objects, you must use the Biweekly
or JCalWriter
classes
instead in order to register the scribe classes.
file
- the file to write toIllegalArgumentException
- if this iCalendar object contains
user-defined property or component objectsIOException
- if there's a problem writing to the filepublic void writeJson(OutputStream out) throws IOException
Marshals this iCalendar object to its JSON representation (jCal).
If this iCalendar object contains user-defined property or component
objects, you must use the Biweekly
or JCalWriter
classes
instead in order to register the scribe classes.
out
- the output stream to write toIllegalArgumentException
- if this iCalendar object contains
user-defined property or component objectsIOException
- if there's a problem writing to the output streampublic void writeJson(Writer writer) throws IOException
Marshals this iCalendar object to its JSON representation (jCal).
If this iCalendar object contains user-defined property or component
objects, you must use the Biweekly
or JCalWriter
classes
instead in order to register the scribe classes.
writer
- the writer to write toIllegalArgumentException
- if this iCalendar object contains
user-defined property or component objectsIOException
- if there's a problem writing to the writerprotected Map<String,Object> toStringValues()
ICalComponent
Gets string representations of any additional fields the component has
(other than sub-components and properties) for the ICalComponent.toString()
method.
Meant to be overridden by child classes. The default implementation returns an empty map.
toStringValues
in class ICalComponent
public int hashCode()
hashCode
in class ICalComponent
public boolean equals(Object obj)
equals
in class ICalComponent
Copyright © 2013–2024 Michael Angstadt. All rights reserved.