org.apache.avalon.excalibur.logger.factory
Class SMTPTargetFactory

java.lang.Object
  extended by org.apache.avalon.framework.logger.AbstractLogEnabled
      extended by org.apache.avalon.excalibur.logger.factory.AbstractTargetFactory
          extended by org.apache.avalon.excalibur.logger.factory.SMTPTargetFactory
All Implemented Interfaces:
LogTargetFactory, org.apache.avalon.framework.configuration.Configurable, org.apache.avalon.framework.context.Contextualizable, org.apache.avalon.framework.logger.LogEnabled

public class SMTPTargetFactory
extends AbstractTargetFactory

SMTPTargetFactory class.

This factory creates SMTPOutputLogTarget's. It uses the context-key attribute to locate the required JavaMail Session from the Context object passed to this factory. The default context-key is session-context.

 <smtp id="target-id" context-key="context-key-to-session-object">
   <format type="raw|pattern|extended">pattern to be used if needed</format>
   <to>address-1@host</to>
   <to>address-N@host</to>
   <from>address@host</from>
   <subject>subject line</subject>
   <maximum-size>number</maximum-size>
   <maximum-delay-time>seconds</maximum-delay-time>
   <debug>false</debug>
 </smtp>
 
The Factory will look for a javax.mail.Session instance in the Context using the specified context-key. If your needs are simple, then it is also possible to define a Session within the configuration by replacing the context-key attribute with a session child element as follows:

 <session>
   <parameter name="mail.host" value="mail.apache.com"/>
 </session>
 
The Session is created by calling Session.getInstance, providing a Properties object whose values are defined in the above block. Any valid name value pair can be specified.

<format>
The type attribute of the pattern element denotes the type of Formatter to be used and according to it the pattern to use for. This elements defaults to:

%7.7{priority} %5.5{time} [%8.8{category}] (%{context}): %{message}\\n%{throwable}

Since:
4.1
Version:
CVS $Revision: 1.14 $ $Date: 2004/03/10 13:54:50 $
Author:
Avalon Development Team

Field Summary
 
Fields inherited from class org.apache.avalon.excalibur.logger.factory.AbstractTargetFactory
m_configuration, m_context
 
Constructor Summary
SMTPTargetFactory()
           
 
Method Summary
protected  javax.mail.Address createAddress(java.lang.String address)
          Helper factory method to create a new Address object.
 org.apache.log.LogTarget createTarget(org.apache.avalon.framework.configuration.Configuration config)
          Creates an SMTPOutputLogTarget based on a Configuration
private  boolean getDebug(org.apache.avalon.framework.configuration.Configuration config)
          Helper method to obtain the debug glag to use from the given configuration object.
protected  org.apache.log.format.Formatter getFormatter(org.apache.avalon.framework.configuration.Configuration config)
          Helper method to obtain a formatter for this factory.
private  javax.mail.Address getFromAddress(org.apache.avalon.framework.configuration.Configuration config)
          Helper method to obtain the from address from the given configuration.
private  int getMaxDelayTime(org.apache.avalon.framework.configuration.Configuration config)
          Helper method to obtain the maximum delay time any particular SMTP message can be queued from a given configuration object.
private  int getMaxSize(org.apache.avalon.framework.configuration.Configuration config)
          Helper method to obtain the maximum size any particular SMTP message can be from a given configuration object.
protected  javax.mail.Session getSession(org.apache.avalon.framework.configuration.Configuration config)
          Helper method to create a JavaMail Session object.
private  java.lang.String getSubject(org.apache.avalon.framework.configuration.Configuration config)
          Helper method to obtain the subject line to use from the given configuration object.
private  javax.mail.Address[] getToAddresses(org.apache.avalon.framework.configuration.Configuration config)
          Helper method to obtain the to address/es from the given configuration.
 
Methods inherited from class org.apache.avalon.excalibur.logger.factory.AbstractTargetFactory
configure, contextualize
 
Methods inherited from class org.apache.avalon.framework.logger.AbstractLogEnabled
enableLogging, getLogger, setupLogger, setupLogger, setupLogger
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SMTPTargetFactory

public SMTPTargetFactory()
Method Detail

createTarget

public final org.apache.log.LogTarget createTarget(org.apache.avalon.framework.configuration.Configuration config)
                                            throws org.apache.avalon.framework.configuration.ConfigurationException
Creates an SMTPOutputLogTarget based on a Configuration

Parameters:
config - a Configuration instance
Returns:
LogTarget instance
Throws:
org.apache.avalon.framework.configuration.ConfigurationException - if an error occurs

getFormatter

protected org.apache.log.format.Formatter getFormatter(org.apache.avalon.framework.configuration.Configuration config)
Helper method to obtain a formatter for this factory.

Parameters:
config - a Configuration instance
Returns:
a Formatter instance

getSession

protected javax.mail.Session getSession(org.apache.avalon.framework.configuration.Configuration config)
                                 throws org.apache.avalon.framework.context.ContextException,
                                        org.apache.avalon.framework.configuration.ConfigurationException
Helper method to create a JavaMail Session object. If your session object has simple needs, you can nest a configuration element named session containing name-value pairs that are passed to Session.getInstance(). If no configuration is found, a Session will be loaded from this factory's context object. You can override this method if you need ot obtain the JavaMail session using some other means.

Returns:
JavaMail Session instance
Throws:
org.apache.avalon.framework.context.ContextException - if an error occurs
org.apache.avalon.framework.configuration.ConfigurationException - if invalid session configuration

getSubject

private java.lang.String getSubject(org.apache.avalon.framework.configuration.Configuration config)
                             throws org.apache.avalon.framework.configuration.ConfigurationException
Helper method to obtain the subject line to use from the given configuration object.

Parameters:
config - a Configuration instance
Returns:
subject line
Throws:
org.apache.avalon.framework.configuration.ConfigurationException

getMaxSize

private int getMaxSize(org.apache.avalon.framework.configuration.Configuration config)
                throws org.apache.avalon.framework.configuration.ConfigurationException
Helper method to obtain the maximum size any particular SMTP message can be from a given configuration object.

Parameters:
config - a Configuration instance
Returns:
maximum SMTP mail size
Throws:
org.apache.avalon.framework.configuration.ConfigurationException

getMaxDelayTime

private int getMaxDelayTime(org.apache.avalon.framework.configuration.Configuration config)
                     throws org.apache.avalon.framework.configuration.ConfigurationException
Helper method to obtain the maximum delay time any particular SMTP message can be queued from a given configuration object.

Parameters:
config - a Configuration instance
Returns:
maximum SMTP mail delay time
Throws:
org.apache.avalon.framework.configuration.ConfigurationException

getToAddresses

private javax.mail.Address[] getToAddresses(org.apache.avalon.framework.configuration.Configuration config)
                                     throws org.apache.avalon.framework.configuration.ConfigurationException,
                                            javax.mail.internet.AddressException
Helper method to obtain the to address/es from the given configuration.

Parameters:
config - Configuration instance
Returns:
an array of Address objects
Throws:
org.apache.avalon.framework.configuration.ConfigurationException - if a configuration error occurs
javax.mail.internet.AddressException - if a addressing error occurs

getFromAddress

private javax.mail.Address getFromAddress(org.apache.avalon.framework.configuration.Configuration config)
                                   throws org.apache.avalon.framework.configuration.ConfigurationException,
                                          javax.mail.internet.AddressException
Helper method to obtain the from address from the given configuration.

Parameters:
config - a Configuration instance
Returns:
an Address object
Throws:
org.apache.avalon.framework.configuration.ConfigurationException - if a configuration error occurs
javax.mail.internet.AddressException - if a addressing error occurs

getDebug

private boolean getDebug(org.apache.avalon.framework.configuration.Configuration config)
                  throws org.apache.avalon.framework.configuration.ConfigurationException
Helper method to obtain the debug glag to use from the given configuration object.

Parameters:
config - a Configuration instance
Returns:
subject line
Throws:
org.apache.avalon.framework.configuration.ConfigurationException

createAddress

protected javax.mail.Address createAddress(java.lang.String address)
                                    throws javax.mail.internet.AddressException
Helper factory method to create a new Address object. Override this method in a subclass if you wish to create other Address types rather than InternetAddress (eg. NewsAddress)

Parameters:
address - address string from configuration
Returns:
an Address object
Throws:
javax.mail.internet.AddressException - if an error occurs