1 19 package org.netbeans.modules.exceptions.web; 20 21 import java.io.IOException ; 22 import java.util.ArrayList ; 23 import java.util.Collections ; 24 import java.util.List ; 25 import java.util.regex.Pattern ; 26 import javax.servlet.jsp.tagext.*; 27 import javax.servlet.jsp.JspWriter ; 28 import javax.servlet.jsp.JspException ; 29 import org.netbeans.modules.exceptions.entity.Issue; 30 import org.netbeans.modules.exceptions.entity.Line; 31 import org.netbeans.modules.exceptions.entity.Stacktrace; 32 33 38 39 public class StacktraceTagHandler extends SimpleTagSupport { 40 41 45 private Issue issue; 46 47 51 public void doTag() throws JspException { 52 53 JspWriter out=getJspContext().getOut(); 54 55 try { 56 Stacktrace stacktrace = issue.getStacktrace(); 57 out.println(); 58 while (stacktrace != null) { 59 out.println(stacktrace.getMessage()); 60 List <Line> lines = new ArrayList (stacktrace.getLineCollection()); 61 Collections.sort(lines, new LineComparator()); 62 for(Line line : lines) { 63 formatLine(out, line); 64 } 65 stacktrace = stacktrace.getAnnotation(); 66 } 67 JspFragment f=getJspBody(); 68 if (f != null) f.invoke(out); 69 70 } catch (java.io.IOException ex) { 71 throw new JspException (ex.getMessage()); 72 } 73 74 } 75 76 public void setIssue(Issue issue) { 77 this.issue = issue; 78 } 79 80 private void formatLine(JspWriter out, Line line) throws IOException { 81 String methodName = line.getMethod().getName(); 82 Pattern pat = Pattern.compile("\\."); 83 String [] items = pat.split(methodName); 84 int i = items.length-2; 85 if (i<0) i=0; 86 StringBuffer fileName = new StringBuffer (); 87 int s = items[i].indexOf("$"); 88 if (s >= 0) { 89 fileName.append(items[i].substring(0, s)); 90 } else { 91 fileName.append(items[i]); 92 } 93 fileName.append(".java"); 94 out.print(" at " + methodName); 95 out.println("(" + fileName + ":" + line.getLinePK().getLinenumber() + ")"); 96 } 97 } 98 | Popular Tags |