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); } }
private static PhoneNumber convertToGooglePhoneNumber(Telephone vCardTelephone) { PhoneNumber phoneNumber = new PhoneNumber(); phoneNumber.setValue(vCardTelephone.getText()); if (vCardTelephone.getPref() != null && vCardTelephone.getPref() == VCARD_PRIMARY_PREF) { phoneNumber.setMetadata(PRIMARY_FIELD_METADATA); } else { phoneNumber.setMetadata(SECONDARY_FIELD_METADATA); } return phoneNumber; }
Statement valueStatement = getValueStatement(telephoneResource); String telephoneNumber = valueStatement.getObject().toString(); Telephone telephoneObject = new Telephone(telephoneNumber); if (telephoneResource.hasProperty(RDF.type)) { telephoneResource.listProperties(RDF.type).forEachRemaining(typeProperty -> telephoneObject.getTypes().add( TelephoneType.find(typeProperty.getResource().getLocalName()))); } else { String telephoneNumber = telephoneResource.getURI(); Telephone telephoneObject = new Telephone(telephoneNumber); vcard.addTelephoneNumber(telephoneObject);
@Override public Telephone copy() { return new Telephone(this); }
@SuppressWarnings("unchecked") private void addPhone(String key, Telephone telephone, Map<String, Object> map) { List<String> collection = (List<String>) map.computeIfAbsent(key, k -> new ArrayList<>()); collection.add(telephone.getText()); }
@Override protected Telephone _parseHtml(HCardElement element, ParseContext context) { Telephone property; String href = element.attr("href"); try { property = new Telephone(TelUri.parse(href)); } catch (IllegalArgumentException e) { //not a tel URI property = new Telephone(element.value()); } List<String> types = element.types(); property.getParameters().putAll(VCardParameters.TYPE, types); return property; }
@Override protected void _validate(List<ValidationWarning> warnings, VCardVersion version, VCard vcard) { if (uri == null && text == null) { warnings.add(new ValidationWarning(8)); } if (uri != null && (version == VCardVersion.V2_1 || version == VCardVersion.V3_0)) { warnings.add(new ValidationWarning(19)); } for (TelephoneType type : getTypes()) { if (type == TelephoneType.PREF) { //ignore because it is converted to a PREF parameter for 4.0 vCards continue; } if (!type.isSupportedBy(version)) { warnings.add(new ValidationWarning(9, type.getValue())); } } }
/** * <p> * Adds a telephone number. * </p> * <p> * <b>Property name:</b> {@code TEL}<br> * <b>Supported versions:</b> {@code 2.1, 3.0, 4.0} * </p> * @param telephoneNumber the telephone number to add (e.g. * "+1 555-555-5555") * @param types the type(s) to assign to the telephone number (e.g. "cell", * "work", etc) * @return the property object that was created * @see <a href="http://tools.ietf.org/html/rfc6350#page-34">RFC 6350 * p.34</a> * @see <a href="http://tools.ietf.org/html/rfc2426#page-14">RFC 2426 * p.14</a> * @see <a href="http://www.imc.org/pdi/vcard-21.doc">vCard 2.1 p.13</a> */ public Telephone addTelephoneNumber(String telephoneNumber, TelephoneType... types) { Telephone property = new Telephone(telephoneNumber); property.getTypes().addAll(Arrays.asList(types)); addTelephoneNumber(property); return property; }
if (telephone.getTypes().isEmpty()) { r.addProperty(VCARD4.hasTelephone, telephone.getText()); } else { Resource telephoneResource = personModel.createResource(); telephoneResource.addProperty(VCARD4.value, telephone.getText()); for (TelephoneType type : telephone.getTypes()) { for (Resource telTypeResource : getPhoneOrMailTypes(type.getValue(), MAP_OF_PHONE_TYPES)) telephoneResource.addProperty(RDF.type, telTypeResource);
@Override protected void _writeXml(Telephone property, XCardElement parent) { String text = property.getText(); if (text != null) { parent.append(VCardDataType.TEXT, text); return; } TelUri uri = property.getUri(); if (uri != null) { parent.append(VCardDataType.URI, uri.toString()); return; } parent.append(VCardDataType.TEXT, ""); }
String primaryValue2 = "411"; String secondaryValue = "(555) 867-5309"; Telephone primaryTelephone1 = new Telephone(primaryValue1); primaryTelephone1.setPref(VCARD_PRIMARY_PREF); Telephone primaryTelephone2 = new Telephone(primaryValue2); primaryTelephone2.setPref(VCARD_PRIMARY_PREF); Telephone secondaryTelephone = new Telephone(secondaryValue); secondaryTelephone.setPref(VCARD_PRIMARY_PREF + 1);
try{ File file = new File(Environment.getExternalStorageDirectory()+"/vcards.vcf"); List<VCard> vcards = Ezvcard.parse(file).all(); for (VCard vcard : vcards){ System.out.println("Name: " + vcard.getFormattedName().getValue()); System.out.println("Telephone numbers:"); for (Telephone tel : vcard.getTelephoneNumbers()){ System.out.println(tel.getTypes() + ": " + tel.getText()); } } }catch(Exception e){e.printStackTrace();}