ezvcard.types
Class BinaryType<T extends MediaTypeParameter>

java.lang.Object
  extended by ezvcard.types.VCardType
      extended by ezvcard.types.BinaryType<T>
Type Parameters:
T - the class used for representing the content type of the resource
All Implemented Interfaces:
Comparable<VCardType>
Direct Known Subclasses:
KeyType, LogoType, PhotoType, SoundType

public abstract class BinaryType<T extends MediaTypeParameter>
extends VCardType

Represents a Type that contains binary data (for example, the "PHOTO" type).

Author:
Michael Angstadt

Field Summary
protected  T contentType
          The content type of the resource (e.g.
protected  byte[] data
          The decoded data.
protected  String url
          The URL to the resource.
 
Fields inherited from class ezvcard.types.VCardType
group, subTypes, typeName
 
Constructor Summary
BinaryType(String name)
           
BinaryType(String name, byte[] data, T type)
           
BinaryType(String name, File file, T type)
           
BinaryType(String name, InputStream in, T type)
           
BinaryType(String name, String url, T type)
           
 
Method Summary
 void addPid(int localId, int clientPidMapRef)
          Adds a PID value.
protected abstract  T buildMediaTypeObj(String mediaType)
          Builds a MediaTypeParameter object based on the information in the MEDIATYPE parameter or data URI of 4.0 vCards.
protected abstract  T buildTypeObj(String type)
          Builds a MediaTypeParameter object based on the value of the TYPE parameter in 2.1/3.0 vCards.
protected  void cannotUnmarshalValue(String value, VCardVersion version, List<String> warnings, CompatibilityMode compatibilityMode, T contentType)
          Called if the unmarshalling code cannot determine how to unmarshal the value.
protected  void doMarshalSubTypes(VCardSubTypes copy, VCardVersion version, List<String> warnings, CompatibilityMode compatibilityMode, VCard vcard)
          Gets the sub types that will be sent over the wire.
protected  void doMarshalText(StringBuilder sb, VCardVersion version, List<String> warnings, CompatibilityMode compatibilityMode)
          Converts this type object to a string for sending over the wire.
protected  void doMarshalXml(XCardElement parent, List<String> warnings, CompatibilityMode compatibilityMode)
          Marshals this type for inclusion in an xCard (XML document).
protected  void doUnmarshalHtml(HCardElement element, List<String> warnings)
          Unmarshals the type from an hCard (HTML document).
protected  void doUnmarshalText(String value, VCardVersion version, List<String> warnings, CompatibilityMode compatibilityMode)
          Unmarshals the type value from off the wire.
protected  void doUnmarshalXml(XCardElement element, List<String> warnings, CompatibilityMode compatibilityMode)
          Unmarshals the type from an xCard (XML document).
 String getAltId()
          Gets the ALTID.
 T getContentType()
          Gets the content type of the resource.
 byte[] getData()
          Gets the binary data of the resource.
 List<Integer[]> getPids()
          Gets all PID parameter values.
 Integer getPref()
          Gets the preference value.
 String getType()
          Gets the vCard 4.0 TYPE parameter.
 String getUrl()
          Gets the URL to the resource
 void removePids()
          Removes all PID values.
 void setAltId(String altId)
          Sets the ALTID.
 void setContentType(T contentType)
          Sets the content type of the resource.
 void setData(byte[] data, T type)
          Sets the binary data of the resource.
 void setPref(Integer pref)
          Sets the preference value.
 void setType(String type)
          Sets the vCard 4.0 TYPE parameter.
 void setUrl(String url, T type)
          Sets the URL to the resource.
 
Methods inherited from class ezvcard.types.VCardType
compareTo, getGroup, getQName, getSubTypes, getSupportedVersions, getTypeName, marshalSubTypes, marshalText, marshalXml, setGroup, unmarshalHtml, unmarshalText, unmarshalXml
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

data

protected byte[] data
The decoded data.


url

protected String url
The URL to the resource.


contentType

protected T extends MediaTypeParameter contentType
The content type of the resource (e.g. "JPEG image").

Constructor Detail

BinaryType

public BinaryType(String name)
Parameters:
name - the type name (e.g. "PHOTO")

BinaryType

public BinaryType(String name,
                  String url,
                  T type)
Parameters:
name - the type name (e.g. "PHOTO")
url - the URL to the resource
type - the content type

BinaryType

public BinaryType(String name,
                  byte[] data,
                  T type)
Parameters:
name - the type name (e.g. "PHOTO")
data - the binary data
type - the content type

BinaryType

public BinaryType(String name,
                  InputStream in,
                  T type)
           throws IOException
Parameters:
name - the type name (e.g. "PHOTO")
in - an input stream to the binary data (will be closed)
type - the content type
Throws:
IOException

BinaryType

public BinaryType(String name,
                  File file,
                  T type)
           throws IOException
Parameters:
name - the type name (e.g. "PHOTO")
file - the file containing the binary data
type - the content type
Throws:
IOException
Method Detail

getData

public byte[] getData()
Gets the binary data of the resource.

Returns:
the binary data or null if there is none

setData

public void setData(byte[] data,
                    T type)
Sets the binary data of the resource.

Parameters:
data - the binary data
type - the content type (e.g. "JPEG image")

getUrl

public String getUrl()
Gets the URL to the resource

Returns:
the URL or null if there is none

setUrl

public void setUrl(String url,
                   T type)
Sets the URL to the resource.

Parameters:
url - the URL
type - the content type (e.g. "JPEG image")

getContentType

public T getContentType()
Gets the content type of the resource.

Returns:
the content type (e.g. "JPEG image")

setContentType

public void setContentType(T contentType)
Sets the content type of the resource.

Parameters:
contentType - the content type (e.g. "JPEG image")

getType

public String getType()
Gets the vCard 4.0 TYPE parameter. This should NOT be used to get the TYPE parameter for 2.1/3.0 vCards. Use getContentType() instead.

vCard versions: 4.0

Returns:
the TYPE value (typically, this will be either "work" or "home") or null if it doesn't exist

setType

public void setType(String type)
Sets the vCard 4.0 TYPE parameter. This should NOT be used to set the TYPE parameter for 2.1/3.0 vCards. Use setContentType(T) instead.

vCard versions: 4.0

Parameters:
type - the TYPE value (should be either "work" or "home") or null to remove

getPids

public List<Integer[]> getPids()
Gets all PID parameter values.

vCard versions: 4.0

Returns:
the PID values or empty set if there are none
See Also:
VCardSubTypes.getPids()

addPid

public void addPid(int localId,
                   int clientPidMapRef)
Adds a PID value.

vCard versions: 4.0

Parameters:
localId - the local ID
clientPidMapRef - the ID used to reference the property's globally unique identifier in the CLIENTPIDMAP property.
See Also:
VCardSubTypes.addPid(int, int)

removePids

public void removePids()
Removes all PID values.

vCard versions: 4.0

See Also:
VCardSubTypes.removePids()

getPref

public Integer getPref()
Gets the preference value.

vCard versions: 4.0

Returns:
the preference value or null if it doesn't exist
See Also:
VCardSubTypes.getPref()

setPref

public void setPref(Integer pref)
Sets the preference value.

vCard versions: 4.0

Parameters:
pref - the preference value or null to remove
See Also:
VCardSubTypes.setPref(java.lang.Integer)

getAltId

public String getAltId()
Gets the ALTID.

vCard versions: 4.0

Returns:
the ALTID or null if it doesn't exist
See Also:
VCardSubTypes.getAltId()

setAltId

public void setAltId(String altId)
Sets the ALTID.

vCard versions: 4.0

Parameters:
altId - the ALTID or null to remove
See Also:
VCardSubTypes.setAltId(java.lang.String)

doMarshalSubTypes

protected void doMarshalSubTypes(VCardSubTypes copy,
                                 VCardVersion version,
                                 List<String> warnings,
                                 CompatibilityMode compatibilityMode,
                                 VCard vcard)
Description copied from class: VCardType
Gets the sub types that will be sent over the wire.

If this method is NOT overridden, then the type's sub types will be sent over the wire as-is. In other words, whatever is in the VCardType.subTypes field will be sent. Child classes can override this method in order to modify the sub types before they are marshalled.

Overrides:
doMarshalSubTypes in class VCardType
Parameters:
copy - the sub types that will be marshalled into the vCard. This object is a copy of the VCardType.subTypes field, so any modifications done to this object will not effect the state of the field.
version - the version vCard that is being generated
warnings - allows the programmer to alert the user to any note-worthy (but non-critical) issues that occurred during the marshalling process
compatibilityMode - allows the programmer to customize the marshalling process depending on the expected consumer of the vCard
vcard - the VCard object that is being marshalled

doMarshalText

protected void doMarshalText(StringBuilder sb,
                             VCardVersion version,
                             List<String> warnings,
                             CompatibilityMode compatibilityMode)
Description copied from class: VCardType
Converts this type object to a string for sending over the wire. It is NOT responsible for folding.

Specified by:
doMarshalText in class VCardType
Parameters:
sb - the buffer to add the marshalled value to
version - the version vCard that is being generated
warnings - allows the programmer to alert the user to any note-worthy (but non-critical) issues that occurred during the marshalling process
compatibilityMode - allows the programmer to customize the marshalling process depending on the expected consumer of the vCard

doUnmarshalText

protected void doUnmarshalText(String value,
                               VCardVersion version,
                               List<String> warnings,
                               CompatibilityMode compatibilityMode)
Description copied from class: VCardType
Unmarshals the type value from off the wire.

Specified by:
doUnmarshalText in class VCardType
Parameters:
value - the unfolded value from off the wire. If the wire value is in the "quoted-printable" encoding, it will be decoded.
version - the version of the vCard that is being read or null if the VERSION type has not been parsed yet (v3.0 and v4.0 require that the VERSION type be at the top of the vCard, but v2.1 has no such requirement)
warnings - allows the programmer to alert the user to any note-worthy (but non-critical) issues that occurred during the unmarshalling process
compatibilityMode - allows you to customize the unmarshalling process depending on where the vCard came from

doMarshalXml

protected void doMarshalXml(XCardElement parent,
                            List<String> warnings,
                            CompatibilityMode compatibilityMode)
Description copied from class: VCardType
Marshals this type for inclusion in an xCard (XML document). All child classes SHOULD override this, but are not required to.

Overrides:
doMarshalXml in class VCardType
Parameters:
parent - the XML element that the type's value will be inserted into. For example, this would be the "<fn>" element for the "FN" type.
warnings - allows the programmer to alert the user to any note-worthy (but non-critical) issues that occurred during the marshalling process
compatibilityMode - allows the programmer to customize the marshalling process depending on the expected consumer of the vCard

doUnmarshalXml

protected void doUnmarshalXml(XCardElement element,
                              List<String> warnings,
                              CompatibilityMode compatibilityMode)
Description copied from class: VCardType
Unmarshals the type from an xCard (XML document).

Overrides:
doUnmarshalXml in class VCardType
Parameters:
element - the XML element that contains the type data. For example, this would be the "<fn>" element for the "FN" type. This object will NOT include the "<parameters>" child element (it is removed after being unmarshalled into a VCardSubTypes object).
warnings - allows the programmer to alert the user to any note-worthy (but non-critical) issues that occurred during the unmarshalling process
compatibilityMode - allows the programmer to customize the unmarshalling process depending on where the vCard came from

doUnmarshalHtml

protected void doUnmarshalHtml(HCardElement element,
                               List<String> warnings)
Description copied from class: VCardType
Unmarshals the type from an hCard (HTML document).

Overrides:
doUnmarshalHtml in class VCardType
Parameters:
element - the HTML element that contains the type data.
warnings - allows the programmer to alert the user to any note-worthy (but non-critical) issues that occurred during the unmarshalling process

cannotUnmarshalValue

protected void cannotUnmarshalValue(String value,
                                    VCardVersion version,
                                    List<String> warnings,
                                    CompatibilityMode compatibilityMode,
                                    T contentType)
Called if the unmarshalling code cannot determine how to unmarshal the value.

Parameters:
value - the value
version - the version of the vCard
warnings - the warnings
compatibilityMode - the compatibility mode
contentType - the content type of the resource of null if unknown

buildMediaTypeObj

protected abstract T buildMediaTypeObj(String mediaType)
Builds a MediaTypeParameter object based on the information in the MEDIATYPE parameter or data URI of 4.0 vCards.

Parameters:
mediaType - the media type string (e.g. "image/jpeg")
Returns:
the parameter object

buildTypeObj

protected abstract T buildTypeObj(String type)
Builds a MediaTypeParameter object based on the value of the TYPE parameter in 2.1/3.0 vCards.

Parameters:
type - the TYPE value
Returns:
the parameter object


Copyright © 2012-2013. All Rights Reserved.