mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2025-09-10 18:59:41 +02:00
Fixed vCard issues. SMACK-116
git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@3315 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
parent
07f5fc9ef6
commit
237ab44301
3 changed files with 145 additions and 60 deletions
|
@ -124,13 +124,35 @@ public class VCard extends IQ {
|
|||
/**
|
||||
* Set generic VCard field.
|
||||
*
|
||||
* @param field value of field. Possible values: NICKNAME, PHOTO, BDAY, JABBERID, MAILER, TZ,
|
||||
* @param field value of field. Possible values: FN, NICKNAME, PHOTO, BDAY, JABBERID, MAILER, TZ,
|
||||
* GEO, TITLE, ROLE, LOGO, NOTE, PRODID, REV, SORT-STRING, SOUND, UID, URL, DESC.
|
||||
*/
|
||||
public String getField(String field) {
|
||||
if ("FN".equals(field)) {
|
||||
return buildFullName();
|
||||
}
|
||||
return (String) otherSimpleFields.get(field);
|
||||
}
|
||||
|
||||
private String buildFullName() {
|
||||
if (otherSimpleFields.containsKey("FN")) {
|
||||
return otherSimpleFields.get("FN").toString().trim();
|
||||
}
|
||||
else {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
if (firstName != null) {
|
||||
sb.append(firstName).append(' ');
|
||||
}
|
||||
if (middleName != null) {
|
||||
sb.append(middleName).append(' ');
|
||||
}
|
||||
if (lastName != null) {
|
||||
sb.append(lastName);
|
||||
}
|
||||
return sb.toString().trim();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set generic VCard field.
|
||||
*
|
||||
|
@ -162,6 +184,13 @@ public class VCard extends IQ {
|
|||
return middleName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the full name of the user, associated with this VCard.
|
||||
*/
|
||||
public String getFullName() {
|
||||
return getField("FN");
|
||||
}
|
||||
|
||||
public void setMiddleName(String middleName) {
|
||||
this.middleName = middleName;
|
||||
}
|
||||
|
@ -540,7 +569,7 @@ public class VCard extends IQ {
|
|||
}
|
||||
|
||||
private boolean hasNameField() {
|
||||
return firstName != null || lastName != null || middleName != null;
|
||||
return firstName != null || lastName != null || middleName != null || otherSimpleFields.containsKey("FN");
|
||||
}
|
||||
|
||||
private boolean hasOrganizationFields() {
|
||||
|
@ -638,7 +667,7 @@ public class VCard extends IQ {
|
|||
|
||||
private void buildActualContent() {
|
||||
if (hasNameField()) {
|
||||
appendFN();
|
||||
appendTag("FN", getFullName());
|
||||
appendN();
|
||||
}
|
||||
|
||||
|
@ -706,7 +735,9 @@ public class VCard extends IQ {
|
|||
Iterator it = otherSimpleFields.entrySet().iterator();
|
||||
while (it.hasNext()) {
|
||||
Map.Entry entry = (Map.Entry) it.next();
|
||||
appendTag(entry.getKey().toString(), (String) entry.getValue());
|
||||
String tag = entry.getKey().toString();
|
||||
if ("FN".equals(tag)) continue;
|
||||
appendTag(tag, (String) entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -721,28 +752,6 @@ public class VCard extends IQ {
|
|||
}
|
||||
}
|
||||
|
||||
private void appendField(String tag) {
|
||||
String value = (String) otherSimpleFields.get(tag);
|
||||
appendTag(tag, value);
|
||||
}
|
||||
|
||||
private void appendFN() {
|
||||
final ContentBuilder contentBuilder = new ContentBuilder() {
|
||||
public void addTagContent() {
|
||||
if (firstName != null) {
|
||||
sb.append(firstName + ' ');
|
||||
}
|
||||
if (middleName != null) {
|
||||
sb.append(middleName + ' ');
|
||||
}
|
||||
if (lastName != null) {
|
||||
sb.append(lastName);
|
||||
}
|
||||
}
|
||||
};
|
||||
appendTag("FN", true, contentBuilder);
|
||||
}
|
||||
|
||||
private void appendN() {
|
||||
appendTag("N", true, new ContentBuilder() {
|
||||
public void addTagContent() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue