BrightSide Workbench Full Report + Source Code
DescribeItCtrl.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.www.describeit;
20 
21 import java.io.PrintWriter;
22 import java.io.StringWriter;
23 import java.util.Collection;
24 import org.turro.contacts.DescribeIt;
25 import org.turro.describeit.DescribeItUtil;
26 import org.turro.elephant.context.IConstructor;
27 import org.turro.html.HTMLHelper;
28 import org.turro.util.IdGenerator;
29 import org.zkoss.lang.Strings;
30 
35 public class DescribeItCtrl {
36 
37  private HTMLHelper html;
38  private String entityPath;
39  private IConstructor constructor;
40 
41  public DescribeItCtrl(IConstructor constructor) {
42  this.constructor = constructor;
43  }
44 
45  public void setEntityPath(String entityPath) {
46  this.entityPath = entityPath;
47  }
48 
49  public void renderDescriptions(boolean container) {
50  renderDescriptions(null, container);
51  }
52 
53  public void renderDescriptions(String describeId, boolean container) {
54  Collection<DescribeIt> descriptions = Strings.isBlank(describeId) ?
55  DescribeItUtil.descriptions(entityPath) :
56  DescribeItUtil.descriptions(describeId, entityPath);
57  if(!descriptions.isEmpty()) {
58  html = new HTMLHelper(constructor);
59  String id = container ? "dic_" + IdGenerator.generate() : constructor.getParameter("domid");
60  if(container) {
61  html.startTag("div", "id='" + id + "'");
62  }
63  for(DescribeIt ci : descriptions) {
64  html.startTag("div", "class='describeit'")
65  .startTag("div", "class='body'")
66  .write(ci.getBody())
67  .endTag()
68  .endTag();
69  }
70  html.endAllTags();
71  }
72  }
73 
74  public String parseDescriptions(String describeId, boolean container) {
75  Collection<DescribeIt> descriptions = Strings.isBlank(describeId) ?
76  DescribeItUtil.descriptions(entityPath) :
77  DescribeItUtil.descriptions(describeId, entityPath);
78  StringWriter sw = new StringWriter();
79  if(!descriptions.isEmpty()) {
80  html = new HTMLHelper(new PrintWriter(sw));
81  String id = container ? "dic_" + IdGenerator.generate() : constructor.getParameter("domid");
82  if(container) {
83  html.startTag("div", "id='" + id + "'");
84  }
85  for(DescribeIt ci : descriptions) {
86  html.startTag("div", "class='describeit'")
87  .startTag("div", "class='body'")
88  .write(ci.getBody())
89  .endTag()
90  .endTag();
91  }
92  html.endAllTags();
93  }
94  return sw.toString();
95  }
96 
97 }
static Collection< DescribeIt > descriptions(Object entity)
HTMLGenerator write(String value)
HTMLGenerator startTag(String tag)
void renderDescriptions(boolean container)
void renderDescriptions(String describeId, boolean container)
String parseDescriptions(String describeId, boolean container)
DescribeItCtrl(IConstructor constructor)