public static Map<String, Object> importVCard(DispatchContext dctx, Map<String, ? extends Object> context) {
LocalDispatcher dispatcher = dctx.getDispatcher();
Delegator delegator = dctx.getDelegator();
Locale locale = (Locale) context.get("locale");
Map<String, Object> result = ServiceUtil.returnSuccess();
Address workAddress = null;
String email = null;
String phone = null;
ByteBuffer byteBuffer = (ByteBuffer) context.get("infile");
byte[] inputByteArray = byteBuffer.array();
InputStream in = new ByteArrayInputStream(inputByteArray);
String partyType = (String) context.get("partyType");
Boolean isGroup = "PartyGroup".equals(partyType); // By default we import a Person.
Map<String, Object> serviceCtx = FastMap.newInstance();
try {
ContactIOFactory ciof = Pim.getContactIOFactory();
ContactUnmarshaller unmarshaller = ciof.createContactUnmarshaller();
Contact[] contacts = unmarshaller.unmarshallContacts(in);
for (Contact contact: contacts) {
PersonalIdentity pid = contact.getPersonalIdentity();
if (!isGroup) {
serviceCtx.put("firstName", pid.getFirstname());
serviceCtx.put("lastName", pid.getLastname());
}
for (Iterator<?> iter = contact.getAddresses(); iter.hasNext();) {
Address address = (AddressImpl) iter.next();
if (contact.isPreferredAddress(address)) {
workAddress = address;
break;
} else if (address.isWork()) {
workAddress = address;
break;
} else { // for now use preferred/work address only
continue;
}