ezvcard.io.scribe
Class ListPropertyScribe<T extends TextListProperty>

java.lang.Object
  extended by ezvcard.io.scribe.VCardPropertyScribe<T>
      extended by ezvcard.io.scribe.ListPropertyScribe<T>
Type Parameters:
T - the property class
Direct Known Subclasses:
CategoriesScribe, NicknameScribe

public abstract class ListPropertyScribe<T extends TextListProperty>
extends VCardPropertyScribe<T>

Marshals properties that contain a list of values.

Author:
Michael Angstadt

Nested Class Summary
 
Nested classes/interfaces inherited from class ezvcard.io.scribe.VCardPropertyScribe
VCardPropertyScribe.DateWriter, VCardPropertyScribe.Result<T extends VCardProperty>, VCardPropertyScribe.SemiStructuredIterator, VCardPropertyScribe.Splitter, VCardPropertyScribe.StructuredIterator
 
Field Summary
 
Fields inherited from class ezvcard.io.scribe.VCardPropertyScribe
clazz, propertyName, qname
 
Constructor Summary
ListPropertyScribe(Class<T> clazz, String propertyName)
           
 
Method Summary
protected  VCardDataType _defaultDataType(VCardVersion version)
           Determines the property's default data type.
protected abstract  T _newInstance()
           
protected  T _parseJson(JCardValue value, VCardDataType dataType, VCardParameters parameters, List<String> warnings)
           Unmarshals a property from a JSON data stream (jCard).
protected  T _parseText(String value, VCardDataType dataType, VCardVersion version, VCardParameters parameters, List<String> warnings)
          Unmarshals a property from a plain-text vCard.
protected  T _parseXml(XCardElement element, VCardParameters parameters, List<String> warnings)
           Unmarshals a property from an XML document (xCard).
protected  JCardValue _writeJson(T property)
           Marshals a property's value to a JSON data stream (jCard).
protected  String _writeText(T property, VCardVersion version)
          Marshals a property's value to a string.
protected  void _writeXml(T property, XCardElement parent)
           Marshals a property's value to an XML element (xCard).
 
Methods inherited from class ezvcard.io.scribe.VCardPropertyScribe
_dataType, _parseHtml, _prepareParameters, dataType, date, date, defaultDataType, escape, getPropertyClass, getPropertyName, getQName, handlePrefParam, list, list, list, missingXmlElements, missingXmlElements, parseHtml, parseJson, parseText, parseXml, prepareParameters, semistructured, semistructured, split, structured, structured, structured, unescape, writeJson, writeText, writeXml
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ListPropertyScribe

public ListPropertyScribe(Class<T> clazz,
                          String propertyName)
Method Detail

_defaultDataType

protected VCardDataType _defaultDataType(VCardVersion version)
Description copied from class: VCardPropertyScribe

Determines the property's default data type.

When writing a plain-text vCard, if the data type of a property instance (as determined by the VCardPropertyScribe.dataType(T, ezvcard.VCardVersion) method) matches the default data type, then a VALUE parameter will *not* be written.

When parsing a plain-text vCard, if a property has no VALUE parameter, then the property's default data type will be passed into the VCardPropertyScribe.parseText(java.lang.String, ezvcard.VCardDataType, ezvcard.VCardVersion, ezvcard.parameter.VCardParameters) method.

Specified by:
_defaultDataType in class VCardPropertyScribe<T extends TextListProperty>
Parameters:
version - the vCard version
Returns:
the default data type or null if unknown

_writeText

protected String _writeText(T property,
                            VCardVersion version)
Description copied from class: VCardPropertyScribe
Marshals a property's value to a string.

Specified by:
_writeText in class VCardPropertyScribe<T extends TextListProperty>
Parameters:
property - the property
version - the version of the vCard that is being generated
Returns:
the marshalled value

_parseText

protected T _parseText(String value,
                       VCardDataType dataType,
                       VCardVersion version,
                       VCardParameters parameters,
                       List<String> warnings)
Description copied from class: VCardPropertyScribe
Unmarshals a property from a plain-text vCard.

Specified by:
_parseText in class VCardPropertyScribe<T extends TextListProperty>
Parameters:
value - the value as read off the wire
dataType - 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, as determined by the VCardPropertyScribe.defaultDataType(ezvcard.VCardVersion) method. Note that the VALUE parameter is removed from the property's parameter list after it has been read.
version - the version of the vCard that is being parsed
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.
warnings - allows the programmer to alert the user to any note-worthy (but non-critical) issues that occurred during the unmarshalling process
Returns:
the unmarshalled property object

_writeXml

protected void _writeXml(T property,
                         XCardElement parent)
Description copied from class: VCardPropertyScribe

Marshals a property's value to an XML element (xCard).

This method should be overridden by child classes that wish to support xCard. 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 VCardPropertyScribe.dataType(T, ezvcard.VCardVersion) method), and the child element's text content will be set to the property's marshalled plain-text value (retrieved using the VCardPropertyScribe.writeText(T, ezvcard.VCardVersion) method).

Overrides:
_writeXml in class VCardPropertyScribe<T extends TextListProperty>
Parameters:
property - the property
parent - the property's XML element

_parseXml

protected T _parseXml(XCardElement element,
                      VCardParameters parameters,
                      List<String> warnings)
Description copied from class: VCardPropertyScribe

Unmarshals a property from an XML document (xCard).

This method should be overridden by child classes that wish to support xCard. The default implementation of this method will find the first child element with the xCard namespace. The element's name will be used as the property's data type and its text content will be passed into the VCardPropertyScribe._parseText(java.lang.String, ezvcard.VCardDataType, ezvcard.VCardVersion, ezvcard.parameter.VCardParameters, java.util.List) method. If no such child element is found, then the parent element's text content will be passed into VCardPropertyScribe._parseText(java.lang.String, ezvcard.VCardDataType, ezvcard.VCardVersion, ezvcard.parameter.VCardParameters, java.util.List) and the data type will be null.

Overrides:
_parseXml in class VCardPropertyScribe<T extends TextListProperty>
Parameters:
element - the property's XML element
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.
warnings - allows the programmer to alert the user to any note-worthy (but non-critical) issues that occurred during the unmarshalling process
Returns:
the unmarshalled property object

_writeJson

protected JCardValue _writeJson(T property)
Description copied from class: VCardPropertyScribe

Marshals a property's value to a JSON data stream (jCard).

This method should be overridden by child classes that wish to support jCard. The default implementation of this method will create a jCard property that has a single JSON string value (generated by the VCardPropertyScribe.writeText(T, ezvcard.VCardVersion) method).

Overrides:
_writeJson in class VCardPropertyScribe<T extends TextListProperty>
Parameters:
property - the property
Returns:
the marshalled value

_parseJson

protected T _parseJson(JCardValue value,
                       VCardDataType dataType,
                       VCardParameters parameters,
                       List<String> warnings)
Description copied from class: VCardPropertyScribe

Unmarshals a property from a JSON data stream (jCard).

This method should be overridden by child classes that wish to support jCard. The default implementation of this method will convert the jCard property value to a string and pass it into the VCardPropertyScribe._parseText(java.lang.String, ezvcard.VCardDataType, ezvcard.VCardVersion, ezvcard.parameter.VCardParameters, java.util.List) method.


The following paragraphs describe the way in which this method's default implementation converts a jCard value to a string:

If the jCard 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 vCard.
["x-foo", {}, "text", "the;value"] --> "the\;value"
["x-foo", {}, "text", 2] --> "2"

If the jCard 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 vCard.
["x-foo", {}, "text", "one", "two,three"] --> "one,two\,three"

If the jCard 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 jCard value starts with a JSON object, then it is converted to an empty string (JSON objects are not supported by this method).
["x-foo", , "text", {"one": 1}] --> ""}

For all other cases, behavior is undefined.

Overrides:
_parseJson in class VCardPropertyScribe<T extends TextListProperty>
Parameters:
value - the property's JSON value
dataType - the data type
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.
warnings - allows the programmer to alert the user to any note-worthy (but non-critical) issues that occurred during the unmarshalling process
Returns:
the unmarshalled property object

_newInstance

protected abstract T _newInstance()


Copyright © 2012-2014 Michael Angstadt. All Rights Reserved.