package sample.org.itscool.upload;
import java.io.IOException;

import org.itscool.commons.request.UploadFile;
import org.itscool.weber.action.Action;
import org.itscool.weber.action.ActionBucket;

public class UploadAction extends Action{
    public String doExecute(ActionBucket bucket){
        UploadBean bean = (UploadBean)bucket.getForm();
        bucket.setAttribute("name", bean.getName());
        bucket.setAttribute("message", bean.getMessage());
        UploadFile file = bean.getFile();
        if(file != null ){
            try{
                file.saveData("C:/");
            }catch(IOException ioe){
                ioe.printStackTrace();
            }
            bucket.setAttribute("fileName", file.getFileName());
            bucket.setAttribute("fileSize", String.valueOf(file.getSize()));
            bucket.setAttribute("dist", file.getPath());
            bucket.setAttribute("path", file.getSavePath());
            
        }else{
            bucket.setAttribute("fileName", "選択されていません");
            bucket.setAttribute("fileSize", "選択されていません");
            bucket.setAttribute("path", "選択されていません");
        }
        return "success";
    }
}

