import java.util.List;
import org.jdom.Document;
import org.jdom.Element;
/*
* Adaptado por Daniel Moros y Yannixia Castellanos de proyecto\
de Sergio Naranjos
* Proyecto de Grado
* Tutor Kenyer Dominguez
* Ultima Fecha Modificacion: Febrero de 2010
* Notas:
* - Mejorada la eficiencia, mantenibilidad y escalabilidad.
* - Agregada Documentacion
*
*/
/**
* Clase encargada de transformar los datos que están \
contenidos en forma de lista
* a un documento XML.
* @author Yannixia Castellanos, Daniel Moros y Sergio Naranjo
*/
public class TransformXML
{
/*
* Funcion que genera un documento XML con los datos requeridos.
* Funciona para exportar actividades del tipo: "InProceedings",\
"Article",
* "InBook","Book","TechReport","Project","ProjectOfDegree" y\
"Award".
*/
/**
* Funcion que genera un documento XML con los datos requeridos.
* Funciona para exportar actividades del tipo: "InProceedings",\
"Article",
* "InBook","Book","TechReport","Project","ProjectOfDegree" y "Award".
* @param datos
* @return Document con el documento generado.
*/
public static Document transformarDatosAXML(List datos) {
Element diddata = new Element("DIDdata");
Document doc = new Document(diddata);
//Creacion del XML
try{
while (!datos.isEmpty()) {
int k = 0;
String tipo = (datos.get(0)).toString();
datos.remove(0);
if(tipo.equals("InProceedings"))
inProceedingsToXML(diddata,datos);
if(tipo.equals("Article"))
ArticleToXML(diddata,datos);
if (tipo.equals("InBook"))
InBookToXML(diddata,datos);
if (tipo.equals("Book"))
BookToXML(diddata,datos);
if (tipo.equals("TechReport"))
TechReportToXML(diddata,datos);
if (tipo.equals("Project"))
ProjectToXML(diddata,datos);
if (tipo.equals("ProjectOfDegree"))
ProjectOfDegreeToXML(diddata,datos);
if(tipo.equals("Award"))
AwardToXML(diddata,datos);
/* Si no cumple con ninguna de las anteriores entonces es
alguna actividad no esperada para exportar */
}
}
catch(Exception e) { System.out.println(e);}
//Fin Creacion del XML
return doc;
}
/**
* Genera la estructura interna de una actividad del tipo Memoria\
contenido
* en la List 'datos'. Coloca su resultado en el Elment 'diddata'
* @param diddata Element donde se irán a~nadiendo los datos\
y etiquetas
* necesarias.
* @param datos List con los datos organizados de actividades a \
procesar.
*/
private static void inProceedingsToXML(Element diddata, List datos) {
String title = (datos.get(0)).toString();datos.remove(0);
String congreso = (datos.get(0)).toString();datos.remove(0);
String ciudad = (datos.get(0)).toString();datos.remove(0);
String pais = (datos.get(0)).toString();datos.remove(0);
String fecha = (datos.get(0)).toString();datos.remove(0);
String year = fecha.substring(0,4);
String month = fecha.substring(8,10);
String nombremedio = (datos.get(0)).toString();datos.remove(0);
String volumen = (datos.get(0)).toString(); datos.remove(0);
String paginicial = (datos.get(0)).toString();datos.remove(0);
String pagfinal = (datos.get(0)).toString();datos.remove(0);
String ISBN = (datos.get(0)).toString();datos.remove(0);
String note = (datos.get(0)).toString(); datos.remove(0);
String fechaIngreso = (datos.get(0)).toString();datos.remove(0);
int mails_size = ((List)(datos.get(0))).size();
Element InProceedings_xml = new Element("InProceedings");
diddata.addContent(InProceedings_xml);
Element autores_xml = new Element("Autores");
Element title_xml = new Element("title");
Element congreso_xml = new Element("congreso");
Element ciudad_xml = new Element("ciudad");
Element pais_xml = new Element("pais");
Element OPTyear_xml = new Element("OPTyear");
Element OPTmonth_xml = new Element("OPTmonth");
Element nombremedio_xml = new Element("nombremedio");
Element volumen_xml = new Element("volumen");
Element paginicial_xml = new Element("paginicial");
Element pagfinal_xml = new Element("pagfinal");
Element ISBN_xml = new Element("ISBN");
Element OPTnote_xml = new Element("OPTnote");
Element DIDingreso_xml = new Element("DIDingreso");
//Estructura
InProceedings_xml.addContent(autores_xml);
InProceedings_xml.addContent(title_xml);
InProceedings_xml.addContent(congreso_xml);
InProceedings_xml.addContent(ciudad_xml);
InProceedings_xml.addContent(pais_xml);
InProceedings_xml.addContent(OPTyear_xml);
InProceedings_xml.addContent(OPTmonth_xml);
InProceedings_xml.addContent(nombremedio_xml);
InProceedings_xml.addContent(volumen_xml);
InProceedings_xml.addContent(paginicial_xml);
InProceedings_xml.addContent(pagfinal_xml);
InProceedings_xml.addContent(ISBN_xml);
InProceedings_xml.addContent(OPTnote_xml);
InProceedings_xml.addContent(DIDingreso_xml);
//Valores
int kk = 0;
while (kk < mails_size) {
Element author_xml = new Element("Author");
Element OPTemail_xml = new Element("OPTemail");
autores_xml.addContent(author_xml);
author_xml.addContent(OPTemail_xml);
String correo_t = ((List)(datos.get(0))).get(kk).toString();
OPTemail_xml.setText(correo_t);
kk++;
}
datos.remove(0);
title_xml.setText(title);
congreso_xml.setText(congreso);
ciudad_xml.setText(ciudad);
pais_xml.setText(pais);
OPTyear_xml.setText(year);
OPTmonth_xml.setText(month);
nombremedio_xml.setText(nombremedio);
volumen_xml.setText(volumen);
paginicial_xml.setText(paginicial);
pagfinal_xml.setText(pagfinal);
ISBN_xml.setText(ISBN);
OPTnote_xml.setText(note);
DIDingreso_xml.setText(fechaIngreso);
}
/**
* Genera la estructura interna de una actividad del tipo Articulo\
de Revista contenido
* en la List 'datos'. Coloca su resultado en el Elment 'diddata'
* @param diddata Element donde se irán a~nadiendo los datos \
y etiquetas
* necesarias.
* @param datos List con los datos organizados de actividades a procesar.
*/
private static void ArticleToXML(Element diddata, List datos) {
String title = (datos.get(0)).toString();datos.remove(0);
String journal = (datos.get(0)).toString();datos.remove(0);
String fecha = (datos.get(0)).toString();datos.remove(0);
String year = fecha.substring(0,4);
String month = fecha.substring(8,10);
String volumen = (datos.get(0)).toString();datos.remove(0);
String pagini = (datos.get(0)).toString();datos.remove(0);
String pagfin = (datos.get(0)).toString();datos.remove(0);
String note = (datos.get(0)).toString();datos.remove(0);
String indice = (datos.get(0)).toString();datos.remove(0);
String fechaIngreso = (datos.get(0)).toString();datos.remove(0);
int mails_size = ((List)(datos.get(0))).size();
Element Article_xml = new Element("Article");
diddata.addContent(Article_xml);
Element autores_xml = new Element("Autores");
Element title_xml = new Element("title");
Element journal_xml = new Element("journal");
Element OPTyear_xml = new Element("OPTyear");
Element OPTmonth_xml = new Element("OPTmonth");
Element volume_xml = new Element("volume");
Element pagini_xml = new Element("pagini");
Element pagfin_xml = new Element("pagfin");
Element OPTnote_xml = new Element("OPTnote");
Element indice_xml = new Element("indice");
Element DIDingreso_xml = new Element("DIDingreso");
//Estructura
Article_xml.addContent(autores_xml);
Article_xml.addContent(title_xml);
Article_xml.addContent(journal_xml);
Article_xml.addContent(OPTyear_xml);
Article_xml.addContent(OPTmonth_xml);
Article_xml.addContent(volume_xml);
Article_xml.addContent(pagini_xml);
Article_xml.addContent(pagfin_xml);
Article_xml.addContent(OPTnote_xml);
Article_xml.addContent(indice_xml);
Article_xml.addContent(DIDingreso_xml);
//Valores
int kk = 0;
while (kk < mails_size) {
Element author_xml = new Element("Author");
Element OPTemail_xml = new Element("OPTemail");
autores_xml.addContent(author_xml);
author_xml.addContent(OPTemail_xml);
String correo_t = ((List)(datos.get(0))).get(kk).toString();
OPTemail_xml.setText(correo_t);
kk++;
}
datos.remove(0);
title_xml.setText(title);
journal_xml.setText(journal);
OPTyear_xml.setText(year);
OPTmonth_xml.setText(month);
volume_xml.setText(volumen);
pagini_xml.setText(pagini);
pagfin_xml.setText(pagfin);
OPTnote_xml.setText(note);
indice_xml.setText(indice);
DIDingreso_xml.setText(fechaIngreso);
}
/**
* Genera la estructura interna de una actividad del tipo Cap'itulo \
de Libros contenido
* en la List 'datos'. Coloca su resultado en el Elment 'diddata'
* @param diddata Element donde se irán a~nadiendo los datos y \
etiquetas
* necesarias.
* @param datos List con los datos organizados de actividades a procesar.
*/
private static void InBookToXML(Element diddata, List datos) {
String title = (datos.get(0)).toString();datos.remove(0);
String editorial = (datos.get(0)).toString();datos.remove(0);
String editores = (datos.get(0)).toString();datos.remove(0);
String ciudad = (datos.get(0)).toString();datos.remove(0);
String pais = (datos.get(0)).toString();datos.remove(0);
String fecha = (datos.get(0)).toString();datos.remove(0);
String year = fecha.substring(0,4);
String month = fecha.substring(8,10);
String pagini = (datos.get(0)).toString();datos.remove(0);
String pagfin = (datos.get(0)).toString();datos.remove(0);
String note = (datos.get(0)).toString();datos.remove(0);
String ISBN = (datos.get(0)).toString();datos.remove(0);
String fechaIngreso = (datos.get(0)).toString();datos.remove(0);
int mails_size = ((List)(datos.get(0))).size();
Element InBook_xml = new Element("InBook");
diddata.addContent(InBook_xml);
Element autores_xml = new Element("Autores");
Element title_xml = new Element("title");
Element editorial_xml = new Element("editorial");
Element editores_xml = new Element("editores");
Element ciudad_xml = new Element("ciudad");
Element pais_xml = new Element("pais");
Element OPTyear_xml = new Element("OPTyear");
Element OPTmonth_xml = new Element("OPTmonth");
Element pagini_xml = new Element("pagini");
Element pagfin_xml = new Element("pagfin");
Element OPTnote_xml = new Element("OPTnote");
Element ISBN_xml = new Element("ISBN");
Element DIDingreso_xml = new Element("DIDingreso");
//Estructura
InBook_xml.addContent(autores_xml);
InBook_xml.addContent(title_xml);
InBook_xml.addContent(editorial_xml);
InBook_xml.addContent(editores_xml);
InBook_xml.addContent(ciudad_xml);
InBook_xml.addContent(pais_xml);
InBook_xml.addContent(OPTyear_xml);
InBook_xml.addContent(OPTmonth_xml);
InBook_xml.addContent(pagini_xml);
InBook_xml.addContent(pagfin_xml);
InBook_xml.addContent(OPTnote_xml);
InBook_xml.addContent(ISBN_xml);
InBook_xml.addContent(DIDingreso_xml);
//Valores
int kk = 0;
while (kk < mails_size) {
Element author_xml = new Element("Author");
Element OPTemail_xml = new Element("OPTemail");
autores_xml.addContent(author_xml);
author_xml.addContent(OPTemail_xml);
String correo_t = ((List)(datos.get(0))).get(kk).toString();
OPTemail_xml.setText(correo_t);
kk++;
}
datos.remove(0);
title_xml.setText(title);
editorial_xml.setText(editorial);
editores_xml.setText(editores);
ciudad_xml.setText(ciudad);
pais_xml.setText(pais);
OPTyear_xml.setText(year);
OPTmonth_xml.setText(month);
pagini_xml.setText(pagini);
pagfin_xml.setText(pagfin);
OPTnote_xml.setText(note);
ISBN_xml.setText(ISBN);
DIDingreso_xml.setText(fechaIngreso);
}
/**
* Genera la estructura interna de una actividad del tipo Libros contenido
* en la List 'datos'. Coloca su resultado en el Elment 'diddata'
* @param diddata Element donde se irán a~nadiendo los datos y etiquetas
* necesarias.
* @param datos List con los datos organizados de actividades a procesar.
*/
private static void BookToXML(Element diddata, List datos) {
String title = (datos.get(0)).toString();datos.remove(0);
String editorial = (datos.get(0)).toString();datos.remove(0);
String ciudad = (datos.get(0)).toString();datos.remove(0);
String pais = (datos.get(0)).toString();datos.remove(0);
String fecha = (datos.get(0)).toString();datos.remove(0);
String year = fecha.substring(0,4);
String note = (datos.get(0)).toString();datos.remove(0);
String ISBN = (datos.get(0)).toString(); datos.remove(0);
String fechaIngreso = (datos.get(0)).toString();datos.remove(0);
int mails_size = ((List)(datos.get(0))).size();
Element Book_xml = new Element("Book");
diddata.addContent(Book_xml);
Element autores_xml = new Element("Autores");
Element title_xml = new Element("title");
Element editorial_xml = new Element("editorial");
Element ciudad_xml = new Element("ciudad");
Element pais_xml = new Element("pais");
Element OPTyear_xml = new Element("OPTyear");
Element OPTnote_xml = new Element("OPTnote");
Element ISBN_xml = new Element("ISBN");
Element DIDingreso_xml = new Element("DIDingreso");
//Estructura
Book_xml.addContent(autores_xml);
Book_xml.addContent(title_xml);
Book_xml.addContent(editorial_xml);
Book_xml.addContent(ciudad_xml);
Book_xml.addContent(pais_xml);
Book_xml.addContent(OPTyear_xml);
Book_xml.addContent(OPTnote_xml);
Book_xml.addContent(ISBN_xml);
Book_xml.addContent(DIDingreso_xml);
//Valores
int kk = 0;
while (kk < mails_size) {
Element author_xml = new Element("Author");
Element OPTemail_xml = new Element("OPTemail");
autores_xml.addContent(author_xml);
author_xml.addContent(OPTemail_xml);
String correo_t = ((List)(datos.get(0))).get(kk).toString();
OPTemail_xml.setText(correo_t);
kk++;
}
datos.remove(0);
title_xml.setText(title);
editorial_xml.setText(editorial);
ciudad_xml.setText(ciudad);
pais_xml.setText(pais);
OPTyear_xml.setText(year);
OPTnote_xml.setText(note);
ISBN_xml.setText(ISBN);
DIDingreso_xml.setText(fechaIngreso);
}
/**
* Genera la estructura interna de una actividad del tipo Informes contenido
* en la List 'datos'. Coloca su resultado en el Elment 'diddata'
* @param diddata Element donde se irán a~nadiendo los datos y etiquetas
* necesarias.
* @param datos List con los datos organizados de actividades a procesar.
*/
private static void TechReportToXML(Element diddata, List datos) {
String title = (datos.get(0)).toString();datos.remove(0);
String fecha = (datos.get(0)).toString();datos.remove(0);
String year = fecha.substring(0,4);
String month = fecha.substring(8,10);
String institucion = (datos.get(0)).toString();datos.remove(0);
String evaluadores = (datos.get(0)).toString();datos.remove(0);
String duracion = (datos.get(0)).toString();datos.remove(0);
String note = (datos.get(0)).toString();datos.remove(0);
String fechaIngreso = (datos.get(0)).toString();datos.remove(0);
int mails_size = ((List)(datos.get(0))).size();
Element TechReport_xml = new Element("TechReport");
diddata.addContent(TechReport_xml);
Element autores_xml = new Element("Autores");
Element title_xml = new Element("title");
Element OPTyear_xml = new Element("OPTyear");
Element OPTmonth_xml = new Element("OPTmonth");
Element institucion_xml = new Element("institucion");
Element evaluadores_xml = new Element("evaluadores");
Element duracion_xml = new Element("duracion");
Element OPTnote_xml = new Element("OPTnote");
Element DIDingreso_xml = new Element("DIDingreso");
//Estructura
TechReport_xml.addContent(autores_xml);
TechReport_xml.addContent(title_xml);
TechReport_xml.addContent(OPTyear_xml);
TechReport_xml.addContent(OPTmonth_xml);
TechReport_xml.addContent(institucion_xml);
TechReport_xml.addContent(evaluadores_xml);
TechReport_xml.addContent(duracion_xml);
TechReport_xml.addContent(OPTnote_xml);
TechReport_xml.addContent(DIDingreso_xml);
//Valores
int kk = 0;
while (kk < mails_size) {
Element author_xml = new Element("Author");
Element OPTemail_xml = new Element("OPTemail");
autores_xml.addContent(author_xml);
author_xml.addContent(OPTemail_xml);
String correo_t = ((List)(datos.get(0))).get(kk).toString();
OPTemail_xml.setText(correo_t);
kk++;
}
datos.remove(0);
title_xml.setText(title);
OPTyear_xml.setText(year);
OPTmonth_xml.setText(month);
institucion_xml.setText(institucion);
evaluadores_xml.setText(evaluadores);
duracion_xml.setText(duracion);
OPTnote_xml.setText(note);
DIDingreso_xml.setText(fechaIngreso);
}
/**
* Genera la estructura interna de una actividad del tipo Proyecto contenido
* en la List 'datos'. Coloca su resultado en el Elment 'diddata'
* @param diddata Element donde se irán a~nadiendo los datos y etiquetas
* necesarias.
* @param datos List con los datos organizados de actividades a procesar.
*/
private static void ProjectToXML(Element diddata, List datos) {
String title = (datos.get(0)).toString();datos.remove(0);
String fecha = (datos.get(0)).toString();datos.remove(0);
String duracion = (datos.get(0)).toString(); datos.remove(0);
String monto = (datos.get(0)).toString();datos.remove(0);
String institucion = (datos.get(0)).toString();datos.remove(0);
String resumen = (datos.get(0)).toString();datos.remove(0);
String note = (datos.get(0)).toString();datos.remove(0);
String fechaIngreso = (datos.get(0)).toString();datos.remove(0);
int mails_size = ((List)(datos.get(0))).size();
Element Project_xml = new Element("Project");
diddata.addContent(Project_xml);
Element autores_xml = new Element("Autores");
Element title_xml = new Element("title");
Element fecha_xml = new Element("fecha");
Element duracion_xml = new Element("duracion");
Element monto_xml = new Element("monto");
Element institucion_xml = new Element("institucion");
Element resumen_xml = new Element("resumen");
Element OPTnote_xml = new Element("OPTnote");
Element DIDingreso_xml = new Element("DIDingreso");
//Estructura
Project_xml.addContent(autores_xml);
Project_xml.addContent(title_xml);
Project_xml.addContent(fecha_xml);
Project_xml.addContent(duracion_xml);
Project_xml.addContent(monto_xml);
Project_xml.addContent(institucion_xml);
Project_xml.addContent(resumen_xml);
Project_xml.addContent(OPTnote_xml);
Project_xml.addContent(DIDingreso_xml);
//Valores
int kk = 0;
while (kk < mails_size) {
Element author_xml = new Element("Author");
Element OPTemail_xml = new Element("OPTemail");
autores_xml.addContent(author_xml);
author_xml.addContent(OPTemail_xml);
String correo_t = ((List)(datos.get(0))).get(kk).toString();
OPTemail_xml.setText(correo_t);
kk++;
}
datos.remove(0);
title_xml.setText(title);
fecha_xml.setText(fecha);
duracion_xml.setText(duracion);
monto_xml.setText(monto);
institucion_xml.setText(institucion);
resumen_xml.setText(resumen);
OPTnote_xml.setText(note);
DIDingreso_xml.setText(fechaIngreso);
}
/**
* Genera la estructura interna de una actividad del tipo Proyecto de Grado\
contenido
* en la List 'datos'. Coloca su resultado en el Elment 'diddata'
* @param diddata Element donde se irán a~nadiendo los datos y etiquetas
* necesarias.
* @param datos List con los datos organizados de actividades a procesar.
*/
private static void ProjectOfDegreeToXML(Element diddata, List datos) {
String title = (datos.get(0)).toString();datos.remove(0);
String tituloacademico = (datos.get(0)).toString();datos.remove(0);
String nivel = (datos.get(0)).toString();datos.remove(0);
String perfil = (datos.get(0)).toString();datos.remove(0);
String fecha = (datos.get(0)).toString();datos.remove(0);
String note = (datos.get(0)).toString();datos.remove(0);
String fechaIngreso = (datos.get(0)).toString(); datos.remove(0);
int mails_size = ((List)(datos.get(0))).size();
Element ProjectOfDegree_xml = new Element("ProjectOfDegree");
diddata.addContent(ProjectOfDegree_xml);
Element tutores_xml = new Element("Tutores");
Element title_xml = new Element("title");
Element tituloacademico_xml = new Element("tituloacademico");
Element nivel_xml = new Element("nivel");
Element perfil_xml = new Element("Autor");
Element fecha_xml = new Element("fecha");
Element OPTnote_xml = new Element("OPTnote");
Element DIDingreso_xml = new Element("DIDingreso");
//Estructura
ProjectOfDegree_xml.addContent(tutores_xml);
ProjectOfDegree_xml.addContent(title_xml);
ProjectOfDegree_xml.addContent(tituloacademico_xml);
ProjectOfDegree_xml.addContent(nivel_xml);
ProjectOfDegree_xml.addContent(perfil_xml);
ProjectOfDegree_xml.addContent(fecha_xml);
ProjectOfDegree_xml.addContent(OPTnote_xml);
ProjectOfDegree_xml.addContent(DIDingreso_xml);
//Valores
int kk = 0;
while (kk < mails_size) {
Element autor_xml = new Element("Author");
Element OPTemail_xml = new Element("OPTemail");
tutores_xml.addContent(autor_xml);
autor_xml.addContent(OPTemail_xml);
String correo_t = ((List)(datos.get(0))).get(kk).toString();
OPTemail_xml.setText(correo_t);
kk++;
}
datos.remove(0);
title_xml.setText(title);
tituloacademico_xml.setText(tituloacademico);
nivel_xml.setText(nivel);
perfil_xml.setText(perfil);
fecha_xml.setText(fecha);
OPTnote_xml.setText(note);
DIDingreso_xml.setText(fechaIngreso);
}
/**
* Genera la estructura interna de una actividad del tipo Premio \
contenido
* en la List 'datos'. Coloca su resultado en el Elment 'diddata'
* @param diddata Element donde se irán a~nadiendo los datos \
y etiquetas
* necesarias.
* @param datos List con los datos organizados de actividades a procesar.
*/
private static void AwardToXML(Element diddata, List datos) {
String title = (datos.get(0)).toString();datos.remove(0);
String fecha = (datos.get(0)).toString();datos.remove(0);
String institucion = (datos.get(0)).toString();datos.remove(0);
String note = (datos.get(0)).toString(); datos.remove(0);
String fechaIngreso = (datos.get(0)).toString();datos.remove(0);
int mails_size = ((List)(datos.get(0))).size();
Element Award_xml = new Element("Award");
diddata.addContent(Award_xml);
Element autores_xml = new Element("Autores");
Element title_xml = new Element("title");
Element fecha_xml = new Element("fecha");
Element institucion_xml = new Element("institucion");
Element OPTnote_xml = new Element("OPTnote");
Element DIDingreso_xml = new Element("DIDingreso");
//Estructura
Award_xml.addContent(autores_xml);
Award_xml.addContent(title_xml);
Award_xml.addContent(fecha_xml);
Award_xml.addContent(institucion_xml);
Award_xml.addContent(OPTnote_xml);
Award_xml.addContent(DIDingreso_xml);
//Valores
int kk = 0;
while (kk < mails_size) {
Element author_xml = new Element("Author");
Element OPTemail_xml = new Element("OPTemail");
autores_xml.addContent(author_xml);
author_xml.addContent(OPTemail_xml);
String correo_t = ((List)(datos.get(0))).get(kk).toString();
OPTemail_xml.setText(correo_t);
kk++;
}
datos.remove(0);
title_xml.setText(title);
fecha_xml.setText(fecha);
institucion_xml.setText(institucion);
OPTnote_xml.setText(note);
DIDingreso_xml.setText(fechaIngreso);
}
}