KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > exceptions > ShowServlet


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 /*
20  * ShowServlet.java
21  *
22  * Created on November 16, 2006, 6:27 PM
23  */

24
25 package org.netbeans.modules.exceptions;
26
27 import java.io.IOException JavaDoc;
28 import java.io.PrintWriter JavaDoc;
29 import java.sql.ResultSet JavaDoc;
30 import java.sql.SQLException JavaDoc;
31 import java.sql.Statement JavaDoc;
32 import javax.servlet.ServletException JavaDoc;
33 import javax.servlet.http.HttpServlet JavaDoc;
34 import javax.servlet.http.HttpServletRequest JavaDoc;
35 import javax.servlet.http.HttpServletResponse JavaDoc;
36 import static org.netbeans.modules.exceptions.Utils.*;
37 /**
38  *
39  * @author jindra
40  * @version
41  */

42 public class ShowServlet extends HttpServlet JavaDoc {
43     private PrintWriter JavaDoc out;
44     private String JavaDoc param;
45     
46     /** Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
47      * @param request servlet request
48      * @param response servlet response
49      */

50     protected void processRequest(HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
51     throws ServletException JavaDoc, IOException JavaDoc {
52         out = response.getWriter();
53         ResultSet JavaDoc result = null;
54         param = request.getParameter("param");
55         try {
56             response.setContentType("text/html;charset=UTF-8");
57             Class.forName("org.apache.derby.jdbc.ClientDriver");
58             Statement JavaDoc stmt = Utils.getConnection().createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
59             stmt.setEscapeProcessing(false);
60             result = Utils.executeQuery(stmt, "SELECT * FROM "+param);
61             out.println("<table border=\"1\"><thead>");
62             if (param.equals(PARAM_SHOW_LINE)) {
63                 out.println("<td>StackTrace ID</td>");
64                 out.println("<td>Method Id</td>");
65                 out.println("<td>File Id</td>");
66                 out.println("<td>Line Number</td>");
67                 out.println("<td>Line Order</td></thead>");
68                 printTab(result, 5);
69             } else if (param.equals(PARAM_SHOW_COMMENT)) {
70                 out.println("<td>Comment ID</td>");
71                 out.println("<td>Issue Id</td>");
72                 out.println("<td>NbUser Id</td>");
73                 out.println("<td>Comment</td></thead>");
74                 printTab(result, 4);
75             } else if (param.equals(PARAM_SHOW_ISSUENBUSER)) {
76                 out.println("<td>Issue Id</td>");
77                 out.println("<td>User Id</td>");
78                 out.println("<td>Date + Time</td></thead>");
79                 printTab(result, 3);
80             } else if (param.equals(PARAM_SHOW_ISSUE)) {
81                 out.println("<td>Issue Id</td>");
82                 out.println("<td>Summary</td>");
83                 out.println("<td>Logger name</td>");
84                 out.println("<td>VM</td>");
85                 out.println("<td>Product version</td>");
86                 out.println("<td>Component</td>");
87                 out.println("<td>SubComponent</td>");
88                 out.println("<td>AssignTo</td>");
89                 out.println("<td>Operating system</td>");
90                 out.println("<td>Severity</td>");
91                 out.println("<td>Link</td></thead>");
92                 printTab(result, 10);
93             } else if (param.equals(PARAM_SHOW_STACKTRACE)) {
94                 out.println("<td>StackTrace ID</td>");
95                 out.println("<td>Message</td>");
96                 out.println("<td>Class name</td>");
97                 out.println("<td>Annotation</td></thead>");
98                 printTab(result, 4);
99             } else if (param.equals(PARAM_SHOW_METHOD)){
100                 out.println("<td>Method ID</td>");
101                 out.println("<td>Method name</td></thead>");
102                 printTab(result, 2);
103             } else if (param.equals(PARAM_SHOW_NBFILES)){
104                 out.println("<td>File ID</td>");
105                 out.println("<td>File name</td></thead>");
106                 printTab(result, 2);
107             } else if (param.equals(PARAM_SHOW_NBUSER)) {
108                 out.println("<td>User ID</td>");
109                 out.println("<td>User name</td></thead>");
110                 printTab(result, 2);
111             } else if (param.equals(PARAM_SHOW_LOGGER)) {
112                 out.println("<td>Log ID</td>");
113                 out.println("<td>Log content</td></thead>");
114                 printTab(result, 1);
115             } else {
116                 out.println("ILLEGAL ARGUMENT");
117             }
118             out.println("</table>");
119             stmt.close();
120         } catch (SQLException JavaDoc ex) {
121             java.util.logging.Logger.getLogger(ShowServlet.class.getName()).log(java.util.logging.Level.SEVERE,
122                     ex.getMessage(), ex);
123         } catch (ClassNotFoundException JavaDoc ex) {
124             java.util.logging.Logger.getLogger(ShowServlet.class.getName()).log(java.util.logging.Level.SEVERE,
125                     ex.getMessage(), ex);
126         };
127         
128     }
129     
130     public void printTab(ResultSet JavaDoc result, int columnsCount) throws SQLException JavaDoc, IOException JavaDoc, ClassNotFoundException JavaDoc{
131         String JavaDoc str;
132         int j;
133         while (result.next()){
134             out.write("<tr>");
135             for (j=1;j<=columnsCount;j++){
136                 out.write("<td>");
137                 str = result.getString(j);
138                 if (str == null) str = "null";
139                 out.write(str);
140                 out.write("</td>\n");
141             }
142             if (param.equals(PARAM_SHOW_ISSUE)){
143                 out.write("<td>");
144                 out.write("<a HREF=Select.jsp?"+SelectIssue.ID_PARAM+"="+result.getString(1)+">show</a>");
145                 out.write("</td>\n");
146             }
147             if (param.equals(PARAM_SHOW_LOGGER)){
148                 String JavaDoc loggerText= Utils.getHTMLLog(result);
149                 out.write("<td>"+loggerText+"</td>");
150             }
151             out.write("</tr>\n");
152         }
153         
154     }
155     
156     // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
157
/** Handles the HTTP <code>GET</code> method.
158      * @param request servlet request
159      * @param response servlet response
160      */

161     protected void doGet(HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
162     throws ServletException JavaDoc, IOException JavaDoc {
163         processRequest(request, response);
164     }
165     
166     /** Handles the HTTP <code>POST</code> method.
167      * @param request servlet request
168      * @param response servlet response
169      */

170     protected void doPost(HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
171     throws ServletException JavaDoc, IOException JavaDoc {
172         processRequest(request, response);
173     }
174     
175     /** Returns a short description of the servlet.
176      */

177     public String JavaDoc getServletInfo() {
178         return "Short description";
179     }
180     // </editor-fold>
181
}
182
Popular Tags