19 package org.turro.attach.www;
21 import java.util.HashSet;
22 import java.util.Iterator;
23 import java.util.List;
24 import org.turro.string.Strings;
25 import org.turro.action.AcceptanceSingleStatus;
26 import org.turro.action.IAcceptances;
27 import org.turro.action.Plugins;
28 import org.turro.attach.db.AttachPU;
29 import org.turro.attach.entity.Attachment;
30 import org.turro.collections.Item;
31 import org.turro.elephant.context.Application;
32 import org.turro.elephant.context.IConstructor;
33 import org.turro.elephant.db.WhereClause;
34 import org.turro.html.FontAwesome;
35 import org.turro.http.HttpUtil;
36 import org.turro.jpa.iterator.DaoHtmlTree;
37 import org.turro.marker.ElephantMarker;
38 import org.turro.path.Path;
46 private boolean publicOnly, lastOnly;
47 private final HashSet<String> restrictedFolders =
new HashSet<>();
58 this.publicOnly = publicOnly;
66 this.lastOnly = lastOnly;
70 return restrictedFolders;
74 if(!Strings.isBlank(restrictedFolder)) {
75 restrictedFolders.add(restrictedFolder);
80 if(restrictedFolders !=
null) {
81 this.restrictedFolders.addAll(restrictedFolders);
87 return value instanceof Long ?
getDao().find(
Attachment.class, (Long) value) : value;
120 wc.
addClause(
"select distinct case when locate('/', a.path, " + (currPath.length() + 2) +
") = 0 then a.path else substring(a.path, 1, locate('/', a.path, " + (currPath.length() + 2) +
") - 1) end from Attachment as a");
122 wc.
addClause(
"where UCASE(a.path) like UCASE(:path)");
127 wc.
addClause(
"and a.publishable = true");
136 wc.
addClause(
"select distinct a from Attachment as a");
137 if(Strings.isBlank(currPath)) {
140 wc.
addClause(
"where UCASE(a.path) = UCASE(:path)");
144 wc.
addClause(
"and a.publishable = true");
147 wc.
addClause(
"and a.modification = (select max(a2.modification) from Attachment as a2 where a2.path = a.path and a2.fileName = a.fileName)");
154 protected Object
getId(Object item) {
174 return FontAwesome.getMimeIcon(
"folder");
213 private void clean(List<Item<Object, Object>> items) {
215 Iterator<Item<Object, Object>> it = items.iterator();
216 while(it.hasNext()) {
217 Item<Object, Object> item = it.next();
219 Path p =
new Path(item.getPath());
220 String tmp = p.getLastNode();
221 if(!Strings.isBlank(tmp) && tmp.startsWith(
"#")) {
222 boolean allowed =
false;
223 for(String restrictedFolder : restrictedFolders) {
224 if((
"#" + restrictedFolder).equalsIgnoreCase(tmp)) {
234 clean(item.getChildren());
static< T > T loadImplementation(Class< T > jclass)
static String getObjectPath(Object object)
String getDateString(IConstructor constructor)
String getShowURL(IConstructor constructor)
String getROShowURL(IConstructor constructor)
String getFileExtension()
static String delAttachment(Attachment attachment, String link)
HashSet< String > getRestrictedFolders()
String getDeleteLink(Item item)
void setLastOnly(boolean lastOnly)
void renderTree(ElephantMarker marker, List< Item< Object, Object >> items)
void renderItem(ElephantMarker marker, Object item)
String parseTree(ElephantMarker marker, List< Item< Object, Object >> items)
Object getEntity(Object value)
String getROShowURL(Item item)
AttachTree(IConstructor constructor)
String getImage(Item item)
String getDateString(Item item)
WhereClause getLeafClause(String currPath)
WhereClause getChildrenClause(String currPath)
Object getId(Object item)
void setPublicOnly(boolean publicOnly)
String getShowURL(Item item)
Object getParentId(Object item)
void addRestrictedFolders(HashSet< String > restrictedFolders)
void addRestrictedFolder(String restrictedFolder)
String getByteString(Item item)
String createPetition(AcceptanceSingleStatus status, Item item)
String parseItem(ElephantMarker marker, Object item)
IConstructor getConstructor()
boolean isInRole(String role)
static Application getApplication()
void addClause(String clause)
void addNamedValue(String name, Object value)
void process(String rootTmpl, String tmpl)
String parse(String rootTmpl, String tmpl)
Object put(Object key, Object value)
String createPetition(String path, IContact contact, String link)
HttpServletRequest getRequest()