001: //The contents of this file are subject to the Mozilla Public License Version 1.1
002: //(the "License"); you may not use this file except in compliance with the
003: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
004: //
005: //Software distributed under the License is distributed on an "AS IS" basis,
006: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
007: //for the specific language governing rights and
008: //limitations under the License.
009: //
010: //The Original Code is "The Columba Project"
011: //
012: //The Initial Developers of the Original Code are Frederik Dietz and Timo Stich.
013: //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
014: //
015: //All Rights Reserved.
016:
017: package org.columba.mail.config;
018:
019: import java.io.File;
020: import java.util.Observer;
021:
022: import org.columba.core.xml.XmlElement;
023: import org.columba.ristretto.message.Address;
024: import org.columba.ristretto.parser.ParserException;
025:
026: /**
027: * Encapsulates an identity used with an account.
028: */
029: public class Identity {
030:
031: private static final String SIGNATURE_FILE = "signature_file";
032: private static final String ORGANISATION = "organisation";
033: private static final String REPLY_ADDRESS = "reply_address";
034: private static final String NAME = "name";
035: private static final String ADDRESS = "address";
036:
037: protected XmlElement e;
038: protected Address address;
039: protected Address replyToAddress;
040:
041: public Identity(XmlElement e) throws ParserException {
042: this .e = e;
043: String value = e.getAttribute(Identity.ADDRESS);
044: if (value != null && value.length() > 0) {
045: address = Address.parse(e.getAttribute(Identity.ADDRESS));
046: address.setDisplayName(e.getAttribute(Identity.NAME));
047: }
048: value = e.getAttribute(Identity.REPLY_ADDRESS);
049: if (value != null && value.length() > 0) {
050: replyToAddress = Address.parse(value);
051: }
052: }
053:
054: public Address getAddress() {
055: return address;
056: }
057:
058: public void setAddress(Address address) {
059: this .address = address;
060: e.addAttribute(Identity.NAME, address.getDisplayName());
061: e.addAttribute(Identity.ADDRESS, address.getMailAddress());
062: }
063:
064: public Address getReplyToAddress() {
065: return replyToAddress;
066: }
067:
068: public void setReplyToAddress(Address address) {
069: replyToAddress = address;
070: if (address != null) {
071: e.addAttribute(Identity.REPLY_ADDRESS, address
072: .getMailAddress());
073: } else {
074: e.getAttributes().remove(Identity.REPLY_ADDRESS);
075: }
076: }
077:
078: public String getOrganisation() {
079: return e.getAttribute(Identity.ORGANISATION);
080: }
081:
082: public void setOrganisation(String organisation) {
083: if (organisation != null) {
084: e.addAttribute(Identity.ORGANISATION, organisation);
085: } else {
086: e.getAttributes().remove(Identity.ORGANISATION);
087: }
088: }
089:
090: /**
091: * Returns the signature that should be attached to outgoing mails.
092: */
093: public File getSignature() {
094: String path = e.getAttribute(Identity.SIGNATURE_FILE);
095: if (path != null) {
096: File signature = new File(path);
097: if (signature.exists() && signature.isFile()) {
098: return signature;
099: }
100: }
101: return null;
102: }
103:
104: /**
105: * Sets the signature to be attached to outgoing mails.
106: */
107: public void setSignature(File signature) {
108: if (signature != null && signature.exists()
109: && signature.isFile()) {
110: e
111: .addAttribute(Identity.SIGNATURE_FILE, signature
112: .getPath());
113: } else {
114: e.getAttributes().remove(Identity.SIGNATURE_FILE);
115: }
116:
117: e.notifyObservers();
118: }
119:
120: public void addObserver(Observer observer) {
121: e.addObserver(observer);
122: }
123:
124: public void removeObserver(Observer observer) {
125: e.deleteObserver(observer);
126: }
127: }
|