PageRenderTime 15ms CodeModel.GetById 9ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/src/main/java/com/googlecode/struts2yuiplugin/components/Tab.java

http://struts2yuiplugin.googlecode.com/
Java | 109 lines | 74 code | 24 blank | 11 comment | 0 complexity | b8893964ab2ee51dec4945e74484a31c MD5 | raw file
  1package com.googlecode.struts2yuiplugin.components;
  2
  3import com.opensymphony.xwork2.util.ValueStack;
  4
  5import javax.servlet.http.HttpServletRequest;
  6import javax.servlet.http.HttpServletResponse;
  7
  8import org.apache.struts2.views.annotations.StrutsTag;
  9import org.apache.struts2.views.annotations.StrutsTagAttribute;
 10
 11import java.io.Writer;
 12
 13/**
 14 * The model for a Tab in a YUI TabView
 15 */
 16@StrutsTag(name = "tab", tldTagClass = "com.googlecode.struts2yuiplugin.views.jsp.ui.TabTag", description = "Renders a Tab in a YUI TabView")
 17public class Tab extends ClosingYUIBean implements OGNLEvaluator {
 18
 19    private static final String OPEN_TEMPLATE = "yuitab";
 20    private static final String TEMPLATE = OPEN_TEMPLATE +"-close";
 21
 22    private boolean selected;
 23
 24    public Tab(ValueStack valueStack, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) {
 25        super(valueStack, httpServletRequest, httpServletResponse);
 26    }
 27
 28    @Override
 29    public void evaluateParams() {
 30        super.evaluateParams();
 31
 32        addParameter("selected", selected);
 33    }
 34
 35    public String getDefaultOpenTemplate() {
 36        return OPEN_TEMPLATE;
 37    }
 38
 39    protected String getDefaultTemplate() {
 40        return TEMPLATE;
 41    }
 42
 43    /**
 44     * Evaluates the OGNL expression
 45     *
 46     * @param expr OGNL expression.
 47     * @return the String value found.
 48     */
 49    public String evaluateExpression(String expr) {
 50        return super.findString(expr);
 51    }
 52
 53    @Override
 54    public boolean start(Writer writer) {
 55        return true; // evaluate body
 56    }
 57
 58    /** This component uses the body so it needs to be buffered */
 59    @Override
 60    public boolean usesBody() {
 61        return true;
 62    }
 63
 64    /** There is no template merging and don't write to output */
 65    @Override
 66    public boolean end(Writer writer, String body) {
 67        evaluateParams();
 68        parameters.put("body", body);
 69        popComponentStack();
 70        return false;  // don't evaluate body again
 71    }
 72
 73    public String getBody() {
 74        return (String) parameters.get("body");
 75    }
 76
 77    public String getId() {
 78        return (String) parameters.get("id");
 79    }
 80
 81    public String getLabel() {
 82        return (String) parameters.get("label");
 83    }
 84
 85    public boolean isSelected() {
 86        return selected;
 87    }
 88
 89    public String getCssClass() {
 90        return (String) parameters.get("cssClass");
 91    }
 92
 93    @Override
 94    @StrutsTagAttribute(description = "HTML id attribute", required = true, rtexprvalue = true)
 95    public void setId(String id) {
 96        super.setId(id);
 97    }
 98
 99    @Override
100    @StrutsTagAttribute(description = "Label expression used for rendering a element specific label", required = true)
101    public void setLabel(String label) {
102        super.setLabel(label);
103    }
104
105    @StrutsTagAttribute(description = "Identifies a tab that is initially selected", required = false)
106    public void setSelected(boolean selected) {
107        this.selected = selected;
108    }
109}