package busquedaDescripcionesServlet;

import java.io.PrintWriter;
import java.util.ArrayList;

import m05bClasses.m05bFileLog;
import test.m05bAnalizaTexto;


/**
 * Inserte aquí la descripción del tipo.
 * Fecha de creación: (20/11/03)
 */
public class m05bBuscaDescripServlet extends javax.servlet.http.HttpServlet {m05bFileLog miLog = new m05bFileLog();
/**
 * Process incoming HTTP GET requests 
 * 
 * @param request Object that encapsulates the request to the servlet 
 * @param response Object that encapsulates the response from the servlet
 */
public void doPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, java.io.IOException {

	performTask(request, response);

}

/**
 * Process incoming HTTP GET requests 
 * 
 * @param request Object that encapsulates the request to the servlet 
 * @param response Object that encapsulates the response from the servlet
 */
public void doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, java.io.IOException {

	performTask(request, response);

}
/**
 * Returns the servlet info string.
 */
public String getServletInfo() {

	return super.getServletInfo();

}
/**
 * Initializes the servlet.
 */
public void init() {
	// insert code to initialize the servlet here

}
/**
 * Process incoming requests for information
 * 
 * @param request Object that encapsulates the request to the servlet 
 * @param response Object that encapsulates the response from the servlet
 */
public void performTask(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) {
	response.setHeader("Cache-Control", "no-cache");
	response.setHeader("Expires", "-1");
	response.setContentType("text/xml");
	String resultado = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
	PrintWriter wr = null;
	try {
    	wr = (PrintWriter)response.getWriter();
    	String tabla = request.getParameter("tabla")==null?"":request.getParameter("tabla");
		String campo = request.getParameter("campo")==null?"":request.getParameter("campo");
		String where = request.getParameter("where")==null?"":request.getParameter("where");
		
		String cadena = request.getParameter("cadena")==null?"":request.getParameter("cadena");
		m05bAnalizaTexto instancia = new m05bAnalizaTexto();
		ArrayList lista = (ArrayList)instancia.buscar(tabla,campo,where,cadena);
		resultado+= "<descripciones>";
		if(cadena==null
				||cadena.equals("")
				||cadena.length()<4){
			resultado+="&nbsp;";
		}else{
			for (int i=0;i<lista.size();i++){
				String desc = (String)lista.get(i);
				resultado+= "<descripcion>"+((desc==null||desc.equals(""))?"&nbsp;":desc)+"</descripcion>";
			}
		}
		resultado+= "</descripciones>";
        wr.println(resultado);
    } catch (Exception e) {
    	wr.println("ERROR-"+e.getMessage());
    }
}
}
