BrightSide Workbench Full Report + Source Code
AttachCtrl.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2013 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 package org.turro.attach.www;
20 
21 import java.util.HashSet;
22 import org.turro.string.Strings;
23 import org.turro.annotation.ElephantControl;
24 import org.turro.elephant.context.IConstructor;
25 import org.turro.entities.Controls;
26 import org.turro.http.HttpUtil;
27 
32 @ElephantControl(name=Controls.CTRL_ATTACHMENT)
33 public class AttachCtrl {
34 
35  private final HashSet<String> restrictedFolders = new HashSet<>();
36  private final IConstructor constructor;
37  private String entityPath, entityRoot, treeTemplate;
38  private AttachTree attachTree;
39  private boolean publicOnly = false, lastOnly = false, readOnly = false;
40 
41  public AttachCtrl(IConstructor constructor) {
42  this.constructor = constructor;
43  }
44 
45  public void setEntityPath(String entityPath) {
46  this.entityPath = entityPath;
47  attachTree = null;
48  }
49 
50  public void setEntityRoot(String entityRoot) {
51  this.entityRoot = entityRoot;
52  attachTree = null;
53  }
54 
55  public void setTreeTemplate(String treeTemplate) {
56  this.treeTemplate = treeTemplate;
57  }
58 
59  public HashSet<String> getRestrictedFolders() {
60  return restrictedFolders;
61  }
62 
63  public void addRestrictedFolder(String restrictedFolder) {
64  if(!Strings.isBlank(restrictedFolder)) restrictedFolders.add(restrictedFolder);
65  }
66 
67  public void addRestrictedFolders(HashSet<String> restrictedFolders) {
68  if(restrictedFolders != null) {
69  this.restrictedFolders.addAll(restrictedFolders);
70  }
71  }
72 
73  public boolean isPublicOnly() {
74  return publicOnly;
75  }
76 
77  public void setPublicOnly(boolean publicOnly) {
78  this.publicOnly = publicOnly;
79  attachTree = null;
80  }
81 
82  public boolean isLastOnly() {
83  return lastOnly;
84  }
85 
86  public void setLastOnly(boolean lastOnly) {
87  this.lastOnly = lastOnly;
88  attachTree = null;
89  }
90 
91  public boolean isReadOnly() {
92  return readOnly;
93  }
94 
95  public void setReadOnly(boolean readOnly) {
96  this.readOnly = readOnly;
97  }
98 
99  public void renderAttachments() {
100  getAttachTree().render();
101  }
102 
103  public String parseAttachments() {
104  return getAttachTree().parse();
105  }
106 
107  public String getNewAttachment() {
108  return AttachAction.newAttachment(entityPath, HttpUtil.getCurrentUrl(constructor.getRequest()), null);
109  }
110 
111  public boolean isEmpty() {
112  return getAttachTree().isEmpty();
113  }
114 
116  if(attachTree == null) {
117  attachTree = new AttachTree(constructor);
118  attachTree.setPublicOnly(publicOnly);
119  attachTree.setLastOnly(lastOnly);
120  attachTree.addRestrictedFolders(restrictedFolders);
121  attachTree.setTreeTemplate(treeTemplate);
122  attachTree.fillTree(entityPath + (!Strings.isBlank(entityRoot) ? entityRoot : ""));
123  }
124  return attachTree;
125  }
126 
127 }
static String newAttachment(String entityPath, String link, String template)
void setLastOnly(boolean lastOnly)
Definition: AttachCtrl.java:86
void setEntityRoot(String entityRoot)
Definition: AttachCtrl.java:50
HashSet< String > getRestrictedFolders()
Definition: AttachCtrl.java:59
void addRestrictedFolder(String restrictedFolder)
Definition: AttachCtrl.java:63
void addRestrictedFolders(HashSet< String > restrictedFolders)
Definition: AttachCtrl.java:67
void setPublicOnly(boolean publicOnly)
Definition: AttachCtrl.java:77
AttachCtrl(IConstructor constructor)
Definition: AttachCtrl.java:41
void setEntityPath(String entityPath)
Definition: AttachCtrl.java:45
void setReadOnly(boolean readOnly)
Definition: AttachCtrl.java:95
void setTreeTemplate(String treeTemplate)
Definition: AttachCtrl.java:55
void setLastOnly(boolean lastOnly)
void setPublicOnly(boolean publicOnly)
void addRestrictedFolders(HashSet< String > restrictedFolders)
void setTreeTemplate(String treeTemplate)
void fillTree(String path)
Definition: DaoTree.java:45