Search in sources :

Example 1 with SKOSXmlDocument

use of skos.SKOSXmlDocument 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 2 with SKOSXmlDocument

use of skos.SKOSXmlDocument in project opentheso by miledrousset.

the class ReadFileSKOS method readBranchFile.

public void readBranchFile(HikariDataSource ds, InputStream filename, String formatDate, boolean useArk, String adressSite) throws Exception {
    thesaurus = new SKOSXmlDocument();
    try {
        // 
        // Get an input factory
        // 
        XMLInputFactory xmlif = XMLInputFactory.newInstance();
        // System.out.println("FACTORY: " + xmlif);
        // 
        // Instantiate a reader UTF8
        // 
        xmlr = xmlif.createXMLStreamReader(filename, "UTF-8");
        // 
        while (xmlr.hasNext()) {
            if (!error) {
                printEvent(xmlr);
            }
            xmlr.next();
        }
        // 
        // Close the reader
        // 
        xmlr.close();
    } catch (ArrayIndexOutOfBoundsException exception) {
        exception.printStackTrace();
    }
}
Also used : SKOSXmlDocument(skos.SKOSXmlDocument)

Example 3 with SKOSXmlDocument

use of skos.SKOSXmlDocument in project opentheso by miledrousset.

the class ReadFileSKOS method readFile.

public void readFile(HikariDataSource ds, InputStream filename, String formatDate, boolean useArk, String adressSite, int idUser, String langueSource) throws Exception {
    thesaurus = new SKOSXmlDocument();
    try {
        // 
        // Get an input factory
        // 
        XMLInputFactory xmlif = XMLInputFactory.newInstance();
        // System.out.println("FACTORY: " + xmlif);
        // 
        // Instantiate a reader UTF8
        // 
        xmlr = xmlif.createXMLStreamReader(filename, "UTF-8");
        // 
        while (xmlr.hasNext()) {
            if (!error) {
                printEvent(xmlr);
            }
            xmlr.next();
        }
        // 
        // Close the reader
        // 
        xmlr.close();
        if (!error) {
            WriteSkosBDD writeSkosBDD = new WriteSkosBDD(ds);
            writeSkosBDD.writeThesaurus(thesaurus, formatDate, useArk, adressSite, idUser, langueSource);
        } else {
            thesaurus = null;
        }
    } catch (ArrayIndexOutOfBoundsException exception) {
        exception.printStackTrace();
    }
}
Also used : SKOSXmlDocument(skos.SKOSXmlDocument)

Example 4 with SKOSXmlDocument

use of skos.SKOSXmlDocument in project opentheso by miledrousset.

the class ReadFileSKOS method readStringBuffer.

public SKOSXmlDocument readStringBuffer(StringBuffer skos) throws Exception {
    thesaurus = new SKOSXmlDocument();
    try {
        // Get an input factory
        // String xmlContent;
        XMLInputFactory inputFactory = XMLInputFactory.newInstance();
        StringReader stringReader = new StringReader(skos.toString());
        XMLStreamReader xMLStreamReader = inputFactory.createXMLStreamReader(stringReader);
        // 
        while (xMLStreamReader.hasNext()) {
            if (!error) {
                // System.err.println(xMLStreamReader.toString());
                printEvent(xMLStreamReader);
            }
            xMLStreamReader.next();
        }
        // 
        // Close the reader
        // 
        xMLStreamReader.close();
        return thesaurus;
    } catch (ArrayIndexOutOfBoundsException exception) {
        exception.printStackTrace();
    }
    return null;
}
Also used : StringReader(java.io.StringReader) SKOSXmlDocument(skos.SKOSXmlDocument)

Example 5 with SKOSXmlDocument

use of skos.SKOSXmlDocument in project opentheso by miledrousset.

the class AlignmentQuery method queryOpentheso.

/**
 * Cette fonction permet de récupérer les alignements présents sur Opentheso
 * pour un concept passé en paramètre et un thésaurus donné
 *
 * @param idC
 * @param idTheso
 * @param lexicalValue
 * @param lang
 * @param requete
 * @param source
 * @return
 */
public ArrayList<NodeAlignment> queryOpentheso(String idC, String idTheso, String lexicalValue, String lang, String requete, String source) {
    if (requete.trim().equals("")) {
        return null;
    }
    if (lexicalValue.trim().equals("")) {
        return null;
    }
    listeAlign = new ArrayList<>();
    // construction de la requête de type (webservices Opentheso)
    lexicalValue = lexicalValue.replaceAll(" ", "%20");
    requete = requete.replace("##lang##", lang);
    requete = requete.replace("##value##", lexicalValue);
    try {
        URL url = new URL(requete);
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        conn.setRequestMethod("GET");
        conn.setRequestProperty("Accept", "application/xml");
        if (conn.getResponseCode() != 200) {
            throw new RuntimeException("Failed : HTTP error code : " + conn.getResponseCode());
        }
        BufferedReader br = new BufferedReader(new InputStreamReader((conn.getInputStream())));
        String output;
        String xmlRecord = "";
        while ((output = br.readLine()) != null) {
            xmlRecord += output;
        }
        byte[] bytes = xmlRecord.getBytes();
        xmlRecord = new String(bytes, Charset.forName("UTF-8"));
        conn.disconnect();
        StringBuffer sb = new StringBuffer(xmlRecord);
        try {
            SKOSXmlDocument sxd = new ReadFileSKOS().readStringBuffer(sb);
            for (SKOSResource resource : sxd.getResourcesList()) {
                NodeAlignment na = new NodeAlignment();
                na.setInternal_id_concept(idC);
                na.setInternal_id_thesaurus(idTheso);
                // "Pactols");
                na.setThesaurus_target(source);
                na.setUri_target(resource.getUri());
                for (SKOSLabel label : resource.getLabelsList()) {
                    switch(label.getProperty()) {
                        case SKOSProperty.prefLabel:
                            if (label.getLanguage().equals(lang)) {
                                na.setConcept_target(label.getLabel());
                            }
                            break;
                        case SKOSProperty.altLabel:
                            if (label.getLanguage().equals(lang)) {
                                if (na.getConcept_target_alt().isEmpty()) {
                                    na.setConcept_target_alt(label.getLabel());
                                } else {
                                    na.setConcept_target_alt(na.getConcept_target_alt() + ";" + label.getLabel());
                                }
                            }
                            break;
                        default:
                            break;
                    }
                }
                for (SKOSDocumentation sd : resource.getDocumentationsList()) {
                    if (sd.getProperty() == SKOSProperty.definition && sd.getLanguage().equals(lang)) {
                        na.setDef_target(sd.getText());
                    }
                }
                listeAlign.add(na);
            }
        } catch (Exception ex) {
            Logger.getLogger(AlignmentQuery.class.getName()).log(Level.SEVERE, null, ex);
        }
    } catch (MalformedURLException e) {
    } catch (IOException e) {
    }
    return listeAlign;
}
Also used : MalformedURLException(java.net.MalformedURLException) SKOSXmlDocument(skos.SKOSXmlDocument) SKOSLabel(skos.SKOSLabel) URL(java.net.URL) MalformedURLException(java.net.MalformedURLException) SAXException(org.xml.sax.SAXException) NodeAlignment(mom.trd.opentheso.bdd.helper.nodes.NodeAlignment) HttpURLConnection(java.net.HttpURLConnection) SKOSResource(skos.SKOSResource) SKOSDocumentation(skos.SKOSDocumentation) ReadFileSKOS(mom.trd.opentheso.core.imports.old.ReadFileSKOS)

Aggregations

SKOSXmlDocument (skos.SKOSXmlDocument)19 JsonHelper (mom.trd.opentheso.core.jsonld.helper.JsonHelper)12 ExportFromBDD (mom.trd.opentheso.core.exports.old.ExportFromBDD)6 UnsupportedEncodingException (java.io.UnsupportedEncodingException)5 GET (javax.ws.rs.GET)5 Path (javax.ws.rs.Path)5 Produces (javax.ws.rs.Produces)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 InputStream (java.io.InputStream)4 ReadFileSKOS (mom.trd.opentheso.core.imports.old.ReadFileSKOS)4 DefaultStreamedContent (org.primefaces.model.DefaultStreamedContent)4 HikariDataSource (com.zaxxer.hikari.HikariDataSource)1 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 StringReader (java.io.StringReader)1 HttpURLConnection (java.net.HttpURLConnection)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 FacesMessage (javax.faces.application.FacesMessage)1