KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > beehive > netui > tags > naming > FormDataNameInterceptor


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.tags.naming;
19
20 import org.apache.beehive.netui.script.ExpressionEvaluationException;
21 import org.apache.beehive.netui.script.ExpressionEvaluator;
22 import org.apache.beehive.netui.script.ExpressionEvaluatorFactory;
23 import org.apache.beehive.netui.util.logging.Logger;
24
25 import javax.servlet.jsp.tagext.Tag JavaDoc;
26
27 /**
28  * A {@link INameInterceptor} that qualifies all non-expression attributes
29  * that are expected to be expressions into valid
30  * expressions. This conversion is for Struts compatability;
31  * In Struts, the "property" property is used to specify which
32  * property on the action form should be rendered in a tag's
33  * HTML. These attributes are converted into expressions
34  * by qualifying them into the <code>actionForm</code> binding
35  * context.
36  * <br/>
37  * <br/>
38  * For example, the <code>dataSource</code> attribute on a text box
39  * tag would be qualified into the <code>actionForm</code> context
40  * if the attribute was not an expression.
41  */

42 public class FormDataNameInterceptor
43         implements INameInterceptor
44 {
45     private static final Logger logger = Logger.getInstance(FormDataNameInterceptor.class);
46
47     /**
48      * Qualify the name of a NetUI JSP tag into the "actionForm" data binding context.
49      * This feature is used to convert non-expression tag names, as those used in Struts,
50      * into actionForm expressions that NetUI consumes.
51      * @param name the name to qualify into the actionForm binding context. If this is "foo", the returned value
52      * is {actionForm.foo}
53      * @return the qualified name or <code>null</code> if an error occurred
54      */

55     public String JavaDoc rewriteName(String JavaDoc name, Tag JavaDoc currentTag)
56             throws ExpressionEvaluationException
57     {
58         ExpressionEvaluator eval = ExpressionEvaluatorFactory.getInstance();
59
60         try {
61             if (!eval.isExpression(name))
62                 return eval.qualify("actionForm", name);
63             return name;
64         }
65         catch (Exception JavaDoc e) {
66             if (logger.isErrorEnabled())
67                 logger.error("Could not qualify name \"" + name + "\" into the actionForm binding context.", e);
68
69             // return the Struts name. This should cause regular Struts databinding to execute so this property will
70
// be updated anyway.
71
return name;
72         }
73     }
74 }
75
Popular Tags