Author: dolander
Date: Sat Aug 7 15:47:47 2004
New Revision: 36074
Added:
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/ExpressionHandling.java
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/INetuiTag.java
Modified:
incubator/beehive/trunk/netui/src/bootstrap/org/apache/beehive/netui/tools/tld/xdoclet/tld.xdt
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/script/common/ImplicitObjectBean.java
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/script/common/ImplicitObjectUtil.java
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/script/el/NetUIReadVariableResolver.java
incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/databinding/script/el/ContainerVariableResolver.java
incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/tags/databinding/datagrid/DataGrid.java
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/AbstractClassicTag.java
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/AbstractSimpleTag.java
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/DataSourceTag.java
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/ErrorHandling.java
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/Body.java
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/Error.java
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/ErrorBaseTag.java
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/Errors.java
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/Html.java
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/HtmlDataSourceTag.java
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/HtmlGroupBaseTag.java
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/tree/Tree.java
incubator/beehive/trunk/netui/src/tags-template/org/apache/beehive/netui/tags/template/DivPanel.java
incubator/beehive/trunk/netui/src/tags-template/org/apache/beehive/netui/tags/template/Section.java
Log:
With this checkin I introduce the AbstractSimpleTag that supports SimpleTag
allowing the
NetUI tags to be written as simple tags. In addition, I converted the Error
and Errors tag
to being simple tags as a proof of concept.
To do this, I moved all of the expression handling into a new
ExpressionHandling class and off
the base tag. In addition, I move expression handling to the dataSource tags
directly.
Finally, there was a bit of work to make the base APIs switch from relying on
Tag to JspTag.
Modified:
incubator/beehive/trunk/netui/src/bootstrap/org/apache/beehive/netui/tools/tld/xdoclet/tld.xdt
==============================================================================
---
incubator/beehive/trunk/netui/src/bootstrap/org/apache/beehive/netui/tools/tld/xdoclet/tld.xdt
(original)
+++
incubator/beehive/trunk/netui/src/bootstrap/org/apache/beehive/netui/tools/tld/xdoclet/tld.xdt
Sat Aug 7 15:47:47 2004
@@ -55,7 +55,7 @@
</XDtClass:forAllClasses>
<XDtNetUITldGen:forAllClasses
-
type="javax.servlet.jsp.tagext.Tag,javax.servlet.jsp.tagext.TagSupport,javax.servlet.jsp.tagext.BodyTagSupport,org.apache.beehive.netui.tags.AbstractBaseTag,org.apache.beehive.netui.tags.DataSourceTag,org.apache.beehive.netui.tags.databinding.base.StructuredBaseTag,org.apache.beehive.netui.tags.html.HtmlBaseTag"
+
type="javax.servlet.jsp.tagext.Tag,javax.servlet.jsp.tagext.JspTag,javax.servlet.jsp.tagext.SimpleTag,javax.servlet.jsp.tagext.TagSupport,javax.servlet.jsp.tagext.SimpleTagSupport,javax.servlet.jsp.tagext.BodyTagSupport,org.apache.beehive.netui.tags.AbstractBaseTag,org.apache.beehive.netui.tags.AbstractSimpleTag,org.apache.beehive.netui.tags.DataSourceTag,org.apache.beehive.netui.tags.databinding.base.StructuredBaseTag,org.apache.beehive.netui.tags.html.HtmlBaseTag"
abstract="false"
extent="hierarchy">
<XDtClass:ifHasClassTag tagName="netui:tag">
@@ -67,7 +67,7 @@
<XDtClass:ifHasClassTag tagName="netui:tag" paramName="tei-class">
<teiclass><XDtClass:classTagValue tagName="netui:tag"
paramName="tei-class"/></teiclass>
</XDtClass:ifHasClassTag>
- <XDtClass:ifHasClassTag tagName="netui:tag" paramName="body-content"
values="JSP,empty,tagdependent">
+ <XDtClass:ifHasClassTag tagName="netui:tag" paramName="body-content"
values="JSP,empty,scriptless,tagdependent">
<bodycontent><XDtClass:classTagValue tagName="netui:tag"
paramName="body-content"/></bodycontent>
</XDtClass:ifHasClassTag>
</XDtConfig:ifConfigParamEquals>
@@ -78,7 +78,7 @@
<XDtClass:ifHasClassTag tagName="netui:tag" paramName="tei-class">
<tei-class><XDtClass:classTagValue tagName="netui:tag"
paramName="tei-class"/></tei-class>
</XDtClass:ifHasClassTag>
- <XDtClass:ifHasClassTag tagName="netui:tag" paramName="body-content"
values="JSP,empty,tagdependent">
+ <XDtClass:ifHasClassTag tagName="netui:tag" paramName="body-content"
values="JSP,empty,scriptless,tagdependent">
<body-content><XDtClass:classTagValue tagName="netui:tag"
paramName="body-content"/></body-content>
</XDtClass:ifHasClassTag>
<XDtClass:ifHasClassTag tagName="netui:tag" paramName="description">
Modified:
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/script/common/ImplicitObjectBean.java
==============================================================================
---
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/script/common/ImplicitObjectBean.java
(original)
+++
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/script/common/ImplicitObjectBean.java
Sat Aug 7 15:47:47 2004
@@ -31,6 +31,7 @@
import javax.servlet.http.HttpSession;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.Tag;
+import javax.servlet.jsp.tagext.JspTag;
// internal imports
import org.apache.beehive.netui.util.logging.Logger;
@@ -45,7 +46,7 @@
private static final Logger _logger =
Logger.getInstance(ImplicitObjectUtil.class);
private PageContext _pageContext;
- private Tag _tag;
+ private JspTag _tag;
private Object _actionForm;
private ServletRequest _request;
private ServletResponse _response;
@@ -93,8 +94,8 @@
_application = servletContext;
}
- public Tag getCurrentTag() {return _tag;}
- public void setCurrentTag(Tag tag)
+ public JspTag getCurrentTag() {return _tag;}
+ public void setCurrentTag(JspTag tag)
{
_tag = tag;
}
Modified:
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/script/common/ImplicitObjectUtil.java
==============================================================================
---
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/script/common/ImplicitObjectUtil.java
(original)
+++
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/script/common/ImplicitObjectUtil.java
Sat Aug 7 15:47:47 2004
@@ -30,6 +30,7 @@
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.el.VariableResolver;
import javax.servlet.jsp.tagext.Tag;
+import javax.servlet.jsp.tagext.JspTag;
// internal imports
import org.apache.beehive.netui.pageflow.GlobalApp;
@@ -58,7 +59,7 @@
private ImplicitObjectUtil() {}
- public static final ImplicitObjectBean getImplicitObjects(PageContext
pageContext, Tag currentTag)
+ public static final ImplicitObjectBean getImplicitObjects(PageContext
pageContext, JspTag currentTag)
{
ImplicitObjectBean bean =
(ImplicitObjectBean)pageContext.getRequest().getAttribute(IMPLICIT_OBJECT_BEAN);
Modified:
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/script/el/NetUIReadVariableResolver.java
==============================================================================
---
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/script/el/NetUIReadVariableResolver.java
(original)
+++
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/script/el/NetUIReadVariableResolver.java
Sat Aug 7 15:47:47 2004
@@ -23,6 +23,7 @@
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.Tag;
+import javax.servlet.jsp.tagext.JspTag;
import javax.servlet.jsp.el.VariableResolver;
// internal imports
@@ -56,10 +57,10 @@
}
private PageContext _pc = null;
- private Tag _currentTag = null;
+ private JspTag _currentTag = null;
private Object _form = null;
- public NetUIReadVariableResolver(Object form, Tag currentTag, PageContext
pc)
+ public NetUIReadVariableResolver(Object form, JspTag currentTag,
PageContext pc)
{
_pc = pc;
_form = form;
@@ -114,7 +115,7 @@
return new String[] {"actionForm", "pageFlow", "globalApp", "request",
"session", "application", "pageContext", "bundle", "container", "url",
"pageInput"};
}
- public Tag getCurrentTag()
+ public JspTag getCurrentTag()
{
return _currentTag;
}
Modified:
incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/databinding/script/el/ContainerVariableResolver.java
==============================================================================
---
incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/databinding/script/el/ContainerVariableResolver.java
(original)
+++
incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/databinding/script/el/ContainerVariableResolver.java
Sat Aug 7 15:47:47 2004
@@ -21,6 +21,8 @@
// java imports
import javax.servlet.jsp.el.VariableResolver;
import javax.servlet.jsp.tagext.Tag;
+import javax.servlet.jsp.tagext.JspTag;
+import javax.servlet.jsp.tagext.SimpleTagSupport;
// internal imports
import org.apache.beehive.netui.script.common.IDataAccessProvider;
@@ -49,14 +51,12 @@
{
assert vr instanceof NetUIReadVariableResolver;
- Tag currentTag = ((NetUIReadVariableResolver)vr).getCurrentTag();
+ JspTag currentTag =
((NetUIReadVariableResolver)vr).getCurrentTag();
if(currentTag == null)
throw new RuntimeException("There is no current tag; the
container binding context can not be created.");
- Tag parent = currentTag.getParent();
- while(parent != null && !(parent instanceof IDataAccessProvider))
- parent = parent.getParent();
+ JspTag parent = SimpleTagSupport.findAncestorWithClass(currentTag,
IDataAccessProvider.class);
if(parent == null)
{
Modified:
incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/tags/databinding/datagrid/DataGrid.java
==============================================================================
---
incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/tags/databinding/datagrid/DataGrid.java
(original)
+++
incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/tags/databinding/datagrid/DataGrid.java
Sat Aug 7 15:47:47 2004
@@ -33,6 +33,7 @@
import org.apache.beehive.netui.databinding.datagrid.util.PagedDataSet;
import org.apache.beehive.netui.tags.AbstractClassicTag;
+import org.apache.beehive.netui.tags.ExpressionHandling;
import org.apache.beehive.netui.script.common.IDataAccessProvider;
import org.apache.beehive.netui.script.common.DataAccessProviderStack;
import org.apache.beehive.netui.util.logging.Logger;
@@ -106,8 +107,9 @@
dataSource = "{" + dataSource + "}";
// ensure the dataSource is a valid expression
- String validExpr = ensureValidExpression(dataSource, "dataSource",
"DataSourceError");
- Object ds = evaluateExpression(validExpr, "dataSource");
+ ExpressionHandling expr = new ExpressionHandling(this);
+ String validExpr = expr.ensureValidExpression(dataSource,
"dataSource", "DataSourceError");
+ Object ds = expr.evaluateExpression(validExpr, "dataSource",
pageContext);
Iterator iterator = IteratorFactory.createIterator(ds);
PagedDataSet dataSet = new PagedDataSet(dataSource, iterator);
Modified:
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/AbstractClassicTag.java
==============================================================================
---
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/AbstractClassicTag.java
(original)
+++
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/AbstractClassicTag.java
Sat Aug 7 15:47:47 2004
@@ -61,7 +61,7 @@
* @netui:tag
*/
public abstract class AbstractClassicTag
- extends BodyTagSupport
+ extends BodyTagSupport implements INetuiTag
{
//@todo: how should we handle errors messages from third party tags?
//@todo: need to implement the flag to turn errors into JSP exceptions
@@ -87,11 +87,6 @@
private static final NameInterceptor formRewriter = new
FormDataNameInterceptor();
/**
- * static flag indicating if we are reporting errors in-page or throwing
JspExceptions.
- */
- private static boolean reportErrorInPage = true;
-
- /**
* String constant for the empty string.
*/
protected static final String EMPTY_STRING = "";
@@ -105,8 +100,8 @@
DefaultNamingChain = Collections.unmodifiableList(l);
}
- private List _errors = null; // the errors registered for
the tag
private ExpressionEvaluator ee = null; // cache the expression
evaluator
+ private ErrorHandling _eh; // This class will track and
handle errors
/////////////////////////// Generic Services support
////////////////////////////
@@ -123,7 +118,7 @@
protected void localRelease()
{
ee = null;
- _errors = null;
+ _eh = null;
// null the current tag
ImplicitObjectBean bean =
ImplicitObjectUtil.getImplicitObjects(pageContext, this);
@@ -210,256 +205,6 @@
}
return sb.toString();
}
- /////////////////////////// Expression Evaluation support
////////////////////////////
-
- /**
- * Return a cached instance of an <code>ExpressionEvaluator</code>. This
will be cached by the
- * tag and release during <code>localRelease</code>.
- * @return the <code>ExpressionEvalutor</code> for tis tag.
- */
- private final ExpressionEvaluator getExpressionEvaluator()
- {
- if (ee == null)
- ee = ExpressionEvaluatorFactory.getInstance();
-
- assert(ee != null);
- return ee;
- }
-
- /**
- * An internal method that is used for evaluating the
<code>dataSource</code>
- * attribute. The <code>dataSource</code> attribute is handled specially
- * becuase it must be of a particular format in order to be usable by
- * NetUI tags. This requirement exists in order to facilitate
- * round-tripping the <code>dataSource</code> attribute as the
- * <code>name</code> attribute of HTML tags. Upon a POST, the
<code>name</code>
- * attribute is used as an l-value for an update expression in order
- * to push any POST-ed data back into the bean from whence it came.
- */
- /**
- * Ensure that the passed in data source is a valid expression.
- * @param dataSource
- * @param attrName
- * @param errorId
- * @return String
- * @throws JspException
- */
- protected String ensureValidExpression(String dataSource, String attrName,
String errorId)
- throws JspException
- {
- try {
- boolean isExpr = isExpression(dataSource);
-
- // @perf: if the isExpr call fails, this is an error condition,
and the containsExpression
- // call cost is irrelevant
- if (!isExpr && containsExpression(dataSource)) {
- String s = Bundle.getString(errorId, new Object[]{dataSource});
- registerTagError(s, null);
- return null;
- }
-
- // known: either a valid expression or doesn't contain an
expression
-
- // assume: this is a Struts expression, not a NetUI one. Attempt
to convert
- // it into a NetUI expression and then check to make sure it
actually became
- // a valid expression.
- if (!isExpr) {
- // attempt to convert to an expression
- dataSource = qualifyAttribute(dataSource);
-
- // if the conversion resulted in an invalid expression
- if (!isExpression(dataSource)) {
- String s = Bundle.getString(errorId, new
Object[]{dataSource});
- registerTagError(s, null);
- return null;
- }
- }
- }
- catch (Exception e) {
- // pass throw JspExceptions
- if (e instanceof JspException)
- throw (JspException) e;
-
- String s = Bundle.getString(errorId, new Object[]{dataSource});
- registerTagError(s, e);
- return null;
- }
- return dataSource;
- }
-
- /**
- * Evaluate an automic expression or literal returning the value.
<code>expr</code> will
- * either be an expression or will be returned as the results. If
<code>expr</code> is an automic
- * expression it will be evaluated and the results returned to the caller.
- * @param expr the value, which is either an automic expression or a
literal value
- * @param attrName the name of the attribute so errors can be reported
- * @param errorId the <code>String</code> value indentifying the bundle
message
- * @return <code>expr</code> if it is a literal, the evaluated value if
<code>expr</code> is an
- * automic expression, or null
- * @throws JspException
- */
- protected Object evaluateAutomicExpressionOrLiteral(String expr, String
attrName, String errorId)
- throws JspException
- {
- Object result = null;
- try {
- if (isExpression(expr)) {
- result = evaluateExpression(expr, attrName);
- }
- else {
- result = expr;
- }
- }
- catch (Exception e) {
- String s = Bundle.getString(errorId, new Object[]{expr, e});
- registerTagError(s, e);
- return null;
- }
-
- return result;
- }
-
- /**
- * Method which will evaluate an expression and return the value. The
expression will be qualified before
- * it is evaluated. Two errors may be reported. The first error is
reported if the <code>expr</code> is
- * not an expression. The second error is reported if there is a general
failure evaluating the expresion.
- * @param expr the expression to be evaluated.
- * @param attrName the name of the attribute containing the expression.
- * @param errorId the name of the expression error the error bundle.
- * @param evalErrorId the name of the evaluation error from the error
bundle.
- * @return an object representing the evaluation of the expression
- * @throws JspException
- */
- protected Object evaluateQualifiedExpression(String expr, String attrName,
String errorId, String evalErrorId)
- throws JspException
- {
- try {
- expr = qualifyAttribute(expr);
-
- if (!isExpression(expr)) {
- String s = Bundle.getString(errorId, new Object[]{expr});
- registerTagError(s, null);
- return null;
- }
-
- return evaluateExpression(expr, attrName);
- }
- catch (Exception e) {
- if (e instanceof JspException)
- throw (JspException) e;
-
- String s = Bundle.getString(evalErrorId, new Object[]{expr, e});
- registerTagError(s, e);
- return null;
- }
- }
-
- /**
- * @param expression
- * @param attrName
- * @return Object
- * @throws JspException
- */
- protected Object evaluateExpression(String expression, String attrName)
- throws JspException
- {
- return evaluateExpressionInternal(expression, attrName);
- }
-
- /**
- */
- private boolean isExpression(String expression)
- {
- // @TODO: eko -- push this into the ExpressionEvaluator
- if (expression == null)
- return false;
- return getExpressionEvaluator().isExpression(expression);
- }
-
- /**
- * Return a boolean indicating if the string contains an expression or not.
- * @param expression a <code>String</code> that may or may not contain an
expresion.
- * @return <code>true</code> if the string contains an expression.
- */
- protected boolean containsExpression(String expression)
- {
- // @todo: this is an assert that needs to be verified
- if (expression == null) {
- System.err.println("Contains found an expresion that is null");
- }
- assert (expression != null) : "The parameter expression must not be
null.";
- return getExpressionEvaluator().containsExpression(expression);
- }
-
- /**
- * This method will update the object identified by the <code>expr</code>
parameter with
- * the value. If the
- * @param expr
- * @param value
- * @throws ExpressionUpdateException
- */
- protected void updateExpression(String expr, Object value)
- throws ExpressionUpdateException, JspException
- {
-
- // @todo: eddie needs to review this, it doesn't seem quite right.
This is called by tree.
- if (isExpression(expr)) {
- ImplicitObjectBean bean =
ImplicitObjectUtil.getImplicitObjects(pageContext, this);
- ExpressionEvaluatorFactory.getInstance().update(expr, value, bean,
false);
- }
- else {
- String s = Bundle.getString("Tags_BindingUpdateExpressionError",
new Object[]{expr});
- registerTagError(s, null);
- }
- }
-
- /**
- * This is the real implementation of evaluateExpression.
- * @param expression
- * @param attrName
- * @return
- * @throws JspException
- */
- private Object evaluateExpressionInternal(String expression, String
attrName)
- throws JspException
- {
- if (logger.isDebugEnabled()) logger.debug("evaluate expression=\"" +
expression + "\"");
-
- Object result = null;
-
- try {
- // @perf: todo -- this is silly...
- ImplicitObjectBean bean =
ImplicitObjectUtil.getImplicitObjects(pageContext, this);
- result = getExpressionEvaluator().evaluateStrict(expression, bean);
- }
- catch (ExpressionEvaluationException ee) {
- // if there is an expression evaluation error set the error and
- // return null;
-
- if (logger.isWarnEnabled())
-
logger.warn(Bundle.getString("Tags_ExpressionEvaluationFailure", expression));
-
- // create the expression info an add it to the error tracking
- EvalErrorInfo info = new EvalErrorInfo();
- info.evalExcp = ee;
- info.expression = expression;
- info.attr = attrName;
- info.tagType = getTagName();
-
- // report the error
- registerError(info);
- assert (_errors != null);
- return null;
- }
- catch (Exception e) {
- String s = Bundle.getString("Tags_ExpressionEvaluationException",
new Object[]{expression, e.toString()});
- registerTagError(s, e);
- return null;
- }
-
- if (logger.isDebugEnabled()) logger.debug("resulting object: " +
result);
- return result;
- }
/////////////////////////// Naming and NamingInterceptor support
////////////////////////////
@@ -487,6 +232,7 @@
* @see org.apache.beehive.netui.tags.naming.NameInterceptor
*/
protected String applyNamingChain(String name)
+ throws JspException
{
assert (name != null) : "The name parameter may not be null";
@@ -524,7 +270,7 @@
info.tagType = getTagName();
// report the error
- registerError(info);
+ registerTagError(info);
return null;
}
}
@@ -605,6 +351,16 @@
/////////////////////////// Generic Error Reporting Support
////////////////////////////
+ protected int reportAndExit(int returnValue)
+ throws JspException
+ {
+ if (hasErrors()) {
+ reportErrors();
+ }
+ localRelease();
+ return returnValue;
+ }
+
/**
* This will report an error from a tag. The error will
* contain a message. If error reporting is turned off,
@@ -617,106 +373,38 @@
public void registerTagError(String message, Throwable e)
throws JspException
{
- assert (message != null) : "parameter 'message' must not be null.";
-
- // add the error to the list of errors
- if (_errors == null)
- _errors = new ArrayList();
-
- TagErrorInfo tei = new TagErrorInfo();
-
- tei.tagType = getTagName();
- tei.message = message;
- _errors.add(tei);
-
- IErrorReporter er = getErrorReporter();
- if (er == null) {
- tei.errorNo = -1;
- if (!reportErrorInPage) {
- String s = Bundle.getString("Tags_NoInPageErrorReporting", new
Object[]{message});
- if (e == null)
- logger.error(s);
- else
- logger.error(s, e);
- localRelease();
- throw new JspException(message);
- }
- return;
- }
-
- // add the error to the ErrorReporter tag
- er.addError(tei);
- assert (tei.errorNo > 0);
- if (!reportErrorInPage) {
- String s = Bundle.getString("Tags_NoInPageErrorReporting", new
Object[]{message});
- if (e == null)
- logger.error(s);
- else
- logger.error(s, e);
- localRelease();
- throw new JspException(s);
- }
- return;
+ ErrorHandling eh = getErrorHandling();
+ eh.registerTagError(message,getTagName(),this,e);
}
- /**
- * This method will add an error to the errors begin tracked by the tag.
After the first time this method
- * is called, <code>hasErrors</code> will return true.
- * @param error The <code>EvalErrorInfo</code> describing the error.
- */
- private void registerError(EvalErrorInfo error)
+ public void registerTagError(AbstractPageError error)
+ throws JspException
{
- assert (error != null);
-
- // add the error to the list of errors
- if (_errors == null)
- _errors = new ArrayList();
-
- _errors.add(error);
-
- IErrorReporter er = getErrorReporter();
- if (er == null) {
- error.errorNo = -1;
- return;
- }
-
- // add the error to the ErrorReporter tag
- er.addError(error);
- assert (error.errorNo > 0);
- }
+ ErrorHandling eh = getErrorHandling();
+ eh.registerTagError(error,this);
+ }
/**
* This method will return <code>true</code> if there have been any errors
registered on this
* tag. Otherwise it returns <code>false</code>
* @return <code>true</code> if errors have been reported on this tag.
- * @see #registerError
*/
protected boolean hasErrors()
{
- return (_errors != null);
+ return (_eh != null);
}
/**
* This method will write out the <code>String</code> returned by
<code>getErrorsReport</code> to the
* response output stream.
* @throws JspException if <code>write</code> throws an exception.
- * @see #getErrorsReport
* @see #write
*/
protected void reportErrors()
throws JspException
{
- write(getErrorsReport());
- }
-
- protected int reportAndExit(int returnValue)
- throws JspException
- {
- if (hasErrors()) {
- reportErrors();
- }
- localRelease();
- return returnValue;
+ assert(_eh != null);
+ write(_eh.getErrorsReport(getTagName()));
}
/**
@@ -724,154 +412,25 @@
* registered for the tag. This method assumes that there are errors in
the tag and asserts
* this is true. Code will typically call <code>hasErrors</code> before
calling this method.
* @return A <code>String</code> that contains all of the errors
registered on this tag.
- * @see #registerError
*/
protected String getErrorsReport()
{
- assert _errors != null;
- assert _errors.size() > 0;
-
- int cnt = _errors.size();
-
- StringBuilder sb = new StringBuilder(128);
-
- // check the first error to see if we are reporting errors at the end
- AbstractPageError info = (AbstractPageError) _errors.get(0);
- if (info.errorNo > 0) {
- String s;
- if (info instanceof EvalErrorInfo) {
- s = Bundle.getString("Expression_Error");
- s = Bundle.getString("Inline_error",
- new Object[]{
- s,
- Integer.toString(info.errorNo),
- getTagName(),
- });
- }
- else if (info instanceof TagErrorInfo) {
- s = Bundle.getString("Tag_Error");
- s = Bundle.getString("Inline_error",
- new Object[]{
- s,
- Integer.toString(info.errorNo),
- getTagName(),
- });
- }
- else {
- s = null;
- assert true : "Unhandled type";
- }
- sb.append(s);
- return s.toString();
- }
-
- // create the errors
- String s;
- s = Bundle.getString("Tag_Header",
- new Object[]{getTagName(), Integer.toString(cnt)});
- sb.append(s);
-
- Object[] args = new Object[4];
- for (int i = 0; i < cnt; i++) {
- Object o = _errors.get(i);
- if (o instanceof EvalErrorInfo) {
- EvalErrorInfo e = (EvalErrorInfo) o;
- assert info != null;
-
- args[0] = Bundle.getString("Expression_Error");
- args[1] = e.attr;
- args[2] = e.expression;
- args[3] = e.evalExcp.getMessage();
- s = Bundle.getString("Expression_Error_Line", args);
- }
- else if (o instanceof TagErrorInfo) {
- TagErrorInfo e = (TagErrorInfo) o;
- assert info != null;
-
- args[0] = Bundle.getString("Tag_Error");
- args[1] = e.message;
- s = Bundle.getString("Tag_Error_Line", args);
- }
- sb.append(s);
- }
-
- s = Bundle.getString("Tag_Footer");
- sb.append(s);
- return sb.toString();
+ assert _eh != null;
+ return _eh.getErrorsReport(getTagName());
}
- /**
- * This method get the current errors and write the formated output
- * @param sb
- */
- protected final void reportCollectedErrors(StringBuilder sb)
- {
-
- IErrorReporter er = getErrorReporter();
- if (er == null)
- return;
-
- assert (sb != null);
- ArrayList errors = er.returnErrors();
- if (errors == null || errors.size() == 0)
- return;
-
- assert(errors.size() > 0);
-
- String s;
- // write the error header
- s = Bundle.getString("Footer_Error_Header");
- sb.append(s);
-
- int cnt = errors.size();
- Object[] args = new Object[5];
- for (int i = 0; i < cnt; i++) {
- Object o = errors.get(i);
- assert (o != null);
- if (o instanceof EvalErrorInfo) {
- EvalErrorInfo err = (EvalErrorInfo) o;
- args[0] = Integer.toString(err.errorNo);
- args[1] = err.tagType;
- args[2] = err.attr;
- args[3] = err.expression;
- args[4] = err.evalExcp.getMessage();
- s = Bundle.getString("Footer_Error_Expr_Body", args);
- sb.append(s);
- }
- else if (o instanceof TagErrorInfo) {
- TagErrorInfo tei = (TagErrorInfo) o;
- args[0] = Integer.toString(tei.errorNo);
- args[1] = tei.tagType;
- args[2] = tei.message;
- s = Bundle.getString("Footer_Error_Tag_Body", args);
- sb.append(s);
- }
- }
-
- // write the error footer
- s = Bundle.getString("Footer_Error_Footer");
- sb.append(s);
- }
/**
- * This method will return the first <code>ErrorReporter</code> in the
parental chain of the
- * tag. Searching starts with this tag.
- * @return an <code>ErrorReporter</code> if one is found in the parental
chain, otherwise null.
+ * This method will return an ErrorHandling instance.
+ * @return
*/
- private IErrorReporter getErrorReporter()
- {
- // check to see if this tag has is an ErrorReporter or has an
ErrorReporter as a parent
- Tag par = this;
- while (par != null) {
- if (par instanceof IErrorReporter) {
- IErrorReporter er = (IErrorReporter) par;
- if (er.isReporting())
- return er;
- }
- par = par.getParent();
+ private ErrorHandling getErrorHandling() {
+ if (_eh == null) {
+ _eh = new ErrorHandling();
}
- return null;
+ return _eh;
}
+
/////////////////////////// JavaScript Support Support
////////////////////////////
/**
Modified:
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/AbstractSimpleTag.java
==============================================================================
---
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/AbstractSimpleTag.java
(original)
+++
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/AbstractSimpleTag.java
Sat Aug 7 15:47:47 2004
@@ -1,7 +1,116 @@
package org.apache.beehive.netui.tags;
+import org.apache.struts.util.RequestUtils;
+import org.apache.beehive.netui.util.Bundle;
+import org.apache.beehive.netui.util.logging.Logger;
+
import javax.servlet.jsp.tagext.SimpleTagSupport;
+import javax.servlet.jsp.tagext.JspTag;
+import javax.servlet.jsp.JspException;
+import javax.servlet.jsp.JspWriter;
+import javax.servlet.jsp.JspContext;
+import javax.servlet.jsp.PageContext;
+import java.io.IOException;
-public class AbstractSimpleTag extends SimpleTagSupport
+public abstract class AbstractSimpleTag extends SimpleTagSupport implements
INetuiTag
{
+ private static final Logger logger =
Logger.getInstance(AbstractSimpleTag.class);
+ private ErrorHandling _eh; // This class will
track and handle errors
+
+ /**
+ * Return the name of the tag. Used by error reporting to get the name of
the tag.
+ * @return the name of the tag.
+ */
+ public abstract String getTagName();
+
+ /**
+ * This method will attempt to cast the JspContext into a PageContext. If
this fails,
+ * it will log an exception.
+ * @return
+ */
+ protected PageContext getPageContext()
+ {
+ JspContext ctxt = getJspContext();
+ if (ctxt instanceof PageContext)
+ return (PageContext) ctxt;
+ // @todo: need to log an error
+ assert(false) : "The JspContext was not a PageContext";
+ return null;
+ }
+
+ /**
+ * This mehod will write the passed string to the response.
+ * @param string to be written to the response.
+ */
+ protected final void write(String string)
+ throws JspException
+ {
+ JspContext ctxt = getJspContext();
+ JspWriter writer = ctxt.getOut();
+ try {
+ writer.print(string);
+ } catch (IOException e) {
+ logger.error(Bundle.getString("Tags_WriteException"), e);
+ if (ctxt instanceof PageContext)
+ RequestUtils.saveException((PageContext) ctxt, e);
+ throw new JspException(e.getMessage(),e);
+ }
+ }
+
+ /**
+ * This will report an error from a tag. The error will
+ * contain a message. If error reporting is turned off,
+ * the message will be returned and the caller should throw
+ * a JspException to report the error.
+ * @param message - the message to register with the error
+ * @throws javax.servlet.jsp.JspException - if in-page error reporting is
turned off this method will always
+ * throw a JspException.
+ */
+ public void registerTagError(String message, Throwable e)
+ throws JspException
+ {
+ ErrorHandling eh = getErrorHandling();
+ eh.registerTagError(message,getTagName(),this,e);
+ }
+
+ public void registerTagError(AbstractPageError error)
+ throws JspException
+ {
+ ErrorHandling eh = getErrorHandling();
+ eh.registerTagError(error,this);
+ }
+
+ /**
+ * This method will return <code>true</code> if there have been any errors
registered on this
+ * tag. Otherwise it returns <code>false</code>
+ * @return <code>true</code> if errors have been reported on this tag.
+ */
+ protected boolean hasErrors()
+ {
+ return (_eh != null);
+ }
+
+ /**
+ * This method will write out the <code>String</code> returned by
<code>getErrorsReport</code> to the
+ * response output stream.
+ * @throws JspException if <code>write</code> throws an exception.
+ * @see #write
+ */
+ protected void reportErrors()
+ throws JspException
+ {
+ assert(_eh != null);
+ write(_eh.getErrorsReport(getTagName()));
+ }
+
+ /**
+ * This method will return an ErrorHandling instance.
+ * @return
+ */
+ private ErrorHandling getErrorHandling() {
+ if (_eh == null) {
+ _eh = new ErrorHandling();
+ }
+ return _eh;
+ }
}
Modified:
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/DataSourceTag.java
==============================================================================
---
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/DataSourceTag.java
(original)
+++
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/DataSourceTag.java
Sat Aug 7 15:47:47 2004
@@ -53,7 +53,6 @@
{
private String _dataSource = null; // backing variable.
-
/**
* Default constructor for this class.
*/
@@ -143,13 +142,14 @@
protected Object evaluateDataSource()
throws JspException
{
+ ExpressionHandling expr = new ExpressionHandling(this);
String dataSource = getDataSource();
- String ds = ensureValidExpression(dataSource, "dataSource",
"DataSourceError");
+ String ds = expr.ensureValidExpression(dataSource, "dataSource",
"DataSourceError");
if (ds == null)
return null;
// have a valid expression
- Object o = evaluateExpression(dataSource, "dataSource");
+ Object o = expr.evaluateExpression(dataSource, "dataSource",
pageContext);
return o;
}
Modified:
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/ErrorHandling.java
==============================================================================
---
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/ErrorHandling.java
(original)
+++
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/ErrorHandling.java
Sat Aug 7 15:47:47 2004
@@ -80,7 +80,8 @@
* is called, <code>hasErrors</code> will return true.
* @param error The <code>EvalErrorInfo</code> describing the error.
*/
- public void registerError(EvalErrorInfo error,JspTag tag)
+ public void registerTagError(AbstractPageError error, JspTag tag)
+ throws JspException
{
assert (error != null);
@@ -105,7 +106,7 @@
* This method will return <code>true</code> if there have been any errors
registered on this
* tag. Otherwise it returns <code>false</code>
* @return <code>true</code> if errors have been reported on this tag.
- * @see #registerError
+ * @see #registerTagError
*/
protected boolean hasErrors()
{
@@ -133,7 +134,7 @@
* registered for the tag. This method assumes that there are errors in
the tag and asserts
* this is true. Code will typically call <code>hasErrors</code> before
calling this method.
* @return A <code>String</code> that contains all of the errors
registered on this tag.
- * @see #registerError
+ * @see #registerTagError
*/
protected String getErrorsReport(String tagName)
{
@@ -213,9 +214,8 @@
* This method get the current errors and write the formated output
* @param sb
*/
- protected final void reportCollectedErrors(StringBuilder sb,JspTag tag)
+ public static void reportCollectedErrors(StringBuilder sb,JspTag tag)
{
-
IErrorReporter er = getErrorReporter(tag);
if (er == null)
return;
@@ -267,9 +267,18 @@
* tag. Searching starts with this tag.
* @return an <code>ErrorReporter</code> if one is found in the parental
chain, otherwise null.
*/
- private IErrorReporter getErrorReporter(JspTag tag)
+ private static IErrorReporter getErrorReporter(JspTag tag)
{
+ if (tag instanceof IErrorReporter && ((IErrorReporter)
tag).isReporting())
+ return (IErrorReporter) tag;
+
// check to see if this tag has is an ErrorReporter or has an
ErrorReporter as a parent
- return (IErrorReporter)
SimpleTagSupport.findAncestorWithClass(tag,IErrorReporter.class);
+ IErrorReporter er = (IErrorReporter)
SimpleTagSupport.findAncestorWithClass(tag,IErrorReporter.class);
+ while (er != null) {
+ if (er.isReporting())
+ return er;
+ er = (IErrorReporter)
SimpleTagSupport.findAncestorWithClass((JspTag) er,IErrorReporter.class);
+ }
+ return null;
}
}
Added:
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/ExpressionHandling.java
==============================================================================
--- (empty file)
+++
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/ExpressionHandling.java
Sat Aug 7 15:47:47 2004
@@ -0,0 +1,197 @@
+package org.apache.beehive.netui.tags;
+
+import org.apache.beehive.netui.script.ExpressionEvaluationException;
+import org.apache.beehive.netui.script.ExpressionEvaluator;
+import org.apache.beehive.netui.script.ExpressionEvaluatorFactory;
+import org.apache.beehive.netui.script.ExpressionUpdateException;
+import org.apache.beehive.netui.script.common.ImplicitObjectBean;
+import org.apache.beehive.netui.script.common.ImplicitObjectUtil;
+import org.apache.beehive.netui.util.Bundle;
+import org.apache.beehive.netui.util.logging.Logger;
+
+import javax.servlet.jsp.JspException;
+import javax.servlet.jsp.PageContext;
+
+public class ExpressionHandling
+{
+ private static final Logger logger =
Logger.getInstance(ExpressionHandling.class);
+
+ private ExpressionEvaluator ee = null; // cache the expression
evaluator
+ private INetuiTag _tag;
+
+ public ExpressionHandling(INetuiTag tag)
+ {
+ _tag = tag;
+ }
+
+ /**
+ * An internal method that is used for evaluating the
<code>dataSource</code>
+ * attribute. The <code>dataSource</code> attribute is handled specially
+ * becuase it must be of a particular format in order to be usable by
+ * NetUI tags. This requirement exists in order to facilitate
+ * round-tripping the <code>dataSource</code> attribute as the
+ * <code>name</code> attribute of HTML tags. Upon a POST, the
<code>name</code>
+ * attribute is used as an l-value for an update expression in order
+ * to push any POST-ed data back into the bean from whence it came.
+ */
+ /**
+ * Ensure that the passed in data source is a valid expression.
+ * @param dataSource
+ * @param attrName
+ * @param errorId
+ * @return String
+ * @throws javax.servlet.jsp.JspException
+ */
+ public String ensureValidExpression(String dataSource, String attrName,
String errorId)
+ throws JspException
+ {
+ try {
+ boolean isExpr = isExpression(dataSource);
+
+ // @perf: if the isExpr call fails, this is an error condition,
and the containsExpression
+ // call cost is irrelevant
+ if (!isExpr && containsExpression(dataSource)) {
+ String s = Bundle.getString(errorId, new Object[]{dataSource});
+ _tag.registerTagError(s, null);
+ return null;
+ }
+
+ if (!isExpr) {
+ String s = Bundle.getString(errorId, new Object[]{dataSource});
+ _tag.registerTagError(s, null);
+ return null;
+ }
+ }
+ catch (Exception e) {
+ // pass throw JspExceptions
+ if (e instanceof JspException)
+ throw (JspException) e;
+
+ String s = Bundle.getString(errorId, new Object[]{dataSource});
+ _tag.registerTagError(s, e);
+ return null;
+ }
+ return dataSource;
+ }
+
+ /**
+ * @param expression
+ * @param attrName
+ * @return Object
+ * @throws JspException
+ */
+ public Object evaluateExpression(String expression, String attrName,
PageContext ctxt)
+ throws JspException
+ {
+ return evaluateExpressionInternal(expression, attrName, ctxt);
+ }
+
+ /**
+ * This method will update the object identified by the <code>expr</code>
parameter with
+ * the value. If the
+ * @param expr
+ * @param value
+ * @throws org.apache.beehive.netui.script.ExpressionUpdateException
+ *
+ */
+ public void updateExpression(String expr, Object value, PageContext
pageContext)
+ throws ExpressionUpdateException, JspException
+ {
+
+ // @todo: eddie needs to review this, it doesn't seem quite right.
This is called by tree.
+ if (isExpression(expr)) {
+ ImplicitObjectBean bean =
ImplicitObjectUtil.getImplicitObjects(pageContext, _tag);
+ ExpressionEvaluatorFactory.getInstance().update(expr, value, bean,
false);
+ }
+ else {
+ String s = Bundle.getString("Tags_BindingUpdateExpressionError",
new Object[]{expr});
+ _tag.registerTagError(s, null);
+ }
+ }
+
+ /**
+ * Return a boolean indicating if the string contains an expression or not.
+ * @param expression a <code>String</code> that may or may not contain an
expresion.
+ * @return <code>true</code> if the string contains an expression.
+ */
+ private boolean containsExpression(String expression)
+ {
+ // @todo: this is an assert that needs to be verified
+ if (expression == null) {
+ System.err.println("Contains found an expresion that is null");
+ }
+ assert (expression != null) : "The parameter expression must not be
null.";
+ return getExpressionEvaluator().containsExpression(expression);
+ }
+
+ /**
+ */
+ private boolean isExpression(String expression)
+ {
+ // @TODO: eko -- push this into the ExpressionEvaluator
+ if (expression == null)
+ return false;
+ return getExpressionEvaluator().isExpression(expression);
+ }
+
+ /**
+ * This is the real implementation of evaluateExpression.
+ * @param expression
+ * @param attrName
+ * @return
+ * @throws JspException
+ */
+ private Object evaluateExpressionInternal(String expression, String
attrName, PageContext pageContext)
+ throws JspException
+ {
+ if (logger.isDebugEnabled()) logger.debug("evaluate expression=\"" +
expression + "\"");
+
+ Object result = null;
+
+ try {
+ // @perf: todo -- this is silly...
+ ImplicitObjectBean bean =
ImplicitObjectUtil.getImplicitObjects(pageContext, _tag);
+ result = getExpressionEvaluator().evaluateStrict(expression, bean);
+ }
+ catch (ExpressionEvaluationException ee) {
+ // if there is an expression evaluation error set the error and
+ // return null;
+
+ if (logger.isWarnEnabled())
+
logger.warn(Bundle.getString("Tags_ExpressionEvaluationFailure", expression));
+
+ // create the expression info an add it to the error tracking
+ EvalErrorInfo info = new EvalErrorInfo();
+ info.evalExcp = ee;
+ info.expression = expression;
+ info.attr = attrName;
+ info.tagType = _tag.getTagName();
+
+ // report the error
+ _tag.registerTagError(info);
+ return null;
+ }
+ catch (Exception e) {
+ String s = Bundle.getString("Tags_ExpressionEvaluationException",
new Object[]{expression, e.toString()});
+ _tag.registerTagError(s, e);
+ return null;
+ }
+
+ if (logger.isDebugEnabled()) logger.debug("resulting object: " +
result);
+ return result;
+ }
+
+ /**
+ * Return a cached instance of an <code>ExpressionEvaluator</code>. This
will be cached by the
+ * tag and release during <code>localRelease</code>.
+ * @return the <code>ExpressionEvalutor</code> for tis tag.
+ */
+ private final ExpressionEvaluator getExpressionEvaluator()
+ {
+ if (ee == null)
+ ee = ExpressionEvaluatorFactory.getInstance();
+
+ assert(ee != null);
+ return ee;
+ }
+}
Added:
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/INetuiTag.java
==============================================================================
--- (empty file)
+++
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/INetuiTag.java
Sat Aug 7 15:47:47 2004
@@ -0,0 +1,13 @@
+package org.apache.beehive.netui.tags;
+
+import javax.servlet.jsp.tagext.JspTag;
+import javax.servlet.jsp.JspException;
+
+public interface INetuiTag extends JspTag
+{
+ String getTagName();
+ void registerTagError(String message, Throwable e)
+ throws JspException;
+ void registerTagError(AbstractPageError error)
+ throws JspException;
+}
Modified:
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/Body.java
==============================================================================
---
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/Body.java
(original)
+++
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/Body.java
Sat Aug 7 15:47:47 2004
@@ -19,6 +19,7 @@
package org.apache.beehive.netui.tags.html;
import org.apache.beehive.netui.tags.IScriptReporter;
+import org.apache.beehive.netui.tags.ErrorHandling;
import org.apache.beehive.netui.tags.rendering.AbstractHtmlState;
import org.apache.beehive.netui.tags.rendering.BodyTag;
import org.apache.beehive.netui.tags.rendering.TagRenderingBase;
@@ -104,7 +105,7 @@
}
// write out any errors
- reportCollectedErrors(results);
+ ErrorHandling.reportCollectedErrors(results,this);
// write out the script before the end tag.
if (sr.isInitScriptWritten()) {
Modified:
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/Error.java
==============================================================================
---
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/Error.java
(original)
+++
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/Error.java
Sat Aug 7 15:47:47 2004
@@ -25,6 +25,7 @@
import org.apache.struts.util.RequestUtils;
import javax.servlet.jsp.JspException;
+import javax.servlet.jsp.PageContext;
import java.util.Iterator;
/**
@@ -63,7 +64,7 @@
* <pre>
* <netui:error bundle="com.project.errorMessages"
value="InvalidName"/></pre>
*
- * @netui:tag name="error" description="Renders an error message with a given
error key value."
+ * @netui:tag name="error" body-content="empty" description="Renders an error
message with a given error key value."
* @netui.tldx:tag requiredchild="#nothing"
renderer="workshop.netui.jspdesigner.tldx.ErrorRenderer"
bodycontentpref="empty" whitespace="indent"
*/
public class Error extends ErrorBaseTag
@@ -101,11 +102,14 @@
* Render the specified error message if it can be found.
* @throws JspException if a JSP exception has occurred
*/
- public int doStartTag() throws JspException
+ public void doTag()
+ throws JspException
{
// Error will try an always work even if there are expression
// errors. The error will be reported at the end.
+ PageContext pageContext = getPageContext();
+
// Were any error messages specified?
ActionErrors errors = null;
try {
@@ -116,13 +120,11 @@
throw e;
}
+ // report any expression errors
if ((errors == null) || errors.isEmpty()) {
- // report any expression errors
if (hasErrors())
reportErrors();
-
- localRelease();
- return SKIP_BODY;
+ return;
}
String qualifiedBundle = getQualifiedBundleName(_bundle);
@@ -130,25 +132,22 @@
boolean prefixPresent = false;
boolean suffixPresent = false;
String locale = _locale;
-
+
if (!isMissingDefaultMessages(pageContext))
{
try {
// Check for presence of error prefix and suffix message keys
prefixPresent =
- RequestUtils.present(pageContext, qualifiedBundle,
locale,
- "error.prefix");
+ RequestUtils.present(pageContext, qualifiedBundle,
locale, "error.prefix");
suffixPresent =
- RequestUtils.present(pageContext, qualifiedBundle,
locale,
- "error.suffix");
+ RequestUtils.present(pageContext, qualifiedBundle,
locale, "error.suffix");
}
catch (JspException e) {
String s = Bundle.getString("Tags_ErrorsException",
new Object[]{e.getMessage()});
registerTagError(s, null);
reportErrors();
- localRelease();
- return SKIP_BODY;
+ return;
}
}
@@ -184,18 +183,5 @@
// report any expression errors
if (hasErrors())
reportErrors();
-
- // Continue processing this page
- localRelease();
- return SKIP_BODY;
- }
-
- /**
- * Release any acquired resources.
- */
- protected void localRelease()
- {
- super.localRelease();
- _value = null;
}
}
Modified:
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/ErrorBaseTag.java
==============================================================================
---
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/ErrorBaseTag.java
(original)
+++
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/ErrorBaseTag.java
Sat Aug 7 15:47:47 2004
@@ -21,7 +21,8 @@
import org.apache.beehive.netui.pageflow.config.PageFlowActionMapping;
import org.apache.beehive.netui.pageflow.config.PageFlowControllerConfig;
import org.apache.beehive.netui.pageflow.internal.InternalConstants;
-import org.apache.beehive.netui.tags.AbstractClassicTag;
+import org.apache.beehive.netui.tags.AbstractSimpleTag;
+import org.apache.beehive.netui.tags.ExpressionHandling;
import org.apache.struts.Globals;
import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionMapping;
@@ -33,7 +34,7 @@
import javax.servlet.jsp.PageContext;
import java.util.Locale;
-abstract public class ErrorBaseTag extends AbstractClassicTag
+abstract public class ErrorBaseTag extends AbstractSimpleTag
{
/**
* The default locale on our server.
@@ -80,7 +81,7 @@
{
if (bundleName != null) {
if (bundleName.indexOf("/") == -1) {
- ModuleConfig mc = (ModuleConfig)
pageContext.getRequest().getAttribute(Globals.MODULE_KEY);
+ ModuleConfig mc = (ModuleConfig)
getPageContext().getRequest().getAttribute(Globals.MODULE_KEY);
// Note that we don't append the module path for the root
module.
if (mc != null && mc.getPrefix() != null &&
mc.getPrefix().length() > 1) {
@@ -98,17 +99,6 @@
}
/**
- * Release any acquired resources.
- */
- protected void localRelease()
- {
- super.localRelease();
-
- _locale = Globals.LOCALE_KEY;
- _bundle = null;
- }
-
- /**
* @param report
* @param bundle
* @return message
@@ -120,10 +110,10 @@
String message = null;
String key = report.getKey();
Object[] messageArgs = report.getValues();
-
- //
+ ExpressionHandling eh = new ExpressionHandling(this);
+ PageContext pageContext = getPageContext();
+
// First, replace expressions in all the message arguments.
- //
if ( messageArgs != null )
{
for ( int i = 0; i < messageArgs.length; ++i )
@@ -137,7 +127,7 @@
if ( strArg.startsWith(
InternalConstants.MESSAGE_IS_EXPRESSION_PREFIX ) )
{
String argExpr= strArg.substring(
InternalConstants.MESSAGE_IS_EXPRESSION_PREFIX_LENGTH );
- messageArgs[i] = evaluateExpression( argExpr, argExpr
);
+ messageArgs[i] = eh.evaluateExpression( argExpr,
argExpr, pageContext);
}
}
}
@@ -153,22 +143,18 @@
else if
(key.startsWith(InternalConstants.MESSAGE_IS_EXPRESSION_PREFIX)) {
// @todo misuse of this api
String expression =
key.substring(InternalConstants.MESSAGE_IS_EXPRESSION_PREFIX_LENGTH);
- message = (String) evaluateExpression(expression, expression);
+ message = (String) eh.evaluateExpression(expression, expression,
pageContext);
}
else {
boolean requestedSpecificBundle = (bundle != null);
-
- //
+
// First look in the default message bundle for the page flow.
- //
if (requestedSpecificBundle || !
isMissingDefaultMessages(pageContext))
{
message = RequestUtils.message(pageContext, bundle, _locale,
key, messageArgs);
}
- //
// If we didn't find it there, look for it in the validation
messages associated with the form bean.
- //
if (message == null && ! requestedSpecificBundle)
{
ActionMapping actionMapping = (ActionMapping)
pageContext.getRequest().getAttribute(Globals.MAPPING_KEY);
@@ -185,9 +171,7 @@
}
}
- //
// If we still didn't find it, try the default validation message
bundle (in beehive-netui-pageflow.jar).
- //
if (message == null && ! requestedSpecificBundle)
{
String qualified =
getQualifiedBundleName("_defaultValidationMessages");
Modified:
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/Errors.java
==============================================================================
---
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/Errors.java
(original)
+++
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/Errors.java
Sat Aug 7 15:47:47 2004
@@ -26,6 +26,7 @@
import org.apache.struts.util.ResponseUtils;
import javax.servlet.jsp.JspException;
+import javax.servlet.jsp.PageContext;
import java.util.Iterator;
/**
@@ -72,7 +73,7 @@
* <pre>
* <netui:errors bundle="com.project.errorMessages" /></pre>
*
- * @netui:tag name="errors" description="Used to report multiple validation
errors."
+ * @netui:tag name="errors" body-content="empty" description="Used to report
multiple validation errors."
* @netui.tldx:tag requiredchild="#nothing"
renderer="workshop.netui.jspdesigner.tldx.ErrorsRenderer"
bodycontentpref="empty" whitespace="indent"
*/
public class Errors extends ErrorBaseTag
@@ -89,8 +90,10 @@
* Render the specified error messages if there are any.
* @throws JspException if a JSP exception has occurred
*/
- public int doStartTag() throws JspException
+ public void doTag()
+ throws JspException
{
+ PageContext pageContext = getPageContext();
// Were any error messages specified?
ActionErrors errors = null;
@@ -103,8 +106,7 @@
}
if ((errors == null) || errors.isEmpty()) {
- localRelease();
- return SKIP_BODY;
+ return;
}
String qualifiedBundle = getQualifiedBundleName(_bundle);
@@ -133,8 +135,7 @@
new Object[]{e.getMessage()});
registerTagError(s, null);
reportErrors();
- localRelease();
- return SKIP_BODY;
+ return;
}
}
@@ -177,10 +178,5 @@
// Print the results to our output writer
ResponseUtils.write(pageContext, results.toString());
-
- // Continue processing this page
- localRelease();
- return SKIP_BODY;
-
}
}
Modified:
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/Html.java
==============================================================================
---
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/Html.java
(original)
+++
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/Html.java
Sat Aug 7 15:47:47 2004
@@ -20,6 +20,7 @@
import org.apache.beehive.netui.tags.AbstractPageError;
import org.apache.beehive.netui.tags.IErrorReporter;
+import org.apache.beehive.netui.tags.ErrorHandling;
import org.apache.beehive.netui.tags.rendering.HtmlTag;
import org.apache.beehive.netui.tags.rendering.TagRenderingBase;
import org.apache.beehive.netui.util.Bundle;
@@ -267,7 +268,7 @@
}
// if there are errors then we should output the error table
- reportCollectedErrors(sb);
+ ErrorHandling.reportCollectedErrors(sb,this);
// @todo: this should also be written out by the body tag if it is
present
if (getScopeId() != null) {
Modified:
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/HtmlDataSourceTag.java
==============================================================================
---
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/HtmlDataSourceTag.java
(original)
+++
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/HtmlDataSourceTag.java
Sat Aug 7 15:47:47 2004
@@ -20,6 +20,7 @@
import org.apache.beehive.netui.tags.AbstractClassicTag;
import org.apache.beehive.netui.tags.IHtmlIdWriter;
+import org.apache.beehive.netui.tags.ExpressionHandling;
import javax.servlet.jsp.JspException;
import java.util.List;
@@ -101,19 +102,21 @@
throws JspException
{
// @todo: at some point we need to switch the expression evaluation to
not require '{'
+ ExpressionHandling expr = new ExpressionHandling(this);
String datasource = "{" + _dataSource + "}";
- String ds = ensureValidExpression(datasource, "dataSource",
"DataSourceError");
+ String ds = expr.ensureValidExpression(datasource, "dataSource",
"DataSourceError");
if (ds == null)
return null;
// have a valid expression
- return evaluateExpression(datasource, "dataSource");
+ return expr.evaluateExpression(datasource, "dataSource", pageContext);
}
/**
* @return String
*/
protected String doNaming()
+ throws JspException
{
assert (_dataSource != null) : "dataSource is Null";
Modified:
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/HtmlGroupBaseTag.java
==============================================================================
---
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/HtmlGroupBaseTag.java
(original)
+++
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/HtmlGroupBaseTag.java
Sat Aug 7 15:47:47 2004
@@ -20,6 +20,7 @@
import org.apache.beehive.netui.tags.AbstractClassicTag;
import org.apache.beehive.netui.tags.IAttributeConsumer;
+import org.apache.beehive.netui.tags.ExpressionHandling;
import org.apache.beehive.netui.script.common.IDataAccessProvider;
import org.apache.beehive.netui.tags.rendering.*;
import org.apache.beehive.netui.util.Bundle;
@@ -395,14 +396,15 @@
protected Object evaluateDataSource()
throws JspException
{
+ ExpressionHandling expr = new ExpressionHandling(this);
String dataSource = "{" + _dataSource + "}";
- String ds = ensureValidExpression(dataSource, "dataSource",
"DataSourceError");
+ String ds = expr.ensureValidExpression(dataSource, "dataSource",
"DataSourceError");
if (ds == null)
return null;
//setDataSource(ds);
// have a valid expression
- return evaluateExpression(dataSource, "dataSource");
+ return expr.evaluateExpression(dataSource, "dataSource", pageContext);
}
protected String doNaming()
Modified:
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/tree/Tree.java
==============================================================================
---
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/tree/Tree.java
(original)
+++
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/tree/Tree.java
Sat Aug 7 15:47:47 2004
@@ -25,6 +25,7 @@
import org.apache.beehive.netui.script.IllegalExpressionException;
import org.apache.beehive.netui.tags.AbstractClassicTag;
import org.apache.beehive.netui.tags.IScriptReporter;
+import org.apache.beehive.netui.tags.ExpressionHandling;
import org.apache.beehive.netui.tags.html.HtmlConstants;
import org.apache.beehive.netui.tags.html.JavaScriptUtils;
import org.apache.beehive.netui.tags.rendering.*;
@@ -127,6 +128,8 @@
private DivTag.State _divState = new DivTag.State();
private SpanTag.State _spanState = new SpanTag.State();
+ private ExpressionHandling _expr;
+
public Tree()
{
_iState.initalizeTreeState();
@@ -516,9 +519,10 @@
throws JspException
{
// See if there is a TreeRoot already defined.
+ _expr = new ExpressionHandling(this);
TreeElement root = null;
try {
- root = getTreeRoot();
+ root = getTreeRoot(_expr);
}
catch (IllegalExpressionException iee) {
String s = Bundle.getString("TreeRootError", new
Object[]{_dataSource, iee.getMessage()});
@@ -576,7 +580,7 @@
InheritableState.DEFAULT_IMAGES);
// errors should have been caught in doBeginTag
- TreeElement treeRoot = getTreeRoot();
+ TreeElement treeRoot = getTreeRoot(_expr);
// if the tree root hasn't been defined, then we need to update the
what the object that is
// pointed at by the dataSource expression.
@@ -584,7 +588,7 @@
if (_rootNode != null) {
try {
String datasource = "{" + _dataSource + "}";
- updateExpression(datasource, _rootNode);
+ _expr.updateExpression(datasource, _rootNode, pageContext);
}
catch (ExpressionUpdateException e) {
String s = Bundle.getString("Tags_UnableToWriteTree", new
Object[]{_dataSource, e.getMessage()});
@@ -689,12 +693,12 @@
* we are rendering.
* @throws JspException if no TreeControl instance can be found
*/
- protected TreeElement getTreeRoot()
+ protected TreeElement getTreeRoot(ExpressionHandling expr)
throws JspException
{
String datasource = "{" + _dataSource + "}";
- Object treeNode = evaluateExpression(datasource, "dataSource");
+ Object treeNode = expr.evaluateExpression(datasource, "dataSource",
pageContext);
if (treeNode == null || hasErrors()) {
return null;
}
Modified:
incubator/beehive/trunk/netui/src/tags-template/org/apache/beehive/netui/tags/template/DivPanel.java
==============================================================================
---
incubator/beehive/trunk/netui/src/tags-template/org/apache/beehive/netui/tags/template/DivPanel.java
(original)
+++
incubator/beehive/trunk/netui/src/tags-template/org/apache/beehive/netui/tags/template/DivPanel.java
Sat Aug 7 15:47:47 2004
@@ -116,11 +116,7 @@
String reqId = DIVPANEL_DIV_ID + _tagId;
String page = req.getParameter(reqId);
if (page == null && _firstPage != null) {
- if (containsExpression(_firstPage)) {
- Object val = evaluateExpression(_firstPage, "firstPage");
- if (val!=null)
- page = val.toString();
- }
+ page = _firstPage;
}
if (page != null) {
renderAttribute(results, DIVPANEL_FIRST_PAGE, page);
Modified:
incubator/beehive/trunk/netui/src/tags-template/org/apache/beehive/netui/tags/template/Section.java
==============================================================================
---
incubator/beehive/trunk/netui/src/tags-template/org/apache/beehive/netui/tags/template/Section.java
(original)
+++
incubator/beehive/trunk/netui/src/tags-template/org/apache/beehive/netui/tags/template/Section.java
Sat Aug 7 15:47:47 2004
@@ -327,12 +327,6 @@
throws JspException {
assert(_name != null);
- if (containsExpression(_name)) {
- Object val = evaluateExpression(_name,"name");
- if (val != null) {
- _name = val.toString();
- }
- }
String realName = rewriteName(_name);
String idScript = addTagIdMapping(_name, realName);