1 23 24 package org.dbforms.taglib; 25 26 import org.apache.commons.logging.Log; 27 import org.apache.commons.logging.LogFactory; 28 29 import javax.servlet.jsp.*; 30 31 32 33 42 public class DbFileTag extends DbBaseInputTag 43 implements javax.servlet.jsp.tagext.TryCatchFinally { 44 private static Log logCat = LogFactory.getLog(DbFileTag.class.getName()); 45 private String accept; 46 47 52 public void setAccept(String accept) { 53 this.accept = accept; 54 } 55 56 57 62 public String getAccept() { 63 return accept; 64 } 65 66 67 70 public void doCatch(Throwable t) throws Throwable { 71 throw t; 72 } 73 74 75 83 public int doEndTag() throws javax.servlet.jsp.JspException { 84 try { 85 StringBuffer tagBuf = new StringBuffer (); 86 87 if (hasReadOnlySet() || getParentForm() 88 .hasReadOnlySet()) { 89 tagBuf.append("<input type=\"text\""); 91 } else { 92 tagBuf.append("<input type=\"file\""); 93 } 94 95 tagBuf.append(prepareName()); 96 97 if (accept != null) { 98 tagBuf.append(" accept=\""); 99 tagBuf.append(accept); 100 tagBuf.append("\""); 101 } 102 103 tagBuf.append(prepareSize()); 104 tagBuf.append(prepareKeys()); 105 tagBuf.append(prepareStyles()); 106 tagBuf.append(prepareEventHandlers()); 107 tagBuf.append("/>"); 108 109 pageContext.getOut() 113 .write(tagBuf.toString()); 114 } catch (java.io.IOException ioe) { 115 throw new JspException("IO Error: " + ioe.getMessage()); 116 } 117 118 return EVAL_PAGE; 119 } 120 121 122 125 public void doFinally() { 126 accept = null; 127 super.doFinally(); 128 } 129 130 131 139 public int doStartTag() throws javax.servlet.jsp.JspException { 140 super.doStartTag(); 141 142 if (!getParentForm() 143 .hasMultipartSet()) { 144 logCat.warn("DbFileTag is used but DbFormTag.multipart is not set (FALSE)"); 145 throw new JspException("DbFileTag is used but DbFormTag.multipart is not set (it is set to \"FALSE\"). you must set it to \"TRUE\" to enable file uploads!"); 146 } 147 148 return SKIP_BODY; 149 } 150 } 151 | Popular Tags |