1 19 20 package org.netbeans.modules.xml.tools.actions; 21 22 import java.util.ArrayList ; 23 import java.util.Arrays ; 24 import org.netbeans.api.xml.cookies.CookieMessage; 25 import org.netbeans.api.xml.cookies.CookieObserver; 26 import org.netbeans.api.xml.cookies.XMLProcessorDetail; 27 28 32 public class QaIOReporter implements CookieObserver { 33 ArrayList messages = new ArrayList (5); 34 35 36 public QaIOReporter() { 37 } 38 39 44 public void receive(CookieMessage msg) { 45 messages.add(msg); 46 } 47 48 50 protected CookieMessage[] getMessages() { 51 return (CookieMessage[]) messages.toArray(); 52 } 53 54 56 protected String getReport() { 57 int[] lines = getErrLines(); 58 Arrays.sort(lines); 59 StringBuffer buf = new StringBuffer (); 60 if (lines.length > 1) { 61 buf.append("There are errors at lines: "); 62 } else if (lines.length > 0) { 63 buf.append("There is error at line: "); 64 } else { 65 buf.append("There is not errors."); 66 } 67 for (int i = 0; i < lines.length; i++) { 68 buf.append("" + lines[i] + "; "); 69 } 70 return buf.toString(); 71 } 72 73 75 protected int[] getErrLines() { 76 int[] tmp = new int[messages.size()]; 77 int index = 0; 78 for (int i = 0; i < messages.size(); i++) { 79 CookieMessage msg = (CookieMessage) messages.get(i); 80 int level = msg.getLevel(); 81 if (level == msg.ERROR_LEVEL || level == msg.FATAL_ERROR_LEVEL) { 82 Object detail = msg.getDetail(XMLProcessorDetail.class); 83 if (detail instanceof XMLProcessorDetail) { 84 tmp[index] = ((XMLProcessorDetail) detail).getLineNumber(); 85 } else { 86 tmp[index] = -2; } 88 index++; 89 } 90 } 91 int[] lines = new int[index]; 92 System.arraycopy(tmp, 0, lines, 0, lines.length); 93 return lines; 94 } 95 96 98 protected int getBugCount() { 99 return getErrLines().length; 100 } 101 } | Popular Tags |