use of org.primefaces.model.DefaultStreamedContent in project opentheso by miledrousset.
the class DownloadBean method thisGroupToSkos.
/**
* Cette fonction permet de retourner pour téléchargement un groupe en SKOS
*
* @param idGroup
* @param idTheso
* @return
*/
public StreamedContent thisGroupToSkos(String idGroup, String idTheso) {
ExportFromBDD exportFromBDD = new ExportFromBDD();
exportFromBDD.setServerAdress(serverAdress);
exportFromBDD.setServerArk(serverArk);
exportFromBDD.setArkActive(arkActive);
StringBuffer skos_local = exportFromBDD.exportThisGroup(connect.getPoolConnexion(), idTheso, idGroup);
InputStream stream;
try {
stream = new ByteArrayInputStream(skos_local.toString().getBytes("UTF-8"));
file = new DefaultStreamedContent(stream, "application/xml", idGroup + "_Group_skos.xml");
} catch (UnsupportedEncodingException ex) {
Logger.getLogger(DownloadBean.class.getName()).log(Level.SEVERE, null, ex);
}
return file;
}
use of org.primefaces.model.DefaultStreamedContent in project opentheso by miledrousset.
the class DownloadBean method thesoToSkosAdvanced.
/**
* Cette fonction permet d'exporter un thésaurus en SKOS en précisant les
* langues et les domaines à exporter
*
* @param idTheso
* @param selectedLanguages
* @param selectedGroups
* @return
*/
public StreamedContent thesoToSkosAdvanced(String idTheso, List<NodeLang> selectedLanguages, List<NodeGroup> selectedGroups) {
progress_per_100 = 0;
progress_abs = 0;
ConceptHelper conceptHelper = new ConceptHelper();
sizeOfTheso = conceptHelper.getAllIdConceptOfThesaurus(connect.getPoolConnexion(), idTheso).size();
ExportFromBDD exportFromBDD = new ExportFromBDD();
exportFromBDD.setServerAdress(serverAdress);
exportFromBDD.setServerArk(serverArk);
exportFromBDD.setArkActive(arkActive);
StringBuffer skos_local = exportFromBDD.exportThesaurusAdvanced(connect.getPoolConnexion(), idTheso, selectedLanguages, selectedGroups, this);
InputStream stream;
try {
stream = new ByteArrayInputStream(skos_local.toString().getBytes("UTF-8"));
file = new DefaultStreamedContent(stream, "application/xml", idTheso + "_skos.rdf");
} catch (UnsupportedEncodingException ex) {
Logger.getLogger(DownloadBean.class.getName()).log(Level.SEVERE, null, ex);
}
progress_per_100 = 0;
progress_abs = 0;
return file;
}
use of org.primefaces.model.DefaultStreamedContent in project opentheso by miledrousset.
the class DownloadBean method getAllAltLabels.
public StreamedContent getAllAltLabels(String idTheso, String codeLang) {
progress_per_100 = 0;
progress_abs = 0;
ExportThesaurus exportThesaurus = new ExportThesaurus();
StringBuilder stringBuilder = exportThesaurus.exportAltLabel(connect.getPoolConnexion(), idTheso, codeLang);
if (stringBuilder == null)
return null;
InputStream stream;
try {
stream = new ByteArrayInputStream(stringBuilder.toString().getBytes("UTF-8"));
file = new DefaultStreamedContent(stream, "text/csv", "AltLabels_" + idTheso + ".csv");
} catch (UnsupportedEncodingException ex) {
Logger.getLogger(DownloadBean.class.getName()).log(Level.SEVERE, null, ex);
}
return file;
}
use of org.primefaces.model.DefaultStreamedContent in project opentheso by miledrousset.
the class StatBean method creatCSVFile.
/**
* #JM
* Méthode pour créer un fichier télécharger
* soit un fichier pour les statistiques du thesaurus soit pour les
* statistiques concepts
* @param idTheso
* @return
*/
public StreamedContent creatCSVFile(String idTheso) {
StringBuffer sbr = new StringBuffer();
try {
// ajou du titre au documen CSV
ArrayList<String> line = new ArrayList<>();
line.add("thesaurus : " + idTheso);
line.add(lang.toUpperCase());
line.add(new Date().toString());
if (this.typeStat == 1)
line.add(lb.getMsg("stat.forTheso"));
if (this.typeStat == 2) {
line.add(lb.getMsg("stat.forConcept"));
if (searchFromDate) {
line.add(lb.getMsg("stat.opt3") + " : " + begin);
line.add(lb.getMsg("stat.opt4") + " : " + end);
line.add((typeDate == 1) ? lb.getMsg("stat.opt2.1") : lb.getMsg("stat.opt2.2"));
}
if (searchFromGroup)
line.add(lb.getMsg("stat.group") + " : " + this.selectedGroup);
}
writeLine(sbr, line);
line = new ArrayList<>();
// ajout entête du tableau
if (this.typeStat == 1) {
line.add(lb.getMsg("stat.statTheso1"));
line.add(lb.getMsg("stat.statTheso2"));
line.add(lb.getMsg("stat.statTheso3"));
line.add(lb.getMsg("stat.statTheso4"));
line.add(lb.getMsg("stat.statTheso5"));
}
if (this.typeStat == 2) {
line.add(lb.getMsg("stat.statCpt1"));
line.add(lb.getMsg("stat.idC"));
line.add(lb.getMsg("stat.statCpt2"));
line.add(lb.getMsg("stat.statCpt3"));
line.add(lb.getMsg("stat.statCpt4"));
}
writeLine(sbr, line);
if (this.typeStat == 1) {
for (NodeStatTheso nst : this.statTheso) {
line = new ArrayList<>();
line.add(nst.getGroup());
line.add("" + nst.getNbDescripteur());
line.add("" + nst.getNbNonDescripteur());
line.add("" + nst.getNbNoTrad());
line.add("" + nst.getNbNotes());
writeLine(sbr, line);
}
}
if (this.typeStat == 2) {
for (NodeStatConcept nsc : this.statConcept) {
line = new ArrayList<>();
line.add(nsc.getValue());
line.add(nsc.getIdConcept());
line.add("" + nsc.getDateCreat());
line.add("" + nsc.getDateEdit());
line.add(nsc.getGroup());
writeLine(sbr, line);
}
}
} catch (IOException e) {
System.out.println("erreur pendant l'écriture du fichier" + e);
return null;
}
InputStream stream;
StreamedContent file = null;
try {
stream = new ByteArrayInputStream(sbr.toString().getBytes("UTF-8"));
String name_file = (typeStat == 1) ? "downloadedCsv_Thesaurus_stat.csv" : "downloadedCsv_concept_stat.csv";
file = new DefaultStreamedContent(stream, "text/csv", name_file);
} catch (UnsupportedEncodingException e) {
System.out.println("erreur création inputStream " + e);
return null;
}
return file;
}
use of org.primefaces.model.DefaultStreamedContent in project opentheso by miledrousset.
the class BaseDeDonnesBean method pdf.
/**
* permet de generer une document pour pouvoir le telecharger
* le format c'est pdf
* @return
* @throws SQLException
* @throws Exception
*/
public StreamedContent pdf() throws SQLException, Exception {
Thesaurus thesaurus = new Thesaurus();
ExportStatistiques expo = new ExportStatistiques();
expo.recuperatefils(connect.getPoolConnexion(), theso.getThesaurus().getId_thesaurus(), theso.getThesaurus().getLanguage(), 2);
Document pdf = new Document(PageSize.LETTER);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PdfWriter writer;
Paragraph para = new Paragraph(expo.getDocument());
writer = PdfWriter.getInstance(pdf, baos);
if (!pdf.isOpen()) {
pdf.open();
}
pdf.addTitle("theso");
pdf.add(para);
// Adding content to pdf
pdf.close();
InputStream stream = new ByteArrayInputStream(baos.toByteArray());
fileDownload = new DefaultStreamedContent(stream, "application/pdf", "Thésaurus" + thesaurus.getId_thesaurus() + ".pdf");
return fileDownload;
}
Aggregations