public class XCalDocument extends Object
Represents an XML document that contains iCalendar objects ("xCal" standard). This class can be used to read and write xCal documents.
Examples:
String xml = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>" + "<icalendar xmlns=\"urn:ietf:params:xml:ns:icalendar-2.0\">" + "<vcalendar>" + "<properties>" + "<prodid><text>-//Example Inc.//Example Client//EN</text></prodid>" + "<version><text>2.0</text></version>" + "</properties>" + "<components>" + "<vevent>" + "<properties>" + "<dtstart><date-time>2013-06-27T13:00:00Z</date-time></dtstart>" + "<dtend><date-time>2013-06-27T15:00:00Z</date-time></dtend>" + "<summary><text>Team Meeting</text></summary>" + "</properties>" + "</vevent>" + "</components>" + "</vcalendar>" + "</icalendar>"; //parsing an existing xCal document XCalDocument xcal = new XCalDocument(xml); List<ICalendar> icals = xcal.parseAll(); //creating an empty xCal document XCalDocument xcal = new XCalDocument(); //ICalendar objects can be added at any time ICalendar ical = new ICalendar(); xcal.add(ical); //retrieving the raw XML DOM Document document = xcal.getDocument(); //call one of the "write()" methods to output the xCal document File file = new File("meeting.xml"); xcal.write(file);
Constructor and Description |
---|
XCalDocument()
Creates an empty xCal document.
|
XCalDocument(Document document)
Wraps an existing XML DOM object.
|
XCalDocument(File file)
Parses an xCal document from a file.
|
XCalDocument(InputStream in)
Parses an xCal document from an input stream.
|
XCalDocument(Reader reader)
Parses an xCal document from a reader.
|
XCalDocument(String xml)
Parses an xCal document from a string.
|
Modifier and Type | Method and Description |
---|---|
void |
add(ICalendar ical)
Adds an iCalendar object to the xCal document.
|
Document |
getDocument()
Gets the raw XML DOM object.
|
List<List<String>> |
getParseWarnings()
Gets the warnings from the last parse operation.
|
ScribeIndex |
getScribeIndex()
Gets the object that manages the component/property scribes.
|
List<ICalendar> |
parseAll()
Parses all the
ICalendar objects from the xCal document. |
ICalendar |
parseFirst()
Parses the first
ICalendar object from the xCal document. |
void |
registerParameterDataType(String parameterName,
ICalDataType dataType)
Registers the data type of an experimental parameter.
|
void |
registerScribe(ICalComponentScribe<? extends ICalComponent> scribe)
Registers an experimental component scribe.
|
void |
registerScribe(ICalPropertyScribe<? extends ICalProperty> scribe)
Registers an experimental property scribe.
|
void |
setScribeIndex(ScribeIndex index)
Sets the object that manages the component/property scribes.
|
String |
toString() |
String |
write()
Writes the xCal document to a string without pretty-printing it.
|
void |
write(File file)
Writes the xCal document to a file without pretty-printing it.
|
void |
write(File file,
int indent)
Writes the xCal document to a file and pretty-prints it.
|
String |
write(int indent)
Writes the xCal document to a string and pretty-prints it.
|
void |
write(OutputStream out)
Writes the xCal document to an output stream without pretty-printing it.
|
void |
write(OutputStream out,
int indent)
Writes the xCal document to an output stream and pretty-prints it.
|
void |
write(Writer writer)
Writes the xCal document to a writer without pretty-printing it.
|
void |
write(Writer writer,
int indent)
Writes the xCal document to a writer and pretty-prints it.
|
public XCalDocument(String xml) throws SAXException
xml
- the xCal document in the form of a stringSAXException
- if there's a problem parsing the XMLpublic XCalDocument(InputStream in) throws SAXException, IOException
in
- the input stream to read the the xCal document fromIOException
- if there's a problem reading from the input streamSAXException
- if there's a problem parsing the XMLpublic XCalDocument(File file) throws SAXException, IOException
file
- the file containing the xCal documentIOException
- if there's a problem reading from the fileSAXException
- if there's a problem parsing the XMLpublic XCalDocument(Reader reader) throws SAXException, IOException
Parses an xCal document from a reader.
Note that use of this constructor is discouraged. It ignores the
character encoding that is defined within the XML document itself, and
should only be used if the encoding is undefined or if the encoding needs
to be ignored for whatever reason. The XCalDocument(InputStream)
constructor should be used instead, since it takes the XML document's
character encoding into account when parsing.
reader
- the reader to read the xCal document fromIOException
- if there's a problem reading from the readerSAXException
- if there's a problem parsing the XMLpublic XCalDocument(Document document)
document
- the XML DOM that contains the xCal documentpublic XCalDocument()
public void registerScribe(ICalPropertyScribe<? extends ICalProperty> scribe)
Registers an experimental property scribe. Can also be used to override the scribe of a standard property (such as DTSTART). Calling this method is the same as calling:
getScribeIndex().register(scribe)
.
scribe
- the scribe to registerpublic void registerScribe(ICalComponentScribe<? extends ICalComponent> scribe)
Registers an experimental component scribe. Can also be used to override the scribe of a standard component (such as VEVENT). Calling this method is the same as calling:
getScribeIndex().register(scribe)
.
scribe
- the scribe to registerpublic ScribeIndex getScribeIndex()
public void setScribeIndex(ScribeIndex index)
index
- the scribe indexpublic void registerParameterDataType(String parameterName, ICalDataType dataType)
parameterName
- the parameter name (e.g. "x-foo")dataType
- the data type or null to removepublic Document getDocument()
public List<List<String>> getParseWarnings()
ICalendar
object has its own warnings list)parseAll()
,
parseFirst()
public List<ICalendar> parseAll()
ICalendar
objects from the xCal document.public ICalendar parseFirst()
ICalendar
object from the xCal document.public void add(ICalendar ical)
ICalendar
object to the XML DOM. This means that any changes that
are made to the ICalendar
object after calling this method will
NOT be applied to the xCal document.ical
- the iCalendar object to addIllegalArgumentException
- if the scribe class for a component or
property object cannot be found (only happens when an experimental
property/component scribe is not registered with the
registerScribe
method.)public String write()
public String write(int indent)
indent
- the number of indent spaces to use for pretty-printingpublic void write(OutputStream out) throws TransformerException
out
- the output streamTransformerException
- if there's a problem writing to the output
streampublic void write(OutputStream out, int indent) throws TransformerException
out
- the output streamindent
- the number of indent spaces to use for pretty-printingTransformerException
- if there's a problem writing to the output
streampublic void write(File file) throws TransformerException, IOException
file
- the fileIOException
- if there's a problem writing to the fileTransformerException
- if there's a problem writing the XMLpublic void write(File file, int indent) throws TransformerException, IOException
file
- the file streamindent
- the number of indent spaces to use for pretty-printingIOException
- if there's a problem writing to the fileTransformerException
- if there's a problem writing the XMLpublic void write(Writer writer) throws TransformerException
writer
- the writerTransformerException
- if there's a problem writing to the writerpublic void write(Writer writer, int indent) throws TransformerException
writer
- the writerindent
- the number of indent spaces to use for pretty-printingTransformerException
- if there's a problem writing to the writerCopyright © 2013-2014 Michael Angstadt. All Rights Reserved.