1 16 package org.apache.cocoon.mail; 17 18 import java.util.HashMap ; 19 import java.util.Map ; 20 21 import org.apache.avalon.framework.context.Contextualizable; 22 import org.apache.avalon.framework.logger.AbstractLogEnabled; 23 import org.apache.cocoon.mail.command.AbstractMailCommand; 24 25 37 public class MailCommandBuilder extends AbstractLogEnabled { 38 39 private Map cmdMap; 41 42 45 public MailCommandBuilder() { 46 configure(); 47 } 48 49 50 56 public AbstractMailCommand buildAbstractMailCommand(MailContext mailContext) { 57 AbstractMailCommand ama = null; 58 59 try { 60 String cmd = mailContext.getParameter("cmd"); 62 if (cmd == null) { 63 cmd = (String )mailContext.get( MailContext.MAIL_CURRENT_WORKING_COMMAND_ENTRY ); 64 } 65 Class clazz = getClassForCommand(cmd); 66 if (clazz != null) { 67 ama = (AbstractMailCommand) clazz.newInstance(); 68 ama.enableLogging(getLogger()); 70 if (ama instanceof Contextualizable) { 72 ((Contextualizable) ama).contextualize(mailContext); 73 } 74 return ama; 75 } else { 76 getLogger().error("Cmd " + String.valueOf(cmd) + " is invalid"); 77 } 78 } catch (Exception e) { 79 String message = "Cannto build AbstractMailCommand"; 80 getLogger().error(message, e); 81 } 82 return ama; 83 } 84 85 86 92 protected Class getClassForCommand( String cmd ) { 93 Class clazz = (Class )cmdMap.get( cmd ); 94 return clazz; 95 } 96 97 103 public boolean isCommandMapped( String cmd ) { 104 return cmdMap.containsKey( cmd ); 105 } 106 107 114 public void configure() { 115 cmdMap = new HashMap (); 116 cmdMap.put("cat-folder", MailCommandManager.MailFolderCatCommand.class); 117 cmdMap.put("refresh-folder", MailCommandManager.MailRefreshFolderCommand.class); 118 cmdMap.put("list-folder", MailCommandManager.MailListFolderCommand.class); 119 cmdMap.put("list-folder-messages", MailCommandManager.MailListMessagesCommand.class); 120 cmdMap.put("search-folder-messages", MailCommandManager.MailSearchMessagesCommand.class); 121 cmdMap.put("cat-message-by-uid", MailCommandManager.MailCatMessageByUIDCommand.class); 122 cmdMap.put("cat-message-by-id", MailCommandManager.MailCatMessageByIdCommand.class); 123 cmdMap.put("cat-attachment-of-message-by-id", MailCommandManager.MailCatAttachmentMessageByIdCommand.class); 124 } 125 126 } 127 128 | Popular Tags |