mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-26 14:02:06 +01:00
Needed to revert change in VCard.
git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@3410 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
parent
55d921645d
commit
892512c596
1 changed files with 41 additions and 70 deletions
|
@ -26,15 +26,16 @@ import org.jivesoftware.smack.XMPPConnection;
|
||||||
import org.jivesoftware.smack.XMPPException;
|
import org.jivesoftware.smack.XMPPException;
|
||||||
import org.jivesoftware.smack.filter.PacketIDFilter;
|
import org.jivesoftware.smack.filter.PacketIDFilter;
|
||||||
import org.jivesoftware.smack.packet.IQ;
|
import org.jivesoftware.smack.packet.IQ;
|
||||||
import org.jivesoftware.smack.packet.Packet;
|
|
||||||
import org.jivesoftware.smack.packet.PacketExtension;
|
|
||||||
import org.jivesoftware.smack.packet.XMPPError;
|
import org.jivesoftware.smack.packet.XMPPError;
|
||||||
|
import org.jivesoftware.smack.packet.Packet;
|
||||||
import org.jivesoftware.smack.util.StringUtils;
|
import org.jivesoftware.smack.util.StringUtils;
|
||||||
|
|
||||||
import java.io.BufferedInputStream;
|
import java.io.BufferedInputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.lang.reflect.Modifier;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.security.MessageDigest;
|
import java.security.MessageDigest;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
@ -123,35 +124,13 @@ public class VCard extends IQ {
|
||||||
/**
|
/**
|
||||||
* Set generic VCard field.
|
* Set generic VCard field.
|
||||||
*
|
*
|
||||||
* @param field value of field. Possible values: FN, NICKNAME, PHOTO, BDAY, JABBERID, MAILER, TZ,
|
* @param field value of field. Possible values: NICKNAME, PHOTO, BDAY, JABBERID, MAILER, TZ,
|
||||||
* GEO, TITLE, ROLE, LOGO, NOTE, PRODID, REV, SORT-STRING, SOUND, UID, URL, DESC.
|
* GEO, TITLE, ROLE, LOGO, NOTE, PRODID, REV, SORT-STRING, SOUND, UID, URL, DESC.
|
||||||
*/
|
*/
|
||||||
public String getField(String field) {
|
public String getField(String field) {
|
||||||
if ("FN".equals(field)) {
|
|
||||||
return buildFullName();
|
|
||||||
}
|
|
||||||
return (String) otherSimpleFields.get(field);
|
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.
|
* Set generic VCard field.
|
||||||
*
|
*
|
||||||
|
@ -183,13 +162,6 @@ public class VCard extends IQ {
|
||||||
return middleName;
|
return middleName;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the full name of the user, associated with this VCard.
|
|
||||||
*/
|
|
||||||
public String getFullName() {
|
|
||||||
return getField("FN");
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setMiddleName(String middleName) {
|
public void setMiddleName(String middleName) {
|
||||||
this.middleName = middleName;
|
this.middleName = middleName;
|
||||||
}
|
}
|
||||||
|
@ -525,40 +497,19 @@ public class VCard extends IQ {
|
||||||
private void copyFieldsFrom(VCard result) {
|
private void copyFieldsFrom(VCard result) {
|
||||||
if (result == null) result = new VCard();
|
if (result == null) result = new VCard();
|
||||||
|
|
||||||
homeAddr = result.homeAddr;
|
Field[] fields = VCard.class.getDeclaredFields();
|
||||||
homePhones = result.homePhones;
|
for (int i = 0; i < fields.length; i++) {
|
||||||
|
Field field = fields[i];
|
||||||
workAddr = result.workAddr;
|
if (field.getDeclaringClass() == VCard.class &&
|
||||||
workPhones = result.workPhones;
|
!Modifier.isFinal(field.getModifiers())) {
|
||||||
|
try {
|
||||||
firstName = result.firstName;
|
field.setAccessible(true);
|
||||||
lastName = result.lastName;
|
field.set(this, field.get(result));
|
||||||
middleName = result.middleName;
|
}
|
||||||
|
catch (IllegalAccessException e) {
|
||||||
emailHome = result.emailHome;
|
throw new RuntimeException("This cannot happen:" + field, e);
|
||||||
emailWork = result.emailWork;
|
}
|
||||||
|
|
||||||
organization = result.organization;
|
|
||||||
organizationUnit = result.organizationUnit;
|
|
||||||
|
|
||||||
otherSimpleFields = result.otherSimpleFields;
|
|
||||||
avatar = result.avatar;
|
|
||||||
|
|
||||||
setType(result.getType());
|
|
||||||
|
|
||||||
setError(result.getError());
|
|
||||||
setFrom(result.getFrom());
|
|
||||||
setTo(result.getTo());
|
|
||||||
setPacketID(result.getPacketID());
|
|
||||||
Iterator iterator = result.getExtensions();
|
|
||||||
while (iterator.hasNext()) {
|
|
||||||
addExtension((PacketExtension) iterator.next());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
iterator = result.getPropertyNames();
|
|
||||||
while(iterator.hasNext()) {
|
|
||||||
String key = (String) iterator.next();
|
|
||||||
setProperty(key, result.getProperty(key));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -589,7 +540,7 @@ public class VCard extends IQ {
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean hasNameField() {
|
private boolean hasNameField() {
|
||||||
return firstName != null || lastName != null || middleName != null || otherSimpleFields.containsKey("FN");
|
return firstName != null || lastName != null || middleName != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean hasOrganizationFields() {
|
private boolean hasOrganizationFields() {
|
||||||
|
@ -687,7 +638,7 @@ public class VCard extends IQ {
|
||||||
|
|
||||||
private void buildActualContent() {
|
private void buildActualContent() {
|
||||||
if (hasNameField()) {
|
if (hasNameField()) {
|
||||||
appendTag("FN", getFullName());
|
appendFN();
|
||||||
appendN();
|
appendN();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -755,9 +706,7 @@ public class VCard extends IQ {
|
||||||
Iterator it = otherSimpleFields.entrySet().iterator();
|
Iterator it = otherSimpleFields.entrySet().iterator();
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
Map.Entry entry = (Map.Entry) it.next();
|
Map.Entry entry = (Map.Entry) it.next();
|
||||||
String tag = entry.getKey().toString();
|
appendTag(entry.getKey().toString(), (String) entry.getValue());
|
||||||
if ("FN".equals(tag)) continue;
|
|
||||||
appendTag(tag, (String) entry.getValue());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -772,6 +721,28 @@ 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() {
|
private void appendN() {
|
||||||
appendTag("N", true, new ContentBuilder() {
|
appendTag("N", true, new ContentBuilder() {
|
||||||
public void addTagContent() {
|
public void addTagContent() {
|
||||||
|
|
Loading…
Reference in a new issue