1 18 package org.apache.beehive.netui.tags.rendering; 19 20 import org.apache.beehive.netui.tags.html.HtmlConstants; 21 22 import java.util.HashMap ; 23 24 28 abstract public class InputFileTag extends TagHtmlBase implements HtmlConstants 29 { 30 public static void add(HashMap html, HashMap htmlQuirks, HashMap xhtml) 31 { 32 html.put(INPUT_FILE_TAG, new HtmlRendering()); 33 htmlQuirks.put(INPUT_FILE_TAG, new HtmlRendering()); 34 xhtml.put(INPUT_FILE_TAG, new XhtmlRendering()); 35 } 36 37 public static class State extends AbstractHtmlControlState 38 { 39 public boolean readonly; 40 41 public void clear() 42 { 43 super.clear(); 44 45 readonly = false; 46 } 47 } 48 49 public void doStartTag(AbstractRenderAppender sb, AbstractTagState renderState) 50 { 51 assert(sb != null) : "Parameter 'sb' must not be null"; 52 assert(renderState != null) : "Parameter 'renderState' must not be null"; 53 assert(renderState instanceof State) : "Paramater 'renderState' must be an instance of InputFileTag.State"; 54 55 State state = (State) renderState; 56 57 renderTag(sb, INPUT); 59 renderAttribute(sb, TYPE, INPUT_FILE); 60 renderAttribute(sb, NAME, state.name); 61 renderAttribute(sb, ID, state.id); 62 renderAttribute(sb, CLASS, state.styleClass); 63 renderReadOnly(sb, state.readonly); 64 65 renderAttributes(AbstractHtmlState.ATTR_GENERAL, sb, state); 66 renderAttribute(sb, STYLE, state.style); 67 renderAttributes(AbstractHtmlState.ATTR_JAVASCRIPT, sb, state); 68 writeEnd(sb); 69 } 70 71 public void doEndTag(AbstractRenderAppender sb) 72 { 73 } 74 75 abstract protected void writeEnd(AbstractRenderAppender sb); 76 77 abstract protected void renderReadOnly(AbstractRenderAppender sb, boolean readonly); 78 79 80 private static class HtmlRendering extends InputFileTag 81 { 82 protected void writeEnd(AbstractRenderAppender sb) 83 { 84 sb.append(">"); 85 } 86 87 protected void renderReadOnly(AbstractRenderAppender sb, boolean readonly) 88 { 89 if (readonly) 90 sb.append(" readonly"); 91 92 } 93 } 94 95 private static class XhtmlRendering extends InputFileTag 96 { 97 protected void writeEnd(AbstractRenderAppender sb) 98 { 99 sb.append(" />"); 100 } 101 102 protected void renderReadOnly(AbstractRenderAppender sb, boolean readonly) 103 { 104 if (readonly) 105 renderAttribute(sb, "readonly", "readonly"); 106 107 } 108 } 109 } 110 | Popular Tags |