Coder Social home page Coder Social logo

Comments (6)

GoogleCodeExporter avatar GoogleCodeExporter commented on July 4, 2024
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.

GoogleCodeExporter avatar GoogleCodeExporter commented on July 4, 2024
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.

GoogleCodeExporter avatar GoogleCodeExporter commented on July 4, 2024
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.

GoogleCodeExporter avatar GoogleCodeExporter commented on July 4, 2024
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.

GoogleCodeExporter avatar GoogleCodeExporter commented on July 4, 2024
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.

GoogleCodeExporter avatar GoogleCodeExporter commented on July 4, 2024

Original comment by mike.angstadt on 13 Oct 2014 at 10:44

  • Changed state: WontFix

from ez-vcard.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.