View Javadoc
1   /* 
2   Copyright (c) 2010, NHIN Direct Project
3   All rights reserved.
4   
5   Authors:
6      Umesh Madan     umeshma@microsoft.com
7      Greg Meyer      gm2552@cerner.com
8    
9   Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
10  
11  Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
12  Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer 
13  in the documentation and/or other materials provided with the distribution.  Neither the name of the The NHIN Direct Project (nhindirect.org). 
14  nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
15  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
16  THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 
17  BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 
18  GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 
19  STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 
20  THE POSSIBILITY OF SUCH DAMAGE.
21  */
22  
23  package org.nhindirect.gateway.smtp;
24  
25  import java.io.File;
26  import java.io.IOException;
27  
28  import org.apache.commons.io.FileUtils;
29  
30  /**
31   * Generic settings for processing messages.
32   * @author Greg Meyer
33   * @author Umesh Madan
34   *
35   */
36  public class MessageProcessingSettings
37  {
38  	private File saveMessagesFolder = null;
39  	
40  	/**
41  	 * Sets the folder where messages will be written to disk.  
42  	 * @param folder The folder where messages will be written to disk. 
43  	 */
44  	public void setSaveMessageFolder(File folder)
45  	{
46  		saveMessagesFolder = folder;
47  		
48  		try
49  		{
50  			ensureSaveMessageFolder();
51  		}
52  		catch (IOException e)
53  		{
54  			/*
55  			 * TODO: log exception
56  			 */
57  			throw new IllegalArgumentException(e);
58  		}
59  	}
60  	
61  	/**
62  	 * Gets the folder where messages will be written to desk.
63  	 * @return The folder where messages will be written to desk.
64  	 */
65  	public File getSaveMessageFolder()
66  	{
67  		return saveMessagesFolder;
68  	}
69  	
70  	/**
71  	 * Indicates if messages should be written to disk.  If this setting is null, then messages will not be written.  This is
72  	 * useful for debugging, but generally should not be set in a production environment.
73  	 * @return
74  	 */
75  	public boolean hasSaveMessageFolder()
76  	{
77  		return getSaveMessageFolder() != null;
78  	}
79  	
80  	/*
81  	 * Ensures that a valid folder exits for messages to be written to.
82  	 */
83  	private void ensureSaveMessageFolder() throws IOException
84  	{
85  		if (hasSaveMessageFolder() && !getSaveMessageFolder().exists())
86  				FileUtils.forceMkdir(getSaveMessageFolder());	
87  	}
88  }