BrightSide Workbench Full Report + Source Code
BrightSide/elephant-dossier/src/main/java/org/turro/dossier/www/PhaseHtmlFilter.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2016 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.dossier.www;
20 
21 import org.turro.string.Strings;
22 import org.turro.dossier.dossier.DossierCounter;
23 import org.turro.elephant.context.IConstructor;
24 import org.turro.marker.ElephantMarker;
25 import org.turro.phase.PhaseDefinitions;
26 
31 public class PhaseHtmlFilter {
32 
33  private String phase, template, allowedCategories;
34  private IConstructor constructor;
35  private String[] types, status;
36  private boolean restricted;
37 
38  public static PhaseHtmlFilter getInstance(IConstructor constructor, String context) {
39  PhaseHtmlFilter filter = (PhaseHtmlFilter) constructor.getSessionAttribute(context + "-phaseFilter");
40  if(filter == null) {
41  filter = new PhaseHtmlFilter();
42  constructor.setSessionAttribute(context + "-phaseFilter", filter);
43  }
44  filter.loadValues(constructor);
45  return filter;
46  }
47 
48  public boolean isEmpty() {
49  return Strings.isBlank(phase);
50  }
51 
52  public void loadValues(IConstructor constructor) {
53  this.constructor = constructor;
54  String tmp = constructor.getParameter("phase");
55  if("clear".equals(tmp)) {
56  phase = null;
57  } else if(tmp != null) {
58  phase = tmp;
59  }
60  }
61 
62  public String getTemplate() {
63  return template;
64  }
65 
66  public void setTemplate(String template) {
67  this.template = template;
68  }
69 
70  public String getAllowedCategories() {
71  return allowedCategories;
72  }
73 
74  public void setAllowedCategories(String allowedCategories) {
75  this.allowedCategories = allowedCategories;
76  }
77 
78  public String[] getTypes() {
79  return types;
80  }
81 
82  public void setTypes(String[] types) {
83  this.types = types;
84  }
85 
86  public String[] getStatus() {
87  return status;
88  }
89 
90  public void setStatus(String[] status) {
91  this.status = status;
92  }
93 
94  public boolean isRestricted() {
95  return restricted;
96  }
97 
98  public void setRestricted(boolean restricted) {
99  this.restricted = restricted;
100  }
101 
102  public String getPhase() {
103  return phase;
104  }
105 
106  public String render() {
107  ElephantMarker em = new ElephantMarker(constructor);
108  em.put("phases", PhaseDefinitions.instance());
109  em.put("dossierCounter", new DossierCounter(allowedCategories, types, status, restricted));
110  em.put("selected", phase);
111  return em.parse("dossier", template);
112  }
113 
114 }
String parse(String rootTmpl, String tmpl)
Object put(Object key, Object value)
static PhaseDefinitions instance()
void setSessionAttribute(String key, Object value)