Clover Coverage Report - KS Contract Documentation Generator 0.0.1-SNAPSHOT
Coverage timestamp: Wed Dec 31 1969 19:00:00 EST
../../../../../../img/srcFileCovDistChart0.png 0% of files have more coverage
261   407   23   29
28   351   0.09   9
9     2.56  
1    
 
  HtmlContractServiceWriter       Line # 34 261 0% 23 298 0% 0.0
 
No Tests
 
1    /*
2    * Copyright 2011 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.osedu.org/licenses/ECL-2.0
9    *
10    * Unless required by applicable law or agreed to in writing, software
11    * distributed under the License is distributed on an "AS IS" BASIS,
12    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13    * See the License for the specific language governing permissions and
14    * limitations under the License.
15    */
16    package org.kuali.student.contract.model.util;
17   
18    import java.util.LinkedHashSet;
19    import java.util.List;
20    import java.util.Set;
21   
22    import org.kuali.student.contract.model.Service;
23    import org.kuali.student.contract.model.ServiceContractModel;
24    import org.kuali.student.contract.model.ServiceMethod;
25    import org.kuali.student.contract.model.ServiceMethodError;
26    import org.kuali.student.contract.model.ServiceMethodParameter;
27    import org.kuali.student.contract.model.XmlType;
28    import org.kuali.student.contract.writer.HtmlWriter;
29   
30    /**
31    *
32    * @author nwright
33    */
 
34    public class HtmlContractServiceWriter {
35   
36    private Service service;
37    private HtmlWriter writer;
38    private ServiceContractModel model;
39    private ModelFinder finder;
40   
 
41  0 toggle public HtmlContractServiceWriter(Service service, String directory,
42    ServiceContractModel model) {
43  0 this.service = service;
44  0 this.writer = new HtmlWriter(directory, service.getName() + ".html",
45    service.getName());
46  0 this.model = model;
47  0 this.finder = new ModelFinder(this.model);
48    }
49   
 
50  0 toggle public void write() {
51  0 writer.print("<a href=\"index.html\">home</a>");
52  0 this.writeStyleSheet();
53  0 writer.writeTag("h1", service.getName());
54   
55  0 writer.indentPrintln("<table id=\"serviceMetaTable\">");
56  0 writer.indentPrintln("<tr>");
57  0 writer.writeTag("th", "class=h", "Name");
58  0 writer.writeTag("td", "id=serviceName colspan=2", service.getKey());
59  0 writer.indentPrintln("</tr>");
60  0 writer.indentPrintln("<tr>");
61  0 writer.writeTag("th", "class=h", "Version");
62  0 writer.writeTag("td", "id=serviceVersion colspan=2", service.getVersion());
63  0 writer.indentPrintln("</tr>");
64  0 writer.indentPrintln("<tr>");
65  0 writer.writeTag("th", "class=h", "Included Services");
66   
67  0 writer.writeTag("td", "id=serviceVersion colspan=2", calcIncludedServices(
68    service.getIncludedServices()));
69  0 writer.indentPrintln("</tr>");
70   
71  0 writer.indentPrintln("</table>");
72   
73    // writer.indentPrintln ("<div class=\"panel\" style=\"border-width: 1px;\">");
74    // writer.indentPrintln ("<div class=\"panelHeader\" style=\"border-bottom-width: 1px;\">");
75  0 writer.indentPrintln("<p>");
76  0 writer.indentPrintln("<table id=\"serviceMetaTable\">");
77  0 writer.indentPrintln("<tr>");
78  0 writer.indentPrintln("<th class=h>");
79  0 writer.indentPrintln(this.addHTMLBreaks(service.getComments()));
80  0 writer.indentPrintln("</th>");
81  0 writer.indentPrintln("</tr>");
82  0 writer.indentPrintln("</table>");
83   
84    // writer.indentPrintln ("</div>");
85    // writer.indentPrintln ("</div>");
86   
87  0 writer.indentPrintln(
88    "<div class=\"panel\" style=\"background-color: rgb(255, 255, 255); border: 1px solid rgb(204, 204, 204);\">");
89  0 writer.indentPrintln(
90    "<div class=\"panelHeader\" style=\"border-bottom: 1px solid rgb(204, 204, 204); background-color: rgb(238, 238, 238);\">");
91  0 writer.indentPrintln("<b><a name=\"ListOfOperations\"></a>Operations</b>");
92  0 writer.indentPrintln(
93    "</div><div class=\"panelContent\" style=\"background-color: rgb(255, 255, 255);\">");
94  0 writer.indentPrintln("<ul>");
95  0 for (ServiceMethod method : finder.getServiceMethodsInService(
96    service.getKey())) {
97  0 writer.indentPrint("<li>");
98  0 writer.print("<a href=\"#" + method.getService() + "-" + method.getName()
99    + "\">" + method.getName() + "</a>");
100  0 writer.print("</li>");
101    }
102  0 writer.indentPrintln("</ul>");
103  0 writer.indentPrintln("</div>");
104  0 writer.indentPrintln("</div>");
105   
106    // now write out the root message structures
107  0 writer.indentPrintln(
108    "<div class=\"panel\" style=\"background-color: rgb(255, 255, 255); border: 1px solid rgb(204, 204, 204);\">");
109  0 writer.indentPrintln(
110    "<div class=\"panelHeader\" style=\"border-bottom: 1px solid rgb(204, 204, 204); background-color: rgb(238, 238, 238);\">");
111  0 writer.indentPrintln(
112    "<b><a name=\"MainMessageStructures\"></a>Main Message Structures</b>");
113  0 writer.indentPrintln(
114    "</div><div class=\"panelContent\" style=\"background-color: rgb(255, 255, 255);\">");
115   
116  0 writer.indentPrintln("<ul>");
117  0 for (XmlType type : this.calcMainMessageStructures()) {
118  0 writer.indentPrint("<li>");
119  0 writer.print("<a href=\"" + type.getName() + ".html"
120    + "\">" + type.getName() + "</a>");
121  0 writer.print("</li>");
122    }
123  0 writer.indentPrintln("</ul>");
124   
125   
126  0 for (ServiceMethod method : finder.getServiceMethodsInService(
127    service.getKey())) {
128  0 this.writeMethod(method);
129    }
130   
131  0 writer.writeHeaderBodyAndFooterOutToFile();
132    }
133   
 
134  0 toggle private String calcIncludedServices(List<String> includedServices) {
135  0 if (includedServices == null) {
136  0 return "&nbsp;";
137    }
138  0 if (includedServices.isEmpty()) {
139  0 return "&nbsp;";
140    }
141  0 StringBuilder bldr = new StringBuilder();
142  0 String comma = "";
143  0 for (String includedService : includedServices) {
144  0 bldr.append(comma);
145  0 comma = ", ";
146  0 bldr.append("<a href=\"" + includedService + ".html"
147    + "\">" + includedService + "</a>");
148    }
149  0 return bldr.toString();
150    }
151   
 
152  0 toggle private Set<XmlType> calcMainMessageStructures() {
153  0 return calcMainMessageStructures(model, service.getKey());
154    }
155   
 
156  0 toggle public static Set<XmlType> calcMainMessageStructures(ServiceContractModel mdl,
157    String serviceOptionaFilter) {
158  0 ModelFinder fndr = new ModelFinder(mdl);
159  0 Set<XmlType> types = new LinkedHashSet();
160  0 for (ServiceMethod method : mdl.getServiceMethods()) {
161  0 if (serviceOptionaFilter != null) {
162  0 if (!method.getService().equalsIgnoreCase(serviceOptionaFilter)) {
163  0 continue;
164    }
165    }
166  0 XmlType type = fndr.findXmlType(stripListFromType(method.getReturnValue().getType()));
167  0 if (type != null) {
168  0 if (type.getPrimitive().equalsIgnoreCase(XmlType.COMPLEX)) {
169  0 types.add(type);
170    }
171    }
172   
173  0 for (ServiceMethodParameter param : method.getParameters()) {
174  0 type = fndr.findXmlType(stripListFromType(param.getType()));
175  0 if (type != null) {
176  0 if (type.getPrimitive().equalsIgnoreCase(XmlType.COMPLEX)) {
177  0 types.add(type);
178    }
179    }
180  0 break;
181    }
182    }
183  0 return types;
184    }
185   
 
186  0 toggle private String addHTMLBreaks(String str) {
187  0 if (str == null) {
188  0 return "&nbsp;";
189    }
190  0 return str.replaceAll("(\r\n|\r|\n|\n\r)", "<br>");
191    }
192   
 
193  0 toggle public void writeMethod(ServiceMethod method) {
194  0 writer.indentPrintln("<p>");
195  0 writer.indentPrintln("<a name=\"" + method.getService() + "-"
196    + method.getName() + "\"></a>");
197  0 writer.indentPrintln("<p>");
198  0 writer.indentPrintln("<table class=\"methodTable\">");
199   
200  0 writer.indentPrintln("<tr>");
201  0 writer.writeTag("th", "class=h", "Method");
202  0 writer.writeTag("th", "class=h colspan=3 class=\"methodName\"",
203    method.getName());
204  0 writer.indentPrintln("</tr>");
205   
206  0 writer.indentPrintln("<tr>");
207  0 writer.writeTag("th", "class=h", "Description");
208  0 writer.writeTag("td", "colspan=3 class=\"methodDesc\"",
209    this.addHTMLBreaks(method.getDescription()));
210  0 writer.indentPrintln("</tr>");
211   
212  0 if (method.getParameters().isEmpty()) {
213  0 writer.indentPrintln("<tr>");
214  0 writer.writeTag("th", "class=h", "Parameters");
215  0 writer.writeTag("td", "class=\"methodParamType\"", "None");
216  0 writer.writeTag("td", "class=\"methodParamName\"", "None");
217  0 writer.writeTag("td", "class=\"methodParamDesc\"", "No Parameters");
218  0 writer.indentPrintln("</tr>");
219    } else {
220  0 boolean firstTime = true;
221  0 for (ServiceMethodParameter param : method.getParameters()) {
222  0 writer.indentPrintln("<tr>");
223  0 if (firstTime) {
224  0 writer.writeTag("th", "class=h rowspan=" + method.getParameters().size(),
225    "Parameters");
226  0 firstTime = false;
227    }
228  0 writer.indentPrint("<td class=\"methodParamType\">");
229  0 writer.indentPrintln("<a href=\"" + stripListFromType(param.getType())
230    + ".html" + "\">"
231    + param.getType() + "</a>");
232  0 writer.indentPrint("</td>");
233  0 writer.writeTag("td", "class=\"methodParamName\"", param.getName());
234  0 writer.writeTag("td", "class=\"methodParamDesc\"", this.addHTMLBreaks(
235    param.getDescription()));
236  0 writer.indentPrintln("</tr>");
237    }
238    }
239  0 writer.indentPrintln("<tr>");
240  0 writer.writeTag("th", "class=h", "Return");
241  0 writer.indentPrint("<td colspan=2 class=\"methodReturnType\">");
242  0 writer.indentPrintln("<a href=\"" + stripListFromType(
243    method.getReturnValue().getType())
244    + ".html" + "\">"
245    + method.getReturnValue().getType() + "</a>");
246  0 writer.indentPrint("</td>");
247  0 writer.writeTag("td", "class=\"methodReturnDesc\"",
248    this.addHTMLBreaks(
249    method.getReturnValue().getDescription()));
250  0 writer.indentPrintln("</tr>");
251  0 writer.indentPrintln("</tr>");
252   
253  0 if (method.getErrors().isEmpty()) {
254  0 writer.indentPrintln("<tr>");
255  0 writer.writeTag("th", "class=h", "Errors");
256  0 writer.writeTag("td", "class=\"methodErrorType\" colspan=2", "NONE");
257  0 writer.writeTag("td", "class=\"methodErrorDesc\"", "No Errors");
258  0 writer.indentPrintln("</tr>");
259    } else {
260  0 boolean firstTime = true;
261  0 for (ServiceMethodError error : method.getErrors()) {
262  0 writer.indentPrintln("<tr>");
263  0 if (firstTime) {
264  0 writer.writeTag("th", "class=h rowspan=" + method.getErrors().size(),
265    "Errors");
266  0 firstTime = false;
267    }
268  0 writer.writeTag("td", "class=\"methodErrorType\" colspan=2",
269    error.getType()); // TODO wrap in link to type
270  0 writer.writeTag("td", "class=\"methodErrorDesc\"", this.addHTMLBreaks(
271    error.getDescription()));
272  0 writer.indentPrintln("</tr>");
273    }
274    }
275  0 writer.indentPrintln("</table>");
276  0 writer.indentPrintln("<p>");
277  0 writer.indentPrintln("<a href=\"#ListOfOperations\">Back to Operations</a>");
278  0 writer.indentPrintln("<p>");
279    }
280   
 
281  0 toggle private static String stripListFromType(String type) {
282  0 if (type.endsWith("List")) {
283  0 return type.substring(0, type.length() - "List".length());
284    }
285  0 return type;
286    }
287   
 
288  0 toggle public void writeStyleSheet() {
289  0 writer.indentPrintln("<style type=\"text/css\">");
290  0 writer.indentPrintln("");
291  0 writer.indentPrintln("table#serviceMetaTable {");
292  0 writer.indentPrintln("border-collapse:collapse;");
293  0 writer.indentPrintln("border:1px solid #000000;");
294  0 writer.indentPrintln("width:95%;");
295  0 writer.indentPrintln("}");
296  0 writer.indentPrintln("table#serviceMetaTable th.h {");
297  0 writer.indentPrintln("border:1px solid #000000;");
298  0 writer.indentPrintln("background-color:#eeeeee;");
299  0 writer.indentPrintln("width:15%;");
300  0 writer.indentPrintln("}");
301  0 writer.indentPrintln("table#serviceMetaTable td#serviceName {");
302  0 writer.indentPrintln("border:1px solid #000000;");
303  0 writer.indentPrintln("width:85%;");
304  0 writer.indentPrintln("}");
305  0 writer.indentPrintln("table#serviceMetaTable td#serviceVersion {");
306  0 writer.indentPrintln("border:1px solid #000000;");
307  0 writer.indentPrintln("width:70%;");
308  0 writer.indentPrintln("}");
309  0 writer.indentPrintln("table#serviceMetaTable td#serviceVersionHistory {");
310  0 writer.indentPrintln("border:1px solid #000000;");
311  0 writer.indentPrintln("width:15%;");
312  0 writer.indentPrintln("}");
313  0 writer.indentPrintln("");
314  0 writer.indentPrintln("</style>");
315   
316   
317  0 writer.indentPrintln("<style type=\"text/css\">");
318  0 writer.indentPrintln("");
319  0 writer.indentPrintln("table.methodTable {");
320  0 writer.indentPrintln("border-collapse:collapse;");
321  0 writer.indentPrintln("border:1px solid #000000;");
322  0 writer.indentPrintln("width:95%;");
323  0 writer.indentPrintln("}");
324  0 writer.indentPrintln("");
325  0 writer.indentPrintln("table.methodTable td.d {");
326  0 writer.indentPrintln("border:1px solid #000000;");
327  0 writer.indentPrintln("}");
328  0 writer.indentPrintln("");
329  0 writer.indentPrintln("table.methodTable th.h {");
330  0 writer.indentPrintln("border:1px solid #000000;");
331  0 writer.indentPrintln("background-color:#eeeeee;");
332  0 writer.indentPrintln("width:15%;");
333  0 writer.indentPrintln("}");
334  0 writer.indentPrintln("");
335  0 writer.indentPrintln("table.methodTable td.methodName {");
336  0 writer.indentPrintln("border:1px solid #000000;");
337  0 writer.indentPrintln("background-color:#f2f2f2;");
338  0 writer.indentPrintln("color:#222222;");
339  0 writer.indentPrintln("text-align:center;");
340  0 writer.indentPrintln("width:85%;");
341  0 writer.indentPrintln("font-weight:bold;");
342  0 writer.indentPrintln("font-style:italic;");
343  0 writer.indentPrintln("}");
344  0 writer.indentPrintln("");
345  0 writer.indentPrintln("table.methodTable td.methodDesc {");
346  0 writer.indentPrintln("border:1px solid #000000;");
347  0 writer.indentPrintln("width:85%;");
348  0 writer.indentPrintln("}");
349  0 writer.indentPrintln("");
350  0 writer.indentPrintln("table.methodTable td.methodParamType {");
351  0 writer.indentPrintln("border:1px solid #000000;");
352  0 writer.indentPrintln("width:21%;");
353  0 writer.indentPrintln("font-style:italic;");
354  0 writer.indentPrintln("}");
355  0 writer.indentPrintln("table.methodTable td.methodParamName {");
356  0 writer.indentPrintln("border:1px solid #000000;");
357  0 writer.indentPrintln("width:21%;");
358  0 writer.indentPrintln("}");
359  0 writer.indentPrintln("table.methodTable td.methodParamDesc {");
360  0 writer.indentPrintln("border:1px solid #000000;");
361  0 writer.indentPrintln("width:43%;");
362  0 writer.indentPrintln("}");
363  0 writer.indentPrintln("table.methodTable td.methodReturnType {");
364  0 writer.indentPrintln("border:1px solid #000000;");
365  0 writer.indentPrintln("width:42%;");
366  0 writer.indentPrintln("font-style:italic;");
367  0 writer.indentPrintln("}");
368  0 writer.indentPrintln("");
369  0 writer.indentPrintln("table.methodTable td.methodReturnDesc {");
370  0 writer.indentPrintln("border:1px solid #000000;");
371  0 writer.indentPrintln("width:43%;");
372  0 writer.indentPrintln("}");
373  0 writer.indentPrintln("");
374  0 writer.indentPrintln("table.methodTable td.methodErrors {");
375  0 writer.indentPrintln("border:1px solid #000000;");
376  0 writer.indentPrintln("width:85%;");
377  0 writer.indentPrintln("}");
378  0 writer.indentPrintln("");
379  0 writer.indentPrintln("");
380  0 writer.indentPrintln("table.methodTable td.methodErrorType {");
381  0 writer.indentPrintln("border:1px solid #000000;");
382  0 writer.indentPrintln("width:42%;");
383  0 writer.indentPrintln("font-style:italic;");
384  0 writer.indentPrintln("}");
385  0 writer.indentPrintln("table.methodTable td.methodErrorDesc {");
386  0 writer.indentPrintln("border:1px solid #000000;");
387  0 writer.indentPrintln("width:43%;");
388  0 writer.indentPrintln("}");
389  0 writer.indentPrintln("");
390  0 writer.indentPrintln("table.methodTable td.capabilityDesc {");
391  0 writer.indentPrintln("border:1px solid #000000;");
392  0 writer.indentPrintln("background:#ffffff;");
393  0 writer.indentPrintln("}");
394  0 writer.indentPrintln("");
395  0 writer.indentPrintln("table.methodTable td.usecaseDesc {");
396  0 writer.indentPrintln("border:1px solid #000000;");
397  0 writer.indentPrintln("background:#ffffff;");
398  0 writer.indentPrintln("}");
399  0 writer.indentPrintln("");
400  0 writer.indentPrintln("table.methodTable td.commentsDesc {");
401  0 writer.indentPrintln("border:1px solid #000000;");
402  0 writer.indentPrintln("background:#ffffff;");
403  0 writer.indentPrintln("}");
404  0 writer.indentPrintln("</style>");
405   
406    }
407    }