18 package org.turro.file;
21 import java.util.ArrayList;
22 import java.util.List;
23 import java.util.Properties;
24 import java.util.logging.Level;
25 import java.util.logging.Logger;
26 import org.amic.util.file.FileUtil;
27 import org.turro.command.Command;
28 import org.turro.command.Context;
29 import org.turro.elephant.context.ElephantContext;
30 import org.turro.file.action.*;
31 import org.turro.file.zul.tree.FileItem;
32 import org.turro.log.SystemLogger;
33 import org.turro.upload.Medias;
34 import org.zkoss.util.media.ContentTypes;
35 import org.zkoss.util.media.Media;
36 import org.zkoss.zk.ui.event.EventListener;
37 import org.zkoss.zk.ui.event.UploadEvent;
38 import org.zkoss.zul.Filedownload;
39 import org.zkoss.zul.Fileupload;
57 if(
file.isDirectory()) {
59 }
else if(
file.isFile()) {
72 return FileUtil.getBaseName(
file);
76 return FileUtil.getExtension(
file);
85 if(fa.getLabel().equals(label)) {
92 public Properties
getProperties() throws FileNotFoundException, IOException {
107 public void delete() {
108 FileUtil.deleteFile(
file);
111 public void copyTo(File destination)
throws IOException {
112 if(destination.isDirectory()) {
113 if(
file.isDirectory()) {
114 FileUtil.copyFolder(
file, destination.getAbsolutePath());
115 }
else if(
file.isFile()) {
116 FileUtil.copyFile(
file, destination.getAbsolutePath());
123 Filedownload.save(
file, ContentTypes.getContentType(FileUtil.getExtension(
file)));
128 }
catch (Exception ex) {
133 public void upload(
final Command command) {
137 Fileupload.get(100,
new EventListener<UploadEvent>() {
139 public void onEvent(UploadEvent event) {
140 ArrayList<File> list =
new ArrayList<>();
141 Media[] medias =
event.getMedias();
142 if(medias ==
null || medias.length == 0)
return;
143 for(Media media : medias) {
144 File newFile =
new File(
file.getAbsolutePath() +
"/" + Document.correctName(media.getName()));
148 if(command !=
null) {
150 Context context =
new Context();
151 context.put(
"files", list);
152 command.execute(context);
153 }
catch (Exception ex) {
162 if(!
file.getParentFile().exists()) {
163 file.getParentFile().mkdirs();
165 Fileupload.get(1,
new EventListener<UploadEvent>() {
167 public void onEvent(UploadEvent event)
throws Exception {
168 Media[] medias =
event.getMedias();
169 if(medias ==
null || medias.length == 0)
return;
170 for(Media media : medias) {
173 if(command !=
null) {
175 Context context =
new Context();
176 context.put(
"file",
file);
177 command.execute(context);
178 }
catch (Exception ex) {
static String getRelativePath(String path)
static String logMsg(String msg)
static boolean isMyType(File file)
static FileWrapper getFileByType(File file)
FileAction getAction(String label)
void uploadContent(final Command command)
List< FileAction > actions
void copyTo(File destination)
void setFileItem(FileItem fileItem)
List< FileAction > getActions()
Properties getProperties()
PropertiesFile propertiesFile
void upload(final Command command)
static boolean isMyType(File file)
static boolean isMyType(File file)
static boolean isMyType(File file)
Properties getProperties()
static boolean isMyType(File file)
static boolean isMyType(File file)
static boolean fits(File file)
static ILogWrapper info()
ILogWrapper comment(String comment)
ILogWrapper entityPath(String path)
ILogWrapper entityName(String name)