/* * SearchInforme.java * * Proyecto Fin de Carrera 2002/2003 * GESTION DE INFORMES DE ALTA CON TECNOLOGIA JAVA * Y BASE DE DATOS XML NATIVAS */ package InformeAlta; import java.io.*; import java.util.Vector; import javax.servlet.*; import javax.servlet.http.*; import org.xmldb.api.base.*; import org.xmldb.api.modules.*; import java.net.*; /** * @author Irene Lavado Gomez */ /** * Definimos la clase SearchInforme para hacer búsquedas en la base de * datos usando Xpath */ public class SearchInforme extends Action { public boolean attributeSearch(HttpServletRequest request, HttpServletResponse response ) throws ServletException, IOException { Collection col = null; Vector vector = null; String xpath = null; try { HttpSession session = request.getSession(true); // Get a collection instance col = getCollection(request,response); XPathQueryService service = (XPathQueryService)col.getService("XPathQueryService",XMLDBAPIVERSION); // Get the seach parameters from the form String searchtype = request.getParameter("SEARCHTYPE"); String searchstring = request.getParameter("SEARCHSTRING"); // Setup xpath string depending on search type if ( searchtype.equals("ValorId") ) { xpath = "/informe/DatosDemograficosPaciente/IdPaciente[" + searchtype + "='" + searchstring + "']"; } else if ( searchtype.equals("Nombre") || searchtype.equals("PrimerApellido") || searchtype.equals("SegundoApellido")) { xpath = "/informe/DatosDemograficosPaciente/NombrePaciente/NombreEstructurado[" + searchtype + "='" + searchstring + "']"; } else if ( searchtype.equals("FechaAdmision")) { xpath = "/informe/AdministracionAltaPaciente/DatosAdmision[" + searchtype + "='" + searchstring + "']"; } ResourceSet resultSet = service.query(xpath); ResourceIterator results = resultSet.getIterator(); Group group = (Group)session.getAttribute("group"); // Limpia el objeto group... group.removeAll(); // Añade los resultados de la búsqueda Xpath a la instancia Group group.addResults(results); } catch(Exception e) { e.printStackTrace(); // there's not much else we can do if the response is committed if (response.isCommitted()) return true; // Catch the exception and send the user to the error page if (e.getMessage() != null ) { response.sendRedirect("/InformeAlta/error.jsp?error=" + URLEncoder.encode(e.getMessage()) ); } else { response.sendRedirect("/InformeAlta/error.jsp" ); } } return true; } public boolean xpathSearch(HttpServletRequest request, HttpServletResponse response ) throws ServletException, IOException { Collection col = null; Vector vector = null; String xpath = null; try { HttpSession session = request.getSession(true); // Get a collection instance col = getCollection(request,response); XPathQueryService service = (XPathQueryService)col.getService("XPathQueryService",XMLDBAPIVERSION); // Get the seach parameters from the form String searchstring = request.getParameter("SEARCHSTRING"); ResourceSet resultSet = service.query(searchstring); ResourceIterator results = resultSet.getIterator(); Group group = (Group)session.getAttribute("group"); // Clear out group object... group.removeAll(); // Add results to Group instance group.addResults(results); } catch(Exception e) { e.printStackTrace(); // there's not much else we can do if the response is committed if (response.isCommitted()) return true; // Catch the exception and send the user to the error page if (e.getMessage() != null ) { response.sendRedirect("/InformeAlta/error.jsp?error=" + URLEncoder.encode(e.getMessage()) ); } else { response.sendRedirect("/InformeAlta/error.jsp" ); } } return true; } }