1 17 package org.columba.mail.config; 18 19 import java.io.File ; 20 import java.util.Observer ; 21 22 import org.columba.core.xml.XmlElement; 23 import org.columba.ristretto.message.Address; 24 import org.columba.ristretto.parser.ParserException; 25 26 29 public class Identity { 30 31 private static final String SIGNATURE_FILE = "signature_file"; 32 private static final String ORGANISATION = "organisation"; 33 private static final String REPLY_ADDRESS = "reply_address"; 34 private static final String NAME = "name"; 35 private static final String ADDRESS = "address"; 36 37 protected XmlElement e; 38 protected Address address; 39 protected Address replyToAddress; 40 41 public Identity(XmlElement e) throws ParserException { 42 this.e = e; 43 String value = e.getAttribute(Identity.ADDRESS); 44 if (value != null && value.length() > 0) { 45 address = Address.parse(e.getAttribute(Identity.ADDRESS)); 46 address.setDisplayName(e.getAttribute(Identity.NAME)); 47 } 48 value = e.getAttribute(Identity.REPLY_ADDRESS); 49 if (value != null && value.length() > 0) { 50 replyToAddress = Address.parse(value); 51 } 52 } 53 54 public Address getAddress() { 55 return address; 56 } 57 58 public void setAddress(Address address) { 59 this.address = address; 60 e.addAttribute(Identity.NAME, address.getDisplayName()); 61 e.addAttribute(Identity.ADDRESS, address.getMailAddress()); 62 } 63 64 public Address getReplyToAddress() { 65 return replyToAddress; 66 } 67 68 public void setReplyToAddress(Address address) { 69 replyToAddress = address; 70 if (address != null) { 71 e.addAttribute(Identity.REPLY_ADDRESS, address.getMailAddress()); 72 } else { 73 e.getAttributes().remove(Identity.REPLY_ADDRESS); 74 } 75 } 76 77 public String getOrganisation() { 78 return e.getAttribute(Identity.ORGANISATION); 79 } 80 81 public void setOrganisation(String organisation) { 82 if (organisation != null) { 83 e.addAttribute(Identity.ORGANISATION, organisation); 84 } else { 85 e.getAttributes().remove(Identity.ORGANISATION); 86 } 87 } 88 89 92 public File getSignature() { 93 String path = e.getAttribute(Identity.SIGNATURE_FILE); 94 if (path != null) { 95 File signature = new File (path); 96 if (signature.exists() && signature.isFile()) { 97 return signature; 98 } 99 } 100 return null; 101 } 102 103 106 public void setSignature(File signature) { 107 if (signature != null && signature.exists() && signature.isFile()) { 108 e.addAttribute(Identity.SIGNATURE_FILE, signature.getPath()); 109 } else { 110 e.getAttributes().remove(Identity.SIGNATURE_FILE); 111 } 112 113 e.notifyObservers(); 114 } 115 116 public void addObserver(Observer observer) { 117 e.addObserver(observer); 118 } 119 120 public void removeObserver(Observer observer) { 121 e.deleteObserver(observer); 122 } 123 } 124 | Popular Tags |