Comments (6)
You can use the `marshalText()` method to convert each property to its
over-the-wire representation:
{{{
VCard vcard = ...
VCardVersion version = ...
CompatibilityMode compat = CompatibilityMode.RFC;
for (VCardType property : vcard){
System.out.print(property.getTypeName());
System.out.print("=");
System.out.println(property.marshalText(version, compat));
}
}}}
Let me know if that helps.
Original comment by mike.angstadt
on 8 Sep 2013 at 12:57
from ez-vcard.
You might also be interested in the `VCardRawReader` class. This class parses
a vCard file without unmarshalling the properties into Java classes:
{{{
StringReader reader = new StringReader(
"BEGIN:VCARD\r\n" +
"VERSION:4.0\r\n" +
"FN:John Doe\r\n" +
"END:VCARD\r\n"
);
VCardRawReader rawReader = new VCardRawReader(reader);
rawReader.start(new VCardDataStreamListener() {
public void beginComponent(String name) {
System.out.println("BEGIN=" + name);
}
public void readVersion(VCardVersion version) {
System.out.println("Version is: " + version);
}
public void invalidVersion(String version) {
System.out.println("Version string is invalid: " + version);
}
public void readProperty(String group, String name, VCardSubTypes parameters, String value) {
System.out.println(name + "=" + value);
}
public void invalidLine(String line) {
System.out.println("Invalid line: " + line);
}
public void endComponent(String name) {
System.out.println("END=" + name);
}
});
}}}
Original comment by mike.angstadt
on 8 Sep 2013 at 1:10
from ez-vcard.
Thanks, it does provide useful workarounds. However, I don’t think these two
proposals really provide a clean solution for this use case.
The first one feels conceptually strange, as I would like to read what has been
parsed already.
The second one would mean I have to read twice the vcard file, using two
different techniques. I need also the classical (normal) parsing method because
I also want to be able to use the higher level structure e.g. to access contact
structured names.
I still think a generic getValue, or getStringValue would be great.
That said, in my situation, I am only writing a small program for my personal
usage, so I don’t need anything really clean or simple. So the provided
workaround works fine for me. Thanks again.
Original comment by olivier.cailloux
on 8 Sep 2013 at 1:16
from ez-vcard.
Thanks for your feedback. I'm glad one of the solutions works for you. Are
you looking for a way to display each property value as a string for debugging
purposes? Perhaps adding "toString()" methods to each property class would be
beneficial.
ez-vcard treats the vCard file format as just one of the many ways a vCard can
be serialized. It aims to separate the serialization code from the data model.
Having a common, format-agnostic data model makes it possible to support all
these formats, as well as any additional formats that may arise in the future.
It makes switching between formats a trivial operation. For example,
converting a plain-text vCard file to an XML document requires just a few lines
of code.
I plan on making this separation more complete by introducing "marshaller"
classes, whose sole responsibility it is to handle the serialization
functionality. This means that methods like "marshalText" will go away and the
VCardType classes will know nothing about how they are represented
over-the-wire (basically, they will contain only getters and setters). The
first solution that I posted above will still work, with a few small
modifications.
Original comment by mike.angstadt
on 8 Sep 2013 at 5:33
from ez-vcard.
I only wanted to compare two vcf files I have (representing my own contacts)
from different sources. My program shows two panes, with on each pane the vcf
content from each source. I thus needed a way to simply show all content (to
make sure I don’t miss any property). I also used the higher level
functionality of ez- to search for matching entries in both sources, e.g.
I don’t think this specific use case would be very common. However, I do
think it is a common requirement to want to access key - value pairs without
having to switch for separate cases according to the type.
A tostring method would be fine, I think. One possible drawback: the
requirement is about being able to list all content of a vcard using key-value
pairs. The toString() method, as a convenient debug string, is sometimes
understood as supposedly being short (though it seems to me this varies a lot
depending on the library). These two req can conflict.
Anyway, you are the developer ;-).
Original comment by olivier.cailloux
on 8 Sep 2013 at 8:05
from ez-vcard.
Original comment by mike.angstadt
on 13 Oct 2014 at 10:44
- Changed state: WontFix
from ez-vcard.
Related Issues (20)
- IMPP: case-insensitive comparison of schemes HOT 1
- VCardWriter - Writes data without proper formatting for Google Contacts - Expected : YYYY-MM-DD ; current : YYYYMMDD HOT 2
- [Q] How do I get the `RawProperty`s? HOT 1
- Version 0.11.3 vulnerabilities HOT 3
- Migration to 0.12.0 while still supporting Android API 21..25 HOT 6
- Add support for Jigsaw modules HOT 1
- Parsing from chunk of text HOT 2
- Custom getter in VCardProperty HOT 9
- Invalid value for "MonthOfYear" caused by wrong BDAY date HOT 1
- Raw property values HOT 4
- Relations and Anniversaries are lost in serialization HOT 2
- what is the way to add social media contact? HOT 1
- Default line folding line length is not null HOT 1
- [Compatibility] Treat KIND values case-insensitive HOT 2
- whole vCard being drop instead of the specific corrupted fields HOT 3
- WhatsApp format of vcard is not supported?
- No Class found in DavX5 HOT 1
- hCard GEO HOT 1
- CRLF is handled incorrectly in vcard 2.1 properties HOT 8
- Wrong value for vCard property VERSION returned HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ez-vcard.