PageRenderTime 19ms CodeModel.GetById 11ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://struts2yuiplugin.googlecode.com/
Java | 120 lines | 99 code | 21 blank | 0 comment | 19 complexity | 0930928afb3a8a2f79a7b5ea5850d36c MD5 | raw file
  1package com.googlecode.struts2yuiplugin.components;
  2
  3import javax.servlet.http.HttpServletRequest;
  4import javax.servlet.http.HttpServletResponse;
  5
  6import org.apache.struts2.StrutsStatics;
  7import org.apache.struts2.components.UIBean;
  8import org.apache.struts2.views.annotations.StrutsTag;
  9import org.apache.struts2.views.annotations.StrutsTagAttribute;
 10import org.apache.struts2.views.annotations.StrutsTagSkipInheritance;
 11
 12import com.opensymphony.xwork2.ActionContext;
 13import com.opensymphony.xwork2.util.ValueStack;
 14
 15@StrutsTagSkipInheritance
 16@StrutsTag(name = "head", tldTagClass = "com.googlecode.struts2yuiplugin.views.jsp.ui.HeadTag", description = "Renders required YUI files")
 17public class Head extends UIBean {
 18    public static final String TEMPLATE = "yuihead";
 19    
 20    private String datepicker;
 21    private String autocompleter;
 22    private String languages;
 23    private String tabview;
 24    private String cssreset;
 25    private String cssfonts;
 26    private String cssgrids;
 27    private String cssbase;
 28
 29    public Head(ValueStack stack, HttpServletRequest request, HttpServletResponse response) {
 30        super(stack, request, response);
 31    }
 32
 33    @Override
 34    @SuppressWarnings("unchecked")
 35    public void evaluateParams() {
 36        super.evaluateParams();
 37        
 38        if (this.datepicker != null) {
 39            this.parameters.put("datepicker", this.findValue(this.datepicker, Boolean.class));
 40        }
 41        if (this.autocompleter != null) {
 42            this.parameters.put("autocompleter", this.findValue(this.autocompleter, Boolean.class));
 43        }
 44        if (this.tabview != null){
 45        	 this.parameters.put("tabview", this.findValue(this.tabview, Boolean.class));
 46        }
 47        if (this.cssreset != null) {
 48        	this.parameters.put("cssreset", this.findValue(this.cssreset, Boolean.class));
 49        }
 50        if(this.cssfonts != null) {
 51        	this.parameters.put("cssfonts", this.findValue(this.cssfonts, Boolean.class));
 52        }
 53        if(this.cssgrids != null) {
 54        	this.parameters.put("cssgrids", this.findValue(this.cssgrids, Boolean.class));
 55        }
 56        if(this.cssbase != null){
 57        	this.parameters.put("cssbase", this.findValue(this.cssbase, Boolean.class));
 58        }
 59        if (this.languages != null) {
 60            String evalLanguages = this.findString(this.languages);
 61            if (evalLanguages != null)
 62                this.addParameter("languages", evalLanguages.split(","));
 63        } else {
 64            ActionContext context = ActionContext.getContext();
 65            HttpServletRequest request = (HttpServletRequest) context
 66                .get(StrutsStatics.HTTP_REQUEST);
 67            this.addParameter("languages", new String[] { request.getLocale()
 68                .getLanguage() });
 69        }
 70    }
 71
 72    @Override
 73    protected String getDefaultTemplate() {
 74        return TEMPLATE;
 75    }
 76
 77    @StrutsTagAttribute(description = "Include javascript files to use YUI datepicker", type = "Boolean", defaultValue = "false")
 78    public void setDatepicker(String datepicker) {
 79        this.datepicker = datepicker;
 80    }
 81
 82    @StrutsTagAttribute(description = "Comma separated list of language names(2 lower case letters). Use to load resources. For example: de,ja")
 83    public void setLanguages(String languages) {
 84        this.languages = languages;
 85    }
 86
 87    @StrutsTagAttribute(description = "Include javascript files to use YUI Autocomplete", type = "Boolean", defaultValue = "false")
 88    public void setAutocompleter(String autocompleter) {
 89        this.autocompleter = autocompleter;
 90    }
 91    
 92    @StrutsTagAttribute(description = "Include javascript files to use YUI TabView", type = "Boolean", defaultValue = "false")
 93    public void setTabview(String tabview){
 94    	this.tabview = tabview;
 95    }
 96
 97    @StrutsTagAttribute(description = "Include YUI Reset CSS file", type = "Boolean", defaultValue = "false")
 98	public void setCssreset(String cssreset) {
 99		this.cssreset = cssreset;
100	}
101
102    @StrutsTagAttribute(description = "Include YUI Fonts CSS file", type = "Boolean", defaultValue = "false")
103	public void setCssfonts(String cssfonts) {
104		this.cssfonts = cssfonts;
105	}
106
107    @StrutsTagAttribute(description = "Include YUI Grids CSS file", type = "Boolean", defaultValue = "false")
108	public void setCssgrids(String cssgrids) {
109		this.cssgrids = cssgrids;
110	}
111
112    @StrutsTagAttribute(description = "Include YUI Base CSS file", type = "Boolean", defaultValue = "false")
113	public void setCssbase(String cssbase) {
114		this.cssbase = cssbase;
115	}
116    
117    
118    
119    
120}