Introduction »
iCal4j may be used for modifying existing iCalendar data or creating new iCalendar data from scratch. Here you will find a few examples indicating the recommended usage of this library.
iCal4j | ||||||||||||||
Home | | | Introduction | | | Wiki | | | Documentation | | | News | | | Support | | | Download | | | License |
iCal4j may be used for modifying existing iCalendar data or creating new iCalendar data from scratch. Here you will find a few examples indicating the recommended usage of this library.
Simply add the iCal4j jar file, the Commons Logging jar file, and the Commons Language jar file to your classpath.
Support for parsing and building an iCalendar object model is provided
by the CalendarParser
and ContentHandler
interfaces. You can provide your own implementations of either
of these, or just use the default implementations as provided by
the CalendarBuilder
class. Note that CalendarBuilder
is not thread-safe, and as such it is good practice to construct a new
instance for each data stream you wish to parse (see Working with TimeZones
for further reasons).
|
The iCal4j API is designed to conform with the standard Java collections
API as much as possible. As such, you will find that for searching and
manipulating a calendar object model you can make use of familiar concepts
such as List
s, Iterator
s, etc.
|
Creating a new calendar is quite straight-forward, in that all you need
to remember is that a Calendar
contains a list of
Properties
and Components
. A calendar must
contain certain standard properties and at least one component to be
valid. You can verify that a calendar is valid via the method
Calendar.validate()
. All iCal4j objects also override
Object.toString()
, so you can verify the resulting calendar
data via this mechanism.
|
Output: |
---|
|
One of the more commonly used components is a VEvent
. To create
a VEvent you can either set the date value and properties manually or you can
make use of the convenience constructors to initialise standard values.
|
Output: |
---|
|
Complete timezone support is now provided by iCal4j, which follows these basic principles:
TimeZoneRegistry
implementation. When parsing existing
iCalendar data you should obtain the appropriate TimeZoneRegistry
via the CalendarBuilder.getRegistry()
method after
calling CalendarBuilder.build()
. In addition to the
default iCal4j timezone definitions this registry instance will also
provide you access to any timezones defined in the parsed iCalendar
data stream. If you are creating a new calendar object you should
call TimeZoneRegistryFactory.getInstance().createRegistry()
to construct a default registry instance.
TimeZoneRegistry
implementation
by sub-classing the TimeZoneRegistyFactory
class and
specifying the following system property:
net.fortuna.ical4j.timezone.registry=<factory_class_name>
This may be useful if you want to read and/or store your timezone definitions in a database.
|
Output: |
---|
|
When saving an iCalendar file iCal4j will automatically validate your
calendar object model to ensure it complies with the
RFC2445 specification.
If you would prefer not to validate your calendar data you can disable the
validation by calling CalendarOutputter.setValidating(false)
.
|
More examples may be found in the API Documentation.