org.apache.james.transport.mailets
Class CommandListservManager

java.lang.Object
  extended byorg.apache.mailet.GenericMailet
      extended byorg.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 03:02:35 -0400 (Fri, 11 Aug 2006) $

Field Summary
protected  Map commandMap
           
protected  List commandPackages
           
protected  String displayName
           
protected  String listDomain
           
protected  String listName
           
protected  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(String name)
          Get a specific command specified by the 'commands' configuration block.
protected  String getCommandName(MailAddress mailAddress)
          Get the name of the command
 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 Object getField(Object instance, String name)
          Retrieves a data field, potentially defined by a super class.
 String getListDomain()
          Get the domain of the list specified by the config param: 'listDomain'.
 String getListName(boolean displayFormat)
          Get the name of this list specified by the config param: 'listName'.
 String getListOwner()
          Gets the owner of this list specified by the config param: 'listOwner'.
 String getResourcesFile()
           
 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(String[] names)
          Initializes an array of resources
protected  void loadCommand(String commandName, 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, String subject, 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 Map commandMap

commandPackages

protected List commandPackages

usersRepository

protected UsersRepository usersRepository

listName

protected String listName

displayName

protected String displayName

listOwner

protected String listOwner

listDomain

protected String listDomain

xmlResources

protected XMLResources xmlResources
Constructor Detail

CommandListservManager

public CommandListservManager()
Method Detail

getListName

public 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 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 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(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 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,
                    String subject,
                    String errorMessage)
             throws 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:
MessagingException

getResourcesFile

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

getStandardProperties

public 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(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 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:
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 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:
MessagingException - - if an exception occurs that interferes with the mailet's normal operation occurred

getCommandName

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

Parameters:
mailAddress -
Returns:
the name of the command

initializeResources

protected void initializeResources()
                            throws Exception
initialize the resources

Throws:
Exception

initUsersRepository

protected void initUsersRepository()
Fetch the repository of users


loadCommands

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

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

loadCommand

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

Parameters:
commandName -
className -
configuration -
Throws:
org.apache.avalon.framework.configuration.ConfigurationException
ClassNotFoundException
IllegalAccessException
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 Object getField(Object instance,
                                 String name)
                          throws IllegalAccessException
Retrieves a data field, potentially defined by a super class.

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


"Copyright © 1999-2006 Apache Jakarta Project. All Rights Reserved."