1 2 package org.objectweb.jac.samples.contacts; 3 4 import java.util.Vector ; 5 import java.util.List ; 6 import java.util.Iterator ; 7 import gnu.regexp.*; 8 9 public class ContactRepository { 10 List contacts = new Vector (); 11 12 16 public List getContacts() { 17 return contacts; 18 } 19 20 24 public void addContact(Person contact) { 25 contacts.add(contact); 26 } 27 28 32 public void removeContact(Person contact) { 33 contacts.remove(contact); 34 } 35 36 41 public List find(String criteria,String company) { 42 Vector result = new Vector (); 43 Iterator it = contacts.iterator(); 44 RE recrit = null; 45 try { 46 if (!criteria.equals("")) 47 recrit = new RE(criteria,RE.REG_ICASE); 48 } catch(Exception e) { 49 e.printStackTrace(); 50 return result; 51 } 52 while (it.hasNext()) { 53 Person contact = (Person) it.next(); 54 String companyName = ""; 56 if (!company.equals("")) { 57 if (contact.getCompany() != null) { 58 companyName = contact.getCompany().getName(); 59 if (company.compareToIgnoreCase(companyName)!=0) { 60 continue; 61 } 62 } 63 } 64 if (recrit==null || 65 recrit.getMatch(contact.getLastName())!=null || 66 recrit.getMatch(contact.getFirstName())!=null) 67 { 68 result.add(contact); 69 } 70 } 71 return result; 72 } 73 74 75 93 94 97 public void mailing() { 98 String toMail = "mailto:"; 99 Iterator it = contacts.iterator(); 100 boolean first = true; 101 while (it.hasNext()) { 102 Person c = (Person)it.next(); 103 if (c.getEmail()!=null && !c.getEmail().equals("") && 104 c.isMailing()) 105 { 106 if (first) { 107 toMail = toMail+c.getEmail(); 108 first = false; 109 } else { 110 toMail = toMail+","+c.getEmail(); 111 } 112 } 113 } 114 try { 115 String command = "mozilla -mail "+toMail; 116 System.out.println("launching "+command); 117 Runtime.getRuntime().exec(command); 118 } catch(Exception e) { 119 e.printStackTrace(); 120 } 121 } 122 123 } 124 | Popular Tags |