/*
 * $Id: EditTypeAction.java 54929 2004-10-16 16:38:42Z germuska $ 
 *
 * Copyright 2000-2004 The Apache Software Foundation.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.apache.struts.webapp.validator;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import java.util.ArrayList;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.util.LabelValueBean;

/**
 * Initializes ActionForm.
 *
 */
public final class EditTypeAction extends Action {

    /**
     * Commons Logging instance.
     */
    private Log log = LogFactory.getFactory().getInstance(this.getClass().getName());

    /**
     * Process the specified HTTP request, and create the corresponding HTTP
     * response (or forward to another web component that will create it).
     * Return an <code>ActionForward</code> instance describing where and how
     * control should be forwarded, or <code>null</code> if the response has
     * already been completed.
     *
     * @param mapping The ActionMapping used to select this instance
     * @param form The optional ActionForm bean for this request (if any)
     * @param request The HTTP request we are processing
     * @param response The HTTP response we are creating
     *
     * @return Action to forward to
     * @exception Exception if an input/output error or servlet exception occurs
     */
    public ActionForward execute(
            ActionMapping mapping,
            ActionForm form,
            HttpServletRequest request,
            HttpServletResponse response)
            throws Exception {

        // Was this transaction cancelled?

        initFormBeans(mapping, form, request);

        return mapping.findForward("success");
    }

    /**
     * Convenience method for initializing form bean.
     * @param mapping The ActionMapping used to select this instance
     * @param request The HTTP request we are processing
     */
    protected void initFormBeans(
            ActionMapping mapping, ActionForm form,
            HttpServletRequest request) {

        // Initialize
        ArrayList satisfactionList = new ArrayList();
        satisfactionList.add(new LabelValueBean("Very Satisfied", "4"));
        satisfactionList.add(new LabelValueBean("Satisfied", "3"));
        satisfactionList.add(new LabelValueBean("Not Very Satisfied", "2"));
        satisfactionList.add(new LabelValueBean("Not Satisfied", "1"));
        request.setAttribute("satisfactionList", satisfactionList);

        ArrayList osTypes = new ArrayList();
        osTypes.add(new LabelValueBean("Mac OsX", "OsX"));
        osTypes.add(new LabelValueBean("Windows 95/98/Me", "Win32"));
        osTypes.add(new LabelValueBean("Windows NT/2000/XP/2003", "WinNT"));
        osTypes.add(new LabelValueBean("Linux", "Linux"));
        osTypes.add(new LabelValueBean("BSD NetBSD/FreeBSD/OpenBSD", "BSD"));
        request.setAttribute("osTypes", osTypes);

        ArrayList languageTypes = new ArrayList();
        languageTypes.add(new LabelValueBean("C++", "C++"));
        languageTypes.add(new LabelValueBean("C#", "C#"));
        languageTypes.add(new LabelValueBean("Java", "java"));
        languageTypes.add(new LabelValueBean("Smalltalk", "Smalltalk"));
        request.setAttribute("languageTypes", languageTypes);
    }
}
