1 18 package org.apache.beehive.netui.tags.html; 19 20 import org.apache.beehive.netui.tags.AbstractSimpleTag; 21 import org.apache.beehive.netui.util.Bundle; 22 23 import javax.servlet.jsp.JspException ; 24 import java.util.Locale ; 25 26 30 public abstract class FormatTag extends AbstractSimpleTag 31 { 32 private String _language = null; 33 private String _country = null; 34 protected String _pattern = null; 36 45 public void setLanguage(String language) 46 { 47 _language = setNonEmptyValueAttribute(language); 48 } 49 50 59 public void setCountry(String country) 60 { 61 _country = setNonEmptyValueAttribute(country); 62 } 63 64 68 public Locale getLocale() 69 throws JspException 70 { 71 Locale loc = null; 72 if (_language != null || _country != null) { 73 if (_language == null) { 75 String s = Bundle.getString("Tags_LocaleRequiresLanguage", new Object []{_country}); 76 registerTagError(s, null); 77 return super.getUserLocale(); 78 } 79 80 if (_country == null) 81 loc = new Locale (_language); 82 else 83 loc = new Locale (_language, _country); 84 } 85 else 86 loc = super.getUserLocale(); 87 88 return loc; 89 } 90 91 101 public void setPattern(String pattern) 102 throws JspException 103 { 104 _pattern = setRequiredValueAttribute(pattern, "patttern"); 105 } 106 107 110 public abstract static class Formatter 111 { 112 private String pattern; 113 114 public String getPattern() 115 { 116 return pattern; 117 } 118 119 public void setPattern(String pattern) 120 { 121 this.pattern = pattern; 122 } 123 124 public String format(Object dataToFormat) throws JspException 125 { 126 if (dataToFormat == null) 128 return null; 129 else 130 return dataToFormat.toString(); 131 } 132 133 public boolean hasError() 134 { 135 return false; 136 } 137 138 public String getErrorMessage() 139 { 140 return null; 141 } 142 } 143 } 144 | Popular Tags |