private void copyPersonData(Map<String, Object> map, VCard card, TransformerContext context) { getMap("homeAddress", map).ifPresent(v -> card.addAddress(context.transform(Address.class, v))); copyEmail(map, card); copyPhones("homePhones", TelephoneType.HOME, map, card); getString("mobilePhone", map).ifPresent(v -> card.addTelephoneNumber(v, TelephoneType.CELL)); getString("birthday", map).ifPresent(v -> card.setBirthday(new Birthday(v))); }
private void copyPersonData(VCard card, Map<String, Object> contact, TransformerContext context) { // Addresses are lossy: there is no distinction in VCard between business and home addresses if (!card.getAddresses().isEmpty()) { safeSet( "homeAddress", context.transform(LinkedHashMap.class, card.getAddresses().get(0)), contact); } card.getEmails().stream().filter(v -> v.getValue() != null).forEach(v -> addEmail(v, contact)); card.getTelephoneNumbers() .stream() .filter(t -> t.getText() != null) .forEach( telephone -> { for (TelephoneType telephoneType : telephone.getTypes()) { if (TelephoneType.CELL.equals(telephoneType)) { // this could overwrite some numbers since MS contacts only have one mobile contact.put("mobilePhone", telephone.getText()); } else if (TelephoneType.WORK.equals(telephoneType)) { addPhone("businessPhones", telephone, contact); } else { addPhone("homePhones", telephone, contact); } } }); if (card.getBirthday() != null) { safeSet("birthday", card.getBirthday().getText(), contact); } }
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { Birthday birthday = new Birthday(); if (reader.getAttribute("gender").charAt(0) == 'm') { birthday.setGenderMale(); } else { birthday.setGenderFemale(); } reader.moveDown(); Person person = (Person)context.convertAnother(birthday, Person.class); birthday.setPerson(person); reader.moveUp(); reader.moveDown(); Calendar date = (Calendar)context.convertAnother(birthday, Calendar.class); birthday.setDate(date); reader.moveUp(); return birthday; }
@Override protected Birthday newInstance(PartialDate partialDate) { return new Birthday(partialDate); } }
@Override protected Birthday newInstance(Date date, boolean hasTime) { return new Birthday(date, hasTime); }
@Override public Birthday copy() { return new Birthday(this); } }
@Override protected Birthday newInstance(String text) { return new Birthday(text); }