19 package org.turro.attach.zul.control;
21 import java.io.ByteArrayOutputStream;
22 import java.io.InputStream;
23 import java.nio.charset.Charset;
24 import java.util.Date;
25 import org.apache.commons.io.input.ReaderInputStream;
26 import org.turro.attach.db.AttachPU;
27 import org.turro.attach.entity.AttachContent;
28 import org.turro.attach.entity.Attachment;
29 import org.turro.elephant.context.Application;
30 import org.turro.entities.Entities;
31 import org.turro.log.SystemLogType;
32 import org.turro.log.SystemLogger;
33 import org.zkoss.util.media.Media;
34 import org.zkoss.zk.ui.event.EventListener;
35 import org.zkoss.zk.ui.event.Events;
36 import org.zkoss.zk.ui.event.UploadEvent;
37 import org.zkoss.zul.Button;
45 private Object entity;
46 private String entityPath;
49 addEventListener(Events.ON_UPLOAD,
this);
58 this.entityPath = entityPath;
62 public void onEvent(UploadEvent event)
throws Exception {
64 Media[] medias =
event.getMedias();
65 if(medias ==
null || medias.length == 0)
return;
66 for(Media media : medias) {
76 if(media.inMemory()) {
77 ac.
setFileContent(media.isBinary() ? media.getByteData() : media.getStringData().getBytes());
79 byte[] buffer =
new byte[102400];
80 InputStream is = media.isBinary() ? media.getStreamData() :
new ReaderInputStream(media.getReaderData(), Charset.defaultCharset());
81 ByteArrayOutputStream baos =
new ByteArrayOutputStream();
83 while((r = is.read(buffer)) != -1) {
84 baos.write(buffer, 0, r);
94 attachment =
new AttachPU().saveObject(attachment);
void setFileContent(byte[] fileContent)
void setOwner(String owner)
void setShowKey(String showKey)
void setOnlyOwner(boolean onlyOwner)
void setModification(Date modification)
void setFileSize(long fileSize)
void setFileContentType(String fileContentType)
void setValidated(boolean validated)
void setPublishable(boolean publishable)
void setComment(String comment)
void setFileName(String fileName)
void setPath(String path)
void setAttachContent(AttachContent attachContent)
IConstructor getConstructor()
boolean isInRole(String role)
static Application getApplication()
static IElephantEntity getController(String path)
static ISystemLogger getInstance()
void doLog(SystemLogType type, Object entity, String comment, Serializable data)