18 package org.turro.attach.zul.navigator;
20 import java.io.ByteArrayOutputStream;
21 import java.io.IOException;
22 import java.io.InputStream;
23 import java.nio.charset.Charset;
24 import java.util.ArrayList;
25 import java.util.Collection;
26 import java.util.Date;
27 import org.apache.commons.io.input.ReaderInputStream;
28 import org.turro.attach.db.AttachPU;
29 import org.turro.attach.entity.AttachContent;
30 import org.turro.attach.entity.Attachment;
31 import org.turro.attach.search.AttachResults;
32 import org.turro.attach.version.AttachVersionMap;
33 import org.turro.attach.zul.FolderNameCombobox;
34 import org.turro.collections.CollectionUtil;
35 import org.turro.command.Command;
36 import org.turro.command.Context;
37 import org.turro.elephant.context.Application;
38 import org.turro.elephant.impl.util.StringParser;
39 import org.turro.elephant.util.Messages;
40 import org.turro.entities.Entities;
41 import org.turro.i18n.I_;
42 import org.turro.log.SystemLogType;
43 import org.turro.log.SystemLogger;
44 import org.turro.plugin.attach.IAttachFolder;
45 import org.turro.zkoss.dialog.InputDialog;
46 import org.turro.zkoss.dialog.InputField;
47 import org.zkoss.lang.Strings;
48 import org.zkoss.util.media.Media;
49 import org.zkoss.zk.ui.HtmlBasedComponent;
50 import org.zkoss.zk.ui.event.DropEvent;
51 import org.zkoss.zk.ui.event.Event;
52 import org.zkoss.zk.ui.event.EventListener;
53 import org.zkoss.zk.ui.event.Events;
54 import org.zkoss.zk.ui.ext.AfterCompose;
55 import org.zkoss.zul.*;
65 private Treechildren children;
66 private String label, realLabel;
68 private boolean loadOnDemand;
70 public AttachFolder(String label, String path,
boolean loadOnDemand) {
73 this.realLabel = label;
75 this.loadOnDemand = loadOnDemand;
76 this.setTooltiptext(label);
80 throw new UnsupportedOperationException(
"Do not use");
84 throw new UnsupportedOperationException(
"Do not use");
88 throw new UnsupportedOperationException(
"Do not use");
96 public void doUpload() throws InterruptedException, IOException {
100 public void addMedias(Media[] medias)
throws InterruptedException, IOException {
101 if(medias ==
null || medias.length == 0)
return;
104 for(Media media : medias) {
114 if(media.inMemory()) {
115 ac.
setFileContent(media.isBinary() ? media.getByteData() : media.getStringData().getBytes());
117 byte[] buffer =
new byte[102400];
118 InputStream is = media.isBinary() ? media.getStreamData() :
new ReaderInputStream(media.getReaderData(), Charset.defaultCharset());
119 ByteArrayOutputStream baos =
new ByteArrayOutputStream();
121 while((r = is.read(buffer)) != -1) {
122 baos.write(buffer, 0, r);
132 attachment =
new AttachPU().saveObject(attachment);
134 if(
getTree().getAttachListener() !=
null) {
146 new InputField(
"Name",
"", null, 0) {
148 protected HtmlBasedComponent createEditor() {
149 return new FolderNameCombobox(AttachFolder.this);
154 public Object execute(Context context) {
156 if(fields.length > 0) {
158 if(
"Name".equals(f.getLabel())) {
161 for(String s : ((String) f.getValue()).split(
"\\/")) {
162 if(!Strings.isBlank(s)) {
177 if(children ==
null) {
178 children =
new Treechildren();
179 appendChild(children);
181 children.appendChild(af);
193 if(children !=
null) {
194 children.getChildren().clear();
199 private void addCells() {
200 Treerow row =
new Treerow();
201 row.setDroppable(
"true");
202 row.addEventListener(Events.ON_DROP,
new EventListener() {
204 public void onEvent(Event event)
throws Exception {
205 final DropEvent dp = (DropEvent) event;
211 a.setPath(Strings.isEmpty(getPath()) ?
"/" : getPath());
220 Treecell cell =
new Treecell(label);
221 cell.setImage(
"/_zul/images/folder.png");
222 row.appendChild(cell);
225 private void addChildrenSpace() {
227 children =
new Treechildren();
228 appendChild(children);
241 this.loadOnDemand = loadOnDemand;
252 private void initLoadOnDemand() {
253 if(!loadOnDemand)
return;
257 addEventListener(Events.ON_OPEN,
new EventListener() {
259 public void onEvent(Event event)
throws Exception {
268 private void fillFolder() {
269 if(children !=
null && children.getChildren().isEmpty()) {
270 for(String s : getFolders()) {
271 addFolder(s, path +
"/" + s);
305 return getFolders().isEmpty();
317 return children !=
null ? CollectionUtil.from(children.getChildren()).<Collection<AttachFolder>>cast() :
new ArrayList<>();
337 results.
setAttachPath(Strings.isEmpty(path) ?
"/" : path +
"/%");
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)
java.util.Set< String > getPathList(String currPath)
void setCkExactPath(boolean ckExactPath)
java.util.List< Attachment > getAttachmentList()
void setAttachPath(String attachPath)
void addAttachment(Attachment attachment)
Collection< String > getFolders()
Collection< Attachment > getAllAttachments()
AttachFolder(String label)
Collection< AttachFolder > getAttachFolders()
void addMedias(Media[] medias)
void setFolderLabel(String label)
AttachFolder addFolder(String label, String path)
AttachFolder(String label, String path, boolean loadOnDemand)
Collection< Attachment > getAttachments()
void setLoadOnDemand(boolean loadOnDemand)
void setPath(String path)
IAttachFolder getParentFolder()
AttachVersionMap getVersionMap()
AttachFolder(String label, Object value)
AttachNavigatorListener getAttachListener()
AttachVersionSet getAttachmentSet()
IConstructor getConstructor()
boolean isInRole(String role)
static Application getApplication()
static String cutString(String value, int maxChars)
static Messages confirmMove()
static IElephantEntity getController(String path)
static String get(String msg)
static ISystemLogger getInstance()
void uploadDone(Attachment file)
void doLog(SystemLogType type, Object entity, String comment, Serializable data)