1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.student.contract.model.util; |
17 | |
|
18 | |
import java.util.HashSet; |
19 | |
import java.util.LinkedHashSet; |
20 | |
import java.util.Set; |
21 | |
|
22 | |
import org.kuali.student.contract.model.MessageStructure; |
23 | |
import org.kuali.student.contract.model.ServiceContractModel; |
24 | |
import org.kuali.student.contract.model.ServiceMethod; |
25 | |
import org.kuali.student.contract.model.ServiceMethodParameter; |
26 | |
import org.kuali.student.contract.model.XmlType; |
27 | |
import org.kuali.student.contract.writer.HtmlWriter; |
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
public class HtmlContractMessageStructureWriter { |
34 | |
|
35 | |
private XmlType xmlType; |
36 | |
private HtmlWriter writer; |
37 | |
private ServiceContractModel model; |
38 | |
private ModelFinder finder; |
39 | |
|
40 | |
public HtmlContractMessageStructureWriter(XmlType xmlType, String directory, |
41 | 0 | ServiceContractModel model) { |
42 | 0 | this.xmlType = xmlType; |
43 | 0 | this.writer = new HtmlWriter(directory, xmlType.getName() + ".html", |
44 | |
xmlType.getName()); |
45 | 0 | this.model = model; |
46 | 0 | this.finder = new ModelFinder(this.model); |
47 | 0 | } |
48 | |
|
49 | |
private String initUpper(String str) { |
50 | 0 | if (str == null) { |
51 | 0 | return null; |
52 | |
} |
53 | 0 | if (str.length() == 0) { |
54 | 0 | return str; |
55 | |
} |
56 | 0 | if (str.length() == 1) { |
57 | 0 | return str.toUpperCase(); |
58 | |
} |
59 | 0 | return str.substring(0, 1).toUpperCase() + str.substring(1); |
60 | |
} |
61 | |
|
62 | |
private boolean isMainMessageStructure(XmlType xmlType) { |
63 | 0 | if (!HtmlContractMessageStructureWriter.calcOtherXmlTypeUsages(model, |
64 | |
xmlType).isEmpty()) { |
65 | 0 | return false; |
66 | |
} |
67 | 0 | return true; |
68 | |
} |
69 | |
|
70 | |
public void write() { |
71 | 0 | writer.println("<a href=\"index.html\">home</a>"); |
72 | 0 | if (this.isMainMessageStructure(xmlType)) { |
73 | 0 | writer.println("<a href=\"../dictionarydocs/" + initUpper(xmlType.getName()) + ".html\">dictionary doc</a>"); |
74 | |
} |
75 | 0 | this.writeStyleSheet(); |
76 | 0 | writer.writeTag("h1", xmlType.getName()); |
77 | |
|
78 | 0 | writer.indentPrintln("<table id=\"structureMetaTable\">"); |
79 | 0 | writer.indentPrintln("<tr>"); |
80 | 0 | writer.writeTag("th", "class=h", "Name"); |
81 | 0 | writer.writeTag("td", "id=structureName colspan=2", xmlType.getName()); |
82 | 0 | writer.indentPrintln("</tr>"); |
83 | |
|
84 | |
|
85 | |
|
86 | |
|
87 | 0 | writer.indentPrintln("<tr>"); |
88 | 0 | writer.writeTag("th", "rowspan=3 class=h", "Usage"); |
89 | 0 | writer.indentPrint("<td id=\"structureVersion\" colspan=2>"); |
90 | 0 | for (String servKey : xmlType.getService().split(",")) { |
91 | 0 | writer.indentPrintln("<a href=\"" + servKey + "Service" + ".html" + "\">" |
92 | |
+ servKey + "Service" + "</a>"); |
93 | |
} |
94 | 0 | writer.indentPrint("</td>"); |
95 | |
|
96 | 0 | writer.indentPrintln("</tr>"); |
97 | 0 | writer.indentPrintln("<tr>"); |
98 | 0 | writer.writeTag("th", "class=h", ""); |
99 | 0 | writer.indentPrint("<td id=\"structureVersion\" colspan=2>"); |
100 | 0 | for (ServiceMethod method : this.calcUsageByMethods(xmlType)) { |
101 | 0 | writer.indentPrintln("<a href=\"" + method.getService() + "Service" |
102 | |
+ ".html" + "#" + method.getService() + "-" |
103 | |
+ method.getName() + "\">" |
104 | |
+ method.getName() + "</a>"); |
105 | |
} |
106 | 0 | writer.indentPrint("</td>"); |
107 | 0 | writer.indentPrintln("</tr>"); |
108 | 0 | writer.indentPrintln("<tr>"); |
109 | 0 | writer.writeTag("th", "class=h", ""); |
110 | 0 | writer.indentPrint("<td id=\"structureVersion\" colspan=2>"); |
111 | 0 | for (String xmlTypeName : this.calcOtherXmlTypeUsages(xmlType)) { |
112 | 0 | XmlType usageType = finder.findXmlType(xmlTypeName); |
113 | 0 | if (usageType == null) { |
114 | 0 | throw new NullPointerException("Coud not find XmlType with name=" |
115 | |
+ xmlTypeName); |
116 | |
} |
117 | 0 | writer.indentPrintln("<a href=\"" + usageType.getName() + ".html" + "\">" |
118 | |
+ usageType.getName() + "</a>"); |
119 | 0 | } |
120 | 0 | writer.indentPrint("</td>"); |
121 | 0 | writer.indentPrintln("</tr>"); |
122 | |
|
123 | 0 | writer.writeTag("th", "class=h", "Type"); |
124 | 0 | writer.writeTag("td", "id=structureVersion colspan=2", |
125 | |
xmlType.getPrimitive()); |
126 | 0 | writer.indentPrintln("</tr>"); |
127 | 0 | writer.indentPrintln("</table>"); |
128 | |
|
129 | 0 | writer.writeTag("h2", "Description"); |
130 | 0 | writer.indentPrintln(this.addHTMLBreaks(xmlType.getDesc())); |
131 | |
|
132 | 0 | if (!xmlType.getPrimitive().equals(XmlType.COMPLEX)) { |
133 | 0 | return; |
134 | |
} |
135 | 0 | writer.indentPrintln( |
136 | |
"<h2><a name=\"StructureDefinition\"></a>Structure Definition</h2>"); |
137 | |
|
138 | |
|
139 | 0 | writer.indentPrintln("<table class=\"structTable\">"); |
140 | 0 | writer.indentPrintln("<tr>"); |
141 | 0 | writer.indentPrintln("<th class=\"h\">ShortName</th>"); |
142 | 0 | writer.indentPrintln("<th class=\"h\">Name</th>"); |
143 | 0 | writer.indentPrintln("<th class=\"h\">Type</th>"); |
144 | 0 | writer.indentPrintln("<th class=\"h\">Description</th>"); |
145 | 0 | writer.indentPrintln("<th class=\"h\">Required?</th>"); |
146 | 0 | writer.indentPrintln("<th class=\"h\">Read only?</th>"); |
147 | 0 | writer.indentPrintln("<th class=\"h\">Cardinality</th>"); |
148 | 0 | writer.indentPrintln("<th class=\"h\">XML Attribute?</th>"); |
149 | |
|
150 | 0 | writer.indentPrintln("<th class=\"h\">Implementation Notes</th>"); |
151 | 0 | writer.indentPrintln("</tr>"); |
152 | |
|
153 | 0 | for (MessageStructure ms : finder.findMessageStructures(xmlType.getName())) { |
154 | 0 | this.writeMessageStructure(ms); |
155 | |
} |
156 | 0 | writer.indentPrintln("</table>"); |
157 | 0 | writer.writeHeaderBodyAndFooterOutToFile(); |
158 | 0 | } |
159 | |
|
160 | |
private String checkForNbsp(String str) { |
161 | 0 | if (str == null) { |
162 | 0 | return " "; |
163 | |
} |
164 | 0 | if (str.trim().isEmpty()) { |
165 | 0 | return " "; |
166 | |
} |
167 | 0 | return str; |
168 | |
} |
169 | |
|
170 | |
private String addHTMLBreaks(String str) { |
171 | 0 | if (str == null) { |
172 | 0 | return " "; |
173 | |
} |
174 | 0 | return str.replaceAll("(\r\n|\r|\n|\n\r)", "<br>"); |
175 | |
} |
176 | |
|
177 | |
public static Set<String> calcUsageByService(ServiceContractModel mdl, XmlType xmlType) { |
178 | 0 | Set<String> services = new HashSet(); |
179 | 0 | for (ServiceMethod method : calcUsageByMethods(mdl, xmlType)) { |
180 | 0 | services.add(method.getService()); |
181 | |
} |
182 | 0 | return services; |
183 | |
} |
184 | |
|
185 | |
private Set<ServiceMethod> calcUsageByMethods(XmlType xmlType) { |
186 | 0 | return calcUsageByMethods(model, xmlType); |
187 | |
} |
188 | |
|
189 | |
public static Set<ServiceMethod> calcUsageByMethods(ServiceContractModel mdl, XmlType xmlType) { |
190 | 0 | Set<ServiceMethod> methods = new LinkedHashSet(); |
191 | 0 | for (ServiceMethod method : mdl.getServiceMethods()) { |
192 | 0 | if (stripListFromType(method.getReturnValue().getType()).equalsIgnoreCase(xmlType.getName())) { |
193 | 0 | methods.add(method); |
194 | 0 | continue; |
195 | |
} |
196 | 0 | for (ServiceMethodParameter param : method.getParameters()) { |
197 | 0 | if (stripListFromType(param.getType()).equalsIgnoreCase(xmlType.getName())) { |
198 | 0 | methods.add(method); |
199 | 0 | break; |
200 | |
} |
201 | |
} |
202 | |
} |
203 | 0 | return methods; |
204 | |
} |
205 | |
|
206 | |
private Set<String> calcOtherXmlTypeUsages(XmlType xmlType) { |
207 | 0 | return calcOtherXmlTypeUsages(model, xmlType); |
208 | |
} |
209 | |
|
210 | |
public static Set<String> calcOtherXmlTypeUsages(ServiceContractModel mdl, |
211 | |
XmlType xmlType) { |
212 | 0 | Set<String> xmlTypeNames = new LinkedHashSet(); |
213 | 0 | for (MessageStructure ms : mdl.getMessageStructures()) { |
214 | 0 | if (ms.getType() == null) { |
215 | 0 | throw new NullPointerException(ms.getId() + " has no type set"); |
216 | |
} |
217 | 0 | if (stripListFromType(ms.getType()).equalsIgnoreCase(xmlType.getName())) { |
218 | 0 | xmlTypeNames.add(ms.getXmlObject()); |
219 | |
} |
220 | |
} |
221 | 0 | return xmlTypeNames; |
222 | |
} |
223 | |
|
224 | |
private void writeMessageStructure(MessageStructure ms) { |
225 | 0 | writer.indentPrintln("<tr>"); |
226 | 0 | writer.writeTag("td", "class=\"structSName\"", ms.getShortName()); |
227 | 0 | writer.writeTag("td", "class=\"structLName\"", ms.getName()); |
228 | 0 | XmlType subType = finder.findXmlType(this.stripListFromType(ms.getType())); |
229 | 0 | if (subType == null) { |
230 | 0 | for (XmlType xmlt : model.getXmlTypes()) { |
231 | 0 | System.out.println(this.getClass().getSimpleName() + ": " |
232 | |
+ xmlt.getName()); |
233 | |
} |
234 | 0 | throw new NullPointerException(ms.getXmlObject() + "." + ms.getShortName() |
235 | |
+ " has type " + ms.getType() |
236 | |
+ " was not found in list of known types"); |
237 | |
} |
238 | 0 | if (subType.getPrimitive().equals(XmlType.COMPLEX)) { |
239 | 0 | writer.indentPrint("<td class=\"structType\">"); |
240 | 0 | writer.indentPrintln("<a href=\"" + subType.getName() + ".html" + "\">" |
241 | |
+ ms.getType() + "</a>"); |
242 | 0 | writer.indentPrint("</td>"); |
243 | |
} else { |
244 | 0 | writer.writeTag("td", "class=\"structType\"", ms.getType()); |
245 | |
} |
246 | 0 | writer.writeTag("td", "class=\"structDesc\"", addHTMLBreaks(missingData( |
247 | |
ms.getDescription()))); |
248 | 0 | writer.writeTag("td", "class=\"structOpt\"", checkForNbsp(ms.getRequired())); |
249 | 0 | writer.writeTag("td", "class=\"structOpt\"", checkForNbsp(ms.getReadOnly())); |
250 | |
|
251 | 0 | writer.writeTag("td", "class=\"structCard\"", ms.getCardinality()); |
252 | 0 | writer.writeTag("td", "class=\"structAttr\"", ms.getXmlAttribute()); |
253 | |
|
254 | 0 | writer.writeTag("td", "class=\"commentsDesc\"", this.checkForNbsp(ms.getImplNotes())); |
255 | 0 | writer.indentPrintln("</tr>"); |
256 | |
|
257 | |
|
258 | |
|
259 | |
|
260 | |
|
261 | 0 | } |
262 | |
|
263 | |
private String missingData(String str) { |
264 | 0 | if (str == null) { |
265 | 0 | return "???"; |
266 | |
} |
267 | 0 | if (str.trim().isEmpty()) { |
268 | 0 | return "???"; |
269 | |
} |
270 | 0 | return str; |
271 | |
} |
272 | |
|
273 | |
private static String stripListFromType(String type) { |
274 | 0 | if (type.endsWith("List")) { |
275 | 0 | return type.substring(0, type.length() - "List".length()); |
276 | |
} |
277 | 0 | return type; |
278 | |
} |
279 | |
|
280 | |
public void writeStyleSheet() { |
281 | 0 | writer.indentPrintln("<style type=\"text/css\">"); |
282 | 0 | writer.indentPrintln(""); |
283 | 0 | writer.indentPrintln("table#structureMetaTable {"); |
284 | 0 | writer.indentPrintln("border-collapse:collapse;"); |
285 | 0 | writer.indentPrintln("border:1px solid #000000;"); |
286 | 0 | writer.indentPrintln("width:95%;"); |
287 | 0 | writer.indentPrintln("}"); |
288 | 0 | writer.indentPrintln("table#structureMetaTable th.h {"); |
289 | 0 | writer.indentPrintln("border:1px solid #000000;"); |
290 | 0 | writer.indentPrintln("background-color:#eeeeee;"); |
291 | 0 | writer.indentPrintln("width:15%;"); |
292 | 0 | writer.indentPrintln("}"); |
293 | 0 | writer.indentPrintln("table#structureMetaTable td#structureName {"); |
294 | 0 | writer.indentPrintln("border:1px solid #000000;"); |
295 | 0 | writer.indentPrintln("width:85%;"); |
296 | 0 | writer.indentPrintln("}"); |
297 | 0 | writer.indentPrintln("table#structureMetaTable td#structureVersion {"); |
298 | 0 | writer.indentPrintln("border:1px solid #000000;"); |
299 | 0 | writer.indentPrintln("width:70%;"); |
300 | 0 | writer.indentPrintln("}"); |
301 | 0 | writer.indentPrintln("table#structureMetaTable td#structureVersionHistory {"); |
302 | 0 | writer.indentPrintln("border:1px solid #000000;"); |
303 | 0 | writer.indentPrintln("width:15%;"); |
304 | 0 | writer.indentPrintln("}"); |
305 | 0 | writer.indentPrintln(""); |
306 | 0 | writer.indentPrintln("</style>"); |
307 | |
|
308 | 0 | writer.indentPrintln("<style type=\"text/css\">"); |
309 | 0 | writer.indentPrintln(""); |
310 | 0 | writer.indentPrintln("table.structTable {"); |
311 | 0 | writer.indentPrintln("border-collapse:collapse;"); |
312 | 0 | writer.indentPrintln("border:1px solid #000000;"); |
313 | 0 | writer.indentPrintln("width:95%;"); |
314 | 0 | writer.indentPrintln("}"); |
315 | 0 | writer.indentPrintln(""); |
316 | 0 | writer.indentPrintln("table.structTable td.d {"); |
317 | 0 | writer.indentPrintln("border:1px solid #000000;"); |
318 | 0 | writer.indentPrintln("}"); |
319 | 0 | writer.indentPrintln(""); |
320 | 0 | writer.indentPrintln("table.structTable th.h {"); |
321 | 0 | writer.indentPrintln("border:1px solid #000000;"); |
322 | 0 | writer.indentPrintln("background-color:#eeeeee;"); |
323 | 0 | writer.indentPrintln("}"); |
324 | 0 | writer.indentPrintln(""); |
325 | 0 | writer.indentPrintln("table.structTable td.structSName {"); |
326 | 0 | writer.indentPrintln("border:1px solid #000000;"); |
327 | 0 | writer.indentPrintln("background-color:#f2f2f2;"); |
328 | 0 | writer.indentPrintln("color:#222222;"); |
329 | 0 | writer.indentPrintln("text-align:left;"); |
330 | 0 | writer.indentPrintln("vertical-align:top;"); |
331 | 0 | writer.indentPrintln("font-weight:bold;"); |
332 | 0 | writer.indentPrintln("font-style:italic;"); |
333 | 0 | writer.indentPrintln(""); |
334 | 0 | writer.indentPrintln("}"); |
335 | 0 | writer.indentPrintln(""); |
336 | 0 | writer.indentPrintln("table.structTable td.structLName {"); |
337 | 0 | writer.indentPrintln("border:1px solid #000000;"); |
338 | 0 | writer.indentPrintln("background:#ffffff;"); |
339 | 0 | writer.indentPrintln("vertical-align:top;"); |
340 | 0 | writer.indentPrintln(""); |
341 | 0 | writer.indentPrintln("}"); |
342 | 0 | writer.indentPrintln(""); |
343 | 0 | writer.indentPrintln("table.structTable td.structType {"); |
344 | 0 | writer.indentPrintln("border:1px solid #000000;"); |
345 | 0 | writer.indentPrintln("background:#ffffff;"); |
346 | 0 | writer.indentPrintln("vertical-align:top;"); |
347 | 0 | writer.indentPrintln("font-style:italic;"); |
348 | 0 | writer.indentPrintln(""); |
349 | 0 | writer.indentPrintln("}"); |
350 | 0 | writer.indentPrintln(""); |
351 | 0 | writer.indentPrintln("table.structTable td.structDesc {"); |
352 | 0 | writer.indentPrintln("border:1px solid #000000;"); |
353 | 0 | writer.indentPrintln("background:#ffffff;"); |
354 | 0 | writer.indentPrintln("vertical-align:top;"); |
355 | 0 | writer.indentPrintln(""); |
356 | 0 | writer.indentPrintln("}"); |
357 | 0 | writer.indentPrintln(""); |
358 | 0 | writer.indentPrintln("table.structTable td.structOpt {"); |
359 | 0 | writer.indentPrintln("border:1px solid #000000;"); |
360 | 0 | writer.indentPrintln("background:#ffffff;"); |
361 | 0 | writer.indentPrintln("vertical-align:top;"); |
362 | 0 | writer.indentPrintln("text-align: center;"); |
363 | 0 | writer.indentPrintln("}"); |
364 | 0 | writer.indentPrintln(""); |
365 | 0 | writer.indentPrintln("table.structTable td.structReq {"); |
366 | 0 | writer.indentPrintln("border:1px solid #000000;"); |
367 | 0 | writer.indentPrintln("background:#ccccff;"); |
368 | 0 | writer.indentPrintln("vertical-align:top;"); |
369 | 0 | writer.indentPrintln("text-align: center;"); |
370 | 0 | writer.indentPrintln("}"); |
371 | 0 | writer.indentPrintln(""); |
372 | 0 | writer.indentPrintln(""); |
373 | 0 | writer.indentPrintln("table.structTable td.structCard {"); |
374 | 0 | writer.indentPrintln("border:1px solid #000000;"); |
375 | 0 | writer.indentPrintln("background:#ffffff;"); |
376 | 0 | writer.indentPrintln("vertical-align:top;"); |
377 | 0 | writer.indentPrintln("text-align: center;"); |
378 | 0 | writer.indentPrintln("}"); |
379 | 0 | writer.indentPrintln(""); |
380 | 0 | writer.indentPrintln("table.structTable td.structAttr {"); |
381 | 0 | writer.indentPrintln("border:1px solid #000000;"); |
382 | 0 | writer.indentPrintln("background:#ffffff;"); |
383 | 0 | writer.indentPrintln("vertical-align:top;"); |
384 | 0 | writer.indentPrintln("text-align: center;"); |
385 | 0 | writer.indentPrintln("}"); |
386 | 0 | writer.indentPrintln(""); |
387 | 0 | writer.indentPrintln("table.structTable td.structElem {"); |
388 | 0 | writer.indentPrintln("border:1px solid #000000;"); |
389 | 0 | writer.indentPrintln("background:#ccccff;"); |
390 | 0 | writer.indentPrintln("vertical-align:top;"); |
391 | 0 | writer.indentPrintln("text-align: center;"); |
392 | 0 | writer.indentPrintln("}"); |
393 | 0 | writer.indentPrintln(""); |
394 | 0 | writer.indentPrintln("table.structTable td.structStatus {"); |
395 | 0 | writer.indentPrintln("border:1px solid #000000;"); |
396 | 0 | writer.indentPrintln("background:#ffffff;"); |
397 | 0 | writer.indentPrintln("vertical-align:top;"); |
398 | 0 | writer.indentPrintln("text-align: center;"); |
399 | 0 | writer.indentPrintln(""); |
400 | 0 | writer.indentPrintln("}"); |
401 | 0 | writer.indentPrintln(""); |
402 | 0 | writer.indentPrintln("table.structTable td.commentsDesc {"); |
403 | 0 | writer.indentPrintln("border:1px solid #000000;"); |
404 | 0 | writer.indentPrintln("background:#ffffff;"); |
405 | 0 | writer.indentPrintln("vertical-align:top;"); |
406 | 0 | writer.indentPrintln(""); |
407 | 0 | writer.indentPrintln("}"); |
408 | 0 | writer.indentPrintln(""); |
409 | 0 | writer.indentPrintln(""); |
410 | 0 | writer.indentPrintln("</style>"); |
411 | |
|
412 | |
|
413 | 0 | } |
414 | |
} |