KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > mail > MailCommandSelector


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.cocoon.mail;
17
18 import java.util.Map JavaDoc;
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 /*
27 usage:
28   <map:select type="mail-selector">
29     <!-- optional -->
30     <map:parameter name="command" value="{request-attribute:cmd}"/>
31     
32     <!-- get value from request.getAttribute( "cmd" ) -->
33     <map:parameter name="command" value="cmd"/>
34     
35     <map:when test="cat-folder">
36     </map:when>
37     
38     <map:otherwise>
39     </map:otherwise>
40
41     <map:when test="command-defined">
42     <map:when test="command-undefined">
43     
44     <map:when test="
45 */

46
47 /**
48  * @deprecated use RequestAttributeSelector, RequestParameterSelector, or ParameterSelector instead.
49  * @version CVS $Id: MailCommandSelector.java 157288 2005-03-12 22:42:07Z sylvain $
50  */

51 public class MailCommandSelector extends AbstractSwitchSelector {
52   
53     public Object JavaDoc getSelectorContext(Map JavaDoc objectModel, Parameters parameters) {
54         Request request = ObjectModelHelper.getRequest(objectModel);
55         // try to get the command from the request-attribute
56
String JavaDoc cmdName = MailContext.MAIL_CURRENT_WORKING_COMMAND_ENTRY;
57         String JavaDoc cmd = (String JavaDoc)request.getAttribute( cmdName );
58       
59         // try to get command from the request parameter
60
if (cmd == null) {
61             cmdName = "cmd";
62             cmd = request.getParameter( cmdName );
63         }
64
65         // try to get command from the session attribute
66
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 JavaDoc)mailContext.get(MailContext.MAIL_CURRENT_WORKING_COMMAND_ENTRY);
73                     } catch (ContextException ce) {
74                         String JavaDoc 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             // uup the command is invalid, we will surly be not able to map it to a valid
88
// AbstractMailAction
89
return null;
90         }
91     }
92
93     public boolean select(String JavaDoc expression, Object JavaDoc 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 JavaDoc cmd = (String JavaDoc)selectorContext;
100             return cmd.equals( expression );
101         }
102     }
103
104 }
105
106
Popular Tags