org.apache.james.transport.mailets
Class CommandListservManager

java.lang.Object
  extended by org.apache.mailet.GenericMailet
      extended by org.apache.james.transport.mailets.CommandListservManager
All Implemented Interfaces:
ICommandListservManager, Mailet, MailetConfig

public class CommandListservManager
extends GenericMailet
implements ICommandListservManager

CommandListservManager is the default implementation of ICommandListservManager. It loads all the configured IListServCommands and delegates to them at runtime.
It isn't responsible for procesing messages sent to the main mailing list, but is responsible for individual commands sent by users, such as: info, subscribe, etc...
Requests sent to the CommandListservManager take the form of:

 <listName>-<commandName>@domain
 
If the command isn't recognized an error will be sent using onError(org.apache.mailet.Mail, java.lang.String, java.lang.String).

The configuration for this mailet sould be in the 'root' processor block.
 <mailet match="CommandListservMatcher=announce@localhost" class="CommandListservManager">
  <listName>announce</listName>
  <displayName>Announce mailing list</displayName>
  <listOwner>owner@localhost</listOwner>
  <repositoryName>list-announce</repositoryName>
  <listDomain>localhost</listDomain>

  <commandpackages>
     <commandpackage>org.apache.james.transport.mailets.listservcommands</commandpackage>
  </commandpackages>

  <commands>
     <command name="subscribe" class="Subscribe"/>
     <command name="subscribe-confirm" class="SubscribeConfirm"/>
     <command name="unsubscribe" class="UnSubscribe"/>
     <command name="unsubscribe-confirm" class="UnSubscribeConfirm"/>
     <command name="error" class="ErrorCommand"/>
     <command name="owner" class="Owner"/>
     <command name="info" class="Info"/>
  </commands>
 </mailet>
 


Todo: refine the command matching so we can have more sophistciated commands such as:
 <listName>-<commandName>-<optCommandParam>@domain
 

Since:
2.2.0
Version:
CVS $Revision: 430699 $ $Date: 2006-08-11 07:02:35 +0000 (ven, 11 ago 2006) $

Field Summary
protected  java.util.Map commandMap
           
protected  java.util.List commandPackages
           
protected  java.lang.String displayName
           
protected  java.lang.String listDomain
           
protected  java.lang.String listName
           
protected  java.lang.String listOwner
           
protected  UsersRepository usersRepository
           
protected  XMLResources xmlResources
           
 
Fields inherited from interface org.apache.james.transport.mailets.ICommandListservManager
ID
 
Constructor Summary
CommandListservManager()
           
 
Method Summary
 IListServCommand getCommand(java.lang.String name)
          Get a specific command specified by the 'commands' configuration block.
protected  java.lang.String getCommandName(MailAddress mailAddress)
          Get the name of the command
 java.util.Map getCommands()
          Get all the available commands
 IListServCommand getCommandTarget(MailAddress mailAddress)
          Based on the to address get a valid or command or null
protected static java.lang.Object getField(java.lang.Object instance, java.lang.String name)
          Retrieves a data field, potentially defined by a super class.
 java.lang.String getListDomain()
          Get the domain of the list specified by the config param: 'listDomain'.
 java.lang.String getListName(boolean displayFormat)
          Get the name of this list specified by the config param: 'listName'.
 java.lang.String getListOwner()
          Gets the owner of this list specified by the config param: 'listOwner'.
 java.lang.String getResourcesFile()
           
 java.util.Properties getStandardProperties()
          Use this to get standard properties for future calls to XMLResources
 UsersRepository getUsersRepository()
          Get the current user repository for this list serv
 void init()
          A convenience method which can be overridden so that there's no need to call super.init(config).
protected  void initializeResources()
          initialize the resources
protected  void initUsersRepository()
          Fetch the repository of users
 XMLResources[] initXMLResources(java.lang.String[] names)
          Initializes an array of resources
protected  void loadCommand(java.lang.String commandName, java.lang.String className, org.apache.avalon.framework.configuration.Configuration configuration)
          Loads and initializes a single command
protected  void loadCommandPackages(org.apache.avalon.framework.configuration.Configuration configuration)
          loads all of the packages for the commands
protected  void loadCommands(org.apache.avalon.framework.configuration.Configuration configuration)
          Load an initialize all of the available commands
 void onError(Mail mail, java.lang.String subject, java.lang.String errorMessage)
          An error occurred, send some sort of message
 void service(Mail mail)
          Called by the mailet container to allow the mailet to process a message.
 
Methods inherited from class org.apache.mailet.GenericMailet
destroy, getInitParameter, getInitParameter, getInitParameterNames, getMailetConfig, getMailetContext, getMailetInfo, getMailetName, init, log, log
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.apache.mailet.Mailet
destroy, getMailetConfig, getMailetInfo, init
 

Field Detail

commandMap

protected java.util.Map commandMap

commandPackages

protected java.util.List commandPackages

usersRepository

protected UsersRepository usersRepository

listName

protected java.lang.String listName

displayName

protected java.lang.String displayName

listOwner

protected java.lang.String listOwner

listDomain

protected java.lang.String listDomain

xmlResources

protected XMLResources xmlResources
Constructor Detail

CommandListservManager

public CommandListservManager()
Method Detail

getListName

public java.lang.String getListName(boolean displayFormat)
Get the name of this list specified by the config param: 'listName'.
eg:
<listName>announce</listName>

Specified by:
getListName in interface ICommandListservManager
Parameters:
displayFormat - is whether you want a display version of this or not
Returns:
the official display name of this list

getListOwner

public java.lang.String getListOwner()
Gets the owner of this list specified by the config param: 'listOwner'.
eg:
<listOwner>owner@localhost</listOwner>

Specified by:
getListOwner in interface ICommandListservManager
Returns:
this is an address like listOwner@localhost

getListDomain

public java.lang.String getListDomain()
Get the domain of the list specified by the config param: 'listDomain'.
eg:
<listDomain>localhost</listDomain>

Specified by:
getListDomain in interface ICommandListservManager
Returns:
a string like localhost

getCommand

public IListServCommand getCommand(java.lang.String name)
Get a specific command specified by the 'commands' configuration block. For instance:
 <commands>
  <command name="subscribe" class="Subscribe"/>
  <command name="subscribe-confirm" class="SubscribeConfirm"/>
  <command name="unsubscribe" class="UnSubscribe"/>
  <command name="unsubscribe-confirm" class="UnSubscribeConfirm"/>
  <command name="error" class="ErrorCommand"/>
  <command name="owner" class="Owner"/>
  <command name="info" class="Info"/>
 </commands>
 

Specified by:
getCommand in interface ICommandListservManager
Parameters:
name - case in-sensitive
Returns:
a IListServCommand if found, null otherwise

getCommands

public java.util.Map getCommands()
Get all the available commands

Specified by:
getCommands in interface ICommandListservManager
Returns:
a map of IListServCommand
See Also:
getCommand(java.lang.String)

getUsersRepository

public UsersRepository getUsersRepository()
Get the current user repository for this list serv

Specified by:
getUsersRepository in interface ICommandListservManager
Returns:
an instance of UsersRepository that is used for the member list of the list serv

onError

public void onError(Mail mail,
                    java.lang.String subject,
                    java.lang.String errorMessage)
             throws javax.mail.MessagingException
An error occurred, send some sort of message

Specified by:
onError in interface ICommandListservManager
Parameters:
subject - the subject of the message to send
mail -
errorMessage -
Throws:
javax.mail.MessagingException

getResourcesFile

public java.lang.String getResourcesFile()
Specified by:
getResourcesFile in interface ICommandListservManager
Returns:
the configuration file for the xml resources

getStandardProperties

public java.util.Properties getStandardProperties()
Use this to get standard properties for future calls to XMLResources

Specified by:
getStandardProperties in interface ICommandListservManager
Returns:
properties with the "LIST_NAME" and the "DOMAIN_NAME" properties

initXMLResources

public XMLResources[] initXMLResources(java.lang.String[] names)
                                throws org.apache.avalon.framework.configuration.ConfigurationException
Initializes an array of resources

Specified by:
initXMLResources in interface ICommandListservManager
Parameters:
names - such as 'header, footer' etc...
Returns:
an initialized array of XMLResources
Throws:
org.apache.avalon.framework.configuration.ConfigurationException

init

public void init()
          throws javax.mail.MessagingException
Description copied from class: GenericMailet

A convenience method which can be overridden so that there's no need to call super.init(config).

Instead of overriding init(MailetConfig), simply override this method and it will be called by GenericMailet.init(MailetConfig config). The MailetConfig object can still be retrieved via getMailetConfig().

Overrides:
init in class GenericMailet
Throws:
javax.mail.MessagingException - if an exception occurs that interrupts the mailet's normal operation

getCommandTarget

public IListServCommand getCommandTarget(MailAddress mailAddress)
Based on the to address get a valid or command or null

Specified by:
getCommandTarget in interface ICommandListservManager
Parameters:
mailAddress -
Returns:
IListServCommand or null

service

public void service(Mail mail)
             throws javax.mail.MessagingException

Called by the mailet container to allow the mailet to process a message.

This method is declared abstract so subclasses must override it.

Specified by:
service in interface Mailet
Specified by:
service in class GenericMailet
Parameters:
mail - - the Mail object that contains the MimeMessage and routing information
Throws:
javax.mail.MessagingException - - if an exception occurs that interferes with the mailet's normal operation occurred

getCommandName

protected java.lang.String getCommandName(MailAddress mailAddress)
Get the name of the command

Parameters:
mailAddress -
Returns:
the name of the command

initializeResources

protected void initializeResources()
                            throws java.lang.Exception
initialize the resources

Throws:
java.lang.Exception

initUsersRepository

protected void initUsersRepository()
Fetch the repository of users


loadCommands

protected void loadCommands(org.apache.avalon.framework.configuration.Configuration configuration)
                     throws java.lang.Exception
Load an initialize all of the available commands

Parameters:
configuration -
Throws:
org.apache.avalon.framework.configuration.ConfigurationException
java.lang.Exception

loadCommand

protected void loadCommand(java.lang.String commandName,
                           java.lang.String className,
                           org.apache.avalon.framework.configuration.Configuration configuration)
                    throws org.apache.avalon.framework.configuration.ConfigurationException,
                           java.lang.ClassNotFoundException,
                           java.lang.IllegalAccessException,
                           java.lang.InstantiationException
Loads and initializes a single command

Parameters:
commandName -
className -
configuration -
Throws:
org.apache.avalon.framework.configuration.ConfigurationException
java.lang.ClassNotFoundException
java.lang.IllegalAccessException
java.lang.InstantiationException

loadCommandPackages

protected void loadCommandPackages(org.apache.avalon.framework.configuration.Configuration configuration)
                            throws org.apache.avalon.framework.configuration.ConfigurationException
loads all of the packages for the commands

Parameters:
configuration -
Throws:
org.apache.avalon.framework.configuration.ConfigurationException

getField

protected static java.lang.Object getField(java.lang.Object instance,
                                           java.lang.String name)
                                    throws java.lang.IllegalAccessException
Retrieves a data field, potentially defined by a super class.

Returns:
null if not found, the object otherwise
Throws:
java.lang.IllegalAccessException


Copyright © 2002-2007 The Apache Software Foundation. All Rights Reserved.