KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > mail > config > Identity


1 //The contents of this file are subject to the Mozilla Public License Version 1.1
2
//(the "License"); you may not use this file except in compliance with the
3
//License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
4
//
5
//Software distributed under the License is distributed on an "AS IS" basis,
6
//WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
7
//for the specific language governing rights and
8
//limitations under the License.
9
//
10
//The Original Code is "The Columba Project"
11
//
12
//The Initial Developers of the Original Code are Frederik Dietz and Timo Stich.
13
//Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
14
//
15
//All Rights Reserved.
16

17 package org.columba.mail.config;
18
19 import java.io.File JavaDoc;
20 import java.util.Observer JavaDoc;
21
22 import org.columba.core.xml.XmlElement;
23 import org.columba.ristretto.message.Address;
24 import org.columba.ristretto.parser.ParserException;
25
26 /**
27  * Encapsulates an identity used with an account.
28  */

29 public class Identity {
30     
31     private static final String JavaDoc SIGNATURE_FILE = "signature_file";
32     private static final String JavaDoc ORGANISATION = "organisation";
33     private static final String JavaDoc REPLY_ADDRESS = "reply_address";
34     private static final String JavaDoc NAME = "name";
35     private static final String JavaDoc 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 JavaDoc 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 JavaDoc getOrganisation() {
78         return e.getAttribute(Identity.ORGANISATION);
79     }
80     
81     public void setOrganisation(String JavaDoc organisation) {
82         if (organisation != null) {
83             e.addAttribute(Identity.ORGANISATION, organisation);
84         } else {
85             e.getAttributes().remove(Identity.ORGANISATION);
86         }
87     }
88     
89     /**
90      * Returns the signature that should be attached to outgoing mails.
91      */

92     public File JavaDoc getSignature() {
93         String JavaDoc path = e.getAttribute(Identity.SIGNATURE_FILE);
94         if (path != null) {
95             File JavaDoc signature = new File JavaDoc(path);
96             if (signature.exists() && signature.isFile()) {
97                 return signature;
98             }
99         }
100         return null;
101     }
102     
103     /**
104      * Sets the signature to be attached to outgoing mails.
105      */

106     public void setSignature(File JavaDoc 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 JavaDoc observer) {
117         e.addObserver(observer);
118     }
119
120     public void removeObserver(Observer JavaDoc observer) {
121         e.deleteObserver(observer);
122     }
123 }
124
Popular Tags