T
- the property classpublic abstract class ICalPropertyScribe<T extends ICalProperty> extends Object
Modifier and Type | Class and Description |
---|---|
protected static class |
ICalPropertyScribe.DateParser
Factory class for parsing dates.
|
protected static class |
ICalPropertyScribe.DateWriter
Factory class for writing dates.
|
protected static interface |
ICalPropertyScribe.ListCallback<T>
Callback function used in conjunction with the
list method |
static class |
ICalPropertyScribe.Result<T>
Represents the result of an unmarshal operation.
|
protected static class |
ICalPropertyScribe.SemiStructuredIterator
Iterates over the fields in a semi-structured value (a structured value
whose components cannot be multi-valued).
|
protected static class |
ICalPropertyScribe.Splitter
A helper class for splitting strings.
|
protected static class |
ICalPropertyScribe.StructuredIterator
Iterates over the fields in a structured value.
|
Modifier and Type | Field and Description |
---|---|
protected Class<T> |
clazz |
protected String |
propertyName |
protected QName |
qname |
Constructor and Description |
---|
ICalPropertyScribe(Class<T> clazz,
String propertyName)
Creates a new scribe.
|
ICalPropertyScribe(Class<T> clazz,
String propertyName,
ICalDataType defaultDataType)
Creates a new scribe.
|
ICalPropertyScribe(Class<T> clazz,
String propertyName,
ICalDataType defaultDataType,
QName qname)
Creates a new scribe.
|
Modifier and Type | Method and Description |
---|---|
protected ICalDataType |
_dataType(T property,
ICalVersion version)
Determines the data type of a property instance.
|
protected ICalDataType |
_defaultDataType(ICalVersion version)
Determines the default data type of this property.
|
protected T |
_parseJson(JCalValue value,
ICalDataType dataType,
ICalParameters parameters,
ParseContext context)
Unmarshals a property from a JSON data stream (jCal).
|
protected abstract T |
_parseText(String value,
ICalDataType dataType,
ICalParameters parameters,
ParseContext context)
Unmarshals a property from a plain-text iCalendar data stream.
|
protected T |
_parseXml(XCalElement element,
ICalParameters parameters,
ParseContext context)
Unmarshals a property from an XML document (xCal).
|
protected ICalParameters |
_prepareParameters(T property,
WriteContext context)
Sanitizes a property's parameters before the property is written.
|
protected JCalValue |
_writeJson(T property,
WriteContext context)
Marshals a property's value to a JSON data stream (jCal).
|
protected abstract String |
_writeText(T property,
WriteContext context)
Marshals a property's value to a string.
|
protected void |
_writeXml(T property,
XCalElement element,
WriteContext context)
Marshals a property's value to an XML element (xCal).
|
ICalDataType |
dataType(T property,
ICalVersion version)
Determines the data type of a property instance.
|
protected static ICalPropertyScribe.DateWriter |
date(Date date)
Formats a date as a string.
|
protected static ICalPropertyScribe.DateWriter |
date(Date date,
ICalProperty property,
WriteContext context) |
protected static ICalPropertyScribe.DateWriter |
date(ICalDate date)
Formats a date as a string.
|
protected static ICalPropertyScribe.DateWriter |
date(ICalDate date,
ICalProperty property,
WriteContext context) |
protected static ICalPropertyScribe.DateParser |
date(String value)
Parses a date string.
|
ICalDataType |
defaultDataType(ICalVersion version)
Determines the default data type of this property.
|
protected static String |
escape(String text)
Escapes all special characters within a iCalendar value.
|
Class<T> |
getPropertyClass()
Gets the property class.
|
String |
getPropertyName()
Gets the property name.
|
QName |
getQName()
Gets this property's local name and namespace for xCal documents.
|
Set<ICalVersion> |
getSupportedVersions()
Gets the iCalendar versions that support this property.
|
protected static ICalParameters |
handleTzidParameter(ICalProperty property,
boolean hasTime,
WriteContext context)
Adds a TZID parameter to a property's parameter list if necessary.
|
protected static boolean |
isInObservance(WriteContext context)
Determines if the property is within an observance component.
|
protected static <T> String |
list(Collection<T> values)
Writes a comma-separated list of values.
|
protected static <T> String |
list(Collection<T> values,
ICalPropertyScribe.ListCallback<T> callback)
Writes a comma-separated list of values.
|
protected static String |
list(Object... values)
Writes a comma-separated list of values.
|
protected static List<String> |
list(String value)
Parses a comma-separated list of values.
|
protected static CannotParseException |
missingXmlElements(ICalDataType... dataTypes)
Creates a
CannotParseException , indicating that the XML elements
that the parser expected to find are missing from the property's XML
element. |
protected static CannotParseException |
missingXmlElements(String... elements)
Creates a
CannotParseException , indicating that the XML elements
that the parser expected to find are missing from property's XML element. |
protected static <T> String |
object(Map<String,List<T>> value)
Writes an object property value to a string.
|
protected static ListMultimap<String,String> |
object(String value)
Parses an object property value.
|
T |
parseJson(JCalValue value,
ICalDataType dataType,
ICalParameters parameters,
ParseContext context)
Unmarshals a property's value from a JSON data stream (jCal).
|
T |
parseText(String value,
ICalDataType dataType,
ICalParameters parameters,
ParseContext context)
Unmarshals a property from a plain-text iCalendar data stream.
|
T |
parseXml(Element element,
ICalParameters parameters,
ParseContext context)
Unmarshals a property's value from an XML document (xCal).
|
ICalParameters |
prepareParameters(T property,
WriteContext context)
Sanitizes a property's parameters before the property is written.
|
protected static ICalPropertyScribe.SemiStructuredIterator |
semistructured(String value)
Parses a list of values that are delimited by semicolons.
|
protected static ICalPropertyScribe.SemiStructuredIterator |
semistructured(String value,
boolean nullEmpties)
Parses a list of values that are delimited by semicolons.
|
protected static ICalPropertyScribe.Splitter |
splitter(char delimiter)
Splits a string by a delimiter, taking escaped characters into account.
|
protected static ICalPropertyScribe.StructuredIterator |
structured(JCalValue value)
Provides an iterator for a jCard structured value.
|
protected static String |
structured(Object... values)
Writes a structured value.
|
protected static ICalPropertyScribe.StructuredIterator |
structured(String value)
Parses a structured value.
|
protected static String |
unescape(String text)
Unescapes all special characters that are escaped with a backslash, as
well as escaped newlines.
|
JCalValue |
writeJson(T property,
WriteContext context)
Marshals a property's value to a JSON data stream (jCal).
|
String |
writeText(T property,
WriteContext context)
Marshals a property's value to a string.
|
void |
writeXml(T property,
Element element,
WriteContext context)
Marshals a property's value to an XML element (xCal).
|
protected final Class<T extends ICalProperty> clazz
protected final String propertyName
public ICalPropertyScribe(Class<T> clazz, String propertyName)
clazz
- the property classpropertyName
- the property name (e.g. "VERSION")public ICalPropertyScribe(Class<T> clazz, String propertyName, ICalDataType defaultDataType)
clazz
- the property classpropertyName
- the property name (e.g. "VERSION")defaultDataType
- the property's default data type (e.g. "text") or
null if unknownpublic ICalPropertyScribe(Class<T> clazz, String propertyName, ICalDataType defaultDataType, QName qname)
clazz
- the property classpropertyName
- the property name (e.g. "VERSION")defaultDataType
- the property's default data type (e.g. "text") or
null if unknownqname
- the XML element name and namespace to use for xCal documents
(by default, the XML element name is set to the lower-cased property
name, and the element namespace is set to the xCal namespace)public Set<ICalVersion> getSupportedVersions()
public Class<T> getPropertyClass()
public String getPropertyName()
public QName getQName()
public final ICalParameters prepareParameters(T property, WriteContext context)
property
- the property to writecontext
- the contextpublic final ICalDataType defaultDataType(ICalVersion version)
version
- the version of the iCalendar object being generatedpublic final ICalDataType dataType(T property, ICalVersion version)
property
- the propertyversion
- the version of the iCalendar object being generatedpublic final String writeText(T property, WriteContext context)
property
- the propertycontext
- the contextSkipMeException
- if the property should not be written to the data
streampublic final void writeXml(T property, Element element, WriteContext context)
property
- the propertyelement
- the property's XML elementcontext
- the contextSkipMeException
- if the property should not be written to the data
streampublic final JCalValue writeJson(T property, WriteContext context)
property
- the propertycontext
- the contextSkipMeException
- if the property should not be written to the data
streampublic final T parseText(String value, ICalDataType dataType, ICalParameters parameters, ParseContext context)
value
- the value as read off the wiredataType
- the data type of the property value. The property's VALUE
parameter is used to determine the data type. If the property has no
VALUE parameter, then this parameter will be set to the property's
default datatype. Note that the VALUE parameter is removed from the
property's parameter list after it has been read.parameters
- the parsed parameterscontext
- the parse contextCannotParseException
- if the scribe could not parse the property's
valueSkipMeException
- if the property should not be added to the final
ICalendar
objectpublic final T parseXml(Element element, ICalParameters parameters, ParseContext context)
element
- the property's XML elementparameters
- the property's parameterscontext
- the contextCannotParseException
- if the scribe could not parse the property's
valueSkipMeException
- if the property should not be added to the final
ICalendar
objectpublic final T parseJson(JCalValue value, ICalDataType dataType, ICalParameters parameters, ParseContext context)
value
- the property's JSON valuedataType
- the data typeparameters
- the parsed parameterscontext
- the contextCannotParseException
- if the scribe could not parse the property's
valueSkipMeException
- if the property should not be added to the final
ICalendar
objectprotected ICalParameters _prepareParameters(T property, WriteContext context)
Sanitizes a property's parameters before the property is written.
This method should be overridden by child classes that wish to tweak the property's parameters before the property is written. The default implementation of this method returns the property's parameters unmodified.
property
- the property to writecontext
- the contextprotected ICalDataType _defaultDataType(ICalVersion version)
Determines the default data type of this property.
This method should be overridden by child classes if a property's default
data type changes depending the iCalendar version. The default
implementation of this method returns the data type that was passed into
the ICalPropertyScribe(Class, String, ICalDataType)
constructor.
Null is returned if this constructor was not invoked.
version
- the version of the iCalendar object being generatedprotected ICalDataType _dataType(T property, ICalVersion version)
Determines the data type of a property instance.
This method should be overridden by child classes if a property's data type changes depending on its value. The default implementation of this method returns the property's default data type.
property
- the propertyversion
- the version of the iCalendar object being generatedprotected abstract String _writeText(T property, WriteContext context)
property
- the propertycontext
- the write contextSkipMeException
- if the property should not be written to the data
streamprotected void _writeXml(T property, XCalElement element, WriteContext context)
Marshals a property's value to an XML element (xCal).
This method should be overridden by child classes that wish to support
xCal. The default implementation of this method will append one child
element to the property's XML element. The child element's name will be
that of the property's data type (retrieved using the dataType(T, biweekly.ICalVersion)
method), and the child element's text content will be set to the
property's marshalled plain-text value (retrieved using the
writeText(T, biweekly.io.WriteContext)
method).
property
- the propertyelement
- the property's XML elementcontext
- the contextSkipMeException
- if the property should not be written to the data
streamprotected JCalValue _writeJson(T property, WriteContext context)
Marshals a property's value to a JSON data stream (jCal).
This method should be overridden by child classes that wish to support
jCal. The default implementation of this method will create a jCard
property that has a single JSON string value (generated by the
writeText(T, biweekly.io.WriteContext)
method).
property
- the propertycontext
- the contextSkipMeException
- if the property should not be written to the data
streamprotected abstract T _parseText(String value, ICalDataType dataType, ICalParameters parameters, ParseContext context)
value
- the value as read off the wiredataType
- the data type of the property value. The property's VALUE
parameter is used to determine the data type. If the property has no
VALUE parameter, then this parameter will be set to the property's
default datatype. Note that the VALUE parameter is removed from the
property's parameter list after it has been read.parameters
- the parsed parameters. These parameters will be
assigned to the property object once this method returns. Therefore, do
not assign any parameters to the property object itself whilst inside of
this method, or else they will be overwritten.context
- the parse contextCannotParseException
- if the scribe could not parse the property's
valueSkipMeException
- if the property should not be added to the final
ICalendar
objectprotected T _parseXml(XCalElement element, ICalParameters parameters, ParseContext context)
Unmarshals a property from an XML document (xCal).
This method should be overridden by child classes that wish to support
xCal. The default implementation of this method will find the first child
element with the xCal namespace. The element's name will be used as the
property's data type and its text content will be passed into the
_parseText(java.lang.String, biweekly.ICalDataType, biweekly.parameter.ICalParameters, biweekly.io.ParseContext)
method. If no such child element is found, then the
parent element's text content will be passed into _parseText(java.lang.String, biweekly.ICalDataType, biweekly.parameter.ICalParameters, biweekly.io.ParseContext)
and
the data type will be null.
element
- the property's XML elementparameters
- the parsed parameters. These parameters will be
assigned to the property object once this method returns. Therefore, do
not assign any parameters to the property object itself whilst inside of
this method, or else they will be overwritten.context
- the contextCannotParseException
- if the scribe could not parse the property's
valueSkipMeException
- if the property should not be added to the final
ICalendar
objectprotected T _parseJson(JCalValue value, ICalDataType dataType, ICalParameters parameters, ParseContext context)
Unmarshals a property from a JSON data stream (jCal).
This method should be overridden by child classes that wish to support
jCal. The default implementation of this method will convert the jCal
property value to a string and pass it into the _parseText(java.lang.String, biweekly.ICalDataType, biweekly.parameter.ICalParameters, biweekly.io.ParseContext)
method.
The following paragraphs describe the way in which this method's default implementation converts a jCal value to a string:
If the jCal value consists of a single, non-array, non-object value, then
the value is converted to a string. Special characters (backslashes,
commas, and semicolons) are escaped in order to simulate what the value
might look like in a plain-text iCalendar object.
["x-foo", {}, "text", "the;value"] --> "the\;value"
["x-foo", {}, "text", 2] --> "2"
If the jCal value consists of multiple, non-array, non-object values,
then all the values are appended together in a single string, separated
by commas. Special characters (backslashes, commas, and semicolons) are
escaped for each value in order to prevent commas from being treated as
delimiters, and to simulate what the value might look like in a
plain-text iCalendar object.
["x-foo", {}, "text", "one", "two,three"] -->
"one,two\,three"
If the jCal value is a single array, then this array is treated as a
"structured value", and converted its plain-text representation. Special
characters (backslashes, commas, and semicolons) are escaped for each
value in order to prevent commas and semicolons from being treated as
delimiters.
["x-foo", {}, "text", ["one", ["two", "three"], "four;five"]]
--> "one;two,three;four\;five"
If the jCal value starts with a JSON object, then the object is converted
to a format identical to the one used in the RRULE and EXRULE properties.
Special characters (backslashes, commas, semicolons, and equal signs) are
escaped for each value in order to preserve the syntax of the string
value.
["x-foo", {}, "text", {"one": 1, "two": [2, 2.5]}] --> "ONE=1;TWO=2,2.5"
For all other cases, behavior is undefined.
value
- the property's JSON valuedataType
- the data typeparameters
- the parsed parameters. These parameters will be
assigned to the property object once this method returns. Therefore, do
not assign any parameters to the property object itself whilst inside of
this method, or else they will be overwritten.context
- the contextCannotParseException
- if the scribe could not parse the property's
valueSkipMeException
- if the property should not be added to the final
ICalendar
objectprotected static boolean isInObservance(WriteContext context)
context
- the write contextprotected static String unescape(String text)
text
- the text to unescapeprotected static String escape(String text)
Escapes all special characters within a iCalendar value. These characters are:
\
),
);
)
Newlines are not escaped by this method. They are escaped when the
iCalendar object is serialized (in the ICalRawWriter
class).
text
- the text to escapeprotected static ICalPropertyScribe.Splitter splitter(char delimiter)
delimiter
- the delimiter (e.g. ',')protected static List<String> list(String value)
value
- the string to parse (e.g. "one,two,th\,ree")protected static String list(Object... values)
values
- the values to writeprotected static <T> String list(Collection<T> values)
values
- the values to writeprotected static <T> String list(Collection<T> values, ICalPropertyScribe.ListCallback<T> callback)
values
- the values to writecallback
- callback function used for converting each value to a
stringprotected static ICalPropertyScribe.SemiStructuredIterator semistructured(String value)
value
- the string to parse (e.g. "one;two;three")protected static ICalPropertyScribe.SemiStructuredIterator semistructured(String value, boolean nullEmpties)
value
- the string to parse (e.g. "one;two;three")nullEmpties
- true to treat empty elements as null, false to treat
them as empty stringsprotected static ICalPropertyScribe.StructuredIterator structured(String value)
value
- the string to parse (e.g. "one;two,three;four")protected static ICalPropertyScribe.StructuredIterator structured(JCalValue value)
value
- the jCard valueprotected static String structured(Object... values)
Writes a structured value.
This method accepts a list of Object
instances.
Collection
objects will be treated as multi-valued components.
Null objects will be treated as empty components. All other objects will
have their toString()
method invoked to generate the string
value.
values
- the values to writeprotected static <T> String object(Map<String,List<T>> value)
value
- the valueprotected static ListMultimap<String,String> object(String value)
value
- the value to parseprotected static ICalPropertyScribe.DateParser date(String value)
value
- the date stringprotected static ICalPropertyScribe.DateWriter date(Date date)
date
- the dateprotected static ICalPropertyScribe.DateWriter date(ICalDate date)
date
- the dateprotected static ICalPropertyScribe.DateWriter date(Date date, ICalProperty property, WriteContext context)
protected static ICalPropertyScribe.DateWriter date(ICalDate date, ICalProperty property, WriteContext context)
protected static ICalParameters handleTzidParameter(ICalProperty property, boolean hasTime, WriteContext context)
property
- the propertyhasTime
- true if the property value has a time component, false if
notcontext
- the write contextprotected static CannotParseException missingXmlElements(ICalDataType... dataTypes)
CannotParseException
, indicating that the XML elements
that the parser expected to find are missing from the property's XML
element.dataTypes
- the expected data types (null for "unknown")protected static CannotParseException missingXmlElements(String... elements)
CannotParseException
, indicating that the XML elements
that the parser expected to find are missing from property's XML element.elements
- the names of the expected XML elements.Copyright © 2013-2015 Michael Angstadt. All Rights Reserved.