# File wfo/form.rb, line 26
  def self.make(form_tree, base_uri, referer_uri=nil, orig_charset=nil)
    action_uri = base_uri + form_tree.get_attr('action')
    method = form_tree.get_attr('method')
    enctype = form_tree.get_attr('enctype')
    accept_charset = form_tree.get_attr('accept-charset')
    form = self.new(action_uri, method, enctype, accept_charset, referer_uri, orig_charset)
    form_tree.traverse_element(
      '{http://www.w3.org/1999/xhtml}input',
      '{http://www.w3.org/1999/xhtml}button',
      '{http://www.w3.org/1999/xhtml}select',
      '{http://www.w3.org/1999/xhtml}textarea') {|control|
      name = control.get_attr('name')
      next if !name
      case control.name
      when '{http://www.w3.org/1999/xhtml}input'
        next if control.get_attr('disabled')
        type = control.get_attr('type')
        type = type ? type.downcase : 'text'
        case type
        when 'text'
          form.add_text(name, control.get_attr('value').to_s)
        when 'hidden'
          form.add_hidden(name, control.get_attr('value').to_s)
        when 'password'
          form.add_password(name, control.get_attr('value').to_s)
        when 'submit'
          form.add_submit_button(name, control.get_attr('value').to_s)
        when 'checkbox'
          checked = control.get_attr('checked') ? :checked : nil
          form.add_checkbox(name, control.get_attr('value').to_s, checked)
        when 'radio'
          checked = control.get_attr('checked') ? :checked : nil
          form.add_radio(name, control.get_attr('value').to_s, checked)
        when 'file'
          form.add_file(name)
        else
          raise "unexpected input type : #{type}"
        end
      when '{http://www.w3.org/1999/xhtml}button'
        next if control.get_attr('disabled')
        raise "unexpected control : #{control.name}"
      when '{http://www.w3.org/1999/xhtml}select'
        next if control.get_attr('disabled')
        multiple = control.get_attr('multiple') ? :multiple : nil
        options = []
        control.traverse_element('{http://www.w3.org/1999/xhtml}option') {|option|
          next if option.get_attr('disabled')
          selected = option.get_attr('selected') ? :selected : nil
          options << [option.get_attr('value'), selected]
        }
        form.add_select(name, multiple, options)
      when '{http://www.w3.org/1999/xhtml}textarea'
        next if control.get_attr('disabled')
        form.add_textarea(name, control.extract_text.to_s)
      else
        raise "unexpected control : #{control.name}"
      end
    }
    form
  end