BrightSide Workbench Full Report + Source Code
VCardPlugin.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2011 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 package org.turro.vcard.util;
19 
20 import java.io.File;
21 import java.io.IOException;
22 import java.util.List;
23 import java.util.logging.Level;
24 import java.util.logging.Logger;
25 import org.amic.util.file.FileUtil;
26 import org.turro.annotation.ElephantPlugin;
27 import org.turro.contacts.Contact;
28 import org.turro.elephant.context.ElephantContext;
29 import org.turro.plugin.IPlugin;
30 import org.turro.vcard.db.VCardFiles;
31 import org.zkoss.util.media.ContentTypes;
32 import org.zkoss.zul.Filedownload;
33 
38 @ElephantPlugin(label="vcard")
39 public class VCardPlugin implements IPlugin {
40 
41  private Contact contact;
42 
43  @Override
44  public void setData(String id, Object data) {
45  if("contact".equals(id)) {
46  contact = (Contact) data;
47  } else if("export".equals(id)) {
48  try {
49  File f = new ExportToVCard((List<Contact>) data).export();
50  if(f.exists()) {
51  Filedownload.save(f, ContentTypes.getContentType(FileUtil.getExtension(f)));
52  }
53  } catch (IOException ex) {
54  Logger.getLogger(VCardPlugin.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(null), ex);
55  }
56  }
57  }
58 
59  @Override
60  public Object getData(String id) {
61  if("import".equals(id)) {
62  try {
63  return new ImportFromVCard().importVCard();
64  } catch (IOException ex) {
65  Logger.getLogger(VCardPlugin.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(null), ex);
66  }
67  } else if("importcsv".equals(id)) {
68  try {
69  return new ImportFromCSV().importCSV();
70  } catch (IOException ex) {
71  Logger.getLogger(VCardPlugin.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(null), ex);
72  }
73  } else if("importFolder".equals(id)) {
74  return VCardFiles.getImportFolder();
75  } else if("qrcode".equals(id)) {
76  return new ExportToVCard(contact).getQRCode();
77  }
78  return null;
79  }
80 
81 }
void setData(String id, Object data)