FileDocCategorySizeDatePackage
StrutsBodyTagSupport.javaAPI DocExample4169Mon Jul 23 13:26:50 BST 2007org.apache.struts2.views.jsp

StrutsBodyTagSupport

public class StrutsBodyTagSupport extends javax.servlet.jsp.tagext.BodyTagSupport
Contains common functonalities for Struts JSP Tags.

Fields Summary
private static final long
serialVersionUID
Constructors Summary
Methods Summary
protected booleanaltSyntax()

        return ContextUtil.isUseAltSyntax(getStack().getContext());
    
protected java.lang.StringfindString(java.lang.String expr)

        return (String) findValue(expr, String.class);
    
protected java.lang.ObjectfindValue(java.lang.String expr)

        if (altSyntax()) {
            // does the expression start with %{ and end with }? if so, just cut it off!
            if (expr.startsWith("%{") && expr.endsWith("}")) {
                expr = expr.substring(2, expr.length() - 1);
            }
        }

        return getStack().findValue(expr);
    
protected java.lang.ObjectfindValue(java.lang.String expr, java.lang.Class toType)

        if (altSyntax() && toType == String.class) {
            return translateVariables(expr, getStack());
        } else {
            if (altSyntax()) {
                // does the expression start with %{ and end with }? if so, just cut it off!
                if (expr.startsWith("%{") && expr.endsWith("}")) {
                    expr = expr.substring(2, expr.length() - 1);
                }
            }

            return getStack().findValue(expr, toType);
        }
    
protected java.lang.StringgetBody()

        if (bodyContent == null) {
            return "";
        } else {
            return bodyContent.getString().trim();
        }
    
protected com.opensymphony.xwork2.util.ValueStackgetStack()

        return TagUtils.getStack(pageContext);
    
public voidsetId(java.lang.String string)

        super.setId(string);
    
protected java.lang.StringtoString(java.lang.Throwable t)

        FastByteArrayOutputStream bout = new FastByteArrayOutputStream();
        PrintWriter wrt = new PrintWriter(bout);
        t.printStackTrace(wrt);
        wrt.close();

        return bout.toString();
    
public static java.lang.StringtranslateVariables(java.lang.String expression, com.opensymphony.xwork2.util.ValueStack stack)

        while (true) {
            int x = expression.indexOf("%{");
            int y = expression.indexOf("}", x);

            if ((x != -1) && (y != -1)) {
                String var = expression.substring(x + 2, y);

                Object o = stack.findValue(var, String.class);

                if (o != null) {
                    expression = expression.substring(0, x) + o + expression.substring(y + 1);
                } else {
                    // the variable doesn't exist, so don't display anything
                    expression = expression.substring(0, x) + expression.substring(y + 1);
                }
            } else {
                break;
            }
        }

        return expression;