BrightSide Workbench Full Report + Source Code
org.turro.attach.zul.control.AttachmentButton Class Reference
Inheritance diagram for org.turro.attach.zul.control.AttachmentButton:
Collaboration diagram for org.turro.attach.zul.control.AttachmentButton:

Public Member Functions

 AttachmentButton ()
 
void setEntity (Object entity)
 
void setEntityPath (String entityPath)
 
void onEvent (UploadEvent event) throws Exception
 

Detailed Description

Author
Lluis TurrĂ³ Cutiller lluis.nosp@m.@tur.nosp@m.ro.or.nosp@m.g

Definition at line 43 of file AttachmentButton.java.

Constructor & Destructor Documentation

◆ AttachmentButton()

org.turro.attach.zul.control.AttachmentButton.AttachmentButton ( )

Definition at line 48 of file AttachmentButton.java.

48  {
49  addEventListener(Events.ON_UPLOAD, this);
50  }

Member Function Documentation

◆ onEvent()

void org.turro.attach.zul.control.AttachmentButton.onEvent ( UploadEvent  event) throws Exception

Definition at line 62 of file AttachmentButton.java.

62  {
63  Application app = Application.getApplication();
64  Media[] medias = event.getMedias();
65  if(medias == null || medias.length == 0) return;
66  for(Media media : medias) {
67  Attachment attachment = new Attachment();
68  attachment.setModification(new Date());
69  attachment.setPath(entityPath);
70  attachment.setOwner(app.getConstructor().getUser().getId());
71  attachment.setOnlyOwner(false);
72  attachment.setComment("");
73  attachment.setShowKey(null);
74  attachment.setPublishable(true);
75  AttachContent ac = new AttachContent();
76  if(media.inMemory()) {
77  ac.setFileContent(media.isBinary() ? media.getByteData() : media.getStringData().getBytes());
78  } else {
79  byte[] buffer = new byte[102400];
80  InputStream is = media.isBinary() ? media.getStreamData() : new ReaderInputStream(media.getReaderData(), Charset.defaultCharset());
81  ByteArrayOutputStream baos = new ByteArrayOutputStream();
82  int r;
83  while((r = is.read(buffer)) != -1) {
84  baos.write(buffer, 0, r);
85  }
86  is.close();
87  ac.setFileContent(baos.toByteArray());
88  }
89  attachment.setAttachContent(ac);
90  attachment.setFileName(media.getName());
91  attachment.setFileContentType(media.getContentType());
92  attachment.setFileSize(ac.getFileContent().length);
93  attachment.setValidated(app.isInRole("attach:self-validate"));
94  attachment = new AttachPU().saveObject(attachment);
95  SystemLogger.getInstance().doLog(SystemLogType.LOG_INFO, attachment, "uploaded", null);
96  }
97  }
Here is the call graph for this function:

◆ setEntity()

void org.turro.attach.zul.control.AttachmentButton.setEntity ( Object  entity)

Definition at line 52 of file AttachmentButton.java.

52  {
53  this.entity = entity;
54  setEntityPath(Entities.getController(entity).getPath());
55  }
Here is the call graph for this function:

◆ setEntityPath()

void org.turro.attach.zul.control.AttachmentButton.setEntityPath ( String  entityPath)

Definition at line 57 of file AttachmentButton.java.

57  {
58  this.entityPath = entityPath;
59  }
Here is the caller graph for this function:

The documentation for this class was generated from the following file: