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 UploadMultipleFilesAction 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<UploadedFilesDetails> uploadedFilesDetailsList = new ArrayList<UploadedFilesDetails>();
	

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

		//Print file path
		for (File file : multipleFileUpload) {
			System.out.println("File :" + file);
		}
		//Iterate file name set in response
		for (String fileName : multipleFileUploadFileName) {
			UploadedFilesDetails uploadedFilesDetails = new UploadedFilesDetails();
			uploadedFilesDetails.setFileName(fileName);	
			uploadedFilesDetailsList.add(uploadedFilesDetails);
		}
		//Print file content type
		for (String fileContentType : multipleFileUploadContentType) {			
			System.out.println("File type : " + fileContentType);
		}

		setUploadedFilesDetailsList(uploadedFilesDetailsList);
		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<UploadedFilesDetails> getUploadedFilesDetailsList() {
		return uploadedFilesDetailsList;
	}


	public void setUploadedFilesDetailsList(
			List<UploadedFilesDetails> uploadedFilesDetailsList) {
		this.uploadedFilesDetailsList = uploadedFilesDetailsList;
	}
	
}
