CompoFileDownloadView.java
2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package fi.codecrew.moya.web.cdiview.voting;
import java.io.ByteArrayInputStream;
import javax.ejb.EJB;
import javax.enterprise.context.RequestScoped;
import javax.faces.model.ListDataModel;
import javax.inject.Inject;
import javax.inject.Named;
import org.primefaces.model.DefaultStreamedContent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import fi.codecrew.moya.beans.VotingBeanLocal;
import fi.codecrew.moya.model.CompoEntry;
import fi.codecrew.moya.model.CompoEntryFile;
import fi.codecrew.moya.web.cdiview.GenericCDIView;
@Named
@RequestScoped
public class CompoFileDownloadView extends GenericCDIView {
private static final long serialVersionUID = -262883747402530562L;
@EJB
private transient VotingBeanLocal votebean;
@Inject
private CompoEntry entry;
private transient ListDataModel<CompoEntryFile> files;
private CompoEntryFile file;
private DefaultStreamedContent dlfile;
private static final Logger logger = LoggerFactory.getLogger(CompoFileDownloadView.class);
public ListDataModel<CompoEntryFile> getFiles()
{
if (files == null)
{
files = new ListDataModel<CompoEntryFile>(votebean.getEntryFiles(entry));
}
return files;
}
public CompoEntryFile getFile() {
return file;
}
public void selectDownloadedFile()
{
file = files.getRowData();
dlfile = new DefaultStreamedContent(new ByteArrayInputStream(file.getFileData()), file.getMimeType(), file.getFileName());
}
public void setFile(CompoEntryFile file) {
this.file = file;
if (file != null)
{
dlfile = new DefaultStreamedContent(new ByteArrayInputStream(file.getFileData()), file.getMimeType(), file.getFileName());
logger.info("Uploading file {}, length {}", file.getFileName(), file.getFileData().length);
}
}
public DefaultStreamedContent getDlfile() {
return dlfile;
}
public void setDlfile(DefaultStreamedContent dlfile) {
this.dlfile = dlfile;
}
public CompoEntry getEntry() {
return entry;
}
public void setEntry(CompoEntry entry) {
this.entry = entry;
}
public void setFiles(ListDataModel<CompoEntryFile> files) {
this.files = files;
}
}