001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.cocoon.mail;
018:
019: import java.util.Map;
020: import org.apache.cocoon.selection.AbstractSwitchSelector;
021: import org.apache.cocoon.util.Deprecation;
022: import org.apache.avalon.framework.parameters.Parameters;
023: import org.apache.cocoon.environment.Request;
024: import org.apache.cocoon.environment.ObjectModelHelper;
025: import org.apache.cocoon.environment.Session;
026: import org.apache.avalon.framework.context.ContextException;
027:
028: /*
029: usage:
030: <map:select type="mail-selector">
031: <!-- optional -->
032: <map:parameter name="command" value="{request-attribute:cmd}"/>
033:
034: <!-- get value from request.getAttribute( "cmd" ) -->
035: <map:parameter name="command" value="cmd"/>
036:
037: <map:when test="cat-folder">
038: </map:when>
039:
040: <map:otherwise>
041: </map:otherwise>
042:
043: <map:when test="command-defined">
044: <map:when test="command-undefined">
045:
046: <map:when test="
047: */
048:
049: /**
050: * @deprecated use RequestAttributeSelector, RequestParameterSelector, or ParameterSelector instead.
051: * @version $Id: MailCommandSelector.java 468424 2006-10-27 15:44:53Z vgritsenko $
052: */
053: public class MailCommandSelector extends AbstractSwitchSelector {
054:
055: public Object getSelectorContext(Map objectModel,
056: Parameters parameters) {
057: Request request = ObjectModelHelper.getRequest(objectModel);
058: // try to get the command from the request-attribute
059: String cmdName = MailContext.MAIL_CURRENT_WORKING_COMMAND_ENTRY;
060: String cmd = (String) request.getAttribute(cmdName);
061:
062: // try to get command from the request parameter
063: if (cmd == null) {
064: cmdName = "cmd";
065: cmd = request.getParameter(cmdName);
066: }
067:
068: // try to get command from the session attribute
069: if (cmd == null) {
070: Session session = request.getSession(false);
071: if (session != null) {
072: MailContext mailContext = (MailContext) session
073: .getAttribute(MailContext.SESSION_MAIL_CONTEXT);
074: if (mailContext != null) {
075: try {
076: cmd = (String) mailContext
077: .get(MailContext.MAIL_CURRENT_WORKING_COMMAND_ENTRY);
078: } catch (ContextException ce) {
079: String message = "Cannot get command entry "
080: + String
081: .valueOf(MailContext.MAIL_CURRENT_WORKING_COMMAND_ENTRY)
082: + " " + "from mailContext from session";
083: getLogger().warn(message, ce);
084: }
085: }
086: }
087: }
088: MailCommandBuilder mcb = new MailCommandBuilder();
089: boolean isMapped = mcb.isCommandMapped(cmd);
090: if (isMapped) {
091: return cmd;
092: } else {
093: // uup the command is invalid, we will surly be not able to map it to a valid
094: // AbstractMailAction
095: return null;
096: }
097: }
098:
099: public boolean select(String expression, Object selectorContext) {
100: Deprecation.logger
101: .warn("The MailCommandSelector is deprecated."
102: + " Use RequestAttributeSelector, RequestParameterSelector, or ParameterSelector instead.");
103: if (selectorContext == null) {
104: return false;
105: } else {
106: String cmd = (String) selectorContext;
107: return cmd.equals(expression);
108: }
109: }
110:
111: }
|