📄 commandlistservmanager.java
字号:
/**************************************************************** * Licensed to the Apache Software Foundation (ASF) under one * * or more contributor license agreements. See the NOTICE file * * distributed with this work for additional information * * regarding copyright ownership. The ASF licenses this file * * to you under the Apache License, Version 2.0 (the * * "License"); you may not use this file except in compliance * * with the License. You may obtain a copy of the License at * * * * http://www.apache.org/licenses/LICENSE-2.0 * * * * Unless required by applicable law or agreed to in writing, * * software distributed under the License is distributed on an * * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * * KIND, either express or implied. See the License for the * * specific language governing permissions and limitations * * under the License. * ****************************************************************/package org.apache.james.transport.mailets;import org.apache.avalon.framework.service.ServiceManager;import org.apache.avalon.framework.configuration.Configuration;import org.apache.avalon.framework.configuration.ConfigurationException;import org.apache.james.Constants;import org.apache.james.services.UsersRepository;import org.apache.james.services.UsersStore;import org.apache.james.transport.mailets.listservcommands.ErrorCommand;import org.apache.james.transport.mailets.listservcommands.IListServCommand;import org.apache.james.util.XMLResources;import org.apache.mailet.GenericMailet;import org.apache.mailet.Mail;import org.apache.mailet.MailAddress;import javax.mail.MessagingException;import java.io.File;import java.lang.reflect.Field;import java.util.ArrayList;import java.util.HashMap;import java.util.Iterator;import java.util.List;import java.util.Locale;import java.util.Map;import java.util.Properties;/** * CommandListservManager is the default implementation of {@link ICommandListservManager}. * It loads all the configured {@link IListServCommand}s and delegates to them at runtime. * <br /> * * 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... * <br /> * * Requests sent to the CommandListservManager take the form of: * <pre> * <listName>-<commandName>@domain * </pre> * * If the command isn't recognized an error will be sent using {@link #onError}. * <br /> * <br /> * * The configuration for this mailet sould be in the 'root' processor block. * <pre> * <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> * </pre> * * <br /> * <br /> * Todo: refine the command matching so we can have more sophistciated commands such as: * <pre> * <listName>-<commandName>-<optCommandParam>@domain * </pre> * * @version CVS $Revision: 430699 $ $Date: 2006-08-11 09:02:35 +0200 (Fr, 11 Aug 2006) $ * @since 2.2.0 */public class CommandListservManager extends GenericMailet implements ICommandListservManager { protected Map commandMap = new HashMap(); protected List commandPackages = new ArrayList(); protected UsersRepository usersRepository; protected String listName; protected String displayName; protected String listOwner; protected String listDomain; protected XMLResources xmlResources; /** * Get the name of this list specified by the config param: 'listName'. * <br /> * eg: <pre><listName>announce</listName></pre> * * @param displayFormat is whether you want a display version of this or not * @return the official display name of this list */ public String getListName(boolean displayFormat) { return displayFormat ? displayName : listName; } /** * Gets the owner of this list specified by the config param: 'listOwner'. * <br /> * eg: <pre><listOwner>owner@localhost</listOwner></pre> * * @return this is an address like listOwner@localhost */ public String getListOwner() { return listOwner; } /** * Get the domain of the list specified by the config param: 'listDomain'. * <br /> * eg: <pre><listDomain>localhost</listDomain></pre> * * @return a string like localhost */ public String getListDomain() { return listDomain; } /** * Get a specific command specified by the 'commands' configuration block. * For instance: * <pre> * <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> * </pre> * @param name case in-sensitive * @return a {@link IListServCommand} if found, null otherwise */ public IListServCommand getCommand(String name) { return (IListServCommand) commandMap.get(name.toLowerCase(Locale.US)); } /** * Get all the available commands * @return a map of {@link IListServCommand} * @see #getCommand */ public Map getCommands() { return commandMap; } /** * Get the current user repository for this list serv * @return an instance of {@link UsersRepository} that is used for the member list of the list serv */ public UsersRepository getUsersRepository() { return usersRepository; } /** * An error occurred, send some sort of message * @param subject the subject of the message to send * @param mail * @param errorMessage */ public void onError(Mail mail, String subject, String errorMessage) throws MessagingException { ErrorCommand errorCommand = (ErrorCommand) getCommand("error"); errorCommand.onError(mail, subject, errorMessage); } /** * @return the configuration file for the xml resources */ public String getResourcesFile() { return getInitParameter("resources"); } /** * Use this to get standard properties for future calls to {@link org.apache.james.util.XMLResources} * @return properties with the "LIST_NAME" and the "DOMAIN_NAME" properties */ public Properties getStandardProperties() { Properties standardProperties = new Properties(); standardProperties.put("LIST_NAME", getListName(false)); standardProperties.put("DISPLAY_NAME", getListName(true)); standardProperties.put("DOMAIN_NAME", getListDomain()); return standardProperties; } /** * Initializes an array of resources * @param names such as 'header, footer' etc... * @return an initialized array of XMLResources * @throws ConfigurationException */ public XMLResources[] initXMLResources(String[] names) throws ConfigurationException {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -