1 package okw.log.log2html;
5 import org.apache.commons.text.StringEscapeUtils;
9 protected static Integer AllCount = 0;
11 protected Integer myID = 0;
13 protected String Info =
"";
18 protected LogBase myParent =
null;
20 protected List<LogBase> myLogs=
new ArrayList<LogBase>();
22 public void setParent(
LogBase fpParent )
27 protected void abort()
39 protected int Level = -1;
40 protected String myIndentionBase =
" ";
42 protected int getLevel()
52 if (this.getParent() !=
null )
54 this.Level = this.getParent().getLevel() + 1;
55 myReturn = this.Level;
67 protected String getLevelIndention()
69 StringBuilder myIndention =
new StringBuilder();
71 int n = this.getLevel();
74 for ( i=1; i<=n; i++ )
76 myIndention.append(myIndentionBase);
79 return myIndention.toString();
83 protected String getLevelIndention(
int shift )
85 StringBuilder myIndention =
new StringBuilder();
87 int n = this.getLevel() + shift;
90 for ( i=1; i<=n; i++ )
92 myIndention.append(myIndentionBase);
95 return myIndention.toString();
98 protected String jsonElement( String Key, String Value)
100 return "\"" + Key +
"\": \"" + Value +
"\"";
103 protected String jsonElementComma( String Key, String Value)
105 return "\"" + Key +
"\": \"" + Value +
"\",";
108 protected String jsonElementComma( String Key, Integer Value )
110 return "\"" + Key +
"\": \"" + Value.toString() +
"\",";
114 protected String jsonElement( String Key, Integer Value )
116 return "\"" + Key +
"\": \"" +
"\"";
119 protected String jsonStructure( String Key, String Value )
121 return "\"" + Key +
"\": {" + Value +
" }";
124 protected String jsonStructureComma( String Key, String Value )
126 return "\"" + Key +
"\": {" + Value +
" },";
129 protected String jsonArray( String Key, String Value )
131 StringBuilder myIndention =
new StringBuilder();
133 myIndention.append(
"\"" + Key +
"\": [" );
134 myIndention.append( Value );
135 myIndention.append(
"]" );
137 return myIndention.toString();
140 protected String jsonArrayElement( String Value )
142 StringBuilder myIndention =
new StringBuilder();
144 myIndention.append(
"{" );
145 myIndention.append( Value );
146 myIndention.append(
"}" );
148 return myIndention.toString();
151 protected String jsonArrayElementComma( String Value )
153 StringBuilder myIndention =
new StringBuilder();
155 myIndention.append(
"{" );
156 myIndention.append( Value );
157 myIndention.append(
"}," );
159 return myIndention.toString();
162 protected Boolean bWarning =
false;
164 protected void setWarning()
171 if (myParent !=
null)
173 myParent.setWarning();
178 protected Boolean getWarning()
184 protected Boolean bException =
false;
186 protected void setException()
193 if (myParent !=
null)
195 myParent.setException();
201 protected Boolean bError =
false;
203 protected void setError()
210 if (myParent !=
null)
217 protected Boolean getError()
223 protected abstract void ErrorCount();
225 protected abstract void ExceptionCount();
227 protected abstract void WarningCount();
229 protected abstract void PassedCount();
231 protected abstract void PrintCount();
233 protected abstract void TestcaseCount();
235 protected abstract void TestcaseFail();
237 protected abstract void TestcasePass();
239 protected abstract void FunctionCount();
241 protected abstract void FunctionFail();
243 protected abstract void FunctionPass();
245 protected abstract void KeyWordCount();
247 protected abstract void KeyWordFail();
249 protected abstract void KeyWordPass();
251 protected abstract void SequenceCount();
253 protected abstract void SequenceFail();
255 protected abstract void SequencePass();
257 protected abstract void StepCount();
259 protected abstract void StepFail();
261 protected abstract void StepPass();
264 protected abstract void LocalACCallCount();
266 protected abstract void LocalACCallFail();
268 protected abstract void LocalACCallPass();
271 protected abstract void RemoteACCallCount();
273 protected abstract void RemoteACCallFail();
275 protected abstract void RemoteACCallPass();
277 protected String getHTMLResult()
279 StringBuilder sbResult =
new StringBuilder();
281 String lvsIndention = this.getLevelIndention();
285 sbResult.append( lvsIndention +
"<div class='" + this.getClass().getSimpleName() +
"'>\n" );
286 sbResult.append( lvsIndention + myIndentionBase +
"<div class='Header'>\n" );
288 if (!this.myLogs.isEmpty())
290 sbResult.append( lvsIndention + myIndentionBase + myIndentionBase +
"<div class='FoldMe' onClick='div_change(" + myID.toString() +
")'></div>\n" );
293 sbResult.append( lvsIndention + myIndentionBase + myIndentionBase +
"<div class='Duration'>" + this.myDuration.getSeconds(
"#0.000") +
" s</div>" );
298 sbResult.append( lvsIndention + myIndentionBase + myIndentionBase +
"<div class='ExceptionSign' title='Exception...'></div>\n" );
304 sbResult.append( lvsIndention + myIndentionBase + myIndentionBase +
"<div class='ErrorSign' title='Error...'></div>\n" );
309 sbResult.append( lvsIndention + myIndentionBase + myIndentionBase +
"<div class='WarningSign' title='Warning...'></div>\n" );
312 if (this.bException || this.bError )
314 sbResult.append( lvsIndention + myIndentionBase + myIndentionBase +
"<div class='Info_Fail'>" + StringEscapeUtils.escapeHtml4(
this.Info ) +
"</div>\n" );
318 sbResult.append( lvsIndention + myIndentionBase + myIndentionBase +
"<div class='SuccessSign' title='Success...'></div>\n" );
319 sbResult.append( lvsIndention + myIndentionBase + myIndentionBase +
"<div class='Info_Pass'>" + StringEscapeUtils.escapeHtml4(
this.Info ) +
"</div>\n" );
322 sbResult.append( lvsIndention + myIndentionBase + myIndentionBase +
"</div>\n" );
325 sbResult.append( lvsIndention + myIndentionBase + myIndentionBase +
"<div class='Body' id='" + myID.toString() +
"' style='display: none;'>\n" );
327 for(
LogBase myLog: this.myLogs )
329 sbResult.append( myLog.getHTMLResult() );
332 sbResult.append( lvsIndention + myIndentionBase + myIndentionBase +
"</div>\n" );
334 sbResult.append( lvsIndention + myIndentionBase + myIndentionBase +
"</div>\n" );
337 return sbResult.toString();
341 protected String getJSONResult()
344 StringBuilder myJSON =
new StringBuilder();
347 if (
"false".equals( okw.OKW_Properties.getInstance().getProperty(
"Log2HTML.Test",
"false" ) ) )
349 myJSON.append( this.jsonElement(
"duration", this.myDuration.getSeconds(
"#0.000") ) );
353 myJSON.append( this.jsonElement(
"duration",
"Duration TestMode" ) );
357 for(
LogBase myLog: this.myLogs )
360 String Element = myLog.getClass().getSimpleName();
361 myJSON.append( this.jsonStructure( Element + EC.toString(), myLog.getJSONResult() ) );
364 return myJSON.toString();