01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: *
17: * $Header:$
18: */
19: package org.apache.beehive.netui.tags.naming;
20:
21: import org.apache.beehive.netui.script.ExpressionEvaluationException;
22: import org.apache.beehive.netui.script.ExpressionEvaluator;
23: import org.apache.beehive.netui.script.ExpressionEvaluatorFactory;
24: import org.apache.beehive.netui.util.logging.Logger;
25:
26: import javax.servlet.jsp.tagext.Tag;
27:
28: /**
29: * A {@link INameInterceptor} that qualifies all non-expression attributes
30: * that are expected to be expressions into valid
31: * expressions. This conversion is for Struts compatability;
32: * In Struts, the "property" property is used to specify which
33: * property on the action form should be rendered in a tag's
34: * HTML. These attributes are converted into expressions
35: * by qualifying them into the <code>actionForm</code> binding
36: * context.
37: * <br/>
38: * <br/>
39: * For example, the <code>dataSource</code> attribute on a text box
40: * tag would be qualified into the <code>actionForm</code> context
41: * if the attribute was not an expression.
42: */
43: public class FormDataNameInterceptor implements INameInterceptor {
44: private static final Logger logger = Logger
45: .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 rewriteName(String name, Tag currentTag)
56: throws ExpressionEvaluationException {
57: ExpressionEvaluator eval = ExpressionEvaluatorFactory
58: .getInstance();
59:
60: try {
61: if (!eval.isExpression(name))
62: return eval.qualify("actionForm", name);
63: return name;
64: } catch (Exception e) {
65: if (logger.isErrorEnabled())
66: logger.error("Could not qualify name \"" + name
67: + "\" 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: }
|