KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > beehive > netui > pageflow > ExpressionMessage


1 /*
2  * Copyright 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  * $Header:$
17  */

18 package org.apache.beehive.netui.pageflow;
19
20 import org.apache.struts.action.ActionMessage;
21 import org.apache.beehive.netui.pageflow.internal.InternalConstants;
22 import org.apache.beehive.netui.pageflow.internal.InternalExpressionUtils;
23 import org.apache.beehive.netui.pageflow.internal.InternalUtils;
24 import org.apache.beehive.netui.util.logging.Logger;
25
26 import javax.servlet.ServletContext JavaDoc;
27 import javax.servlet.http.HttpServletRequest JavaDoc;
28
29 /**
30  * Extension of the base Struts ActionMessage; instead of retrieving messages and their arguments from message
31  * resources, it calculates them by evaluating JSP 2.0-style expressions (or, in the degenerate case, from hardcoded
32  * strings).
33  */

34 public class ExpressionMessage
35         extends ActionMessage
36 {
37     /**
38      * Constructor, using an array for the message arguments.
39      *
40      * @param expression the JSP 2.0-style expression (e.g., <code>${pageFlow.myProperty}</code>) or literal string
41      * that will be used as the message.
42      * @param messageArgExpressions an array of JSP 2.0-style expressions <i>or</i> raw Objects to be used as arguments
43      * to the message. Expressions are evaluated; all other Objects are passed as-is.
44      */

45     public ExpressionMessage( String JavaDoc expression, Object JavaDoc[] messageArgExpressions )
46     {
47         super( InternalConstants.MESSAGE_IS_EXPRESSION_PREFIX + expression, prefixArgs( messageArgExpressions ) );
48     }
49     
50     /**
51      * Constructor, for a message without message arguments.
52      *
53      * @param expression the JSP 2.0-style expression (e.g., <code>${pageFlow.myProperty}</code>) or literal string
54      * that will be used as the message.
55      */

56     public ExpressionMessage( String JavaDoc expression )
57     {
58         this( expression, null );
59     }
60     
61     /**
62      * Constructor, for a message with a single argument.
63      *
64      * @param expression the JSP 2.0-style expression (e.g., <code>${pageFlow.myProperty}</code>) or literal string
65      * that will be used as the message.
66      * @param messageArgExpression a JSP 2.0-style expression <i>or</i> raw Object to be used the argument
67      * to the message. Expressions are evaluated; all other Objects are passed as-is.
68      */

69     public ExpressionMessage( String JavaDoc expression, Object JavaDoc messageArgExpression )
70     {
71         this( expression, new Object JavaDoc[]{ messageArgExpression } );
72     }
73     
74     /**
75      * Constructor, for a message with two arguments.
76      *
77      * @param expression the JSP 2.0-style expression (e.g., <code>${pageFlow.myProperty}</code>) or literal string
78      * that will be used as the message.
79      * @param messageArgExpression1 a JSP 2.0-style expression <i>or</i> raw Object to be used the first argument
80      * to the message. Expressions are evaluated; all other Objects are passed as-is.
81      * @param messageArgExpression2 a JSP 2.0-style expression <i>or</i> raw Object to be used the second argument
82      * to the message. Expressions are evaluated; all other Objects are passed as-is.
83      */

84     public ExpressionMessage( String JavaDoc expression, Object JavaDoc messageArgExpression1, Object JavaDoc messageArgExpression2 )
85     {
86         this( expression, new Object JavaDoc[]{ messageArgExpression1, messageArgExpression2 } );
87     }
88     
89     /**
90      * Constructor, for a message with two arguments.
91      *
92      * @param expression the JSP 2.0-style expression (e.g., <code>${pageFlow.myProperty}</code>) or literal string
93      * that will be used as the message.
94      * @param messageArgExpression1 a JSP 2.0-style expression <i>or</i> raw Object to be used the first argument
95      * to the message. Expressions are evaluated; all other Objects are passed as-is.
96      * @param messageArgExpression2 a JSP 2.0-style expression <i>or</i> raw Object to be used the second argument
97      * to the message. Expressions are evaluated; all other Objects are passed as-is.
98      * @param messageArgExpression3 a JSP 2.0-style expression <i>or</i> raw Object to be used the third argument
99      * to the message. Expressions are evaluated; all other Objects are passed as-is.
100      */

101     public ExpressionMessage( String JavaDoc expression, Object JavaDoc messageArgExpression1, Object JavaDoc messageArgExpression2,
102                               Object JavaDoc messageArgExpression3 )
103     {
104         this( expression, new Object JavaDoc[]{ messageArgExpression1, messageArgExpression2, messageArgExpression3 } );
105     }
106     
107     private static Object JavaDoc[] prefixArgs( Object JavaDoc[] messageArgExpressions )
108     {
109         if ( messageArgExpressions == null ) return null;
110         
111         Object JavaDoc[] ret = new Object JavaDoc[ messageArgExpressions.length ];
112         
113         for ( int i = 0; i < messageArgExpressions.length; i++ )
114         {
115             ret[i] = InternalConstants.MESSAGE_IS_EXPRESSION_PREFIX + messageArgExpressions[i];
116         }
117         
118         return ret;
119     }
120 }
121
Popular Tags