01: // ========================================================================
02: // $Id: Form.java,v 1.4 2004/05/09 20:31:28 gregwilkins Exp $
03: // Copyright 1996-2004 Mort Bay Consulting Pty. Ltd.
04: // ------------------------------------------------------------------------
05: // Licensed under the Apache License, Version 2.0 (the "License");
06: // you may not use this file except in compliance with the License.
07: // You may obtain a copy of the License at
08: // http://www.apache.org/licenses/LICENSE-2.0
09: // Unless required by applicable law or agreed to in writing, software
10: // distributed under the License is distributed on an "AS IS" BASIS,
11: // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12: // See the License for the specific language governing permissions and
13: // limitations under the License.
14: // ========================================================================
15:
16: package org.mortbay.html;
17:
18: import java.io.IOException;
19: import java.io.Writer;
20:
21: import org.mortbay.jetty.MimeTypes;
22:
23: /* -------------------------------------------------------------------- */
24: /** HTML Form.
25: * The specialized Block can contain HTML Form elements as well as
26: * any other HTML elements
27: */
28: public class Form extends Block {
29: public static final String encodingWWWURL = MimeTypes.FORM_ENCODED;
30: public static final String encodingMultipartForm = "multipart/form-data";
31: private String method = "POST";
32:
33: /* ----------------------------------------------------------------- */
34: /** Constructor.
35: */
36: public Form() {
37: super ("form");
38: }
39:
40: /* ----------------------------------------------------------------- */
41: /** Constructor.
42: * @param submitURL The URL to submit the form to
43: */
44: public Form(String submitURL) {
45: super ("form");
46: action(submitURL);
47: }
48:
49: /* ----------------------------------------------------------------- */
50: /** Constructor.
51: * @param submitURL The URL to submit the form to
52: */
53: public Form action(String submitURL) {
54: attribute("action", submitURL);
55: return this ;
56: }
57:
58: /* ----------------------------------------------------------------- */
59: /** Set the form target.
60: */
61: public Form target(String t) {
62: attribute("target", t);
63: return this ;
64: }
65:
66: /* ----------------------------------------------------------------- */
67: /** Set the form method.
68: */
69: public Form method(String m) {
70: method = m;
71: return this ;
72: }
73:
74: /* ------------------------------------------------------------ */
75: /** Set the form encoding type.
76: */
77: public Form encoding(String encoding) {
78: attribute("enctype", encoding);
79: return this ;
80: }
81:
82: /* ----------------------------------------------------------------- */
83: public void write(Writer out) throws IOException {
84: attribute("method", method);
85: super.write(out);
86: }
87: }
|