01: /**
02: * Copyright 2006 Webmedia Group Ltd.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: **/package org.araneaframework.jsp.tag.uilib.form.element;
16:
17: import java.io.Writer;
18: import java.util.Iterator;
19: import javax.servlet.jsp.JspException;
20: import org.araneaframework.jsp.tag.basic.AttributedTagInterface;
21: import org.araneaframework.jsp.tag.uilib.form.BaseFormElementHtmlTag;
22: import org.araneaframework.jsp.util.JspUtil;
23: import org.araneaframework.uilib.form.control.FileUploadControl;
24:
25: /**
26: * Standard text input form element tag.
27: *
28: * @author Oleg Mürk
29: *
30: * @jsp.tag
31: * name = "fileUpload"
32: * body-content = "JSP"
33: * description = "Form file upload field, represents UiLib 'FileUploadControl'."
34: */
35: public class FormFileUploadHtmlTag extends BaseFormElementHtmlTag {
36: protected Long size = null;
37:
38: {
39: baseStyleClass = "aranea-file-upload";
40: }
41:
42: protected int doStartTag(Writer out) throws Exception {
43: int r = super .doStartTag(out);
44: addContextEntry(AttributedTagInterface.HTML_ELEMENT_KEY, null);
45: return r;
46: }
47:
48: protected int doEndTag(Writer out) throws Exception {
49: assertControlType("FileUploadControl");
50:
51: // Prepare
52: String name = this .getFullFieldId();
53: FileUploadControl.ViewModel viewModel = ((FileUploadControl.ViewModel) controlViewModel);
54:
55: // Build accepted mime-types list
56: String accept = null;
57: if (viewModel.getPermittedMimeFileTypes() != null) {
58: StringBuffer acceptBuffer = new StringBuffer();
59: for (Iterator i = viewModel.getPermittedMimeFileTypes()
60: .iterator(); i.hasNext();) {
61: String mimeType = (String) i.next();
62: acceptBuffer.append(mimeType);
63: if (i.hasNext())
64: acceptBuffer.append(",");
65: }
66: accept = acceptBuffer.toString();
67: }
68:
69: // Write
70: JspUtil.writeOpenStartTag(out, "input");
71: JspUtil.writeAttribute(out, "id", name);
72: JspUtil.writeAttribute(out, "name", name);
73: JspUtil.writeAttribute(out, "class", getStyleClass());
74: JspUtil.writeAttribute(out, "style", getStyle());
75: JspUtil.writeAttribute(out, "type", "file");
76: JspUtil.writeAttribute(out, "accept", accept);
77: JspUtil.writeAttribute(out, "size", size);
78: JspUtil.writeAttribute(out, "tabindex", tabindex);
79: JspUtil.writeAttributes(out, attributes);
80: JspUtil.writeCloseStartEndTag_SS(out);
81:
82: JspUtil.writeStartTag_SS(out, "script");
83: out.write("_ap.setSystemFormEncoding('multipart/form-data');");
84: JspUtil.writeEndTag_SS(out, "script");
85:
86: super .doEndTag(out);
87: return EVAL_PAGE;
88: }
89:
90: public void setSize(String size) throws JspException {
91: this .size = (Long) evaluate("size", size, Long.class);
92: }
93: }
|