Search in sources :

Example 1 with DefaultStreamedContent

use of org.primefaces.model.DefaultStreamedContent in project opentheso by miledrousset.

the class DownloadBean method thesoTxtCsv.

/**
 * Permet d'exporter le thésauurus au format txt (tabulé et hiérarchisé)
 * avec des options de colonnes supplémentaires NT, BT, RT, Notes, traductions
 * ceci figure dans le tableau (String[] selectedOptions)
 * @param idTheso
 * @param selectedGroups
 * @param codeLang
 * @param selectedOptions
 * @return
 * MR
 */
public StreamedContent thesoTxtCsv(String idTheso, List<NodeGroup> selectedGroups, String codeLang, ArrayList<String> selectedOptions) {
    progress_per_100 = 0;
    progress_abs = 0;
    NodePreference nodePreference = new PreferencesHelper().getThesaurusPreference(connect.getPoolConnexion(), idTheso);
    if (nodePreference == null)
        return null;
    ExportTxtHelper exportTxtHelper = new ExportTxtHelper();
    exportTxtHelper.setThesaurusDatas(connect.getPoolConnexion(), idTheso, codeLang, selectedGroups, nodePreference, selectedOptions);
    exportTxtHelper.exportToTxtCsv();
    InputStream stream;
    try {
        stream = new ByteArrayInputStream(exportTxtHelper.getTxtBuff().toString().getBytes("UTF-8"));
        file = new DefaultStreamedContent(stream, "text/csv", "Txt_" + 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) UnsupportedEncodingException(java.io.UnsupportedEncodingException) NodePreference(mom.trd.opentheso.bdd.helper.nodes.NodePreference) PreferencesHelper(mom.trd.opentheso.bdd.helper.PreferencesHelper) ExportTxtHelper(mom.trd.opentheso.core.exports.helper.ExportTxtHelper)

Example 2 with DefaultStreamedContent

use of org.primefaces.model.DefaultStreamedContent in project opentheso by miledrousset.

the class DownloadBean method thesoSkos.

/**
 * Cette fonction permet d'exporter un thésaurus au format SKOS à partir de
 * son identifiant. Le résultat est enregistré dans la variable 'skos' du
 * downloadBean si la taille est petite, ou dans la variable 'file' du
 * downloadBean sinon. Dans le premier cas on affiche la variable, dans le
 * second cas l'utilisateur télécharge de fichier.
 *
 * @param idTheso
 * @return
 */
public StreamedContent thesoSkos(String idTheso) {
    /**
     * Cette initialisation est pour exporter les PACTOLS au format accepté
     * par Koha
     */
    // ExportFromBDD_Frantiq exportFromBDD = new ExportFromBDD_Frantiq();
    /**
     * ici c'est la classe à utiliser pour un export standard au foramt SKOS
     */
    ExportFromBDD exportFromBDD = new ExportFromBDD();
    exportFromBDD.setServerAdress(serverAdress);
    exportFromBDD.setServerArk(serverArk);
    exportFromBDD.setArkActive(arkActive);
    StringBuffer skos_local = exportFromBDD.exportThesaurus(connect.getPoolConnexion(), idTheso);
    InputStream stream;
    try {
        stream = new ByteArrayInputStream(skos_local.toString().getBytes("UTF-8"));
        file = new DefaultStreamedContent(stream, "application/xml", idTheso + "_skos.xml");
    } catch (UnsupportedEncodingException ex) {
        Logger.getLogger(DownloadBean.class.getName()).log(Level.SEVERE, null, ex);
    }
    vue.setThesoToSkosCsvFile(true);
    return file;
/*        if (temp.length() <= 1500000) {
            skos = temp.toString();
            vue.setThesoToSkosCsv(true);
        } else {
            InputStream stream;
            try {
                stream = new ByteArrayInputStream(temp.toString().getBytes("UTF-8"));
                file = new DefaultStreamedContent(stream, "application/xml ", "downloadedSkos.xml");
            } catch (UnsupportedEncodingException ex) {
                Logger.getLogger(DownloadBean.class.getName()).log(Level.SEVERE, null, ex);
            }
            vue.setThesoToSkosCsvFile(true);
        }*/
}
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 3 with DefaultStreamedContent

use of org.primefaces.model.DefaultStreamedContent in project opentheso by miledrousset.

the class DownloadBean method brancheToJsonLd.

/**
 * Cette fonction permet de retourner une branche en JsonLd
 *
 * @param idConcept
 * @param idTheso
 * @return
 */
public StreamedContent brancheToJsonLd(String idConcept, String idTheso) {
    ExportFromBDD exportFromBDD = new ExportFromBDD();
    exportFromBDD.setServerAdress(serverAdress);
    exportFromBDD.setServerArk(serverArk);
    exportFromBDD.setArkActive(arkActive);
    StringBuffer skos_local = exportFromBDD.exportBranchOfConcept(connect.getPoolConnexion(), idTheso, idConcept);
    JsonHelper jsonHelper = new JsonHelper();
    SKOSXmlDocument sKOSXmlDocument = jsonHelper.readSkosDocument(skos_local);
    StringBuffer jsonLd = jsonHelper.getJsonLd(sKOSXmlDocument);
    InputStream stream;
    try {
        stream = new ByteArrayInputStream(jsonLd.toString().getBytes("UTF-8"));
        file = new DefaultStreamedContent(stream, "application/xml", idConcept + "_Branch_jsonld.xml");
    } catch (UnsupportedEncodingException ex) {
        Logger.getLogger(DownloadBean.class.getName()).log(Level.SEVERE, null, ex);
    }
    return file;
}
Also used : JsonHelper(mom.trd.opentheso.core.jsonld.helper.JsonHelper) DefaultStreamedContent(org.primefaces.model.DefaultStreamedContent) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) UnsupportedEncodingException(java.io.UnsupportedEncodingException) SKOSXmlDocument(skos.SKOSXmlDocument) ExportFromBDD(mom.trd.opentheso.core.exports.old.ExportFromBDD)

Example 4 with DefaultStreamedContent

use of org.primefaces.model.DefaultStreamedContent in project opentheso by miledrousset.

the class DownloadBean method thesoSkosFrantiq.

/**
 * Cette fonction permet d'exporter un thésaurus au format SKOS à partir de
 * son identifiant. Le résultat est enregistré dans la variable 'skos' du
 * downloadBean si la taille est petite, ou dans la variable 'file' du
 * downloadBean sinon. Dans le premier cas on affiche la variable, dans le
 * second cas l'utilisateur télécharge de fichier.
 *
 * @param idTheso
 */
public void thesoSkosFrantiq(String idTheso) {
    /**
     * Cette initialisation est pour exporter les PACTOLS au format accepté
     * par Koha
     */
    ExportFromBDD_Frantiq exportFromBDD = new ExportFromBDD_Frantiq();
    /**
     * ici c'est la classe à utiliser pour un export standard au foramt SKOS
     */
    // ExportFromBDD exportFromBDD = new ExportFromBDD();
    exportFromBDD.setServerAdress(serverAdress);
    exportFromBDD.setServerArk(serverArk);
    exportFromBDD.setArkActive(arkActive);
    StringBuffer temp = exportFromBDD.exportThesaurus(connect.getPoolConnexion(), idTheso);
    if (temp.length() <= 1500000) {
        skos = temp.toString();
        vue.setThesoToSkosCsv(true);
    } else {
        InputStream stream;
        try {
            stream = new ByteArrayInputStream(temp.toString().getBytes("UTF-8"));
            file = new DefaultStreamedContent(stream, "application/xml ", "downloadedSkos.xml");
        } catch (UnsupportedEncodingException ex) {
            Logger.getLogger(DownloadBean.class.getName()).log(Level.SEVERE, null, ex);
        }
        vue.setThesoToSkosCsvFile(true);
    }
}
Also used : DefaultStreamedContent(org.primefaces.model.DefaultStreamedContent) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ExportFromBDD_Frantiq(mom.trd.opentheso.core.exports.old.ExportFromBDD_Frantiq)

Example 5 with DefaultStreamedContent

use of org.primefaces.model.DefaultStreamedContent in project opentheso by miledrousset.

the class DownloadBean method thesoPDF.

public StreamedContent thesoPDF(String idTheso, List<NodeLang> selectedLanguages, List<NodeGroup> selectedGroups, String codeLang, String codeLang2, int type) {
    progress_per_100 = 0;
    progress_abs = 0;
    NodePreference nodePreference = new PreferencesHelper().getThesaurusPreference(connect.getPoolConnexion(), idTheso);
    if (nodePreference == null)
        return null;
    sizeOfTheso = new ConceptHelper().getAllIdConceptOfThesaurus(connect.getPoolConnexion(), idTheso).size();
    ExportRdf4jHelper exportRdf4jHelper = new ExportRdf4jHelper();
    exportRdf4jHelper.setInfos(connect.getPoolConnexion(), "dd-mm-yyyy", false, idTheso, nodePreference.getCheminSite());
    exportRdf4jHelper.setNodePreference(nodePreference);
    exportRdf4jHelper.addThesaurus(idTheso, selectedLanguages);
    exportRdf4jHelper.addGroup(idTheso, selectedLanguages, selectedGroups);
    exportRdf4jHelper.addConcept(idTheso, this, selectedLanguages);
    WritePdf writePdf = new WritePdf(exportRdf4jHelper.getSkosXmlDocument(), codeLang, codeLang2, type);
    InputStream stream;
    stream = new ByteArrayInputStream(writePdf.getOutput().toByteArray());
    file = new DefaultStreamedContent(stream, "application/pdf", "test.pdf");
    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) WritePdf(mom.trd.opentheso.core.exports.pdf.WritePdf) ExportRdf4jHelper(mom.trd.opentheso.core.exports.rdf4j.helper.ExportRdf4jHelper) NodePreference(mom.trd.opentheso.bdd.helper.nodes.NodePreference) PreferencesHelper(mom.trd.opentheso.bdd.helper.PreferencesHelper)

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