1 18 package org.apache.beehive.netui.tags.html; 19 20 import org.apache.beehive.netui.util.internal.InternalStringBuilder; 21 22 import org.apache.beehive.netui.tags.HtmlUtils; 23 import org.apache.beehive.netui.tags.rendering.AbstractRenderAppender; 24 25 import javax.servlet.jsp.JspException ; 26 import java.util.ArrayList ; 27 28 31 public abstract class LabelBase extends HtmlBaseTag 32 implements IFormattable 33 { 34 protected static final String DEFAULT_NULL_TEXT = ""; 35 36 protected Object _defaultValue; protected Object _value; protected boolean _escapeWhiteSpace = true; protected boolean _formatterErrors = false; protected boolean _formatDefaultValue = false; private ArrayList _formatters; 43 57 public void setDefaultValue(Object defaultValue) 58 { 59 _defaultValue = defaultValue; 60 } 61 62 73 public void setFormatDefaultValue(boolean formatDisplay) 74 { 75 _formatDefaultValue = formatDisplay; 76 } 77 78 87 public void setValue(Object value) 88 { 89 _value = value; 90 } 91 92 107 public void setEscapeWhiteSpaceForHtml(boolean escapeWhiteSpace) 108 { 109 _escapeWhiteSpace = escapeWhiteSpace; 110 111 } 112 113 117 public void addFormatter(FormatTag.Formatter formatter) 118 { 119 if (_formatters == null) 120 _formatters = new ArrayList (); 121 _formatters.add(formatter); 122 } 123 124 128 public void formatterHasError() 129 { 130 _formatterErrors = true; 131 } 132 133 141 protected void filter(String value, AbstractRenderAppender writer, boolean markupHTMLSpaceReturn) 142 { 143 if (value.equals(" ")) { 144 writer.append(" "); 145 return; 146 } 147 148 HtmlUtils.filter(value, writer, markupHTMLSpaceReturn); 149 } 150 151 154 protected void localRelease() 155 { 156 super.localRelease(); 157 158 _defaultValue = null; 159 _escapeWhiteSpace = true; 160 _formatters = null; 161 _formatterErrors = false; 162 _formatDefaultValue = false; 163 _value = null; 164 } 165 166 169 protected String formatText(Object text) 170 throws JspException 171 { 172 InternalStringBuilder errors = null; 173 if (text == null) 174 return null; 175 176 if (_formatters == null) 177 return text.toString(); 178 179 for (int i = 0; i < _formatters.size(); i++) { 180 FormatTag.Formatter currentFormatter = (FormatTag.Formatter) _formatters.get(i); 181 182 if (currentFormatter.hasError()) { 185 if (errors == null) { 186 errors = new InternalStringBuilder(32); 187 } 188 assert(errors != null); 189 errors.append(currentFormatter.getErrorMessage()); 190 continue; 191 } 192 193 try { 195 text = currentFormatter.format(text); 196 } 197 catch (JspException e) { 198 registerTagError(e.getMessage(), e); 199 } 200 } 201 if (errors != null) { 204 return errors.toString() + text.toString(); 205 } 206 return text.toString(); 207 } 208 } 209 | Popular Tags |