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);
Modifier and Type | Class and Description |
---|---|
class |
XCalDocument.XCalDocumentStreamWriter |
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 this XML document.
|
Document |
getDocument()
Gets the raw XML DOM object.
|
List<ICalendar> |
getICalendars()
Parses all iCalendar objects from this XML document.
|
StreamReader |
reader()
Creates a
StreamReader object that parses iCalendar objects from
this XML document. |
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.
|
XCalDocument.XCalDocumentStreamWriter |
writer()
Creates a
StreamWriter object that adds iCalendar objects to this
XML document. |
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 Document getDocument()
public List<ICalendar> getICalendars()
public void add(ICalendar ical)
ical
- the iCalendar object to addpublic StreamReader reader()
StreamReader
object that parses iCalendar objects from
this XML document.public XCalDocument.XCalDocumentStreamWriter writer()
StreamWriter
object that adds iCalendar objects to this
XML document.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-2015 Michael Angstadt. All Rights Reserved.