View Javadoc

    1   // ========================================================================
    2   // $Id: Form.java,v 1.4 2004/05/09 20:31:28 gregwilkins Exp $
    3   // Copyright 1996-2004 Mort Bay Consulting Pty. Ltd.
    4   // ------------------------------------------------------------------------
    5   // Licensed under the Apache License, Version 2.0 (the "License");
    6   // you may not use this file except in compliance with the License.
    7   // You may obtain a copy of the License at
    8   // http://www.apache.org/licenses/LICENSE-2.0
    9   // 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  import java.io.IOException;
    18  import java.io.Writer;
    19
    20  import org.mortbay.jetty.MimeTypes;
    21
    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  {
    30      public static final String encodingWWWURL = MimeTypes.FORM_ENCODED;
    31      public static final String encodingMultipartForm = "multipart/form-data";
    32      private String method="POST";
    33
    34      /* ----------------------------------------------------------------- */
    35      /** Constructor.
    36       */
    37      public Form()
    38      {
    39          super("form");
    40      }
    41
    42      /* ----------------------------------------------------------------- */
    43      /** Constructor.
    44       * @param submitURL The URL to submit the form to
    45       */
    46      public Form(String submitURL)
    47      {
    48          super("form");
    49          action(submitURL);
    50      }
    51
    52      /* ----------------------------------------------------------------- */
    53      /** Constructor.
    54       * @param submitURL The URL to submit the form to
    55       */
    56      public Form action(String submitURL)
    57      {
    58          attribute("action",submitURL);
    59          return this;
    60      }
    61
    62      /* ----------------------------------------------------------------- */
    63      /** Set the form target.
    64       */
    65      public Form target(String t)
    66      {
    67          attribute("target",t);
    68          return this;
    69      }
    70
    71      /* ----------------------------------------------------------------- */
    72      /** Set the form method.
    73       */
    74      public Form method(String m)
    75      {
    76          method=m;
    77          return this;
    78      }
    79
    80      /* ------------------------------------------------------------ */
    81      /** Set the form encoding type.
    82       */
    83      public Form encoding(String encoding){
    84          attribute("enctype", encoding);
    85          return this;
    86      }
    87      /* ----------------------------------------------------------------- */
    88      public void write(Writer out)
    89           throws IOException
    90      {
    91          attribute("method",method);
    92          super.write(out);
    93      }
    94  }
    95
    96
    97
    98