19 package org.turro.entities;
22 import java.io.IOException;
23 import java.util.ArrayList;
24 import java.util.Arrays;
25 import java.util.Collection;
26 import java.util.Collections;
27 import java.util.List;
28 import java.util.logging.Level;
29 import java.util.logging.Logger;
30 import org.amic.util.file.FileUtil;
31 import org.turro.string.Strings;
32 import org.turro.action.AcceptanceSingleStatus;
33 import org.turro.annotation.ElephantEntity;
34 import org.turro.attach.db.AttachPU;
35 import org.turro.attach.entity.Attachment;
36 import org.turro.attach.zul.AttachmentUtil;
37 import org.turro.collections.KeyValueMap;
38 import org.turro.elephant.context.ElephantContext;
39 import org.turro.elephant.db.WhereClause;
40 import org.turro.file.FileWrapper;
41 import org.turro.i18n.I_;
42 import org.turro.jpa.Dao;
43 import org.turro.path.Path;
44 import org.turro.plugin.contacts.IContact;
45 import org.turro.wd.entities.AttachWd;
69 if(
path.getSize() == 2) {
70 if(
null !=
path.getRoot())
switch (
path.getRoot()) {
93 }
else if(
entity instanceof File) {
94 return ((File)
entity).getName();
103 String root =
path.getRoot();
104 if(
null != root)
switch (root) {
106 return I_.
get(
"Attachment");
108 return I_.
get(
"File");
129 String root =
path.getRoot();
130 if(
null != root)
switch (root) {
132 return "/_zul/images/clip.png";
134 return "/_zul/images/clip.png";
144 String root =
path.getRoot();
145 if(
null != root)
switch (root) {
181 return Collections.EMPTY_LIST;
194 File file = File.createTempFile(
"attach_",
"_mail");
197 }
catch (IOException ex) {
200 }
else if(
entity instanceof File) {
218 }
else if(
entity instanceof File) {
231 }
else if(
entity instanceof File) {
251 }
else if(
entity instanceof File) {
259 public Collection
getEntitites(String search,
int maxResults, KeyValueMap kvm) {
260 ArrayList<Object> list =
new ArrayList<>();
261 list.addAll(searchAttachments(search, maxResults, kvm));
266 public Collection
getEntitites(String root, String search,
int maxResults, KeyValueMap kvm) {
267 ArrayList<Object> list =
new ArrayList<>();
268 if(
null != root)
switch (root) {
270 list.addAll(searchAttachments(search, maxResults, kvm));
305 return super.itsMine(rootPath) ||
"file".equals(rootPath);
315 return Arrays.asList(
"attachment",
"file");
333 private List<Object> searchAttachments(String search,
int maxResults, KeyValueMap kvm) {
335 wc.
addClause(
"select c from Attachment c");
336 wc.
addClause(
"where c.fileName like :search");
339 return getDao().getResultList(wc, maxResults);
343 if(
object instanceof Attachment) {
344 Attachment attachment = (Attachment)
object;
345 if(
new File(ElephantContext.getRealPath(
"/_internal/system/mime/" + attachment.getFileExtension() +
".png")).exists()) {
346 return "/_internal/system/mime/" + attachment.getFileExtension() +
".png";
348 }
else if(
object instanceof File) {
349 File file = (File)
object;
351 return "/_internal/system/mime/" + FileUtil.getExtension(file) +
".png";
354 return "/_internal/system/mime/empty.png";
static String getObjectExtendedPath(Object object)
static String getObjectPath(Object object)
AcceptanceSingleStatus getSingleStatus()
boolean isRequiresAcceptance()
static boolean download(Attachment attachment)
static String getRealPath(String path)
static String logMsg(String msg)
void addClause(String clause)
void addNamedValue(String name, Object value)
IElephantEntity getParent()
boolean canShowInContext(IContact contact, Object relatedEntity)
Collection getEntitites(String root, String search, int maxResults, KeyValueMap kvm)
List< IElephantEntity > getChildren()
String getExtendedWebPath()
Collection getEntitites(String search, int maxResults, KeyValueMap kvm)
IElephantEntity createInstance(Object entity)
Object configureCtrl(Object ctrl, IContact contact)
IElephantEntity createInstance(String entityPath)
AttachEntities(String entityPath)
Collection< String > getAllowedRoots()
AttachEntities(Object entity)
String getHierarchicalPath()
boolean itsMine(String rootPath)
boolean canPublish(IContact contact)
boolean canEdit(IContact contact)
boolean itsMine(Object entity)
boolean isValidLongEntity()
static String get(String msg)
boolean isInRole(String role)
static void writeToFile(Attachment attachment, File file)
static final String PATH_SEPARATOR
String getHierarchicalPath()