Java - Place text between list values

0

I am using the StrSubtitutor to create parts of a document that will be previewed in a window with ckeditor. The question is that I need to use some lists of objects for some data and must have some texts in between, explain with an example:

Chain patron:

The employee (s)

 ${listaobjetos} 
 ${objeto.nombre}

with the code

 ${objeto.codigo} 

I realize I was logged in last time

 ${objeto.utimasesion} 
 ${finlistaobjetos}

Then I discovered that in the apache libres libres has a class called StrSubstitutor that allows me to replace variables in text strings and together with StrLookup I can load the list of variables that I have stored in the DB, but, in the documentation it does not specifies nothing about these cases. Try activating the recursivities of StrSubstitutor without any results.

In this way, I come to you so that you can guide me in this because I have little experience with this type of chain treatment.

    
asked by darkpastiurs 05.01.2018 в 17:54
source

1 answer

1

I think you can solve it by applying an algorithm that you can develop yourself, unless you have to have a structure with parameters and then replace it with what you need. Ejm:

public class Plantillas {

String documento = "empresa.Nombre\n"+
                   "empresa.Domicilio\n"+ 
                   "empresa.Ciudad, empresa.Pais\n"+

                    "Atte. D pto. de personal o Recursos Humanos Ciudad\n"+

                    "fecha.dia/fecha.mes/fecha.año\n"+
                    "Estimados señores:\n"+
                    "Por medio de la presente, dejo asentada mi decisión de terminar mi relación laborar con\n"+ 
                    "esta empresa a partir del DD/MM/AA\n"+

                    "Solo  me  motiva  esta  decisión  asuntos  profesionales  que  ustedes  seguramente  podrán"+ 
                    "comprender, pues necesito desarrollar mis habilidades como mis conocimientos para los" +
                    "que  me  he  formado  y  no puedo  perder  la  oportunidad  de  cumplir  mi  desarrollo"+ 
                    "profesional en otra empresa. Hoy  doy  a  conocer  esta  decisión  cumpliendo  con  el  plazo  que  establece  la  ley,  dos"+ 
                    "meses  antes  de  finalizar  mi  relación  laboral  el DD/MM/AA. Fecha  en  la  cual  ya  no" +
                    "perteneceré al personal de esta empresa. No obstante quiero dejarles en claro mi satisfacción por la confianza que han depositado"+ 
                    "en mí, durante el tiempo que pertenecí al personal con el que transcurrí mis días."+
                    "Les  agradezco  también  por  haberme  dado  la  o portunidad  de  conocer  la  gran  calidad"+ 
                    "humana de todo el personal de esta empresa, donde también pude desarrollarme.";

public void sustituirPalabrasClaves(){
    documento = documento.replaceAll("empresa.Nombre", "NESTLE");
    documento = documento.replaceAll("empresa.Domicilio", "Aragua");
    documento = documento.replaceAll("empresa.Ciudad", "Santa Cruz");
    documento = documento.replaceAll("empresa.Pais", "Venezuela");

    documento = documento.replaceAll("fecha.dia", "07");
    documento = documento.replaceAll("fecha.mes", "01");
    documento = documento.replaceAll("fecha.año", "2018");

    System.out.println("Texto final: \n"+documento);



}
    
answered by 07.01.2018 / 15:35
source