|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectezvcard.types.VCardType
ezvcard.types.BinaryType<KeyTypeParameter>
ezvcard.types.KeyType
public class KeyType
A public key for encryption.
Adding a key
VCard vcard = new VCard(); //URL (vCard 4.0 only; KEYs cannot have URLs in vCard 2.1 and 3.0) KeyType key = new KeyType("http://www.mywebsite.com/pubkey.pgp", KeyTypeParameter.PGP); vcard.addKey(key); //binary data byte data[] = ... key = new KeyType(data, KeyTypeParameter.PGP); vcard.addKey(key); //plain text value key = new KeyType(); key.setText("...", KeyTypeParameter.PGP); vcard.addKey(key); //if "KeyTypeParameter" does not have the pre-defined constant that you need, then create a new instance //arg 1: the value of the 2.1/3.0 TYPE parameter //arg 2: the value to use for the 4.0 MEDIATYPE parameter and for 4.0 data URIs //arg 3: the file extension of the data type (optional) KeyTypeParameter param = new KeyTypeParameter("mykey", "application/my-key", "mkey"); key = new KeyType("http://www.mywebsite.com/pubkey.enc", param); vcard.addKey(key);
Getting the keys
VCard vcard = ... int fileCount = 0; for (KeyType key : vcard.getKeys()){ //the key will have either a URL or a binary data //only 4.0 vCards are allowed to use URLs for keys if (key.getData() == null){ System.out.println("Key URL: " + key.getUrl()); } else { KeyTypeParameter type = key.getContentType(); if (type == null) { //the vCard may not have any content type data associated with the key System.out.println("Saving a key file..."); } else { System.out.println("Saving a \"" + type.getMediaType() + "\" file..."); } String folder; if (type == KeyTypeParameter.PGP){ //it is safe to use "==" instead of "equals()" folder = "pgp-keys"; } else { folder = "other-keys"; } byte data[] = key.getData(); String filename = "key" + fileCount; if (type != null && type.getExtension() != null){ filename += "." + type.getExtension(); } OutputStream out = new FileOutputStream(new File(folder, filename)); out.write(data); out.close(); fileCount++; } }
vCard property name: KEY
vCard versions: 2.1, 3.0, 4.0
Field Summary | |
---|---|
static String |
NAME
|
Fields inherited from class ezvcard.types.BinaryType |
---|
contentType, data, url |
Fields inherited from class ezvcard.types.VCardType |
---|
group, subTypes, typeName |
Constructor Summary | |
---|---|
KeyType()
|
|
KeyType(byte[] data,
KeyTypeParameter type)
|
|
KeyType(File file,
KeyTypeParameter type)
|
|
KeyType(InputStream in,
KeyTypeParameter type)
|
|
KeyType(String url,
KeyTypeParameter type)
|
Method Summary | |
---|---|
protected KeyTypeParameter |
buildMediaTypeObj(String mediaType)
Builds a MediaTypeParameter object based on the information in
the MEDIATYPE parameter or data URI of 4.0 vCards. |
protected KeyTypeParameter |
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,
KeyTypeParameter 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 |
doUnmarshalXml(XCardElement element,
List<String> warnings,
CompatibilityMode compatibilityMode)
Unmarshals the type from an xCard (XML document). |
String |
getText()
Gets the plain text representation of the key. |
void |
setText(String text,
KeyTypeParameter type)
Sets a plain text representation of the key. |
Methods inherited from class ezvcard.types.BinaryType |
---|
addPid, doUnmarshalText, getAltId, getContentType, getData, getPids, getPref, getType, getUrl, removePids, setAltId, setContentType, setData, setPref, setType, setUrl |
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 |
---|
public static final String NAME
Constructor Detail |
---|
public KeyType()
public KeyType(byte[] data, KeyTypeParameter type)
data
- the binary datatype
- the type of key (e.g. PGP)public KeyType(String url, KeyTypeParameter type)
url
- the URL to the key (vCard 4.0 only)type
- the type of key (e.g. PGP)public KeyType(InputStream in, KeyTypeParameter type) throws IOException
in
- an input stream to the binary data (will be closed)type
- the content type (e.g. PGP)
IOException
- if there's a problem reading from the input streampublic KeyType(File file, KeyTypeParameter type) throws IOException
file
- the key filetype
- the content type (e.g. PGP)
IOException
- if there's a problem reading from the fileMethod Detail |
---|
public void setText(String text, KeyTypeParameter type)
text
- the key in plain texttype
- the key typepublic String getText()
protected KeyTypeParameter buildTypeObj(String type)
BinaryType
MediaTypeParameter
object based on the value of the TYPE
parameter in 2.1/3.0 vCards.
buildTypeObj
in class BinaryType<KeyTypeParameter>
type
- the TYPE value
protected KeyTypeParameter buildMediaTypeObj(String mediaType)
BinaryType
MediaTypeParameter
object based on the information in
the MEDIATYPE parameter or data URI of 4.0 vCards.
buildMediaTypeObj
in class BinaryType<KeyTypeParameter>
mediaType
- the media type string (e.g. "image/jpeg")
protected void doMarshalSubTypes(VCardSubTypes copy, VCardVersion version, List<String> warnings, CompatibilityMode compatibilityMode, VCard vcard)
VCardType
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.
doMarshalSubTypes
in class BinaryType<KeyTypeParameter>
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 generatedwarnings
- allows the programmer to alert the user to any
note-worthy (but non-critical) issues that occurred during the
marshalling processcompatibilityMode
- allows the programmer to customize the
marshalling process depending on the expected consumer of the vCardvcard
- the VCard
object that is being marshalledprotected void doMarshalText(StringBuilder sb, VCardVersion version, List<String> warnings, CompatibilityMode compatibilityMode)
VCardType
doMarshalText
in class BinaryType<KeyTypeParameter>
sb
- the buffer to add the marshalled value toversion
- the version vCard that is being generatedwarnings
- allows the programmer to alert the user to any
note-worthy (but non-critical) issues that occurred during the
marshalling processcompatibilityMode
- allows the programmer to customize the
marshalling process depending on the expected consumer of the vCardprotected void doMarshalXml(XCardElement parent, List<String> warnings, CompatibilityMode compatibilityMode)
VCardType
doMarshalXml
in class BinaryType<KeyTypeParameter>
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 processcompatibilityMode
- allows the programmer to customize the
marshalling process depending on the expected consumer of the vCardprotected void doUnmarshalXml(XCardElement element, List<String> warnings, CompatibilityMode compatibilityMode)
VCardType
doUnmarshalXml
in class BinaryType<KeyTypeParameter>
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 processcompatibilityMode
- allows the programmer to customize the
unmarshalling process depending on where the vCard came fromprotected void doUnmarshalHtml(HCardElement element, List<String> warnings)
VCardType
doUnmarshalHtml
in class BinaryType<KeyTypeParameter>
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 processprotected void cannotUnmarshalValue(String value, VCardVersion version, List<String> warnings, CompatibilityMode compatibilityMode, KeyTypeParameter contentType)
BinaryType
cannotUnmarshalValue
in class BinaryType<KeyTypeParameter>
value
- the valueversion
- the version of the vCardwarnings
- the warningscompatibilityMode
- the compatibility modecontentType
- the content type of the resource of null if unknown
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |