1 16 17 package org.apache.taglibs.i18n; 18 19 import java.io.IOException ; 20 import java.text.Format ; 21 import java.text.DateFormat ; 22 import java.util.Enumeration ; 23 import java.util.Locale ; 24 25 import javax.servlet.ServletRequest ; 26 import javax.servlet.jsp.JspException ; 27 import javax.servlet.jsp.JspWriter ; 28 import javax.servlet.jsp.PageContext ; 29 import javax.servlet.jsp.tagext.Tag ; 30 import javax.servlet.jsp.tagext.TagSupport ; 31 32 37 public class FormatStringTag extends TagSupport { 38 39 protected static final String _tagname = "i18n:formatString"; 40 41 42 private String value; 43 44 private String defaultText = ""; 45 46 47 public int doStartTag() throws JspException { 50 return EVAL_BODY_INCLUDE; 51 } 52 53 public int doEndTag() throws JspException { 54 try { 55 JspWriter out = pageContext.getOut(); 56 String text = getValue(); 57 if ( text == null ) { 58 text = getDefaultText(); 59 if ( text == null ) { 60 text = ""; 61 } 62 } 63 out.print( text ); 64 } 65 catch ( IOException e ) { 66 handleIOException( e ); 67 } 68 return EVAL_PAGE; 69 } 70 71 public void release() { 72 super.release(); 73 value = null; 74 defaultText = ""; 75 } 76 77 public String getValue() { 80 return value; 81 } 82 83 public void setValue( String value ) { 84 this.value = value; 85 } 86 87 public String getDefaultText() { 88 return defaultText; 89 } 90 91 public void setDefaultText( String defaultText ) { 92 this.defaultText = defaultText; 93 } 94 95 protected void handleIOException( IOException e ) throws JspException { 98 pageContext.getServletContext().log( this._tagname + " tag, IOException: " + e ); 99 throw new JspException ( this._tagname + " tag, IOException: " + e ); 100 } 101 } 102 103 104 | Popular Tags |