1 19 package org.netbeans.modules.exceptions.web; 20 21 import java.io.*; 22 import java.net.*; 23 import java.util.Iterator ; 24 import java.util.List ; 25 import java.util.Vector ; 26 import javax.persistence.EntityManagerFactory; 27 import javax.persistence.Persistence; 28 import javax.persistence.Query; 29 import javax.servlet.*; 30 import javax.servlet.http.*; 31 32 37 public class Subcomponents extends HttpServlet { 38 39 43 EntityManagerFactory emf = Persistence.createEntityManagerFactory("StrutsExceptionsPU"); 44 45 49 protected void processRequest(HttpServletRequest request, HttpServletResponse response) 50 throws ServletException, IOException { 51 response.setContentType("text/plain;charset=UTF-8"); 52 PrintWriter out = response.getWriter(); 53 String component = request.getParameter("component"); 54 List sc = getSubcomponents(component); 55 if (sc != null) { 56 for(Iterator <Vector > it = sc.iterator(); it.hasNext(); ) { 57 Vector v = it.next(); 58 out.print(v.elementAt(0)); 59 if (it.hasNext()) out.print(","); 60 } 61 } 62 out.close(); 63 } 64 65 70 protected void doGet(HttpServletRequest request, HttpServletResponse response) 71 throws ServletException, IOException { 72 processRequest(request, response); 73 } 74 75 79 protected void doPost(HttpServletRequest request, HttpServletResponse response) 80 throws ServletException, IOException { 81 processRequest(request, response); 82 83 84 } 85 86 88 public String getServletInfo() { 89 return "Short description"; 90 } 91 92 public List getSubcomponents(String component) { 93 javax.persistence.EntityManager em = emf.createEntityManager(); 94 try { 95 Query q = em.createNativeQuery("SELECT DISTINCT i.subcomponent FROM Issue i WHERE i.component=#component"); 99 q.setParameter("component", component); 100 return q.getResultList(); 101 } 102 catch (Exception e) { 103 java.util.logging.Logger.getLogger(getClass().getName()).log(java.util.logging.Level.SEVERE, 104 "exception caught", 105 e); 106 } 108 finally { 109 em.close(); 110 } 111 return null; 112 } 113 } 115 | Popular Tags |