|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectbiweekly.io.xml.XCalDocument
public class XCalDocument
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 Summary | |
---|---|
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. |
Method Summary | |
---|---|
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. |
ICalMarshallerRegistrar |
getRegistrar()
Gets the object that manages the component/property marshaller objects. |
List<ICalendar> |
parseAll()
Parses all the ICalendar objects from the xCal document. |
ICalendar |
parseFirst()
Parses the first ICalendar object from the xCal document. |
void |
registerMarshaller(ICalComponentMarshaller<? extends ICalComponent> marshaller)
Registers an experimental component marshaller. |
void |
registerMarshaller(ICalPropertyMarshaller<? extends ICalProperty> marshaller)
Registers an experimental property marshaller. |
void |
registerParameterDataType(String parameterName,
ICalDataType dataType)
Registers the data type of an experimental parameter. |
void |
setRegistrar(ICalMarshallerRegistrar registrar)
Sets the object that manages the component/property marshaller objects. |
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. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public XCalDocument(String xml) throws SAXException
xml
- the xCal document in the form of a string
SAXException
- if there's a problem parsing the XMLpublic XCalDocument(InputStream in) throws SAXException, IOException
in
- the input stream to read the the xCal document from
IOException
- if there's a problem reading from the input stream
SAXException
- if there's a problem parsing the XMLpublic XCalDocument(File file) throws SAXException, IOException
file
- the file containing the xCal document
IOException
- if there's a problem reading from the file
SAXException
- 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 from
IOException
- if there's a problem reading from the reader
SAXException
- if there's a problem parsing the XMLpublic XCalDocument(Document document)
document
- the XML DOM that contains the xCal documentpublic XCalDocument()
Method Detail |
---|
public void registerMarshaller(ICalPropertyMarshaller<? extends ICalProperty> marshaller)
Registers an experimental property marshaller. Can also be used to override the marshaller of a standard property (such as DTSTART). Calling this method is the same as calling:
getRegistrar().register(marshaller)
.
marshaller
- the marshaller to registerpublic void registerMarshaller(ICalComponentMarshaller<? extends ICalComponent> marshaller)
Registers an experimental component marshaller. Can also be used to override the marshaller of a standard component (such as VEVENT). Calling this method is the same as calling:
getRegistrar().register(marshaller)
.
marshaller
- the marshaller to registerpublic ICalMarshallerRegistrar getRegistrar()
public void setRegistrar(ICalMarshallerRegistrar registrar)
registrar
- the marshaller registrarpublic 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 add
IllegalArgumentException
- if the marshaller class for a component
or property object cannot be found (only happens when an experimental
property/component marshaller is not registered with the
registerMarshaller
method.)public String write()
public String write(int indent)
indent
- the number of indent spaces to use for pretty-printing
public void write(OutputStream out) throws TransformerException
out
- the output stream
TransformerException
- 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-printing
TransformerException
- if there's a problem writing to the output
streampublic void write(File file) throws TransformerException, IOException
file
- the file
IOException
- if there's a problem writing to the file
TransformerException
- 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-printing
IOException
- if there's a problem writing to the file
TransformerException
- if there's a problem writing the XMLpublic void write(Writer writer) throws TransformerException
writer
- the writer
TransformerException
- 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-printing
TransformerException
- if there's a problem writing to the writerpublic String toString()
toString
in class Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |