* @return {@link String}
*/
public String buildVCardString() throws VCardBuildException
{
if(vcard == null) {
throw new VCardBuildException("Cannot build a null VCard.");
}
StringBuilder sb = new StringBuilder();
/*
* Begin
* Must be present.
*/
try {
buildBeginType(sb, vcard.getBegin());
}
catch(VCardBuildException vbe) {
if(isThrowsExceptions) {
throw new VCardBuildException(vbe.getMessage(), vbe);
}
else {
handleError(vbe.getMessage(), vbe, ErrorSeverity.FATAL);
}
}
/*
* Version
* Must be present.
*/
try {
buildVersionType(sb, vcard.getVersion());
}
catch(VCardBuildException vbe) {
if(isThrowsExceptions) {
throw new VCardBuildException(vbe.getMessage(), vbe);
}
else {
handleError(vbe.getMessage(), vbe, ErrorSeverity.FATAL);
}
}
/*
* N
* Must be present.
*/
try {
buildNType(sb, vcard.getN());
}
catch(VCardBuildException vbe) {
if(isThrowsExceptions) {
throw new VCardBuildException(vbe.getMessage(), vbe);
}
else {
handleError(vbe.getMessage(), vbe, ErrorSeverity.FATAL);
}
}
/*
* Formatted Name
* Must be present.
*/
try {
buildFNType(sb, vcard.getFN());
}
catch(VCardBuildException vbe) {
if(isThrowsExceptions) {
throw new VCardBuildException(vbe.getMessage(), vbe);
}
else {
handleError(vbe.getMessage(), vbe, ErrorSeverity.FATAL);
}
}
/*
* Name
*/
if(vcard.hasName()) {
try {
buildNameType(sb, vcard.getName());
}
catch(VCardBuildException vbe) {
if(isThrowsExceptions) {
throw new VCardBuildException(vbe.getMessage(), vbe);
}
else {
handleError(vbe.getMessage(), vbe, ErrorSeverity.FATAL);
}
}
}
/*
* Profile
*/
if(vcard.hasProfile()) {
try {
buildProfileType(sb, vcard.getProfile());
}
catch(VCardBuildException vbe) {
if(isThrowsExceptions) {
throw new VCardBuildException(vbe.getMessage(), vbe);
}
else {
handleError(vbe.getMessage(), vbe, ErrorSeverity.FATAL);
}
}
}
/*
* Source
*/
if(vcard.hasSource()) {
try {
buildSourceType(sb, vcard.getSource());
}
catch(VCardBuildException vbe) {
if(isThrowsExceptions) {
throw new VCardBuildException(vbe.getMessage(), vbe);
}
else {
handleError(vbe.getMessage(), vbe, ErrorSeverity.FATAL);
}
}
}
/*
* Nicknames
* TODO nicknames are present in Outlook mode with V2.1
*/
if(vcard.hasNicknames()) {
try {
buildNicknameType(sb, vcard.getNicknames());
}
catch(VCardBuildException vbe) {
if(isThrowsExceptions) {
throw new VCardBuildException(vbe.getMessage(), vbe);
}
else {
handleError(vbe.getMessage(), vbe, ErrorSeverity.WARNING);
}
}
}
/*
* Title
*/
if(vcard.hasTitle()) {
try {
buildTitleType(sb, vcard.getTitle());
}
catch(VCardBuildException vbe) {
if(isThrowsExceptions) {
throw new VCardBuildException(vbe.getMessage(), vbe);
}
else {
handleError(vbe.getMessage(), vbe, ErrorSeverity.WARNING);
}
}
}
/*
* Role
*/
if(vcard.hasRole()) {
try {
buildRoleType(sb, vcard.getRole());
}
catch(VCardBuildException vbe) {
if(isThrowsExceptions) {
throw new VCardBuildException(vbe.getMessage(), vbe);
}
else {
handleError(vbe.getMessage(), vbe, ErrorSeverity.WARNING);
}
}
}
/*
* Geographic Position
*/
if(vcard.hasGeo()) {
try {
buildGeoType(sb, vcard.getGeo());
}
catch(VCardBuildException vbe) {
if(isThrowsExceptions) {
throw new VCardBuildException(vbe.getMessage(), vbe);
}
else {
handleError(vbe.getMessage(), vbe, ErrorSeverity.WARNING);
}
}
}
/*
* Organizations
*/
if(vcard.hasOrg()) {
try {
buildOrgType(sb, vcard.getOrg());
}
catch(VCardBuildException vbe) {
if(isThrowsExceptions) {
throw new VCardBuildException(vbe.getMessage(), vbe);
}
else {
handleError(vbe.getMessage(), vbe, ErrorSeverity.WARNING);
}
}
}
/*
* Mailer
*/
if(vcard.hasMailer()) {
try {
buildMailerType(sb, vcard.getMailer());
}
catch(VCardBuildException vbe) {
if(isThrowsExceptions) {
throw new VCardBuildException(vbe.getMessage(), vbe);
}
else {
handleError(vbe.getMessage(), vbe, ErrorSeverity.WARNING);
}
}
}
/*
* Time Zone
*/
if(vcard.hasTz()) {
try {
buildTzType(sb, vcard.getTz());
}
catch(VCardBuildException vbe) {
if(isThrowsExceptions) {
throw new VCardBuildException(vbe.getMessage(), vbe);
}
else {
handleError(vbe.getMessage(), vbe, ErrorSeverity.WARNING);
}
}
}
/*
* URL
*/
if(vcard.hasUrls()) {
List<UrlType> urls = vcard.getUrls();
for(UrlType urlType : urls) {
try {
buildUrlType(sb, urlType);
}
catch(VCardBuildException vbe) {
if(isThrowsExceptions) {
throw new VCardBuildException(vbe.getMessage(), vbe);
}
else {
handleError(vbe.getMessage(), vbe, ErrorSeverity.WARNING);
}
}
}
}
/*
* Revision
*/
if(vcard.hasRev()) {
try {
buildRevType(sb, vcard.getRev());
}
catch(VCardBuildException vbe) {
if(isThrowsExceptions) {
throw new VCardBuildException(vbe.getMessage(), vbe);
}
else {
handleError(vbe.getMessage(), vbe, ErrorSeverity.WARNING);
}
}
}
/*
* UID
*/
if(vcard.hasUid()) {
try {
buildUidType(sb, vcard.getUid());
}
catch(VCardBuildException vbe) {
if(isThrowsExceptions) {
throw new VCardBuildException(vbe.getMessage(), vbe);
}
else {
handleError(vbe.getMessage(), vbe, ErrorSeverity.WARNING);
}
}
}
/*
* Birthday
*/
if(vcard.hasBDay()) {
try {
buildBDayType(sb, vcard.getBDay());
}
catch(VCardBuildException vbe) {
if(isThrowsExceptions) {
throw new VCardBuildException(vbe.getMessage(), vbe);
}
else {
handleError(vbe.getMessage(), vbe, ErrorSeverity.WARNING);
}
}
}
/*
* Addresses & Labels
*/
if(vcard.hasAdrs()) {
List<AdrType> addresses = vcard.getAdrs();
for(AdrType adrType : addresses) {
try {
buildAdrType(sb, adrType);
}
catch(VCardBuildException vbe) {
if(isThrowsExceptions) {
throw new VCardBuildException(vbe.getMessage(), vbe);
}
else {
handleError(vbe.getMessage(), vbe, ErrorSeverity.WARNING);
}
}
if(adrType.hasLabel()) {
LabelType label = adrType.getLabel();
try {
buildLabelType(sb, label);
}
catch(VCardBuildException vbe) {
if(isThrowsExceptions) {
throw new VCardBuildException(vbe.getMessage(), vbe);
}
else {
handleError(vbe.getMessage(), vbe, ErrorSeverity.WARNING);
}
}
}
}
}
/*
* Telephone Numbers
*/
if(vcard.hasTels()) {
List<TelType> telephones = vcard.getTels();
for(TelType telType : telephones) {
try {
buildTelType(sb, telType);
}
catch(VCardBuildException vbe) {
if(isThrowsExceptions) {
throw new VCardBuildException(vbe.getMessage(), vbe);
}
else {
handleError(vbe.getMessage(), vbe, ErrorSeverity.WARNING);
}
}
}
}
/*
* Email
*/
if(vcard.hasEmails()) {
List<EmailType> emails = vcard.getEmails();
for(EmailType emailType : emails) {
try {
buildEmailType(sb, emailType);
}
catch(VCardBuildException vbe) {
if(isThrowsExceptions) {
throw new VCardBuildException(vbe.getMessage(), vbe);
}
else {
handleError(vbe.getMessage(), vbe, ErrorSeverity.WARNING);
}
}
}
}
/*
* Notes
*/
if(vcard.hasNotes()) {
List<NoteType> notes = vcard.getNotes();
for(NoteType noteType : notes) {
try {
buildNoteType(sb, noteType);
}
catch(VCardBuildException vbe) {
if(isThrowsExceptions) {
throw new VCardBuildException(vbe.getMessage(), vbe);
}
else {
handleError(vbe.getMessage(), vbe, ErrorSeverity.WARNING);
}
}
}
}
/*
* Categories
*/
if(vcard.hasCategories()) {
try {
buildCategoriesType(sb, vcard.getCategories());
}
catch(VCardBuildException vbe) {
if(isThrowsExceptions) {
throw new VCardBuildException(vbe.getMessage(), vbe);
}
else {
handleError(vbe.getMessage(), vbe, ErrorSeverity.WARNING);
}
}
}
/*
* Security Class
*/
if(vcard.hasSecurityClass()) {
try {
buildClassType(sb, vcard.getSecurityClass());
}
catch(VCardBuildException vbe) {
if(isThrowsExceptions) {
throw new VCardBuildException(vbe.getMessage(), vbe);
}
else {
handleError(vbe.getMessage(), vbe, ErrorSeverity.WARNING);
}
}
}
/*
* Product ID
*/
if(vcard.hasProdId()) {
try {
buildProdIdType(sb, vcard.getProdId());
}
catch(VCardBuildException vbe) {
if(isThrowsExceptions) {
throw new VCardBuildException(vbe.getMessage(), vbe);
}
else {
handleError(vbe.getMessage(), vbe, ErrorSeverity.WARNING);
}
}
}
/*
* Sort String
*/
if(vcard.hasSortString()) {
try {
buildSortStringType(sb, vcard.getSortString());
}
catch(VCardBuildException vbe) {
if(isThrowsExceptions) {
throw new VCardBuildException(vbe.getMessage(), vbe);
}
else {
handleError(vbe.getMessage(), vbe, ErrorSeverity.WARNING);
}
}
}
/*
* Keys
*/
if(vcard.hasKeys()) {
List<KeyType> keys = vcard.getKeys();
for(KeyType keyType : keys) {
try {
buildKeyType(sb, keyType);
}
catch(VCardBuildException vbe) {
if(isThrowsExceptions) {
throw new VCardBuildException(vbe.getMessage(), vbe);
}
else {
handleError(vbe.getMessage(), vbe, ErrorSeverity.WARNING);
}
}
}
}
/*
* Photos
*/
if(vcard.hasPhotos()) {
List<PhotoType> photos = vcard.getPhotos();
for(PhotoType photoType : photos) {
try {
buildPhotoType(sb, photoType);
}
catch(VCardBuildException vbe) {
if(isThrowsExceptions) {
throw new VCardBuildException(vbe.getMessage(), vbe);
}
else {
handleError(vbe.getMessage(), vbe, ErrorSeverity.WARNING);
}
}
}
}
/*
* Logos
*/
if(vcard.hasLogos()) {
List<LogoType> logos = vcard.getLogos();
for(LogoType logoType : logos) {
try {
buildLogoType(sb, logoType);
}
catch(VCardBuildException vbe) {
if(isThrowsExceptions) {
throw new VCardBuildException(vbe.getMessage(), vbe);
}
else {
handleError(vbe.getMessage(), vbe, ErrorSeverity.WARNING);
}
}
}
}
/*
* Sounds
*/
if(vcard.hasSounds()) {
List<SoundType> sounds = vcard.getSounds();
for(SoundType soundType : sounds) {
try {
buildSoundType(sb, soundType);
}
catch(VCardBuildException vbe) {
if(isThrowsExceptions) {
throw new VCardBuildException(vbe.getMessage(), vbe);
}
else {
handleError(vbe.getMessage(), vbe, ErrorSeverity.WARNING);
}
}
}
}
/*
* Agents
*/
if(vcard.hasAgents()) {
List<AgentType> agents = vcard.getAgents();
for(AgentType agentType : agents) {
try {
buildAgentType(sb, agentType);
}
catch(VCardBuildException vbe) {
if(isThrowsExceptions) {
throw new VCardBuildException(vbe.getMessage(), vbe);
}
else {
handleError(vbe.getMessage(), vbe, ErrorSeverity.WARNING);
}
}
}
}
/*
* IMPP. RFC 4770 extension
*/
if(vcard.hasImpps()) {
List<ImppType> impps = vcard.getIMPPs();
for(ImppType imppType : impps) {
try {
buildImppType(sb, imppType);
}
catch(VCardBuildException vbe) {
if(isThrowsExceptions) {
throw new VCardBuildException(vbe.getMessage(), vbe);
}
else {
handleError(vbe.getMessage(), vbe, ErrorSeverity.WARNING);
}
}
}
}
/*
* Extensions
*/
if(vcard.hasExtendedTypes()) {
List<ExtendedType> extensions = vcard.getExtendedTypes();
for(ExtendedType extendedType : extensions) {
try {
buildExtendedType(sb, extendedType);
}
catch(VCardBuildException vbe) {
if(isThrowsExceptions) {
throw new VCardBuildException(vbe.getMessage(), vbe);
}
else {
handleError(vbe.getMessage(), vbe, ErrorSeverity.WARNING);
}
}
}
}
/*
* End
* Must be present.
*/
try {
buildEndType(sb, vcard.getEnd());
}
catch(VCardBuildException vbe) {
if(isThrowsExceptions) {
throw new VCardBuildException(vbe.getMessage(), vbe);
}
else {
handleError(vbe.getMessage(), vbe, ErrorSeverity.FATAL);
}
}