OpenKeyWord  Build_ID: 457, Datum: 01.02.2020 07:45:48
Dont repeat yourself. - Do it once and only once!
LogBase.java
1 package okw.log.log2html;
2 
3 import java.util.*;
4 
5 import org.apache.commons.text.StringEscapeUtils;
6 
7 public abstract class LogBase {
8 
9  protected static Integer AllCount = 0;
10 
11  protected Integer myID = 0;
12 
13  protected String Info = "";
14 
15  protected LogTimer myDuration = new LogTimer();
16 
17  // Ein Parent ist immer ein Knoten!
18  protected LogBase myParent = null;
19 
20  protected List<LogBase> myLogs= new ArrayList<LogBase>();
21 
22  public void setParent( LogBase fpParent )
23  {
24  myParent = fpParent;
25  }
26 
27  protected void abort()
28  {
29  setError();
30  }
31 
32 
33  public LogBase getParent()
34  {
35  return myParent;
36  }
37 
38 
39  protected int Level = -1;
40  protected String myIndentionBase = " ";
41 
42  protected int getLevel()
43  {
44  int myReturn;
45 
46  if (Level >= 0)
47  {
48  myReturn = Level;
49  }
50  else
51  {
52  if (this.getParent() != null )
53  {
54  this.Level = this.getParent().getLevel() + 1;
55  myReturn = this.Level;
56  }
57  else
58  {
59  myReturn = 0;
60  }
61  }
62 
63  return myReturn;
64  }
65 
66 
67  protected String getLevelIndention()
68  {
69  StringBuilder myIndention = new StringBuilder();
70 
71  int n = this.getLevel();
72  int i;
73 
74  for ( i=1; i<=n; i++ )
75  {
76  myIndention.append(myIndentionBase);
77  }
78 
79  return myIndention.toString();
80  }
81 
82 
83  protected String getLevelIndention( int shift )
84  {
85  StringBuilder myIndention = new StringBuilder();
86 
87  int n = this.getLevel() + shift;
88  int i;
89 
90  for ( i=1; i<=n; i++ )
91  {
92  myIndention.append(myIndentionBase);
93  }
94 
95  return myIndention.toString();
96  }
97 
98  protected String jsonElement( String Key, String Value)
99  {
100  return "\"" + Key + "\": \"" + Value + "\"";
101  }
102 
103  protected String jsonElementComma( String Key, String Value)
104  {
105  return "\"" + Key + "\": \"" + Value + "\",";
106  }
107 
108  protected String jsonElementComma( String Key, Integer Value )
109  {
110  return "\"" + Key + "\": \"" + Value.toString() + "\",";
111  }
112 
113 
114  protected String jsonElement( String Key, Integer Value )
115  {
116  return "\"" + Key + "\": \"" + "\"";
117  }
118 
119  protected String jsonStructure( String Key, String Value )
120  {
121  return "\"" + Key + "\": {" + Value + " }";
122  }
123 
124  protected String jsonStructureComma( String Key, String Value )
125  {
126  return "\"" + Key + "\": {" + Value + " },";
127  }
128 
129  protected String jsonArray( String Key, String Value )
130  {
131  StringBuilder myIndention = new StringBuilder();
132 
133  myIndention.append( "\"" + Key + "\": [" );
134  myIndention.append( Value );
135  myIndention.append( "]" );
136 
137  return myIndention.toString();
138  }
139 
140  protected String jsonArrayElement( String Value )
141  {
142  StringBuilder myIndention = new StringBuilder();
143 
144  myIndention.append( "{" );
145  myIndention.append( Value );
146  myIndention.append( "}" );
147 
148  return myIndention.toString();
149  }
150 
151  protected String jsonArrayElementComma( String Value )
152  {
153  StringBuilder myIndention = new StringBuilder();
154 
155  myIndention.append( "{" );
156  myIndention.append( Value );
157  myIndention.append( "}," );
158 
159  return myIndention.toString();
160  }
161 
162  protected Boolean bWarning = false;
163 
164  protected void setWarning()
165  {
166  if (!bWarning)
167  {
168  bWarning = true;
169 
170 
171  if (myParent != null)
172  {
173  myParent.setWarning();
174  }
175  }
176  }
177 
178  protected Boolean getWarning()
179  {
180  return bWarning;
181  }
182 
183 
184  protected Boolean bException = false;
185 
186  protected void setException()
187  {
188  if (!bException)
189  {
190  //SetFail();
191  bException = true;
192 
193  if (myParent != null)
194  {
195  myParent.setException();
196  }
197  }
198  }
199 
200 
201  protected Boolean bError = false;
202 
203  protected void setError()
204  {
205  if (!bError)
206  {
207  // SetFail();
208  bError = true;
209 
210  if (myParent != null)
211  {
212  myParent.setError();
213  }
214  }
215  }
216 
217  protected Boolean getError()
218  {
219  return bError;
220  }
221 
222  // Node Statistics
223  protected abstract void ErrorCount();
224 
225  protected abstract void ExceptionCount();
226 
227  protected abstract void WarningCount();
228 
229  protected abstract void PassedCount();
230 
231  protected abstract void PrintCount();
232 
233  protected abstract void TestcaseCount();
234 
235  protected abstract void TestcaseFail();
236 
237  protected abstract void TestcasePass();
238 
239  protected abstract void FunctionCount();
240 
241  protected abstract void FunctionFail();
242 
243  protected abstract void FunctionPass();
244 
245  protected abstract void KeyWordCount();
246 
247  protected abstract void KeyWordFail();
248 
249  protected abstract void KeyWordPass();
250 
251  protected abstract void SequenceCount();
252 
253  protected abstract void SequenceFail();
254 
255  protected abstract void SequencePass();
256 
257  protected abstract void StepCount();
258 
259  protected abstract void StepFail();
260 
261  protected abstract void StepPass();
262 
263  // Precondition
264  protected abstract void LocalACCallCount();
265 
266  protected abstract void LocalACCallFail();
267 
268  protected abstract void LocalACCallPass();
269 
270  // Postcondition
271  protected abstract void RemoteACCallCount();
272 
273  protected abstract void RemoteACCallFail();
274 
275  protected abstract void RemoteACCallPass();
276 
277  protected String getHTMLResult()
278  {
279  StringBuilder sbResult = new StringBuilder();
280 
281  String lvsIndention = this.getLevelIndention();
282 
283  //sbResult.append( lvsIndention + "<blockquote class='" + this.getClass().getSimpleName() + "'>\n" );
284 
285  sbResult.append( lvsIndention + "<div class='" + this.getClass().getSimpleName() + "'>\n" );
286  sbResult.append( lvsIndention + myIndentionBase +"<div class='Header'>\n" );
287 
288  if (!this.myLogs.isEmpty())
289  {
290  sbResult.append( lvsIndention + myIndentionBase + myIndentionBase + "<div class='FoldMe' onClick='div_change(" + myID.toString() + ")'></div>\n" );
291  }
292 
293  sbResult.append( lvsIndention + myIndentionBase + myIndentionBase + "<div class='Duration'>" + this.myDuration.getSeconds("#0.000") + " s</div>" );
294 
295  // Exception-icon einfügen wenn bException = true
296  if (this.bException)
297  {
298  sbResult.append( lvsIndention + myIndentionBase + myIndentionBase + "<div class='ExceptionSign' title='Exception...'></div>\n" );
299  }
300 
301  // Error-icon einfügen wenn bError = true
302  if (this.bError)
303  {
304  sbResult.append( lvsIndention + myIndentionBase + myIndentionBase + "<div class='ErrorSign' title='Error...'></div>\n" );
305  }
306 
307  if (this.bWarning)
308  {
309  sbResult.append( lvsIndention + myIndentionBase + myIndentionBase + "<div class='WarningSign' title='Warning...'></div>\n" );
310  }
311 
312  if (this.bException || this.bError )
313  {
314  sbResult.append( lvsIndention + myIndentionBase + myIndentionBase + "<div class='Info_Fail'>" + StringEscapeUtils.escapeHtml4( this.Info ) + "</div>\n" );
315  }
316  else
317  {
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" );
320  }
321 
322  sbResult.append( lvsIndention + myIndentionBase + myIndentionBase + "</div>\n" ); // end Header
323 
324 
325  sbResult.append( lvsIndention + myIndentionBase + myIndentionBase +"<div class='Body' id='" + myID.toString() +"' style='display: none;'>\n" );
326 
327  for( LogBase myLog: this.myLogs )
328  {
329  sbResult.append( myLog.getHTMLResult() );
330  }
331 
332  sbResult.append( lvsIndention + myIndentionBase + myIndentionBase + "</div>\n" ); // end Body
333 
334  sbResult.append( lvsIndention + myIndentionBase + myIndentionBase + "</div>\n" ); // end Rahmen
335  //sbResult.append( lvsIndention + "</blockquote>\n");
336 
337  return sbResult.toString();
338  }
339 
340 
341  protected String getJSONResult()
342  {
343 
344  StringBuilder myJSON = new StringBuilder();
345 
346  // Duration
347  if ( "false".equals( okw.OKW_Properties.getInstance().getProperty( "Log2HTML.Test", "false" ) ) )
348  {
349  myJSON.append( this.jsonElement( "duration", this.myDuration.getSeconds("#0.000") ) );
350  }
351  else
352  {
353  myJSON.append( this.jsonElement( "duration", "Duration TestMode" ) );
354  }
355  Integer EC = 0;
356 
357  for( LogBase myLog: this.myLogs )
358  {
359  EC++;
360  String Element = myLog.getClass().getSimpleName();
361  myJSON.append( this.jsonStructure( Element + EC.toString(), myLog.getJSONResult() ) );
362  }
363 
364  return myJSON.toString();
365  }
366 }
okw.log.log2html.LogBase
Definition: LogBase.java:7
okw.log.log2html.LogTimer
Definition: LogTimer.java:11