
package fr.gouv.finances.dgfip.xemelios.facturessansengagementtiers;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import fr.gouv.finances.dgfip.xemelios.txt2xml.AbstractTxt2Xml;
import fr.gouv.finances.dgfip.xemelios.txt2xml.Txt2Xml;

public class FacturesSansEngagementTiersTxt2Xml extends AbstractTxt2Xml implements Txt2Xml {

    private static final org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(FacturesSansEngagementTiersTxt2Xml.class);
    private final static String ENCODING_TXT = "UTF-8";
    private final static String ENCODING_XML = "ISO-8859-15";
    private final static int LENGTH_ENTETE = 504;
    private final static int LENGTH_LINE = 795;
    private final static int LENGTH_RESPONSABLE= 712;
    private final static int LENGTH_LINE_INCONNUE = 10299;
    private final static int LENGTH_NOTE= 10299;
    private final static String TAG_FEN = "FEN0052A";
    private final static String TAG_ETAT = "FACTURE";
    private final static String TAG_ENTETE = "ENTETE";
    private final static String TAG_LIGNE = "LIGNE_POSTE";
    private final static String TAG_RESPONSABLE = "RESPONSABLE";
    private final static String TAG_NOTE = "LIGNE_NOTE";
    private final static String NAMESPACE = "FEN0052A";
    private final static String TAG_LIGNE_INCONNUE = "LIGNE_INCONNUE";

    

    public FacturesSansEngagementTiersTxt2Xml() {
        super();
    }
    /*
    public static void main(final String[] args) {
    DpDirecteTxt2Xml thisDP = new DpDirecteTxt2Xml();
    thisDP.transform(new File("C:/TEMP/AIFE/FEN0029A/FEN0029A_SIS001_SIS001002900151"));
    }         
     */

    public boolean isXmlFile(File input, String encoding) {
        boolean ret = false;
        try {
            BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(input), encoding));
            String line = br.readLine();
            int i = 0;
            while (line != null) {
                if (line.trim().length() > 0) {
                    i++;
                    if (i == 1 && line.trim().matches("[<][?]xml version[=].* encoding[=].*[?][>]")) {
                        return true;
                    } else {
                        return false;
                    }
                }
                line = br.readLine();
            }
        } catch (Exception e) {
            logger.debug("Problème dans isXmlFile() :\n", e);
        }
        return ret;
    }

    public File transform(File f) {
        File ret = null;
        try {
            if (isXmlFile(f, ENCODING_TXT)) {
                ret = f;
            } else {
                ret = makeTransformFacturesSansEngagementTiers(f);
            }
        } catch (Exception e) {
            logger.debug("Problème de transformation du flux !", e);
        }
        return ret;
    }

    /**
     * @param f
     * @return
     * @throws IOException
     */
    private File makeTransformFacturesSansEngagementTiers(File f) throws IOException {

//		File outputFile = new File("C:/TEMP/AIFE", "tmp-"+f.getName()+".xml"); /* Avec la main */
        File outputFile = new File(System.getProperty("java.io.tmpdir"), f.getName());
        outputFile.createNewFile();

        FileOutputStream fos = null;
        FileInputStream fis = null;
        try {
            fos = new FileOutputStream(outputFile);
            fos.write(("<?xml version=\"1.0\" encoding=\"" + ENCODING_XML + "\"?>\n<"+TAG_FEN+" xmlns=\""+NAMESPACE+"\" xmlns:txt2xml=\"http://www.xemelios.org/namespaces#txt2xml\">\n").getBytes(ENCODING_XML));
            fis = new FileInputStream(f);
            BufferedReader br = new BufferedReader(new InputStreamReader(fis, ENCODING_TXT));
            String line = br.readLine();
            int nbLignesParcourues = 0;
            while (line != null) {
                nbLignesParcourues++;
                if (line.trim().length() > 0) {
                    if (line.substring(0, 1).equals("E")) {
                        fos.write(makeTranformEntete(line, nbLignesParcourues));
                    } else if (line.substring(0, 1).equals("P")) {
                        fos.write(makeTranformLine(line, nbLignesParcourues));  
                    }
                    else if (line.substring(0, 1).equals("R")) {
                        fos.write(makeTranformResponsable(line, nbLignesParcourues));
                    }
                    else if (line.substring(0, 1).equals("T")) {
                        fos.write(makeTranformNote(line, nbLignesParcourues));
                    }
                    else if ((!line.substring(0, 1).equals("E"))&& (!line.substring(0, 1).equals("P"))&& (!line.substring(0, 1).equals("R"))&& (!line.substring(0, 1).equals("T"))&& (!line.substring(0, 1).equals("L"))) {
                        System.out.println("isLineUnknown!");                  	
                                            fos.write(makeTranformLineInconnue(line, nbLignesParcourues)); 
                                        }
                }
                line = br.readLine();
            }
            fos.write(("\t</"+TAG_ETAT+">\n</"+TAG_FEN+">").getBytes(ENCODING_XML));
            fos.flush();
        } catch (UnsupportedEncodingException uee) {
            logger.debug("Problème d'écriture avec encoding !");
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (fos != null) {
                fos.close();
            }
            if (fis != null) {
                fis.close();
            }
        }
        logger.info("Le fichier de sortie de transformation se trouve ici : " + outputFile.getAbsolutePath());
        return outputFile;
    }

    private byte[] makeTranformEntete(String line, int nbLignesParcourues) throws UnsupportedEncodingException {
        StringBuffer sb = null;
        if (nbLignesParcourues > 1) {
            sb = new StringBuffer("\t</"+TAG_ETAT+">\n\t<"+TAG_ETAT+">\n\t\t<"+TAG_ENTETE+" txt2xml:LineTxt=\"" + nbLignesParcourues + "\">\n");
        } else {
            sb = new StringBuffer("\t<"+TAG_ETAT+">\n\t\t<"+TAG_ENTETE+" txt2xml:LineTxt=\"" + nbLignesParcourues + "\">\n");
        }
        /* Compris entre LENGTH_ENTETE-2 && LENGTH_ENTETE */
        if ( line.length() >= LENGTH_ENTETE-1) {
            /* Variables à récupérer
             * 		Lot3 - Format pivot AE FEN0070A - Réception des demandes de paiement directes V2.2.doc
             */
            try {           
        
                String typeTitre = line.substring(1, 2);
                String idAmg = line.substring(2, 8);
                String idTitreAmg = line.substring(8, 48);
                String compCode = line.substring(48, 52);
                String docDate = line.substring(52, 60);
                String texte1 = line.substring(60, 85);
                String currency  = line.substring(85, 90);
                String numDossier = line.substring(90, 120);
                String texteLib = line.substring(120, 180);
                String reference = line.substring(180, 196);
                String numFact  = line.substring(196, 236);
                String typeFux = line.substring(236, 237);
                String codeLib = line.substring(237, 239);
                String codepaysosd = line.substring(239, 253);
                
                
                sb.append("\t\t\t<TYPE_TITRE txt2xml:TxtValue=\"").append(typeTitre).append("\">").append(typeTitre.trim()).append("</TYPE_TITRE>\n");
                sb.append("\t\t\t<ID_AMG txt2xml:TxtValue=\"").append(idAmg).append("\">").append(idAmg.trim()).append("</ID_AMG>\n");
                sb.append("\t\t\t<ID_TITRE_AMG txt2xml:TxtValue=\"").append(idTitreAmg).append("\">").append(idTitreAmg.trim()).append("</ID_TITRE_AMG>\n");
                sb.append("\t\t\t<COMP_CODE txt2xml:TxtValue=\"").append(compCode).append("\">").append(compCode.trim()).append("</COMP_CODE>\n");
                              
                if (docDate.trim().length() > 0) {

                sb.append("\t\t\t<DOC_DATE txt2xml:TxtValue=\"").append(docDate).append("\">").append(docDate.trim()).append("</DOC_DATE>\n");
                }
                if (texte1.trim().length() > 0) {
                sb.append("\t\t\t<TEXTE1 txt2xml:TxtValue=\"").append(texte1).append("\">").append(texte1.trim()).append("</TEXTE1>\n");
                }
                sb.append("\t\t\t<CURRENCY txt2xml:TxtValue=\"").append(currency).append("\">").append(currency.trim()).append("</CURRENCY>\n");
                
                if (numDossier.trim().length() > 0) {
                sb.append("\t\t\t<NUM_DOSSIER txt2xml:TxtValue=\"").append(numDossier).append("\">").append(numDossier.trim()).append("</NUM_DOSSIER>\n");
                }
                
                if (texteLib.trim().length() > 0) {
                sb.append("\t\t\t<TEXTE_LIB txt2xml:TxtValue=\"").append(texteLib).append("\">").append(texteLib.trim()).append("</TEXTE_LIB>\n");
                }
                sb.append("\t\t\t<REFERENCE txt2xml:TxtValue=\"").append(reference).append("\">").append(reference.trim()).append("</REFERENCE>\n");
               
                if (numFact.trim().length() > 0) {
                sb.append("\t\t\t<NUM_FACT txt2xml:TxtValue=\"").append(numFact).append("\">").append(numFact.trim()).append("</NUM_FACT>\n");
                
                }
                if (typeFux.trim().length() > 0) {
                sb.append("\t\t\t<TYPE_FLUX txt2xml:TxtValue=\"").append(typeFux).append("\">").append(typeFux.trim()).append("</TYPE_FLUX>\n");
                }
                
                if (codeLib.trim().length() > 0) {
                sb.append("\t\t\t<CODE_LIB txt2xml:TxtValue=\"").append(codeLib).append("\">").append(codeLib.trim()).append("</CODE_LIB>\n");
                }
                
                if (codepaysosd.trim().length() > 0) {
                    sb.append("\t\t\t<CODE_PAYS_OSD txt2xml:TxtValue=\"").append(codepaysosd).append("\">").append(codepaysosd.trim()).append("</CODE_PAYS_OSD>\n");
                    } 
                
                
            } catch (Exception e) {
                System.out.println("ENTETE : Erreur de transfmormation : " + line);
            }
        }
        sb.append("\t\t</"+TAG_ENTETE+">\n");
        return sb.toString().getBytes(ENCODING_XML);
    }

    private byte[] makeTranformLine(String line, int nbLignesParcourues) throws UnsupportedEncodingException {
        StringBuffer sb = new StringBuffer("\t\t<"+TAG_LIGNE+" txt2xml:LineTxt=\"" + nbLignesParcourues + "\">\n");
        if ( line.length() >= LENGTH_LINE-1) { 
        
            String  typeTitre  = line.substring(1, 2);
            String  idAmg = line.substring(2, 8);
            String  idTitreAmg = line.substring(8, 48);
            String  poste= line.substring(48, 51);
            String  posteTexte = line.substring(51, 101);
            String  compt = line.substring(101, 107);
            String  montant = line.substring(107, 119);
            String  affectation = line.substring(119, 131);
            String  compteGene = line.substring(131, 141);
            String  idFonctTiers= line.substring(141, 221);
            String  typeTiers= line.substring(221, 222);
            String  crComptes= line.substring(222, 226);
            String  cmmtItem= line.substring(226, 232);
            String  pmnttres= line.substring(232, 234);
            String  fund = line.substring(234, 244);
            String  pymtMeth= line.substring(244, 245);
            String  idFonctCompt= line.substring(245, 325);
            String  costCentre = line.substring(325, 335);
            String  profitCtr = line.substring(335, 345);
            String  fondsCtr = line.substring(345, 361);
            String  foncArea = line.substring(361, 377);
            String  acrivite= line.substring(377, 401);
            String  taxCode = line.substring(401, 403);
            String  wbsElemE= line.substring(403, 427);
            String  natureMinist= line.substring(427, 438);
            String  localMinst= line.substring(438, 460);
            String  localInterMinist= line.substring(460, 468);
            String  cper= line.substring(468, 483);
            String  presage= line.substring(483, 498);
            String  axe1= line.substring(498, 520);
            String  tFonc= line.substring(520, 544);
        
            sb.append("\t\t\t<TYPE_TITRE txt2xml:TxtValue=\"").append(typeTitre).append("\">").append(typeTitre.trim()).append("</TYPE_TITRE>\n");
            sb.append("\t\t\t<ID_AMG txt2xml:TxtValue=\"").append(idAmg).append("\">").append(idAmg.trim()).append("</ID_AMG>\n");
            sb.append("\t\t\t<ID_TITRE_AMG txt2xml:TxtValue=\"").append(idTitreAmg).append("\">").append(idTitreAmg.trim()).append("</ID_TITRE_AMG>\n");
            sb.append("\t\t\t<POSTE txt2xml:TxtValue=\"").append(poste).append("\">").append(poste.trim()).append("</POSTE>\n");
          
             if (posteTexte.trim().length() > 0) {
            sb.append("\t\t\t<POSTE_TEXTE txt2xml:TxtValue=\"").append(posteTexte).append("\">").append(posteTexte.trim()).append("</POSTE_TEXTE>\n");
            }
            
            sb.append("\t\t\t<COMPT txt2xml:TxtValue=\"").append(compt).append("\">").append(compt.trim()).append("</COMPT>\n");
            sb.append("\t\t\t<MONTANT txt2xml:TxtValue=\"").append(montant).append("\">").append(montant.trim()).append("</MONTANT>\n");
            sb.append("\t\t\t<AFFECTATION txt2xml:TxtValue=\"").append(affectation).append("\">").append(affectation.trim()).append("</AFFECTATION>\n");
            sb.append("\t\t\t<COMPTE_GENE txt2xml:TxtValue=\"").append(compteGene).append("\">").append(compteGene.trim()).append("</COMPTE_GENE>\n");
            sb.append("\t\t\t<ID_FONCT_TIERS txt2xml:TxtValue=\"").append(idFonctTiers).append("\">").append(idFonctTiers.trim()).append("</ID_FONCT_TIERS>\n");
            sb.append("\t\t\t<TYPE_TIERS txt2xml:TxtValue=\"").append(typeTiers).append("\">").append(typeTiers.trim()).append("</TYPE_TIERS>\n");
            sb.append("\t\t\t<GR_COMPTES txt2xml:TxtValue=\"").append(crComptes).append("\">").append(crComptes.trim()).append("</GR_COMPTES>\n");
            sb.append("\t\t\t<CMMT_ITEM txt2xml:TxtValue=\"").append(cmmtItem).append("\">").append(cmmtItem.trim()).append("</CMMT_ITEM>\n");
                
           
            if (pmnttres.trim().length() > 0) {
            sb.append("\t\t\t<PMNTTRMS txt2xml:TxtValue=\"").append(pmnttres).append("\">").append(pmnttres.trim()).append("</PMNTTRMS>\n");
            }
            if (fund.trim().length() > 0) {
                sb.append("\t\t\t<FUND txt2xml:TxtValue=\"").append(fund).append("\">").append(fund.trim()).append("</FUND>\n");
            }
           
            if (pymtMeth.trim().length() > 0) {
            sb.append("\t\t\t<PYMT_METH txt2xml:TxtValue=\"").append(pymtMeth).append("\">").append(pymtMeth.trim()).append("</PYMT_METH>\n");
            }
            if (idFonctCompt.trim().length() > 0) {
                sb.append("\t\t\t<ID_FONCT_COMPT txt2xml:TxtValue=\"").append(idFonctCompt).append("\">").append(idFonctCompt.trim()).append("</ID_FONCT_COMPT>\n");
            }
            if (costCentre.trim().length() > 0) {
                sb.append("\t\t\t<COST_CENTER txt2xml:TxtValue=\"").append(costCentre).append("\">").append(costCentre.trim()).append("</COST_CENTER>\n");
            }
            
            sb.append("\t\t\t<PROFIT_CTR txt2xml:TxtValue=\"").append(profitCtr).append("\">").append(profitCtr.trim()).append("</PROFIT_CTR>\n");
            sb.append("\t\t\t<FUNDS_CTR txt2xml:TxtValue=\"").append(fondsCtr).append("\">").append(fondsCtr.trim()).append("</FUNDS_CTR>\n");
          
  
            if (foncArea.trim().length() > 0) {
                sb.append("\t\t\t<FUNC_AREA txt2xml:TxtValue=\"").append(foncArea).append("\">").append(foncArea.trim()).append("</FUNC_AREA>\n");
            }
            if (acrivite.trim().length() > 0) {
                sb.append("\t\t\t<ACTIVITE txt2xml:TxtValue=\"").append(acrivite).append("\">").append(acrivite.trim()).append("</ACTIVITE>\n");
            }
            
            if (taxCode.trim().length() > 0) {
                sb.append("\t\t\t<TAX_CODE txt2xml:TxtValue=\"").append(taxCode).append("\">").append(taxCode.trim()).append("</TAX_CODE>\n");
            }
            
            if (wbsElemE.trim().length() > 0) {
                sb.append("\t\t\t<WBS_ELEM_E txt2xml:TxtValue=\"").append(wbsElemE).append("\">").append(wbsElemE.trim()).append("</WBS_ELEM_E>\n");
            }
            if (natureMinist.trim().length() > 0) {
                sb.append("\t\t\t<NATURE_MINIST txt2xml:TxtValue=\"").append(natureMinist).append("\">").append(natureMinist.trim()).append("</NATURE_MINIST>\n");
            }
            if (localMinst.trim().length() > 0) {
                sb.append("\t\t\t<LOCAL_MINIST txt2xml:TxtValue=\"").append(localMinst).append("\">").append(localMinst.trim()).append("</LOCAL_MINIST>\n");
            }
            if (localInterMinist.trim().length() > 0) {
                sb.append("\t\t\t<LOCAL_INTER_MINIST txt2xml:TxtValue=\"").append(localInterMinist).append("\">").append(localInterMinist.trim()).append("</LOCAL_INTER_MINIST>\n");
            }
            if (cper.trim().length() > 0) {
                sb.append("\t\t\t<CPER txt2xml:TxtValue=\"").append(cper).append("\">").append(cper.trim()).append("</CPER>\n");
            }
            if (presage.trim().length() > 0) {
                sb.append("\t\t\t<PRESAGE txt2xml:TxtValue=\"").append(presage).append("\">").append(presage.trim()).append("</PRESAGE>\n");
            }
            
            if (axe1.trim().length() > 0) {
                sb.append("\t\t\t<AXE1 txt2xml:TxtValue=\"").append(axe1).append("\">").append(axe1.trim()).append("</AXE1>\n");
            }
            
            if (tFonc.trim().length() > 0) {
                sb.append("\t\t\t<TRC_FONC txt2xml:TxtValue=\"").append(tFonc).append("\">").append(tFonc.trim()).append("</TRC_FONC>\n");
            }
        }
        sb.append("\t\t</"+TAG_LIGNE+">\n");
        return sb.toString().getBytes(ENCODING_XML);
    }
    
    private byte[] makeTranformResponsable(String line, int nbLignesParcourues) throws UnsupportedEncodingException {
        StringBuffer sb = new StringBuffer("\t\t<"+TAG_RESPONSABLE+" txt2xml:LineTxt=\"" + nbLignesParcourues + "\">\n");
        if ( line.length() >= LENGTH_RESPONSABLE-1) { 
        
            String  typeTitre  = line.substring(1, 2);			
            String  idAmg = line.substring(2, 8);			
            String  idTitreAmg = line.substring(8, 48);			
            String  nomResp= line.substring(48, 88);			
            String  prenomResp = line.substring(88, 128);			
            String  qualResp = line.substring(128, 168);			
            String  service = line.substring(168, 208);			
            String  contact = line.substring(208, 278);			
            String  numRue = line.substring(278, 284);			
            String  nomRue= line.substring(284, 314); 			
            String  cp= line.substring(314, 324);			
            String  city= line.substring(324, 359);			
            String  country= line.substring(359, 361);			
            String  telner= line.substring(361, 386);			
            String  faxnr = line.substring(386, 411);			
            String  email= line.substring(411, 461);			


            sb.append("\t\t\t<TYPE_TITRE txt2xml:TxtValue=\"").append(typeTitre).append("\">").append(typeTitre.trim()).append("</TYPE_TITRE>\n");
            sb.append("\t\t\t<ID_AMG txt2xml:TxtValue=\"").append(idAmg).append("\">").append(idAmg.trim()).append("</ID_AMG>\n");
            sb.append("\t\t\t<ID_TITRE_AMG txt2xml:TxtValue=\"").append(idTitreAmg).append("\">").append(idTitreAmg.trim()).append("</ID_TITRE_AMG>\n");
            
            if (nomResp.trim().length() > 0) {
            sb.append("\t\t\t<NOM_RESP txt2xml:TxtValue=\"").append(nomResp).append("\">").append(nomResp.trim()).append("</NOM_RESP>\n");
            }
             if (prenomResp.trim().length() > 0) {
            sb.append("\t\t\t<PRENOM_RESP txt2xml:TxtValue=\"").append(prenomResp).append("\">").append(prenomResp.trim()).append("</PRENOM_RESP>\n");
            }
             if (qualResp.trim().length() > 0) {
            sb.append("\t\t\t<QUAL_RESP txt2xml:TxtValue=\"").append(qualResp).append("\">").append(qualResp.trim()).append("</QUAL_RESP>\n");
             }           
             if (service.trim().length() > 0) {
            sb.append("\t\t\t<SERVICE txt2xml:TxtValue=\"").append(service).append("\">").append(service.trim()).append("</SERVICE>\n");
             }
             if (contact.trim().length() > 0) {
           sb.append("\t\t\t<CONTACT txt2xml:TxtValue=\"").append(contact).append("\">").append(contact.trim()).append("</CONTACT>\n");
             }
             if (numRue.trim().length() > 0) {
            sb.append("\t\t\t<NUM_RUE txt2xml:TxtValue=\"").append(numRue).append("\">").append(numRue.trim()).append("</NUM_RUE>\n");
             }
             if (nomRue.trim().length() > 0) {
           sb.append("\t\t\t<NOM_RUE txt2xml:TxtValue=\"").append(nomRue).append("\">").append(nomRue.trim()).append("</NOM_RUE>\n");
             }
             if (cp.trim().length() > 0) {
            sb.append("\t\t\t<CP txt2xml:TxtValue=\"").append(cp).append("\">").append(cp.trim()).append("</CP>\n");
             }
             if (city.trim().length() > 0) {
            sb.append("\t\t\t<CITY txt2xml:TxtValue=\"").append(city).append("\">").append(city.trim()).append("</CITY>\n");
             }
             if (country.trim().length() > 0) {
             sb.append("\t\t\t<COUNTRY txt2xml:TxtValue=\"").append(country).append("\">").append(country.trim()).append("</COUNTRY>\n");
             }       
            if (telner.trim().length() > 0) {
            sb.append("\t\t\t<TELNR txt2xml:TxtValue=\"").append(telner).append("\">").append(telner.trim()).append("</TELNR>\n");
            }
            if (faxnr.trim().length() > 0) {
                sb.append("\t\t\t<FAXNR txt2xml:TxtValue=\"").append(faxnr).append("\">").append(faxnr.trim()).append("</FAXNR>\n");
            }
            if (email.trim().length() > 0) {
            sb.append("\t\t\t<EMAIL txt2xml:TxtValue=\"").append(email).append("\">").append(email.trim()).append("</EMAIL>\n");
            }
           
        }
        sb.append("\t\t</"+TAG_RESPONSABLE+">\n");
        return sb.toString().getBytes(ENCODING_XML);
    }
    
    
    private byte[] makeTranformNote(String line, int nbLignesParcourues) throws UnsupportedEncodingException {
        StringBuffer sb = new StringBuffer("\t\t<"+TAG_NOTE+" txt2xml:LineTxt=\"" + nbLignesParcourues + "\">\n");
        if (line.length() >= LENGTH_NOTE-1) { 
        
            String  typeTitre  = line.substring(1, 2);
            String  idAmg = line.substring(2, 8);
            String idTitreAmg = line.substring(8, 48);
            String  texte= line.substring(48, 10049);

            sb.append("\t\t\t<TYPE_TITRE txt2xml:TxtValue=\"").append(typeTitre).append("\">").append(typeTitre.trim()).append("</TYPE_TITRE>\n");
            sb.append("\t\t\t<ID_AMG txt2xml:TxtValue=\"").append(idAmg).append("\">").append(idAmg.trim()).append("</ID_AMG>\n");
            sb.append("\t\t\t<ID_TITRE_AMG txt2xml:TxtValue=\"").append(idTitreAmg).append("\">").append(idTitreAmg.trim()).append("</ID_TITRE_AMG>\n");
            sb.append("\t\t\t<TEXTE txt2xml:TxtValue=\"").append(texte).append("\">").append(texte.trim()).append("</TEXTE>\n");
      
            
        }
        sb.append("\t\t</"+TAG_NOTE+">\n");
        return sb.toString().getBytes(ENCODING_XML);
  }
    
    private byte[] makeTranformLineInconnue(String line, int nbLignesParcourues) throws UnsupportedEncodingException {
   	 System.out.println("makeTranformLine : "+line);
        StringBuffer sb = new StringBuffer("\t\t<"+TAG_LIGNE_INCONNUE+" txt2xml:LineTxt=\"" + nbLignesParcourues + "\">\n");
        if (line.trim().length() != 0) {
            sb.append("\t\t\t<LIGNE_INCONNUE txt2xml:TxtValue=\"").append(line).append("\">").append(line.trim()).append("</LIGNE_INCONNUE>\n");
        }
        sb.append("\t\t</"+TAG_LIGNE_INCONNUE+">\n");
        return sb.toString().getBytes(ENCODING_XML);
    }  
    
}
