1
2
3
4
5
6
7
8 package com.buckosoft.PicMan.web;
9
10 import java.util.Iterator;
11 import java.util.LinkedList;
12 import java.util.List;
13
14 import org.apache.commons.logging.Log;
15 import org.apache.commons.logging.LogFactory;
16
17 import com.buckosoft.PicMan.db.DatabaseFacade;
18
19 import com.buckosoft.PicMan.domain.Chain;
20 import com.buckosoft.PicMan.domain.Set;
21 import com.buckosoft.PicMan.domain.System;
22
23
24
25
26
27
28 public class HtmlUtils {
29 protected final Log logger = LogFactory.getLog(getClass());
30 static private final String eol = "\r\n";
31
32 private DatabaseFacade dbf;
33
34 public void setDatabase(DatabaseFacade dbf) { this.dbf = dbf; }
35 public DatabaseFacade getDatabase() { return(dbf); }
36
37 public List<String> getFilterColumnsAsHtml(List<String> in) {
38 LinkedList<String> out = new LinkedList<String>();
39 Iterator<String> it = in.iterator();
40 String[] b;
41 String s;
42 while (it.hasNext()) {
43 s = "";
44 b = ((String)it.next()).split("_");
45 for (int i=0; i<b.length; i++) {
46 if (i != 0)
47 s += "<br/>";
48 s += b[i];
49 }
50 out.add(s);
51 }
52 return(out);
53 }
54
55
56
57
58
59
60
61 public String getContactSelectorHtml(Chain chain, String setName, String uri) {
62 List<Integer> sizes = dbf.getSizes();
63 StringBuffer sb = new StringBuffer();
64 for (int i=0; i<chain.getContactCount(); i++) {
65 sb.append("<tr>");
66 Iterator<Integer> iter = sizes.iterator();
67 while (iter.hasNext()) {
68 int size = ((Integer)iter.next()).intValue();
69 sb.append("<td>");
70 if (chain.hasSetSize(setName, size)) {
71 sb.append("<a href=\"");
72 sb.append(uri);
73 sb.append("?cid=" + chain.getCid() + "&set=" + setName + "&size=" + size + "&item=" + i + "\">");
74 sb.append(System.getUuid(setName, size, i));
75 sb.append("</a>");
76 } else {
77 sb.append(" ");
78 }
79 sb.append("</td>");
80 }
81 sb.append("</tr>" + eol);
82 }
83 return(sb.toString());
84 }
85
86
87
88
89
90
91 public String getSetSizeCheckboxesHtml(Chain chain) {
92 List<Set> sets = dbf.getSets();
93
94 int[] sizes = dbf.getSizeArray();
95 StringBuffer sb = new StringBuffer();
96 StringBuffer sx = new StringBuffer();
97 int i;
98
99 Iterator<Set> iter = sets.iterator();
100 boolean[] sizesIncluded = new boolean[sizes.length];
101 for (i=0; i<sizesIncluded.length; i++)
102 sizesIncluded[i] = false;
103 i=0;
104 while (iter.hasNext()) {
105 Set set = (Set)iter.next();
106 String setName = set.getName();
107
108
109
110
111
112
113 for (int sizesIndex=0; sizesIndex<sizes.length; sizesIndex++) {
114 int size = sizes[sizesIndex];
115 if (chain.hasSetSize(setName, size)) {
116 sizesIncluded[sizesIndex] = true;
117 }
118 }
119 }
120 sb.append("<tr><td>");
121 sb.append(sx);
122 sb.append(" </td><td> </td>");
123 sb.append(eol);
124 for (i=0; i<sizesIncluded.length; i++) {
125 if (!sizesIncluded[i]) {
126 sb.append("<td> </td>");
127 } else {
128 sb.append("<td>");
129 sb.append("<input type=\"checkbox\" id=\"col_");
130 sb.append(sizes[i]);
131 sb.append("\" name=\"col_");
132 sb.append(sizes[i]);
133 sb.append("\" onclick=\"colClick(");
134 sb.append(sizes[i]);
135 sb.append(")\"/>");
136 sb.append(sizes[i]);
137 sb.append("</td>");
138 }
139 sb.append(eol);
140 }
141 sb.append("</tr>");
142 sb.append(eol);
143
144
145
146
147
148
149
150
151
152 iter = sets.iterator();
153 while (iter.hasNext()) {
154 Set set = (Set)iter.next();
155 String setName = set.getName();
156 boolean included = false;
157 sx.setLength(0);
158 for (int sizesIndex=0; sizesIndex<sizes.length; sizesIndex++) {
159 int size = sizes[sizesIndex];
160 sx.append("<td>");
161 if (chain.hasSetSize(setName, size)) {
162 included = true;
163 String ssName = setName + "_" + size;
164
165
166
167 sx.append("<input type=\"checkbox\" id=\"x_");
168 sx.append(ssName);
169 sx.append("\" name=\"x_");
170 sx.append(ssName);
171 sx.append("\"/>");
172 sx.append(ssName);
173 } else {
174 sx.append(" ");
175 }
176 sx.append("</td>");
177 sx.append(eol);
178 }
179 if (included) {
180 sb.append("<tr><td>");
181 sb.append("<input type=\"checkbox\" id=\"row_");
182 sb.append(setName);
183 sb.append("\" name=\"row_");
184 sb.append(setName);
185 sb.append("\" onclick=\"rowClick('");
186 sb.append(setName);
187 sb.append("');\"/>");
188
189 sb.append("</td><td>:</td>");
190 sb.append(eol);
191
192 sb.append(sx);
193 sb.append("</tr>");
194 sb.append(eol);
195 }
196 }
197 return(sb.toString());
198 }
199
200 }