BrightSide Workbench Full Report + Source Code
RegistryHTMLFormatter.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2011 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 package org.turro.registry;
19 
20 import org.turro.string.Strings;
21 import org.turro.elephant.impl.util.StringParser;
22 import org.turro.html.*;
23 
28 public class RegistryHTMLFormatter {
29 
30  private HTMLGenerator html;
31  private Changes changes;
32 
33  public RegistryHTMLFormatter(HTMLGenerator html, Changes changes) {
34  this.html = html;
35  this.changes = changes == null ? new Changes() : changes;
36  }
37 
39  ChangeCategory last = null;
40  changes.clearEquals();
41  html.startTable("width='100%' style='width:100%'");
42  html.startTableCol("");
43  for(IChange c : changes) {
44  if(!c.getCategory().equals(last)) {
45  if(!Strings.isBlank(c.getCategory().getCaption())) {
46  last = c.getCategory();
47  html.startTag("div", " style='border-bottom: solid 1px #eeeeee;font-weight:bold; margin-top:10px;'")
48  .write(c.getCategory().getCaption())
49  .endTag();
50  }
51  }
52  if(Strings.isBlank(c.getLabel()) && c.isOnlyNew()) {
53  html.startTag("p")
54  .write(StringParser.toHTML(c.getNewValueString()))
55  .endTag();
56  } else if(c.isOnlyNew()) {
57  html.startTag("p")
58  .write(StringParser.toHTML(c.getLabel()))
59  .write(": ")
60  .write(StringParser.toHTML(c.getNewValueString()))
61  .endTag();
62  } else {
63  html.startTag("p")
64  .write(StringParser.toHTML(c.getLabel()))
65  .write(" [")
66  .write(StringParser.toHTML(c.getOldValueString()))
67  .write("]: ")
68  .write(StringParser.toHTML(c.getNewValueString()))
69  .endTag();
70  }
71  }
72  html.endAllTags();
73  return html;
74  }
75 
76 }
static String toHTML(String value)
HTMLGenerator write(String value)
HTMLGenerator startTag(String tag)
HTMLGenerator startTableCol(String attributes)
HTMLGenerator startTable(String attributes)
RegistryHTMLFormatter(HTMLGenerator html, Changes changes)