Using PDI plugin

Questions and answers on developing, deploying and using plugins and JavaBeans

Using PDI plugin

Postby sergei.sheinin » Sat Nov 29, 2014 5:01 pm

Is there a good example that I may refer to in how to use PDI plugin for reading a vCard? I have following code where the "application.output(c.addresses)" produces empty array output "[]":

Code: Select all
/**
* @type {String}
*
* @properties={typeid:35,uuid:"1099B45F-9838-4A55-80BC-767252D996C8"}
*/
var vCard = 'BEGIN:VCARD\n\
VERSION:4.0\n\
N:Gump;Forrest;;;\n\
FN:Forrest Gump\n\
ORG:Bubba Gump Shrimp Co.\n\
TITLE:Shrimp Man\n\
PHOTO;MEDIATYPE=image/gif:http://www.example.com/dir_photos/my_photo.gif\n\
TEL;TYPE=work,voice;VALUE=uri:tel:+1-111-555-1212\n\
TEL;TYPE=home,voice;VALUE=uri:tel:+1-404-555-1212\n\
ADR;TYPE=work;LABEL="100 Waters Edge\nBaytown, LA 30314\nUnited States of America"\n\
  :;;100 Waters Edge;Baytown;LA;30314;United States of America\n\
ADR;TYPE=home;LABEL="42 Plantation St.\nBaytown, LA 30314\nUnited States of America"\n\
:;;42 Plantation St.;Baytown;LA;30314;United States of America\n\
EMAIL:forrestgump@example.com\n\
REV:20080424T195243Z\n\
END:VCARD';

/**
* @properties={typeid:24,uuid:"00B657EA-C406-4137-99C2-DC0F7E57F478"}
*/
function test(){

   var c = plugins.PDI.VCard(vCard)
   application.output(c.validate())             // <null>
   
   application.output(c.addresses)              // []
      
   
}
Sergei Sheinin
JavaScript, RDBMS
http://js2dx.com
sergei.sheinin
 
Posts: 79
Joined: Wed May 07, 2014 3:22 pm

Re: Using PDI plugin

Postby patrick » Sat Nov 29, 2014 6:31 pm

A vCard can contain more than one "card". So you start reading using

Code: Select all
var cards = plugins.PDI.AddressBook("F:\\test.txt")
var card = c.VCards[0];
application.output(card.addresses);


I'm not sure the underlaying library fully supports vcard 4...
Patrick Ruhsert
Servoy DACH
patrick
 
Posts: 3703
Joined: Wed Jun 11, 2003 10:33 am
Location: Munich, Germany

Re: Using PDI plugin

Postby sergei.sheinin » Sun Nov 30, 2014 2:56 am

I changed the vcard code to v2.1 but the result didn't change. I would like to be able to use vCard from a text variable if possible for the test rather than file. I think that is what "plugins.PDI.VCard()" function is for, correct me if I'm wrong.

Code: Select all
var vCard = 'BEGIN:VCARD\n\
VERSION:2.1\n\
N:Gump;Forrest\n\
FN:Forrest Gump\n\
ORG:Bubba Gump Shrimp Co.\n\
TITLE:Shrimp Man\n\
PHOTO;GIF:http://www.example.com/dir_photos/my_photo.gif\n\
TEL;WORK;VOICE:(111) 555-1212\n\
TEL;HOME;VOICE:(404) 555-1212\n\
ADR;WORK:;;100 Waters Edge;Baytown;LA;30314;United States of America\n\
LABEL;WORK;ENCODING=QUOTED-PRINTABLE:100 Waters Edge=0D=0ABaytown, LA 30314=0D=0AUnited States of America\n\
ADR;HOME:;;42 Plantation St.;Baytown;LA;30314;United States of America\n\
LABEL;HOME;ENCODING=QUOTED-PRINTABLE:42 Plantation St.=0D=0ABaytown, LA 30314=0D=0AUnited States of America\n\
EMAIL;PREF;INTERNET:forrestgump@example.com\n\
REV:20080424T195243Z\n\
END:VCARD';
Sergei Sheinin
JavaScript, RDBMS
http://js2dx.com
sergei.sheinin
 
Posts: 79
Joined: Wed May 07, 2014 3:22 pm

Re: Using PDI plugin

Postby patrick » Sun Nov 30, 2014 2:24 pm

No, the empty VCard constructor is for creating new vcards...
Patrick Ruhsert
Servoy DACH
patrick
 
Posts: 3703
Joined: Wed Jun 11, 2003 10:33 am
Location: Munich, Germany

Re: Using PDI plugin

Postby sergei.sheinin » Sun Nov 30, 2014 2:40 pm

May I have a suggestion how to create vcard object from a string please?

In my code I have "var c = plugins.PDI.VCard(<string>)" and it doesn't seem to work.
Sergei Sheinin
JavaScript, RDBMS
http://js2dx.com
sergei.sheinin
 
Posts: 79
Joined: Wed May 07, 2014 3:22 pm

Re: Using PDI plugin

Postby patrick » Sun Nov 30, 2014 2:55 pm

Write it to a file and read it from there
Patrick Ruhsert
Servoy DACH
patrick
 
Posts: 3703
Joined: Wed Jun 11, 2003 10:33 am
Location: Munich, Germany

Re: Using PDI plugin

Postby sergei.sheinin » Sun Nov 30, 2014 3:54 pm

Ok, although I expected "plugins.PDI.VCard(<string>)" to produce a vcard object it didn't work. I am now trying to read from file and get null pointer error:


Code: Select all
   var f = plugins.file.convertToJSFile('C:\\projects\\docs\\100bob\\vcard.txt');
   application.output(f.size())                                   // DISPLAYS CORRRECT SIZE, so the file is accessible and was read

   try {
     var y = plugins.PDI.AddressBook(['C:\\projects\\docs\\100bob\\vcard.txt']);}
   catch(err) {
      application.output(err.message)}                  //  java.lang.NullPointerException: null
   
   try{
      var x = plugins.PDI.AddressBook([f]);}
   catch(err){application.output(err.message)}         // java.lang.NullPointerException: null
   


I also tried with f.getBytes() with same null pointer error. The content of 2.1 version vCard is above in the thread (the file has "\n\" endings removed).

Please advise and if possible provide a working example.
Sergei Sheinin
JavaScript, RDBMS
http://js2dx.com
sergei.sheinin
 
Posts: 79
Joined: Wed May 07, 2014 3:22 pm

Re: Using PDI plugin

Postby patrick » Sun Nov 30, 2014 4:18 pm

Why are you passing an array? Just look at my code example. All really simple. I tested my code above and it worked as expected. P.S.: Don't forget to register the plugin, otherwise you get null all over.
Patrick Ruhsert
Servoy DACH
patrick
 
Posts: 3703
Joined: Wed Jun 11, 2003 10:33 am
Location: Munich, Germany

Re: Using PDI plugin

Postby sergei.sheinin » Sun Nov 30, 2014 4:33 pm

If I don't pass it as array I get "The function AddressBook([Array<None>]) is not applicable for the arguments (String)".

I register plugin at top of the code and it returns "true".


Please help.
Sergei Sheinin
JavaScript, RDBMS
http://js2dx.com
sergei.sheinin
 
Posts: 79
Joined: Wed May 07, 2014 3:22 pm

Re: Using PDI plugin

Postby patrick » Sun Nov 30, 2014 4:41 pm

Why don't you simply try my example above?

The plugin is quite old in terms of Servoy's plugin API. It still runs with Servoy 3.5 and was never updated to the latest plugin API to not break compatibility. It uses an old fashioned way of receiving arguments as an object[] that is routed internally depending what kind of object[] comes in. So ignore that warning and just use my code example. You will not get rid of that warning.
Patrick Ruhsert
Servoy DACH
patrick
 
Posts: 3703
Joined: Wed Jun 11, 2003 10:33 am
Location: Munich, Germany

Re: Using PDI plugin

Postby sergei.sheinin » Sun Nov 30, 2014 4:55 pm

Code: Select all
try {
     var y = plugins.PDI.AddressBook('C:\\projects\\docs\\100bob\\vcard.txt');}
   catch(err) {
      application.output(err.message)} // java.lang.NullPointerException: null



This also produces null pointer. Any ideas?
Sergei Sheinin
JavaScript, RDBMS
http://js2dx.com
sergei.sheinin
 
Posts: 79
Joined: Wed May 07, 2014 3:22 pm

Re: Using PDI plugin

Postby patrick » Sun Nov 30, 2014 4:58 pm

No, because yesterday exactly that worked for me nicely.

Anyway, this doesn't really belong into the Servoy forum since it is not related to Servoy. I suggest you contact support@servoy-plugins.de and attach the servoy_log file, so they can see what is Null there in your case.
Patrick Ruhsert
Servoy DACH
patrick
 
Posts: 3703
Joined: Wed Jun 11, 2003 10:33 am
Location: Munich, Germany

Re: Using PDI plugin

Postby sergei.sheinin » Sun Nov 30, 2014 5:02 pm

May you by chance provide a vcard file with which it worked?
Sergei Sheinin
JavaScript, RDBMS
http://js2dx.com
sergei.sheinin
 
Posts: 79
Joined: Wed May 07, 2014 3:22 pm

Re: Using PDI plugin

Postby patrick » Sun Nov 30, 2014 5:29 pm

sure. it's the same you use, that vcard from wikipedia.
Attachments
test.txt
(629 Bytes) Downloaded 341 times
Patrick Ruhsert
Servoy DACH
patrick
 
Posts: 3703
Joined: Wed Jun 11, 2003 10:33 am
Location: Munich, Germany

Re: Using PDI plugin

Postby sergei.sheinin » Mon Dec 01, 2014 12:20 pm

I wrote to support@servoy-plugins.de and they sent me pdi.jar in attachment. When I replaced the file it worked without any problems.
Sergei Sheinin
JavaScript, RDBMS
http://js2dx.com
sergei.sheinin
 
Posts: 79
Joined: Wed May 07, 2014 3:22 pm


Return to Plugins and Beans

Who is online

Users browsing this forum: No registered users and 5 guests

cron