/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

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