1 16 package org.apache.cocoon.mail; 17 18 import java.util.Map ; 19 import org.apache.cocoon.selection.AbstractSwitchSelector; 20 import org.apache.cocoon.util.Deprecation; 21 import org.apache.avalon.framework.parameters.Parameters; 22 import org.apache.cocoon.environment.Request; 23 import org.apache.cocoon.environment.ObjectModelHelper; 24 import org.apache.cocoon.environment.Session; 25 import org.apache.avalon.framework.context.ContextException; 26 46 47 51 public class MailCommandSelector extends AbstractSwitchSelector { 52 53 public Object getSelectorContext(Map objectModel, Parameters parameters) { 54 Request request = ObjectModelHelper.getRequest(objectModel); 55 String cmdName = MailContext.MAIL_CURRENT_WORKING_COMMAND_ENTRY; 57 String cmd = (String )request.getAttribute( cmdName ); 58 59 if (cmd == null) { 61 cmdName = "cmd"; 62 cmd = request.getParameter( cmdName ); 63 } 64 65 if (cmd == null) { 67 Session session = request.getSession( false ); 68 if (session != null) { 69 MailContext mailContext = (MailContext)session.getAttribute( MailContext.SESSION_MAIL_CONTEXT ); 70 if (mailContext != null) { 71 try { 72 cmd = (String )mailContext.get(MailContext.MAIL_CURRENT_WORKING_COMMAND_ENTRY); 73 } catch (ContextException ce) { 74 String message = "Cannot get command entry " + 75 String.valueOf(MailContext.MAIL_CURRENT_WORKING_COMMAND_ENTRY) + " " + 76 "from mailContext from session"; 77 getLogger().warn( message, ce ); 78 } 79 } 80 } 81 } 82 MailCommandBuilder mcb = new MailCommandBuilder(); 83 boolean isMapped = mcb.isCommandMapped( cmd ); 84 if (isMapped) { 85 return cmd; 86 } else { 87 return null; 90 } 91 } 92 93 public boolean select(String expression, Object selectorContext) { 94 Deprecation.logger.warn("The MailCommandSelector is deprecated." 95 + " Use RequestAttributeSelector, RequestParameterSelector, or ParameterSelector instead."); 96 if (selectorContext == null) { 97 return false; 98 } else { 99 String cmd = (String )selectorContext; 100 return cmd.equals( expression ); 101 } 102 } 103 104 } 105 106 | Popular Tags |