contact and account info modifications for jabber and icq

cusax-fix
Damian Minkov 18 years ago
parent f88c23fca1
commit 712790e4f5

@ -40,7 +40,7 @@ public class InfoRetreiver
/**
* As all the Full User Info comes in
* sequences of 8 packets acording to the
* sequences of 8 packets according to the
* requestID we keep the stored Info so far.
*/
private static Hashtable retreivedInfo = new Hashtable();
@ -132,9 +132,13 @@ protected List getContactDetails(String uin)
icqProvider.getAimConnection().getInfoService().getOscarConnection()
.sendSnacRequest(infoRequest, responseRetriever);
responseRetriever.waitForLastInfo(10000);
responseRetriever.waitForLastInfo(60000);
result = responseRetriever.result;
if(result == null)
result = new LinkedList();
retreivedDetails.put(uin, result);
}
@ -160,34 +164,42 @@ public void handleResponse(SnacResponseEvent e)
if (snac instanceof MetaBasicInfoCmd)
{
logger.info("received basic info");
readBasicUserInfo((MetaBasicInfoCmd)snac);
}
else if (snac instanceof MetaMoreInfoCmd)
{
logger.info("received meta more info");
readMoreUserInfo((MetaMoreInfoCmd)snac);
}
else if (snac instanceof MetaEmailInfoCmd)
{
logger.info("received email info");
readEmailUserInfo((MetaEmailInfoCmd)snac);
}
else if (snac instanceof MetaHomepageCategoryInfoCmd)
{
logger.info("received home page info");
readHomePageUserInfo((MetaHomepageCategoryInfoCmd)snac);
}
else if (snac instanceof MetaWorkInfoCmd)
{
logger.info("received work info");
readWorkUserInfo((MetaWorkInfoCmd)snac);
}
else if (snac instanceof MetaNotesInfoCmd)
{
logger.info("received notes info");
readUserAboutInfo((MetaNotesInfoCmd)snac);
}
else if (snac instanceof MetaInterestsInfoCmd)
{
logger.info("received interest info");
readInterestsUserInfo((MetaInterestsInfoCmd)snac);
}
else if (snac instanceof MetaAffiliationsInfoCmd)
{
logger.info("received affiliations info");
readAffilationsUserInfo((MetaAffiliationsInfoCmd)snac);
result =

@ -99,6 +99,8 @@ public class OperationSetServerStoredAccountInfoIcqImpl
*/
public Iterator getAllAvailableDetails()
{
assertConnected();
return infoRetreiver.getContactDetails(uin).iterator();
}
@ -113,6 +115,8 @@ public Iterator getAllAvailableDetails()
*/
public Iterator getDetails(Class detailClass)
{
assertConnected();
return infoRetreiver.getDetails(uin, detailClass);
}
@ -128,6 +132,8 @@ public Iterator getDetails(Class detailClass)
*/
public Iterator getDetailsAndDescendants(Class detailClass)
{
assertConnected();
return infoRetreiver.getDetailsAndDescendants(uin, detailClass);
}
@ -169,6 +175,24 @@ public boolean isDetailClassSupported(Class detailClass)
{
return supportedTypes.get(detailClass) != null;
}
/**
* Utility method throwing an exception if the icq stack is not properly
* initialized.
* @throws java.lang.IllegalStateException if the underlying ICQ stack is
* not registered and initialized.
*/
private void assertConnected() throws IllegalStateException
{
if (icqProvider == null)
throw new IllegalStateException(
"The icq provider must be non-null and signed on the ICQ "
+"service before being able to communicate.");
if (!icqProvider.isRegistered())
throw new IllegalStateException(
"The icq provider must be signed on the ICQ service before "
+"being able to communicate.");
}
/**
* Adds the specified detail to the list of details registered on-line
@ -194,6 +218,8 @@ public boolean isDetailClassSupported(Class detailClass)
public void addDetail(GenericDetail detail) throws IllegalArgumentException,
OperationFailedException, ArrayIndexOutOfBoundsException
{
assertConnected();
if(!isDetailClassSupported(detail.getClass()))
throw new IllegalArgumentException(
"implementation does not support such details " +
@ -335,6 +361,8 @@ else if(detail.equals(ServerStoredDetails.GenderDetail.MALE))
public boolean removeDetail(GenericDetail detail) throws
OperationFailedException
{
assertConnected();
// as there is no remove method for the details we will
// set it with empty or default value
@ -457,6 +485,8 @@ public boolean replaceDetail(GenericDetail currentDetailValue,
GenericDetail newDetailValue) throws
ClassCastException, OperationFailedException
{
assertConnected();
if(!newDetailValue.getClass().equals(currentDetailValue.getClass()))
throw new ClassCastException("New value to be replaced is not as the current one");

@ -17,11 +17,17 @@ public class OperationSetServerStoredContactInfoIcqImpl
implements OperationSetServerStoredContactInfo
{
private InfoRetreiver infoRetreiver;
/**
* The icq provider that created us.
*/
private ProtocolProviderServiceIcqImpl icqProvider = null;
protected OperationSetServerStoredContactInfoIcqImpl
(InfoRetreiver infoRetreiver)
(InfoRetreiver infoRetreiver, ProtocolProviderServiceIcqImpl icqProvider)
{
this.infoRetreiver = infoRetreiver;
this.icqProvider = icqProvider;
}
/**
* returns the user details from the specified class or its descendants
@ -35,6 +41,8 @@ public class OperationSetServerStoredContactInfoIcqImpl
*/
public Iterator getDetailsAndDescendants(Contact contact, Class detailClass)
{
assertConnected();
if(detailClass.equals(ServerStoredDetails.ImageDetail.class) &&
contact.getImage() != null)
{
@ -56,6 +64,8 @@ public Iterator getDetailsAndDescendants(Contact contact, Class detailClass)
*/
public Iterator getDetails(Contact contact, Class detailClass)
{
assertConnected();
if(detailClass.equals(ServerStoredDetails.ImageDetail.class) &&
contact.getImage() != null)
{
@ -76,6 +86,8 @@ public Iterator getDetails(Contact contact, Class detailClass)
*/
public Iterator getAllDetailsForContact(Contact contact)
{
assertConnected();
List res = infoRetreiver.getContactDetails(contact.getAddress());
if(contact.getImage() != null)
@ -86,4 +98,22 @@ public Iterator getAllDetailsForContact(Contact contact)
return res.iterator();
}
/**
* Utility method throwing an exception if the icq stack is not properly
* initialized.
* @throws java.lang.IllegalStateException if the underlying ICQ stack is
* not registered and initialized.
*/
private void assertConnected() throws IllegalStateException
{
if (icqProvider == null)
throw new IllegalStateException(
"The icq provider must be non-null and signed on the ICQ "
+"service before being able to communicate.");
if (!icqProvider.isRegistered())
throw new IllegalStateException(
"The icq provider must be signed on the ICQ service before "
+"being able to communicate.");
}
}

@ -472,7 +472,8 @@ protected void initialize(String screenname,
this.infoRetreiver = new InfoRetreiver(this, screenname);
OperationSetServerStoredContactInfo serverStoredContactInfo =
new OperationSetServerStoredContactInfoIcqImpl(infoRetreiver);
new OperationSetServerStoredContactInfoIcqImpl
(infoRetreiver, this);
supportedOperationSets.put(
OperationSetServerStoredContactInfo.class.getName(),

@ -30,6 +30,9 @@ public class OperationSetServerStoredContactInfoJabberImpl
// here is kept all the details retreived so far
private Hashtable retreivedDetails = new Hashtable();
private static final String TAG_FN_OPEN = "<FN>";
private static final String TAG_FN_CLOSE = "</FN>";
protected OperationSetServerStoredContactInfoJabberImpl(
ProtocolProviderServiceJabberImpl provider)
@ -135,6 +138,10 @@ private List getContactDetails(String contactAddress)
String tmp = null;
tmp = checkForFullName(card);
if(tmp != null)
result.add(new ServerStoredDetails.DisplayNameDetail(tmp));
tmp = card.getFirstName();
if(tmp != null)
result.add(new ServerStoredDetails.FirstNameDetail(tmp));
@ -150,51 +157,98 @@ private List getContactDetails(String contactAddress)
tmp = card.getNickName();
if(tmp != null)
result.add(new ServerStoredDetails.NicknameDetail(tmp));
// Home Details
// addrField one of
// POSTAL, PARCEL, (DOM | INTL), PREF, POBOX, EXTADR, STREET,
// LOCALITY, REGION, PCODE, CTRY
tmp = card.getAddressFieldHome("STREET");
if(tmp != null)
result.add(new ServerStoredDetails.AddressDetail(tmp));
tmp = card.getAddressFieldHome("LOCALITY");
if(tmp != null)
result.add(new ServerStoredDetails.CityDetail(tmp));
tmp = card.getAddressFieldHome("REGION");
if(tmp != null)
result.add(new ServerStoredDetails.ProvinceDetail(tmp));
tmp = card.getAddressFieldHome("PCODE");
if(tmp != null)
result.add(new ServerStoredDetails.PostalCodeDetail(tmp));
// tmp = card.getAddressFieldHome("CTRY");
// if(tmp != null)
// result.add(new ServerStoredDetails.CountryDetail(tmp);
// phoneType one of
//VOICE, FAX, PAGER, MSG, CELL, VIDEO, BBS, MODEM, ISDN, PCS, PREF
tmp = card.getPhoneHome("VOICE");
if(tmp != null)
result.add(new ServerStoredDetails.PhoneNumberDetail(tmp));
tmp = card.getPhoneHome("FAX");
if(tmp != null)
result.add(new ServerStoredDetails.FaxDetail(tmp));
tmp = card.getPhoneHome("PAGER");
if(tmp != null)
result.add(new ServerStoredDetails.PagerDetail(tmp));
// addrField one of
// POSTAL, PARCEL, (DOM | INTL), PREF, POBOX,
// EXTADR, STREET, LOCALITY, REGION, PCODE, CTRY
// String[] types = new String[]{"POSTAL", "PARCEL", "DOM", "INTL",
// "PREF", "POBOX", "EXTADR",
// "STREET", "LOCALITY", "REGION",
// "PCODE", "CTRY"};
// for (String t : types)
// {
// System.out.println("getAddressFieldHome(" + t + ") - " + card.getAddressFieldHome(t));
// }
//phoneType one of
// VOICE, FAX, PAGER, MSG, CELL, VIDEO, BBS, MODEM, ISDN, PCS, PREF
// types = new String[]{"VOICE", "FAX", "PAGER", "MSG", "CELL",
// "VIDEO", "BBS", "MODEM", "ISDN", "PCS", "PREF"};
// for (String t : types)
// {
// System.out.println("getPhoneHome(" + t + ") - " + card.getPhoneHome(t));
// }
tmp = card.getPhoneHome("CELL");
if(tmp != null)
result.add(new ServerStoredDetails.MobilePhoneDetail(tmp));
tmp = card.getEmailHome();
if(tmp != null)
result.add(new ServerStoredDetails.EmailAddressDetail(tmp));
// Work Details
// addrField one of
// POSTAL, PARCEL, (DOM | INTL), PREF, POBOX, EXTADR, STREET,
// LOCALITY, REGION, PCODE, CTRY
tmp = card.getAddressFieldWork("STREET");
if(tmp != null)
result.add(new ServerStoredDetails.WorkAddressDetail(tmp));
tmp = card.getAddressFieldWork("LOCALITY");
if(tmp != null)
result.add(new ServerStoredDetails.WorkCityDetail(tmp));
tmp = card.getAddressFieldWork("REGION");
if(tmp != null)
result.add(new ServerStoredDetails.WorkProvinceDetail(tmp));
tmp = card.getAddressFieldWork("PCODE");
if(tmp != null)
result.add(new ServerStoredDetails.WorkPostalCodeDetail(tmp));
// tmp = card.getAddressFieldWork("CTRY");
// if(tmp != null)
// result.add(new ServerStoredDetails.WorkCountryDetail(tmp);
// addrField one of
// POSTAL, PARCEL, (DOM | INTL), PREF, POBOX, EXTADR, STREET,
// LOCALITY, REGION, PCODE, CTRY
// types = new String[]{"POSTAL", "PARCEL", "DOM", "INTL", "PREF",
// "POBOX", "EXTADR", "STREET", "LOCALITY", "REGION", "PCODE", "CTRY"};
// for (String t : types)
// {
// System.out.println("getAddressFieldWork(" + t + ") - " + card.getAddressFieldWork(t));
// }
// phoneType one of
// VOICE, FAX, PAGER, MSG, CELL, VIDEO, BBS, MODEM, ISDN, PCS, PREF
// types = new String[]{"VOICE", "FAX", "PAGER", "MSG", "CELL",
// "VIDEO", "BBS", "MODEM", "ISDN", "PCS", "PREF"};
// for (String t : types)
// {
// System.out.println("getPhoneWork(" + t + ") - " + card.getPhoneWork(t));
// }
//VOICE, FAX, PAGER, MSG, CELL, VIDEO, BBS, MODEM, ISDN, PCS, PREF
tmp = card.getPhoneWork("VOICE");
if(tmp != null)
result.add(new ServerStoredDetails.WorkPhoneDetail(tmp));
tmp = card.getPhoneWork("FAX");
if(tmp != null)
result.add(new WorkFaxDetail(tmp));
tmp = card.getPhoneWork("PAGER");
if(tmp != null)
result.add(new WorkPagerDetail(tmp));
tmp = card.getPhoneWork("CELL");
if(tmp != null)
result.add(new ServerStoredDetails.WorkMobilePhoneDetail(tmp));
tmp = card.getEmailWork();
if(tmp != null)
result.add(new ServerStoredDetails.EmailAddressDetail(tmp));
@ -225,6 +279,24 @@ private List getContactDetails(String contactAddress)
return new LinkedList(result);
}
private String checkForFullName(VCard card)
{
String vcardXml = card.toXML();
int indexOpen = vcardXml.indexOf(TAG_FN_OPEN);
if(indexOpen == -1)
return null;
int indexClose = vcardXml.indexOf(TAG_FN_CLOSE, indexOpen);
// something is wrong!
if(indexClose == -1)
return null;
return vcardXml.substring(indexOpen + TAG_FN_OPEN.length(), indexClose);
}
/**
* Work department
*/
@ -236,4 +308,30 @@ public WorkDepartmentNameDetail(String workDepartmentName)
super("Work Department Name", workDepartmentName);
}
}
/**
* Fax at work
*/
public static class WorkFaxDetail
extends ServerStoredDetails.FaxDetail
{
public WorkFaxDetail(String number)
{
super(number);
super.detailDisplayName = "WorkFax";
}
}
/**
* Pager at work
*/
public static class WorkPagerDetail
extends ServerStoredDetails.PhoneNumberDetail
{
public WorkPagerDetail(String number)
{
super(number);
super.detailDisplayName = "WorkPager";
}
}
}
Loading…
Cancel
Save