package com.javahonk.action;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;

import com.opensymphony.xwork2.ActionSupport;

@Results({ @Result(name = "error", location = "/index.jsp"),
		@Result(name = "success", location = "/success.jsp"),
		@Result(name = "input", location = "/index.jsp") })
public class UploadSingleFilesAction extends ActionSupport {

	private static final long serialVersionUID = 1L;
	private List<File> multipleFileUpload = new ArrayList<File>();
	private List<String> multipleFileUploadFileName = new ArrayList<String>();
	private List<String> multipleFileUploadContentType = new ArrayList<String>();
	private List<SingleFileUploadDetails> singleFileUploadDetailsList = new ArrayList<SingleFileUploadDetails>();
	

	@Override
	@Action(value = "/uploadSingleFilesAction")
	public String execute() throws Exception {

		SingleFileUploadDetails singleFileUploadDetails = new SingleFileUploadDetails();
		//Print file path
		for (File file : multipleFileUpload) {
			singleFileUploadDetails.setFilePath(file.getPath());			
		}
		
		for (String fileContentType : multipleFileUploadContentType) {
			singleFileUploadDetails.setFileContentType(fileContentType);			
		}
		for (String fileName : multipleFileUploadFileName) {
			singleFileUploadDetails.setFileName(fileName);
		}
		
		singleFileUploadDetailsList.add(singleFileUploadDetails);
		setSingleFileUploadDetailsList(singleFileUploadDetailsList);
		return ActionSupport.SUCCESS;
	}


	public List<File> getMultipleFileUpload() {
		return multipleFileUpload;
	}


	public void setMultipleFileUpload(List<File> multipleFileUpload) {
		this.multipleFileUpload = multipleFileUpload;
	}


	public List<String> getMultipleFileUploadFileName() {
		return multipleFileUploadFileName;
	}


	public void setMultipleFileUploadFileName(
			List<String> multipleFileUploadFileName) {
		this.multipleFileUploadFileName = multipleFileUploadFileName;
	}


	public List<String> getMultipleFileUploadContentType() {
		return multipleFileUploadContentType;
	}


	public void setMultipleFileUploadContentType(
			List<String> multipleFileUploadContentType) {
		this.multipleFileUploadContentType = multipleFileUploadContentType;
	}


	public List<SingleFileUploadDetails> getSingleFileUploadDetailsList() {
		return singleFileUploadDetailsList;
	}


	public void setSingleFileUploadDetailsList(
			List<SingleFileUploadDetails> singleFileUploadDetailsList) {
		this.singleFileUploadDetailsList = singleFileUploadDetailsList;
	}    
	
}
