Search in sources :

Example 6 with DefaultStreamedContent

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;
}
Also used : DefaultStreamedContent(org.primefaces.model.DefaultStreamedContent) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ExportFromBDD(mom.trd.opentheso.core.exports.old.ExportFromBDD)

Example 7 with DefaultStreamedContent

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;
}
Also used : DefaultStreamedContent(org.primefaces.model.DefaultStreamedContent) ConceptHelper(mom.trd.opentheso.bdd.helper.ConceptHelper) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ExportFromBDD(mom.trd.opentheso.core.exports.old.ExportFromBDD)

Example 8 with DefaultStreamedContent

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;
}
Also used : DefaultStreamedContent(org.primefaces.model.DefaultStreamedContent) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ExportThesaurus(mom.trd.opentheso.core.exports.helper.ExportThesaurus) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 9 with DefaultStreamedContent

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;
}
Also used : DefaultStreamedContent(org.primefaces.model.DefaultStreamedContent) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) NodeStatConcept(mom.trd.opentheso.bdd.helper.nodes.statistic.NodeStatConcept) ArrayList(java.util.ArrayList) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) Date(java.util.Date) NodeStatTheso(mom.trd.opentheso.bdd.helper.nodes.statistic.NodeStatTheso) ByteArrayInputStream(java.io.ByteArrayInputStream) StreamedContent(org.primefaces.model.StreamedContent) DefaultStreamedContent(org.primefaces.model.DefaultStreamedContent)

Example 10 with DefaultStreamedContent

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;
}
Also used : DefaultStreamedContent(org.primefaces.model.DefaultStreamedContent) PdfWriter(com.itextpdf.text.pdf.PdfWriter) Thesaurus(mom.trd.opentheso.bdd.datas.Thesaurus) ByteArrayInputStream(java.io.ByteArrayInputStream) ExportStatistiques(mom.trd.opentheso.core.exports.helper.ExportStatistiques) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Document(com.itextpdf.text.Document) Paragraph(com.itextpdf.text.Paragraph)

Aggregations

ByteArrayInputStream (java.io.ByteArrayInputStream)21 InputStream (java.io.InputStream)21 DefaultStreamedContent (org.primefaces.model.DefaultStreamedContent)21 UnsupportedEncodingException (java.io.UnsupportedEncodingException)19 ExportFromBDD (mom.trd.opentheso.core.exports.old.ExportFromBDD)11 ConceptHelper (mom.trd.opentheso.bdd.helper.ConceptHelper)4 JsonHelper (mom.trd.opentheso.core.jsonld.helper.JsonHelper)4 SKOSXmlDocument (skos.SKOSXmlDocument)4 PreferencesHelper (mom.trd.opentheso.bdd.helper.PreferencesHelper)2 NodePreference (mom.trd.opentheso.bdd.helper.nodes.NodePreference)2 ExportStatistiques (mom.trd.opentheso.core.exports.helper.ExportStatistiques)2 ExportTabulateHelper (mom.trd.opentheso.core.exports.helper.ExportTabulateHelper)2 Document (com.itextpdf.text.Document)1 Paragraph (com.itextpdf.text.Paragraph)1 PdfWriter (com.itextpdf.text.pdf.PdfWriter)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 FacesMessage (javax.faces.application.FacesMessage)1