-
Notifications
You must be signed in to change notification settings - Fork 93
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Custom getter in VCardProperty #133
Comments
Not quite sure what you're trying to accomplish. The VCard vcard = new VCard();
vcard.setFormattedName("John Doe");
Address adr = new Address();
adr.setStreetAddress("123 Main St");
adr.setLocality("New York");
adr.setRegion("NY");
adr.setPostalCode("12345");
vcard.addAddress(adr);
System.out.println(vcard.toString()); Prints:
|
Hi mangstadt, In fact I am trying to import cards into a database:
And this for each value of each property, independently of each other... If I have the possibility to use a customized getter here is the code I get to import:
What will the code look like if I don't have a custom getter? |
I would like to add that this mode of use has the advantage of separating the processing of data (class Address, Email...) from the import logic (global processing). EDIT: And this is important if i want the user to be able to choose which vCard properties he wants to import |
You could serialize the vCard using |
I need to be more specific about the purpose. This extension vCardOOo has some particularities:
I already have an extension that does exactly the same thing but with Google contacts: gContactOOo All these extensions are written in Python except the parsing part for vCardOOo where I use ez-vcard which is the best API on vCard. ;-) So I admit that my need is really specific, but if I want to be able to follow my specifications I will just use my modified version of ez-vcard (all my jar libraries are embedded in the extension oxt files) |
Using sub-classes can be problematic. I might do something like this instead: public Map<String, String> getPropertiesValue(VCardProperty property) {
if (property instanceof Address) {
return getPropertiesValue((Address)property);
}
if (property instanceof Categories) {
return getPropertiesValue((Categories)property);
}
//etc
}
public Map<String, String> getPropertiesValue(Address property) {
Map<String, String> values = new LinkedHashMap<>();
if (getPoBox() != null) values.put("poBox", getPoBox());
//...
return values;
} |
Can you confirm that if I follow your recommendations then it is no longer necessary to modify the VCardProperty class, but only the Address, Email, etc. subclasses? In the implementation of my class Address which extends the class ezvcard.property.Address what are the methods that must be implemented? Thank you for these hints. |
If your goal is to convert each vCard property object (Address, Categories, etc) to a VCard vcard = ...
for (VCardProperty property : vcard.getProperties()) {
Map<String,String> values = getPropertiesValue(property);
} |
Yes in fact I am looking to have a single method whatever the property to obtain 3 things:
|
I am trying to retrieve all the values by calling a custom method on a VCardProperty. (Address, Email, Categories...)
I'm not a Java specialist, but I can't manage to do this without modifying the VCardProperty class.
Thank you for your help.
The text was updated successfully, but these errors were encountered: