package asignacionServlet;

import java.io.BufferedOutputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import m05bClasses.m05bCamposInformes;
import m05bClasses.m05bComun;
import m05bClasses.m05bConexion;
import m05bClasses.m05bConstantes;
import m05bClasses.m05bConstantesInformes;
import m05bClasses.m05bFileLog;

import org.apache.fop.apps.Driver;
import org.xml.sax.InputSource;


public class m05bImpDecretoServlet extends javax.servlet.http.HttpServlet
{
   java.sql.Connection conn=null;
   m05bFileLog miLog = new m05bFileLog();
   public static final String FO_REQUEST_PARAM = "fo";
//    Logger log = null;

   public void doPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, java.io.IOException
   {
 	   try{
		      doGet(request, response);
		    }catch (Exception e){
		      miLog.addTraza(e);
		    }
   }

   public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException
   {
      performTask(request, response);
   }
//        if(log == null)
//        {
//            Hierarchy hierarchy = Hierarchy.getDefaultHierarchy();
//            log = hierarchy.getLoggerFor("fop");
//            log.setPriority(Priority.WARN);
//        }

   public void performTask(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws ServletException
   {
   	try
   	   {
	    java.sql.Connection conn=null;
	    PreparedStatement pstmt = null;
	    ResultSet rs = null;
   	   
      try
      {  
      	 HttpSession session = request.getSession(true);
         m05bConexion miConex = new m05bConexion();
		 conn = miConex.getConnection();
	     conn.setAutoCommit(false);  // Al final si todo ha ido bien se hace commit
         m05bComun miComun = new m05bComun();
         
	     //Obtención codigo asignacion
		 String asignacion = request.getParameter("NSolicitud");
	        
	     String sSentenciaUpdate= " UPDATE "+
	     	    m05bConstantes.TAB_ASIGNACION+
	     	    " SET "+ m05bConstantes.COL_01_DECRETO+"='S',"+ m05bConstantes.COL_01_FDECRETO+
                " = TO_DATE(TO_CHAR(SYSDATE,'dd/mm/yyyy'),'dd/mm/yyyy')"+	     	 
                " WHERE " + 
                m05bConstantes.COL_01_CODASIG+"='"+asignacion+"' AND "+
                m05bConstantes.COL_01_DECRETO+"='N'";
	     System.out.println(sSentenciaUpdate);
      	 // Obtención de información de BD
      	 	 	// Vehículo
      	 String matricula=request.getParameter("Matricula");
      	 m05bCamposInformes miVehiculo = new m05bCamposInformes();
      	 String vehiculo[] = miVehiculo.getDatosVehiculo(matricula);
      	 String tarjeta = miVehiculo.getTarjeta(matricula);
      	 
      	 if(tarjeta==null)
      		tarjeta="";    
      	 String viaT = miVehiculo.getViaT(matricula);
      	 if(viaT==null)
      		viaT="";      	 
      	
      	 	 	// Titular
      	 String cargo = (String) session.getAttribute("PDFCargo");  // Se pone en la sesion en JSP Asignaciones
      	 String ecargo = miVehiculo.getCargoEusk((String) session.getAttribute("PDFCodCargo"));   // Se pone en la sesion en JSP Asignaciones
      	 String nombre = (String) session.getAttribute("PDFNombre");  // Se pone en la sesion en JSP Asignaciones
      	 String tipoPer = (String) session.getAttribute("PDFTipoPer");  // Se pone en la sesion en JSP Asignaciones
      	 if(tipoPer==null || tipoPer.toUpperCase().equals("NULL"))
      	 	tipoPer="";
      	 	// Departamento
      	 String departamento = (String) session.getAttribute("PDFDpto");
      	 String edepartamento = miVehiculo.getDepartEusk((String) session.getAttribute("PDFCodDpto"));
      	 	 	// Firma
      	 String firma = miVehiculo.getFirma(m05bConstantesInformes.CAR_C_ASIGNACION);


         String xlnetsini = miComun.leerPropiedad("xlnets");
         //String urlprin = xlnetsini.substring(0, xlnetsini.indexOf("/", 8));

         //String foParam = request.getParameter(FO_REQUEST_PARAM);
         String sFoFileDir = "/datos/m05b/tmp/";
         File foFileDir = new File(sFoFileDir);
         File tmpFoFile = File.createTempFile("m05b", "Fo", foFileDir);


         FileOutputStream tmpFoFileStream = new FileOutputStream(tmpFoFile);

         String sLinea;

         sLinea = "<?xml version=\"1.0\" encoding=\"windows-1252\"?>\n";
         tmpFoFileStream.write(sLinea.getBytes());
         
         sLinea = "<fo:root xmlns:fo=\"http://www.w3.org/1999/XSL/Format\">\n";
         tmpFoFileStream.write(sLinea.getBytes());
		 // LAYOUT DEL LISTADO 
	         sLinea = "<fo:layout-master-set>\n";
	         tmpFoFileStream.write(sLinea.getBytes());
		         sLinea = "	<fo:simple-page-master master-name=\"general\" page-height=\"29.5cm\" page-width=\"21cm\" margin-top=\"2cm\" margin-bottom=\"2cm\" margin-left=\"2cm\" margin-right=\"2.5cm\">\n";
			     tmpFoFileStream.write(sLinea.getBytes());
			         sLinea = "		<fo:region-before extent=\"0cm\"/>\n";
			         tmpFoFileStream.write(sLinea.getBytes());
			         sLinea = "		<fo:region-body margin-bottom=\"0cm\" margin-top=\"0cm\"/>\n";
			         tmpFoFileStream.write(sLinea.getBytes());
			         sLinea = "		<fo:region-after extent=\"0cm\"/>\n";
			         tmpFoFileStream.write(sLinea.getBytes());
			         sLinea = "		<fo:region-start extent=\"0cm\"/>\n";
			         tmpFoFileStream.write(sLinea.getBytes());
			         sLinea = "		<fo:region-end extent=\"0cm\"/>\n";
			         tmpFoFileStream.write(sLinea.getBytes());
		         sLinea = "	</fo:simple-page-master>\n";
		         tmpFoFileStream.write(sLinea.getBytes());
	         sLinea = "</fo:layout-master-set>\n";
	         tmpFoFileStream.write(sLinea.getBytes());
		 // PAGE-SEQUENCE DEL LISTADO 
	         sLinea = "<fo:page-sequence master-reference=\"general\">\n";
	         tmpFoFileStream.write(sLinea.getBytes());
		         sLinea = "	<fo:flow flow-name=\"xsl-region-body\">\n";
		         tmpFoFileStream.write(sLinea.getBytes());

		         // --------------    CABECERA DEL LISTADO    --------------
                        //Cabecera 1
		            sLinea = "		<fo:block-container position=\"absolute\" top=\"0cm\" left=\"3.4cm\" width=\"10.5cm\" height=\"1.7cm\">\n";
		            tmpFoFileStream.write(sLinea.getBytes());
		            	//  Escudo
			            sLinea = "			<fo:external-graphic src=\"" +  "/datos/m05b/file/images/fop/cabeceraHacFin.jpg\" height=\"1.7cm\" width=\"10.5cm\"/>\n";
			            tmpFoFileStream.write(sLinea.getBytes());
		            sLinea = "      </fo:block-container>\n";
		            tmpFoFileStream.write(sLinea.getBytes());
		            
		            sLinea = "		<fo:block-container position=\"absolute\" top=\"2.5cm\" left=\"0.69cm\" width=\"16cm\" height=\"2cm\">\n";
		            tmpFoFileStream.write(sLinea.getBytes());
		            	// Título Euskera
			            sLinea = "			<fo:block font-family=\"Helvetica\" font-weight=\"bold\" font-size=\"10pt\">\n " + m05bConstantesInformes.TIT_E_ASIG_DECRETO;
			            tmpFoFileStream.write(sLinea.getBytes());
			            sLinea = "	    	</fo:block>\n";
		            	tmpFoFileStream.write(sLinea.getBytes());
			            sLinea = "			<fo:block>\n</fo:block>";
			            tmpFoFileStream.write(sLinea.getBytes());		            	
		            	// Título Castellano
		            	sLinea = "	    	<fo:block font-family=\"Helvetica\" font-size=\"10pt\">\n";
		            	tmpFoFileStream.write(sLinea.getBytes());
			            	sLinea = "      	<fo:inline text-decoration=\"underline\">\n" + m05bConstantesInformes.TIT_C_ASIG_DECRETO + "</fo:inline>\n";
				            tmpFoFileStream.write(sLinea.getBytes());
		            	sLinea = "	    	</fo:block>\n";
		            	tmpFoFileStream.write(sLinea.getBytes());
		            sLinea = "      </fo:block-container>\n";
		            tmpFoFileStream.write(sLinea.getBytes());
		            
		         // --------------    DETALLE DEL LISTADO    --------------

		            sLinea = "      <fo:block-container position=\"absolute\" top=\"4.2cm\" left=\"0.69cm\" width=\"15cm\" height=\"5.5cm\">\n";
		            tmpFoFileStream.write(sLinea.getBytes());
		            	// Detalle-1
		            	sLinea= "       <fo:table>\n";
		            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-column column-width=\"75mm\"/>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-column column-width=\"10mm\"/>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-column column-width=\"75mm\"/>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-body font-family=\"Helvetica\" font-size=\"10pt\">\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
			            		sLinea = "	    <fo:table-row>\n";
			            		tmpFoFileStream.write(sLinea.getBytes());
			            			// CAB1 - Euskera
			            			sLinea = "	    <fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block font-weight=\"bold\">\n " + m05bConstantesInformes.CAB1_E_ASIGNACION + "</fo:block>\n";
							            tmpFoFileStream.write(sLinea.getBytes());
			            			sLinea = "	    </fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
			            			// CAB1 - Inermedia
			            			sLinea = "	    <fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block font-weight=\"bold\">\n " + "</fo:block>\n";
							            tmpFoFileStream.write(sLinea.getBytes());
			            			sLinea = "	    </fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());

			            			// CAB1 - Castellano
			            			sLinea = "	    <fo:table-cell>\n";
			            			   tmpFoFileStream.write(sLinea.getBytes());
							         sLinea = "      <fo:block >\n " + m05bConstantesInformes.CAB1_C_ASIGNACION + "</fo:block>\n";
						               tmpFoFileStream.write(sLinea.getBytes());
			            			sLinea = "	    </fo:table-cell>\n";
			            			  tmpFoFileStream.write(sLinea.getBytes());							            	
			            		sLinea = "	    </fo:table-row>\n\n\n";
			            		tmpFoFileStream.write(sLinea.getBytes());
			            		sLinea = "	    <fo:table-row>\n";
			            		tmpFoFileStream.write(sLinea.getBytes());
			            			// CAB2 - Euskera
			            			sLinea = "	    <fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block font-weight=\"bold\" text-align=\"center\"  padding-top=\"8pt\">\n " + m05bConstantesInformes.CAB2_E_ASIGNACION + "</fo:block>\n";
							            tmpFoFileStream.write(sLinea.getBytes());
			            			sLinea = "	    </fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
			            			// CAB2 - Intermedia
			            			sLinea = "	    <fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block font-weight=\"bold\" text-align=\"center\"  padding-top=\"8pt\">\n "+ "</fo:block>\n";
							            tmpFoFileStream.write(sLinea.getBytes());
			            			sLinea = "	    </fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());

			            			// CAB2 - Castellano
			            			sLinea = "	    <fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block text-align=\"center\"  padding-top=\"8pt\">\n " + m05bConstantesInformes.CAB2_C_ASIGNACION + "</fo:block>\n";
							            tmpFoFileStream.write(sLinea.getBytes());
			            			sLinea = "	    </fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());							            	
			            		sLinea = "	    </fo:table-row>\n";
			            		tmpFoFileStream.write(sLinea.getBytes());
			            		sLinea = "	    <fo:table-row>\n";
			            		tmpFoFileStream.write(sLinea.getBytes());
			            			// DET1 - Euskera
			            			sLinea = "	    <fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
			            			
			            			if(tipoPer.equals("S")){
			            				//Es una persona
			            				sLinea = "      <fo:block font-weight=\"bold\" padding-top=\"8pt\">\n<![CDATA[ " + m05bConstantesInformes.DET11_E_ASIG_DECRETO + edepartamento + m05bConstantesInformes.DET12_E_ASIG_DECRETO + ecargo + m05bConstantesInformes.DET13_E_ASIG_DECRETO + nombre + m05bConstantesInformes.DET14_E_ASIG_DECRETO + "]]></fo:block>\n";  
			            			}else{
			            				//No es una persona
			            				if(cargo==null || cargo.trim().equals("")){
			            					//No tiene cargo
			            					
			            					sLinea = "      <fo:block font-weight=\"bold\" padding-top=\"8pt\">\n <![CDATA[" + m05bConstantesInformes.DET11_E_ASIG_DECRETO + edepartamento + m05bConstantesInformes.DET12_E_ASIG_DECRETO + ecargo + m05bConstantesInformes.DET13_E_ASIG_DECRETO + nombre + m05bConstantesInformes.DET14_E_ASIG_DECRETO_SINCARGO + "]]></fo:block>\n";    
			            				}else{
			            					sLinea = "      <fo:block font-weight=\"bold\" padding-top=\"8pt\">\n <![CDATA[" + m05bConstantesInformes.DET11_E_ASIG_DECRETO + edepartamento + m05bConstantesInformes.DET12_E_ASIG_DECRETO + ecargo + m05bConstantesInformes.DET13_E_ASIG_DECRETO + nombre + m05bConstantesInformes.DET14_E_ASIG_DECRETO + "]]></fo:block>\n";
										       
			            				}	
			            			}
			            			 
			            			tmpFoFileStream.write(sLinea.getBytes());
			            			sLinea = "	    </fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
			            			// DET1 - Intermedia
			            			sLinea = "	    <fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block font-weight=\"bold\" padding-top=\"8pt\">\n " +  "</fo:block>\n";
							            tmpFoFileStream.write(sLinea.getBytes());
			            			sLinea = "	    </fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());

			            			// DET1 - Castellano
			            			sLinea = "	    <fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
							        //TODO La linea dependerá del tipoPer
			            			if(tipoPer.equals("S")){
			            				//Es una persona
			            				sLinea = "      <fo:block  padding-top=\"8pt\">\n<![CDATA[ " + m05bConstantesInformes.DET11_C_ASIG_DECRETO + cargo + m05bConstantesInformes.DET12_C_ASIG_DECRETO  + departamento + " D./Dña. " + nombre +  "]]></fo:block>\n";
			            			}else{
			            				//No es una persona
			            				if(cargo==null || cargo.trim().equals("")){
			            					//No tiene cargo
			            					
			            					sLinea = "      <fo:block  padding-top=\"8pt\">\n <![CDATA[" + m05bConstantesInformes.DET11_C_ASIG_DECRETO2  + m05bConstantesInformes.DET12_C_ASIG_DECRETO_SINCARGO  + departamento +", " + nombre +  "]]></fo:block>\n";
			            				}else{
			            					sLinea = "      <fo:block  padding-top=\"8pt\">\n <![CDATA[" + m05bConstantesInformes.DET11_C_ASIG_DECRETO2 + cargo + m05bConstantesInformes.DET12_C_ASIG_DECRETO  + departamento +", " + nombre +  "]]></fo:block>\n";
			            				}	
			            			}
							        tmpFoFileStream.write(sLinea.getBytes());
			            			sLinea = "	    </fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
			            		sLinea = "	    </fo:table-row>\n";
			            		tmpFoFileStream.write(sLinea.getBytes());
			            		sLinea = "	    <fo:table-row>\n";
			            		tmpFoFileStream.write(sLinea.getBytes());
			            			// CAB3 - Euskera
			            			sLinea = "	    <fo:table-cell padding-top=\"10pt\">\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block font-weight=\"bold\" >\n " + m05bConstantesInformes.CPO_E_ASIG_DECRETO + "</fo:block>\n";
							            tmpFoFileStream.write(sLinea.getBytes());
			            			sLinea = "	    </fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
			            			// CAB3 - Intermedia
			            			sLinea = "	    <fo:table-cell padding-top=\"10pt\">\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block font-weight=\"bold\" >\n " +  "</fo:block>\n";
							            tmpFoFileStream.write(sLinea.getBytes());
			            			sLinea = "	    </fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());

			            			// CAB3 - Castellano
			            			sLinea = "	    <fo:table-cell padding-top=\"10pt\">\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block >\n " + m05bConstantesInformes.CPO_C_ASIG_DECRETO + "</fo:block>\n";
							            tmpFoFileStream.write(sLinea.getBytes());
			            			sLinea = "	    </fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());							            	
			            		sLinea = "	    </fo:table-row>\n";
			            		tmpFoFileStream.write(sLinea.getBytes());

		            		sLinea = "	    </fo:table-body>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());			            								            		
			            sLinea= "       </fo:table>\n";
		            	tmpFoFileStream.write(sLinea.getBytes());
		            sLinea = "      </fo:block-container>\n";
		            tmpFoFileStream.write(sLinea.getBytes());
						// Cuerpo
		            sLinea = "      <fo:block-container position=\"absolute\" top=\"10cm\" left=\"3cm\" width=\"15cm\" height=\"6.5cm\">\n";
		            tmpFoFileStream.write(sLinea.getBytes());
		           		sLinea= "       <fo:table>\n";
		            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-column column-width=\"40mm\"/>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-column column-width=\"40mm\"/>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-column column-width=\"40mm\"/>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-body font-family=\"Helvetica\" font-size=\"10pt\">\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
			            		sLinea = "	    <fo:table-row>\n";
			            		tmpFoFileStream.write(sLinea.getBytes());
			            			// Ibilbigailua 
			            			sLinea = "	    <fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block font-weight=\"bold\">\n Ibilbigailua.</fo:block>";
							            tmpFoFileStream.write(sLinea.getBytes());
			            			sLinea = "	    </fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
			            			// Marka
			            			sLinea = "	    <fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block font-weight=\"bold\">\n Marka:</fo:block>\n";
							            tmpFoFileStream.write(sLinea.getBytes());
			            			sLinea = "	    </fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
		            			// Valor BD
			            			sLinea = "	    <fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block>\n<![CDATA[" + vehiculo[0] + "]]></fo:block>\n";
							            tmpFoFileStream.write(sLinea.getBytes());
			            			sLinea = "	    </fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());			            			
			            		sLinea = "	    </fo:table-row>\n";
			            		tmpFoFileStream.write(sLinea.getBytes());
			            		sLinea = "	    <fo:table-row>\n";
			            		tmpFoFileStream.write(sLinea.getBytes());
			            			// Vehículo 
			            			sLinea = "	    <fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block>\n Vehículo.</fo:block>";
							            tmpFoFileStream.write(sLinea.getBytes());
			            			sLinea = "	    </fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
			            			// Marca
			            			sLinea = "	    <fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block>\n Marca:</fo:block>\n";
							            tmpFoFileStream.write(sLinea.getBytes());
			            			sLinea = "	    </fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
			            			//  Celda en blanco
			            			sLinea = "	    <fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block>\n</fo:block>";
							            tmpFoFileStream.write(sLinea.getBytes());
			            			sLinea = "	    </fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
			            		sLinea = "	    </fo:table-row>\n";
			            		tmpFoFileStream.write(sLinea.getBytes());
								sLinea = "	    <fo:table-row>\n";
			            		tmpFoFileStream.write(sLinea.getBytes());
			            			//  Celda en blanco
			            			sLinea = "	    <fo:table-cell padding-top=\"8pt\">\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block>\n</fo:block>";
							            tmpFoFileStream.write(sLinea.getBytes());
			            			sLinea = "	    </fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
			            			// Mota
			            			sLinea = "	    <fo:table-cell padding-top=\"8pt\">\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block font-weight=\"bold\">\n Mota:</fo:block>\n";
							            tmpFoFileStream.write(sLinea.getBytes());
			            			sLinea = "	    </fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
		            			// Valor BD
			            			sLinea = "	    <fo:table-cell padding-top=\"8pt\">\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block><![CDATA[" + vehiculo[1] + "]]></fo:block>\n";
							            tmpFoFileStream.write(sLinea.getBytes());
			            			sLinea = "	    </fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());			            			
			            		sLinea = "	    </fo:table-row>\n";
			            		tmpFoFileStream.write(sLinea.getBytes());	
								sLinea = "	    <fo:table-row>\n";
			            		tmpFoFileStream.write(sLinea.getBytes());
			            			//  Celda en blanco
			            			sLinea = "	    <fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block>\n</fo:block>";
							            tmpFoFileStream.write(sLinea.getBytes());
			            			sLinea = "	    </fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
			            			// Modelo
			            			sLinea = "	    <fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block>\n Modelo:</fo:block>\n";
							            tmpFoFileStream.write(sLinea.getBytes());
			            			sLinea = "	    </fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
			            			//  Celda en blanco
			            			sLinea = "	    <fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block>\n</fo:block>";
							            tmpFoFileStream.write(sLinea.getBytes());
			            			sLinea = "	    </fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
			            		sLinea = "	    </fo:table-row>\n";
			            		tmpFoFileStream.write(sLinea.getBytes());			            		
								sLinea = "	    <fo:table-row>\n";
			            		tmpFoFileStream.write(sLinea.getBytes());
			            			//  Celda en blanco
			            			sLinea = "	    <fo:table-cell padding-top=\"8pt\">\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block>\n</fo:block>";
							            tmpFoFileStream.write(sLinea.getBytes());
			            			sLinea = "	    </fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
			            			// Matrikula
			            			sLinea = "	    <fo:table-cell padding-top=\"8pt\">\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block font-weight=\"bold\">\n Matrikula:</fo:block>\n";
							            tmpFoFileStream.write(sLinea.getBytes());
			            			sLinea = "	    </fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
		            			// Valor BD
			            			sLinea = "	    <fo:table-cell padding-top=\"8pt\">\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block>\n <![CDATA[" + matricula + "]]></fo:block>\n";
							            tmpFoFileStream.write(sLinea.getBytes());
			            			sLinea = "	    </fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());			            			
			            		sLinea = "	    </fo:table-row>\n";
			            		tmpFoFileStream.write(sLinea.getBytes());			            		
								sLinea = "	    <fo:table-row>\n";
			            		tmpFoFileStream.write(sLinea.getBytes());
			            			//  Celda en blanco
			            			sLinea = "	    <fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block>\n</fo:block>";
							            tmpFoFileStream.write(sLinea.getBytes());
			            			sLinea = "	    </fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
			            			// Matricula
			            			sLinea = "	    <fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block>\n Matrícula:</fo:block>\n";
							            tmpFoFileStream.write(sLinea.getBytes());
			            			sLinea = "	    </fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
			            			//  Celda en blanco
			            			sLinea = "	    <fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block>\n</fo:block>";
							            tmpFoFileStream.write(sLinea.getBytes());
			            			sLinea = "	    </fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
			            		sLinea = "	    </fo:table-row>\n";
			            		tmpFoFileStream.write(sLinea.getBytes());
								sLinea = "	    <fo:table-row>\n";
			            		tmpFoFileStream.write(sLinea.getBytes());
			            			//  Celda en blanco
			            			sLinea = "	    <fo:table-cell padding-top=\"8pt\">\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block>\n</fo:block>";
							            tmpFoFileStream.write(sLinea.getBytes());
			            			sLinea = "	    </fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
			            			// Txartela zk
			            			sLinea = "	    <fo:table-cell padding-top=\"8pt\">\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block font-weight=\"bold\">\n Txartela zk.:</fo:block>\n";
							            tmpFoFileStream.write(sLinea.getBytes());
			            			sLinea = "	    </fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
		            			// Valor BD
			            			sLinea = "	    <fo:table-cell padding-top=\"8pt\">\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block>\n <![CDATA[" + tarjeta + "]]></fo:block>\n";
							            tmpFoFileStream.write(sLinea.getBytes());
			            			sLinea = "	    </fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());			            			
			            		sLinea = "	    </fo:table-row>\n";
			            		tmpFoFileStream.write(sLinea.getBytes());
								 sLinea = "	    <fo:table-row>\n";
			            		 tmpFoFileStream.write(sLinea.getBytes());
			            		 	//  Celda en blanco
			            		 	 sLinea = "	    <fo:table-cell>\n";
			            			 tmpFoFileStream.write(sLinea.getBytes());
							             sLinea = "      <fo:block>\n</fo:block>";
							             tmpFoFileStream.write(sLinea.getBytes());
			            			 sLinea = "	    </fo:table-cell>\n";
			            			 tmpFoFileStream.write(sLinea.getBytes());
			            			 // Nº Tarjeta
			            			 sLinea = "	    <fo:table-cell>\n";
			            			 tmpFoFileStream.write(sLinea.getBytes());
							             sLinea = "      <fo:block>\n Tarjeta</fo:block>\n";
							             tmpFoFileStream.write(sLinea.getBytes());
			            			 sLinea = "	    </fo:table-cell>\n";
			            			 tmpFoFileStream.write(sLinea.getBytes());
			            			 //  Celda en blanco
			            			 sLinea = "	    <fo:table-cell>\n";
			            			 tmpFoFileStream.write(sLinea.getBytes());
							             sLinea = "      <fo:block>\n</fo:block>";
							             tmpFoFileStream.write(sLinea.getBytes());
			            			 sLinea = "	    </fo:table-cell>\n";
			            			 tmpFoFileStream.write(sLinea.getBytes());
			            		 sLinea = "	    </fo:table-row>\n";
		            			 tmpFoFileStream.write(sLinea.getBytes());
		                 		if (!(viaT.equals(""))){	
									sLinea = "	    <fo:table-row>\n";
				            		tmpFoFileStream.write(sLinea.getBytes());
				            			//  Celda en blanco
				            			sLinea = "	    <fo:table-cell padding-top=\"8pt\">\n";
				            			tmpFoFileStream.write(sLinea.getBytes());
								            sLinea = "      <fo:block>\n</fo:block>";
								            tmpFoFileStream.write(sLinea.getBytes());
				            			sLinea = "	    </fo:table-cell>\n";
				            			tmpFoFileStream.write(sLinea.getBytes());
				            			// VIAT
				            			sLinea = "	    <fo:table-cell padding-top=\"8pt\">\n";
				            			tmpFoFileStream.write(sLinea.getBytes());
								            sLinea = "      <fo:block font-weight=\"bold\">\n ViaT zk.:</fo:block>\n";
								            tmpFoFileStream.write(sLinea.getBytes());
				            			sLinea = "	    </fo:table-cell>\n";
				            			tmpFoFileStream.write(sLinea.getBytes());
			            			// Valor BD
				            			sLinea = "	    <fo:table-cell padding-top=\"8pt\">\n";
				            			tmpFoFileStream.write(sLinea.getBytes());
								            sLinea = "      <fo:block>\n<![CDATA[ " + viaT + "]]></fo:block>\n";
								            tmpFoFileStream.write(sLinea.getBytes());
				            			sLinea = "	    </fo:table-cell>\n";
				            			tmpFoFileStream.write(sLinea.getBytes());			            			
				            		sLinea = "	    </fo:table-row>\n";
				            		tmpFoFileStream.write(sLinea.getBytes());
									 sLinea = "	    <fo:table-row>\n";
				            		 tmpFoFileStream.write(sLinea.getBytes());
				            		 	//  Celda en blanco
				            		 	 sLinea = "	    <fo:table-cell>\n";
				            			 tmpFoFileStream.write(sLinea.getBytes());
								             sLinea = "      <fo:block>\n</fo:block>";
								             tmpFoFileStream.write(sLinea.getBytes());
				            			 sLinea = "	    </fo:table-cell>\n";
				            			 tmpFoFileStream.write(sLinea.getBytes());
				            			 // Nº Tarjeta
				            			 sLinea = "	    <fo:table-cell>\n";
				            			 tmpFoFileStream.write(sLinea.getBytes());
								             sLinea = "      <fo:block>\n Nº ViaT:</fo:block>\n";
								             tmpFoFileStream.write(sLinea.getBytes());
				            			 sLinea = "	    </fo:table-cell>\n";
				            			 tmpFoFileStream.write(sLinea.getBytes());
				            			 //  Celda en blanco
				            			 sLinea = "	    <fo:table-cell>\n";
				            			 tmpFoFileStream.write(sLinea.getBytes());
								             sLinea = "      <fo:block>\n</fo:block>";
								             tmpFoFileStream.write(sLinea.getBytes());
				            			 sLinea = "	    </fo:table-cell>\n";
				            			 tmpFoFileStream.write(sLinea.getBytes());
				            		 sLinea = "	    </fo:table-row>\n";
			            			 tmpFoFileStream.write(sLinea.getBytes());		                 			
		                 		}
			            	sLinea = "	    </fo:table-body>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());			            								            		
			            sLinea= "       </fo:table>\n";
		            	tmpFoFileStream.write(sLinea.getBytes());   
		            sLinea = "      </fo:block-container>\n";
		            tmpFoFileStream.write(sLinea.getBytes());

		            sLinea = "      <fo:block-container position=\"absolute\" top=\"15.5cm\" left=\"0.69cm\" width=\"15cm\" height=\"5.5cm\">\n";
		            tmpFoFileStream.write(sLinea.getBytes());	
		            	// Detalle-3
		            	sLinea= "       <fo:table>\n";
		            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-column column-width=\"75mm\"/>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-column column-width=\"10mm\"/>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-column column-width=\"75mm\"/>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-body font-family=\"Helvetica\" font-size=\"10pt\">\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
			            		sLinea = "	    <fo:table-row>\n";
			            		tmpFoFileStream.write(sLinea.getBytes());
			            			// Euskera
			            			sLinea = "	    <fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block font-weight=\"bold\">\n " + m05bConstantesInformes.DET2_E_ASIG_DECRETO + "</fo:block>\n";
							            tmpFoFileStream.write(sLinea.getBytes());
			            			sLinea = "	    </fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
			            			// Intermedia
			            			sLinea = "	    <fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block font-weight=\"bold\">\n " +  "</fo:block>\n";
							            tmpFoFileStream.write(sLinea.getBytes());
			            			sLinea = "	    </fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());

			            			// Castellano
			            			sLinea = "	    <fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block>\n " + m05bConstantesInformes.DET2_C_ASIG_DECRETO + "</fo:block>\n";
							            tmpFoFileStream.write(sLinea.getBytes());
			            			sLinea = "	    </fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());							            	
			            		sLinea = "	    </fo:table-row>\n";
			            		tmpFoFileStream.write(sLinea.getBytes());

			            		sLinea = "	    <fo:table-row margin-left=\"1cm\">\n";
			            		tmpFoFileStream.write(sLinea.getBytes());
			            			// DOC1 - Euskera
			            			sLinea = "	    <fo:table-cell padding-top=\"6pt\">\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block font-weight=\"bold\">\n " + m05bConstantesInformes.DOC1_E_ASIG_DECRETO + "</fo:block>\n";
							            tmpFoFileStream.write(sLinea.getBytes());
			            			sLinea = "	    </fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
			            			// DOC1 - Intermedio
			            			sLinea = "	    <fo:table-cell padding-top=\"6pt\">\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block font-weight=\"bold\">\n " + "</fo:block>\n";
							            tmpFoFileStream.write(sLinea.getBytes());
			            			sLinea = "	    </fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());

			            			// DOC1 - Castellano
			            			sLinea = "	    <fo:table-cell padding-top=\"6pt\">\n";
			            			   tmpFoFileStream.write(sLinea.getBytes());
							         sLinea = "      <fo:block >\n " + m05bConstantesInformes.DOC1_C_ASIG_DECRETO + "</fo:block>\n";
						               tmpFoFileStream.write(sLinea.getBytes());
			            			sLinea = "	    </fo:table-cell>\n";
			            			  tmpFoFileStream.write(sLinea.getBytes());							            	
			            		sLinea = "	    </fo:table-row>\n";
			            		tmpFoFileStream.write(sLinea.getBytes());
			            		sLinea = "	    <fo:table-row margin-left=\"1cm\">\n";
			            		tmpFoFileStream.write(sLinea.getBytes());
			            			// DOC2 - Euskera
			            			sLinea = "	    <fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block font-weight=\"bold\">\n " + m05bConstantesInformes.DOC2_E_ASIG_DECRETO + "</fo:block>\n";
							            tmpFoFileStream.write(sLinea.getBytes());
			            			sLinea = "	    </fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
			            			// DOC2 - Intermedio
			            			sLinea = "	    <fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block font-weight=\"bold\">\n " +  "</fo:block>\n";
							            tmpFoFileStream.write(sLinea.getBytes());
			            			sLinea = "	    </fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());

			            			// DOC2 - Castellano
			            			sLinea = "	    <fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block >\n " + m05bConstantesInformes.DOC2_C_ASIG_DECRETO + "</fo:block>\n";
							            tmpFoFileStream.write(sLinea.getBytes());
			            			sLinea = "	    </fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());							            	
			            		sLinea = "	    </fo:table-row>\n";
			            		tmpFoFileStream.write(sLinea.getBytes());
			            		sLinea = "	    <fo:table-row margin-left=\"1cm\">\n";
			            		tmpFoFileStream.write(sLinea.getBytes());
			            			// DOC3 - Euskera
			            			sLinea = "	    <fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block font-weight=\"bold\">\n " + m05bConstantesInformes.DOC3_E_ASIG_DECRETO + "</fo:block>\n";
							            tmpFoFileStream.write(sLinea.getBytes());
			            			sLinea = "	    </fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
			            			// DOC3 - Intermedio
			            			sLinea = "	    <fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block font-weight=\"bold\">\n " + "</fo:block>\n";
							            tmpFoFileStream.write(sLinea.getBytes());
			            			sLinea = "	    </fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());

			            			// DOC3 - Castellano
			            			sLinea = "	    <fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block >\n " + m05bConstantesInformes.DOC3_C_ASIG_DECRETO +  "</fo:block>\n";
							            tmpFoFileStream.write(sLinea.getBytes());
			            			sLinea = "	    </fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
			            		sLinea = "	    </fo:table-row>\n";
			            		tmpFoFileStream.write(sLinea.getBytes());
			            		sLinea = "	    <fo:table-row margin-left=\"1cm\">\n";
			            		tmpFoFileStream.write(sLinea.getBytes());
			            			// DOC4 - Euskera
			            			sLinea = "	    <fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block font-weight=\"bold\" >\n " + m05bConstantesInformes.DOC4_E_ASIG_DECRETO+ "</fo:block>\n";
							            tmpFoFileStream.write(sLinea.getBytes());
			            			sLinea = "	    </fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
	            			            // DOC4 - Intermedio
			            			sLinea = "	    <fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block font-weight=\"bold\" >\n " +  "</fo:block>\n";
							            tmpFoFileStream.write(sLinea.getBytes());
			            			sLinea = "	    </fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());

			            			// DOC4 - Castellano
			            			sLinea = "	    <fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block >\n " + m05bConstantesInformes.DOC4_C_ASIG_DECRETO + "</fo:block>\n";
							            tmpFoFileStream.write(sLinea.getBytes());
			            			sLinea = "	    </fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());							            	
			            		sLinea = "	    </fo:table-row>\n";
			            		tmpFoFileStream.write(sLinea.getBytes());
			            		sLinea = "	    <fo:table-row margin-left=\"1cm\">\n";
			            		tmpFoFileStream.write(sLinea.getBytes());
			            			// DOC5 - Euskera
			            			sLinea = "	    <fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block font-weight=\"bold\">\n " + m05bConstantesInformes.DOC5_E_ASIG_DECRETO+ "</fo:block>\n";
							            tmpFoFileStream.write(sLinea.getBytes());
			            			sLinea = "	    </fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
			            			// DOC5 - Intermedio
			            			sLinea = "	    <fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block font-weight=\"bold\">\n " +  "</fo:block>\n";
							            tmpFoFileStream.write(sLinea.getBytes());
			            			sLinea = "	    </fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());

			            			// DOC5 - Castellano
			            			sLinea = "	    <fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block>\n " + m05bConstantesInformes.DOC5_C_ASIG_DECRETO + "</fo:block>\n";
							            tmpFoFileStream.write(sLinea.getBytes());
			            			sLinea = "	    </fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());							            	
			            		sLinea = "	    </fo:table-row>\n";
			            		tmpFoFileStream.write(sLinea.getBytes());
			            		sLinea = "	    <fo:table-row margin-left=\"1cm\">\n";
			            		tmpFoFileStream.write(sLinea.getBytes());
			            			// DOC6 - Euskera
			            			sLinea = "	    <fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block font-weight=\"bold\" >\n " + m05bConstantesInformes.DOC6_E_ASIG_DECRETO+ "</fo:block>\n";
							            tmpFoFileStream.write(sLinea.getBytes());
			            			sLinea = "	    </fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
			            			// DOC6 - Intermedio
			            			sLinea = "	    <fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block font-weight=\"bold\" >\n " +  "</fo:block>\n";
							            tmpFoFileStream.write(sLinea.getBytes());
			            			sLinea = "	    </fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());

			            			// DOC6 - Castellano
			            			sLinea = "	    <fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block >\n " + m05bConstantesInformes.DOC6_C_ASIG_DECRETO + "</fo:block>\n";
							            tmpFoFileStream.write(sLinea.getBytes());
			            			sLinea = "	    </fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());							            	
			            		sLinea = "	    </fo:table-row>\n";
			            		tmpFoFileStream.write(sLinea.getBytes());


			            		sLinea = "	    <fo:table-row>\n";
			            		tmpFoFileStream.write(sLinea.getBytes());
			            			// Euskera
			            			sLinea = "	    <fo:table-cell padding-top=\"8pt\">\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block font-weight=\"bold\">\n " + m05bConstantesInformes.DET3_E_ASIG_DECRETO + "</fo:block>\n";
							            tmpFoFileStream.write(sLinea.getBytes());
			            			sLinea = "	    </fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
			            			// Intermedia
			            			sLinea = "	    <fo:table-cell padding-top=\"8pt\">\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block font-weight=\"bold\">\n " + "</fo:block>\n";
							            tmpFoFileStream.write(sLinea.getBytes());
			            			sLinea = "	    </fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());

			            			// Castellano
			            			sLinea = "	    <fo:table-cell padding-top=\"8pt\">\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block>\n " + m05bConstantesInformes.DET3_C_ASIG_DECRETO + "</fo:block>\n";
							            tmpFoFileStream.write(sLinea.getBytes());
			            			sLinea = "	    </fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());							            	
			            		sLinea = "	    </fo:table-row>\n";
			            		tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    </fo:table-body>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());			            								            		
			            sLinea= "       </fo:table>\n";
		            	tmpFoFileStream.write(sLinea.getBytes());
		            sLinea = "      </fo:block-container>\n";
		            tmpFoFileStream.write(sLinea.getBytes());


		         // --------------    PIE DE PAGINA DEL LISTADO EN   --------------
					sLinea = "      <fo:block-container position=\"absolute\" top=\"21cm\" left=\"0.65cm\" width=\"15cm\" height=\"2cm\">\n";
		            tmpFoFileStream.write(sLinea.getBytes());
		            	sLinea= "       <fo:table>\n";
		            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-column column-width=\"75mm\"/>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-column column-width=\"10mm\"/>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-column column-width=\"75mm\"/>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-body font-family=\"Helvetica\" font-size=\"10pt\">\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
			            		sLinea = "	    <fo:table-row>\n";
			            		tmpFoFileStream.write(sLinea.getBytes());
			            			// En Castellano 
			            			sLinea = "	    <fo:table-cell padding-top=\"6pt\">\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block text-align=\"center\"  font-weight=\"bold\">\n" +  m05bConstantesInformes.EN_E_ASIGNACION + "</fo:block>";
							            tmpFoFileStream.write(sLinea.getBytes());
			            			sLinea = "	    </fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
			            			// Intermedio
			            			sLinea = "	    <fo:table-cell padding-top=\"6pt\">\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block font-weight=\"bold\">\n </fo:block>\n";
							            tmpFoFileStream.write(sLinea.getBytes());
			            			sLinea = "	    </fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
		            			// Puntos
			            			sLinea = "	    <fo:table-cell padding-top=\"6pt\">\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block>\n  </fo:block>\n";
							            tmpFoFileStream.write(sLinea.getBytes());
			            			sLinea = "	    </fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());			            			
			            		sLinea = "	    </fo:table-row>\n";
			            		tmpFoFileStream.write(sLinea.getBytes());
			            		sLinea = "	    <fo:table-row>\n";
			            		tmpFoFileStream.write(sLinea.getBytes());
			            			// En Euskera 
			            			sLinea = "	    <fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block text-align=\"center\">\n" + m05bConstantesInformes.EN_C_ASIGNACION + "</fo:block>";
							            tmpFoFileStream.write(sLinea.getBytes());
			            			sLinea = "	    </fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
			            			// Intermedio
			            			sLinea = "	    <fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block>\n .......................................................... </fo:block>\n";
							            tmpFoFileStream.write(sLinea.getBytes());
			            			sLinea = "	    </fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
		            			// Puntos
			            			sLinea = "	    <fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block>\n </fo:block>\n";
							            tmpFoFileStream.write(sLinea.getBytes());
			            			sLinea = "	    </fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
			            		sLinea = "	    </fo:table-row>\n";
			            		tmpFoFileStream.write(sLinea.getBytes());

		            		sLinea = "	    </fo:table-body>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
			            sLinea= "       </fo:table>\n";
		            	tmpFoFileStream.write(sLinea.getBytes());
		            sLinea = "      </fo:block-container>\n";
		            tmpFoFileStream.write(sLinea.getBytes());
                        //PIE DE PAGINA FIRMA
					sLinea = "      <fo:block-container position=\"absolute\" top=\"24cm\" left=\"0.65cm\" width=\"15cm\" height=\"2cm\">\n";
		            tmpFoFileStream.write(sLinea.getBytes());
		            	sLinea= "       <fo:table>\n";
		            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-column column-width=\"40mm\"/>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-column column-width=\"20mm\"/>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-column column-width=\"20mm\"/>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-column column-width=\"80mm\"/>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-body font-family=\"Helvetica\" font-size=\"10pt\">\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
		                              // FIRMA CASTELLANO
			            		sLinea = "	    <fo:table-row>\n";
			            		tmpFoFileStream.write(sLinea.getBytes());
		            			// Intermedio
			            			sLinea = "	    <fo:table-cell padding-top=\"6pt\">\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block>\n  </fo:block>\n";
							            tmpFoFileStream.write(sLinea.getBytes());
			            			sLinea = "	    </fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());			            			
                                          //Fiema en Castellano
			            			sLinea = "	    <fo:table-cell padding-top=\"6pt\">\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block font-weight=\"bold\" text-align=\"right\">" + m05bConstantesInformes.FIR_E_ASIGNACION+ "</fo:block>";
							            tmpFoFileStream.write(sLinea.getBytes());
			            			sLinea = "	    </fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());	
		            			// Firma en euskera
			            			sLinea = "	    <fo:table-cell padding-top=\"6pt\">\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block text-align=\"left\"> / " + m05bConstantesInformes.FIR_C_ASIGNACION+ "</fo:block>";
							            tmpFoFileStream.write(sLinea.getBytes());
			            			sLinea = "	    </fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
		            			// Responsable
			            			sLinea = "	    <fo:table-cell padding-top=\"6pt\">\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block  text-align=\"left\">\n<![CDATA[" + firma + "]]></fo:block>\n";
							            tmpFoFileStream.write(sLinea.getBytes());
			            			sLinea = "	    </fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());			            			
			            		sLinea = "	    </fo:table-row>\n";
			            		tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    </fo:table-body>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());			            								            		
			            sLinea= "       </fo:table>\n";
		            	tmpFoFileStream.write(sLinea.getBytes());
		            sLinea = "      </fo:block-container>\n";
		            tmpFoFileStream.write(sLinea.getBytes());
                        //PIE DE PAGINA Director de Recursos
					sLinea = "      <fo:block-container position=\"absolute\" top=\"24.7cm\" left=\"0.65cm\" width=\"15cm\" height=\"2cm\">\n";
		            tmpFoFileStream.write(sLinea.getBytes());
		            	sLinea= "       <fo:table>\n";
		            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-column column-width=\"80mm\"/>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-column column-width=\"80mm\"/>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-body font-family=\"Helvetica\" font-size=\"10pt\">\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
		                              // FIRMA CASTELLANO
			            		sLinea = "	    <fo:table-row>\n";
			            		tmpFoFileStream.write(sLinea.getBytes());
                                          //Fiema en Castellano
			            			sLinea = "	    <fo:table-cell >\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block font-weight=\"bold\" text-align=\"right\">" + m05bConstantesInformes.CAR_E_ASIGNACION+ "</fo:block>";
							            tmpFoFileStream.write(sLinea.getBytes());
			            			sLinea = "	    </fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());	
		            			// Firma en euskera
			            			sLinea = "	    <fo:table-cell >\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block text-align=\"left\">" + "/" + m05bConstantesInformes.CAR_C_ASIGNACION+ "</fo:block>";
							            tmpFoFileStream.write(sLinea.getBytes());
			            			sLinea = "	    </fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
			            		sLinea = "	    </fo:table-row>\n";
			            		tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    </fo:table-body>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());			            								            		
			            sLinea= "       </fo:table>\n";
		            	tmpFoFileStream.write(sLinea.getBytes());
		            sLinea = "      </fo:block-container>\n";
		            tmpFoFileStream.write(sLinea.getBytes());
                        //PIE DE PAGINA Pie
					sLinea = "      <fo:block-container position=\"absolute\" top=\"25.7cm\" left=\"0.65cm\" width=\"15cm\" height=\"2cm\">\n";
		            tmpFoFileStream.write(sLinea.getBytes());
		            	sLinea= "       <fo:table>\n";
		            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-column column-width=\"160mm\"/>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-body font-family=\"Helvetica\" font-size=\"8pt\">\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
		                              // FIRMA CASTELLANO
			            		sLinea = "	    <fo:table-row>\n";
			            		tmpFoFileStream.write(sLinea.getBytes());
                                          //Fiema en Castellano
			            			sLinea = "	    <fo:table-cell >\n";
			            			tmpFoFileStream.write(sLinea.getBytes());
							            sLinea = "      <fo:block text-align=\"center\">" + m05bConstantesInformes.PIE_ASIGNACION+ "</fo:block>";
							            tmpFoFileStream.write(sLinea.getBytes());
			            			sLinea = "	    </fo:table-cell>\n";
			            			tmpFoFileStream.write(sLinea.getBytes());	
			            		sLinea = "	    </fo:table-row>\n";
			            		tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    </fo:table-body>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());			            								            		
			            sLinea= "       </fo:table>\n";
		            	tmpFoFileStream.write(sLinea.getBytes());
		            sLinea = "      </fo:block-container>\n";
		            tmpFoFileStream.write(sLinea.getBytes());

		         sLinea = "      </fo:flow>\n";
                 tmpFoFileStream.write(sLinea.getBytes());
                 
         	 sLinea = "   </fo:page-sequence>\n";
             tmpFoFileStream.write(sLinea.getBytes());
             
         sLinea = "</fo:root>\n";
         tmpFoFileStream.write(sLinea.getBytes());
         

         tmpFoFileStream.close();

         pstmt = conn.prepareStatement(sSentenciaUpdate);
         rs = pstmt.executeQuery();
         conn.commit();

         FileInputStream file = new FileInputStream(sFoFileDir + tmpFoFile.getName());

         renderFO(new InputSource(file), response);

         tmpFoFile.delete();

         response.flushBuffer();
         

	    } catch (SQLException ex1) {
	    	conn.rollback();
	    	miLog.addTraza(ex1);
			response.sendRedirect("m05bError.jsp");
		} 	finally{
				if (rs != null)
					rs.close();
				if (pstmt != null)
					pstmt.close();
				if (conn != null)
					conn.close();
		}
	}
	catch(Throwable theException)
	{
		// uncomment the following line when unexpected exceptions
		// are occuring to aid in debugging the problem.
		
		miLog.addTraza(theException);
		try {
			response.sendRedirect("m05bError.jsp");
		} catch (IOException e) {
			// TODO Auto-generated catch block
			miLog.addTraza(e);
		}
	}
    }

    /**
     * renders an FO inputsource into a PDF file which is rendered
     * directly to the response object's OutputStream
     */
    public void renderFO(InputSource foFile, HttpServletResponse response) throws ServletException
    {
        try
        {
            ByteArrayOutputStream out = new ByteArrayOutputStream();

	    	response.reset();
            OutputStream oOut=response.getOutputStream();
            BufferedOutputStream bOut=new BufferedOutputStream(oOut);
            Driver driver = new Driver(foFile, out);
            driver.setRenderer(Driver.RENDER_PDF);
            driver.run();

            response.setContentLength(out.size());
	    response.setContentType("application/pdf");


            bOut.write(out.toByteArray());
	    out.close();
	    bOut.flush();
            bOut.close();
//	    response.flushBuffer();
        }
        catch (Exception ex)
        {
            throw new ServletException(ex);
        }
    }
}