package org.brain.bean;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpServletRequest;
import org.brain.pojos.Files;
import org.brain.pojos.Images;
import org.brain.pojos.User;
import org.brain.tool.ToolBean;
@ManagedBean(name="fileList")
@RequestScoped
public class FileList {
User user;
List<Files> filList = new ArrayList<Files>();
public List<Files> getFilList() {
return filList;
}
public void setFilList(List<Files> filList) {
this.filList = filList;
}
public FileList() {
// TODO Auto-generated constructor stub
user = ToolBean.getUserSession();
String path;
HttpServletRequest request = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
path=request.getRealPath("/");
path = path+"/file/"+user.getUsername();
File file = new File(path);
if(!file.exists())
{
file.mkdirs();
}
String[] filePath = file.list();
if(filePath.length > 0)
{
for(String str : filePath)
filList.add(new Files(str, "file/"+user.getUsername()+"/"+str));
}
}
public void updateList()
{
String path;
HttpServletRequest request = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
path=request.getRealPath("/");
path = path+"/file/"+user.getUsername();
File file = new File(path);
String[] filePath = file.list();
if(filePath.length > 0)
{
filList.clear();
for(String str : filePath)
filList.add(new Files(str, "file/"+user.getUsername()+"/"+str));
}
}
public String FilePath()
{
return "testResult";
}
}