001 package org.rakeshv.mail;
002
003 import java.util.Collection;
004
005 import org.rakeshv.BaseObject;
006 import org.rakeshv.CustomException;
007
008 import org.rakeshv.xml.mail.ApplicationSettings;
009 import org.rakeshv.xml.mail.AttachmentSettings;
010 import org.rakeshv.xml.mail.ImageSettings;
011 import org.rakeshv.xml.mail.MailServerPreferences;
012 import org.rakeshv.xml.mail.ServerSettings;
013
014 /**
015 * A wrapper bean that provides easy access to all the properties
016 * configured in the application wide mail server preferences XML
017 * file. This class provides convenience methods that serve the
018 * purpose of hiding the complexity of the XML and object model from
019 * the application.
020 *
021 * <p>Copyright 2004, Rakesh Vidyadharan</p>
022 *
023 * @author Rakesh Vidyadharan 7<sup><small>th</small></sup> November, 2004
024 * @version $Id: ServerPreferences.java,v 1.1 2005/04/26 11:30:35 rakesh Exp $
025 */
026 public class ServerPreferences extends BaseObject
027 {
028 /**
029 * The fully qualified path to the file that contains the preferences.
030 */
031 private String fileName;
032
033 /**
034 * The reference to the <code>MailServerPreferences</code> object
035 * that is wrapped by this object.
036 */
037 private MailServerPreferences mailServerPreferences;
038
039 /**
040 * Default constructor. No special actions required.
041 */
042 public ServerPreferences()
043 {
044 super();
045 }
046
047 /**
048 * Returns {@link #fileName}.
049 *
050 * @return String The value/reference of/to fileName.
051 */
052 public final String getFileName()
053 {
054 return fileName;
055 }
056
057 /**
058 * Set {@link #fileName}. After setting the fileName, create the
059 * appropriate instance of {@link #mailServerPreferences} with the
060 * contents of the specified file.
061 *
062 * @param fileName The value to set.
063 * @throws MailException If errors are encountered while reading or
064 * parsing the file.
065 */
066 public final void setFileName( String fileName )
067 throws MailException
068 {
069 this.fileName = fileName;
070
071 try
072 {
073 mailServerPreferences = new MailServerPreferences( fileName );
074 }
075 catch ( Throwable t )
076 {
077 throw new MailException( true,
078 "Error reading/parsing properties file " +
079 fileName + ".", t );
080 }
081 }
082
083 /**
084 * Returns {@link #mailServerPreferences}.
085 *
086 * @return MailServerPreferences The value/reference of/to mailServerPreferences.
087 */
088 public final MailServerPreferences getMailServerPreferences()
089 {
090 return mailServerPreferences;
091 }
092
093 /**
094 * Set {@link #mailServerPreferences}.
095 *
096 * @param mailServerPreferences The value to set.
097 */
098 public final void setMailServerPreferences(
099 MailServerPreferences mailServerPreferences )
100 {
101 this.mailServerPreferences = mailServerPreferences;
102 }
103
104 /**
105 * Wrapper method that returns the <code>connectionProtocol</code>
106 * element value.
107 *
108 * @return String - The connection protocol to use (usually imap).
109 */
110 public final String getConnectionProtocol()
111 {
112 return mailServerPreferences.getServerSettings().getConnectionProtocol();
113 }
114
115 /**
116 * Wrapper method that returns the <code>port</code>
117 * element value.
118 *
119 * @return int - The port number to connect to (usually 143)
120 */
121 public final int getPort()
122 {
123 return mailServerPreferences.getServerSettings().getPort();
124 }
125
126 /**
127 * Wrapper method that returns the <code>mailTransportProtocol</code>
128 * element value.
129 *
130 * @return String - The mail protocol to use (usually smtp).
131 */
132 public final String getMailTransportProtocol()
133 {
134 return mailServerPreferences.getServerSettings().getMailTransportProtocol();
135 }
136
137 /**
138 * Wrapper method that returns the <code>host</code>
139 * element value.
140 *
141 * @return String - The fully qualified name of the server to connect
142 * to.
143 */
144 public final String getHost()
145 {
146 return mailServerPreferences.getServerSettings().getHost();
147 }
148
149 /**
150 * Wrapper method that returns the collection of <code>domain</code>
151 * element values.
152 *
153 * @return Collection - The collection of additional domains which the
154 * server supports.
155 */
156 public final Collection getDomain()
157 {
158 return mailServerPreferences.getServerSettings().getDomain();
159 }
160
161 /**
162 * Wrapper method that returns the <code>inboxFolder</code>
163 * element value.
164 *
165 * @return String - The name of the inbox folder.
166 */
167 public final String getInboxFolder()
168 {
169 return mailServerPreferences.getServerSettings().getInboxFolder();
170 }
171
172 /**
173 * Wrapper method that returns the <code>attachmentRootDirectory</code>
174 * element value.
175 *
176 * @return String - The fully qualified path for the root directory
177 * for storing attachments.
178 */
179 public final String getAttachmentRootDirectory()
180 {
181 return mailServerPreferences.getApplicationSettings().getAttachmentSettings().getAttachmentRootDirectory();
182 }
183
184 /**
185 * Wrapper method that returns the <code>webserverAttachmentPath</code>
186 * element value.
187 *
188 * @return String - The application relative/absolute path for
189 * accessing the attachments.
190 */
191 public final String getWebserverAttachmentPath()
192 {
193 return mailServerPreferences.getApplicationSettings().getAttachmentSettings().getWebserverAttachmentPath();
194 }
195
196 /**
197 * Wrapper method that returns the <code>deletedImage</code>
198 * element value.
199 *
200 * @return String - The absolute/relative path for the deleted image.
201 */
202 public final String getDeletedImage()
203 {
204 return mailServerPreferences.getApplicationSettings().getImageSettings().getDeletedImage();
205 }
206
207 /**
208 * Wrapper method that returns the <code>newImage</code>
209 * element value.
210 *
211 * @return String - The absolute/relative path for the new image.
212 */
213 public final String getNewImage()
214 {
215 return mailServerPreferences.getApplicationSettings().getImageSettings().getNewImage();
216 }
217
218 /**
219 * Wrapper method that returns the <code>readImage</code>
220 * element value.
221 *
222 * @return String - The absolute/relative path for the read image.
223 */
224 public final String getReadImage()
225 {
226 return mailServerPreferences.getApplicationSettings().getImageSettings().getReadImage();
227 }
228
229 /**
230 * Wrapper method that returns the <code>repliedImage</code>
231 * element value.
232 *
233 * @return String - The absolute/relative path for the replied image.
234 */
235 public final String getRepliedImage()
236 {
237 return mailServerPreferences.getApplicationSettings().getImageSettings().getRepliedImage();
238 }
239 }