Différences
Ci-dessous, les différences entre deux révisions de la page.
Les deux révisions précédentes Révision précédente Prochaine révision | Révision précédente Dernière révision Les deux révisions suivantes | ||
scrutaridata:exportapi:java [2010/02/11 18:01] vincent |
scrutaridata:exportapi:java [2016/07/06 18:28] vincent |
||
---|---|---|---|
Ligne 4: | Ligne 4: | ||
* Fichier JAR : [[http://dataexport.scrutari.net/impl/java/ScrutariDataExport.jar]] | * Fichier JAR : [[http://dataexport.scrutari.net/impl/java/ScrutariDataExport.jar]] | ||
- | * Sources : [[http://dataexport.scrutari.net/impl/java/ScrutariDataExport-src.tar.gz]] | + | * Sources : [[http://dataexport.scrutari.net/impl/java/ScrutariDataExport-src.zip]] |
* JavaDoc : [[http://dataexport.scrutari.net/impl/java/javadoc]] | * JavaDoc : [[http://dataexport.scrutari.net/impl/java/javadoc]] | ||
+ | |||
+ | Les sources peuvent être également obtenue via le dépôt Subversion : | ||
+ | |||
+ | svn co http://depot.exemole.fr/svn/java/ScrutariDataExport/src/ | ||
===== Utilisation de l'implémentation ===== | ===== Utilisation de l'implémentation ===== | ||
Ligne 13: | Ligne 17: | ||
<code java> | <code java> | ||
- | public static net.scrutari.dataexport.api.ScrutariDataExport newInstance(java.lang.Appendable appendable, int indentLength, boolean includeXMLDeclaration) | + | ScrutariDataExport newInstance(java.lang.Appendable appendable, int indentLength, boolean includeXMLDeclaration) |
</code> | </code> | ||
+ | Cette méthode prend comme argument : | ||
+ | |||
+ | * Appendable appendable : instance de l'interface ''Appendable'' qui indique la destination où est enregistré le XML généré (typiquement, une instance de ''Writer'') ; les éventuelles exceptions de type ''IOException'' renvoyée par l'instance d'Appendable sont encapsulées dans une exception ''net.scrutari.dataexport.api.ExportIOException'' (qui étend ''RuntimeException'') | ||
+ | * int indentLength : indique s'il faut indenter le code XML pour le rendre plus lisible, cette valeur peut être supérieure à zéro si le code est inclus dans un code XML plus large. Pour n'avoir ni indentation ni passage à la ligne (et donc un code XML plus ramassé), il faut indiquer la valeur ''-999'' | ||
+ | * boolean includeXMLDeclaration : indique s'il faut rajouter la déclaration XML (''<?xml version="1.0" encoding="UTF-8"?>'') au début du code XML généré. | ||
+ | |||
+ | La méthode renvoie une instance de l'interface ScrutariDataExport dont les méthodes correspondent à celles définies par l'API ([[scrutaridata:exportapi:scrutaridataexport|ScrutariDataExport]]), cette interface appartient au paquet **net.scrutari.dataexport.api** qui comprend toute la traduction en interface Java de l'API. | ||
+ | |||
+ | ===== Exemple d'utilisation ===== | ||
+ | |||
+ | L'exemple ci-dessous montre l'utilisation de l'API pour générer un simple fichier. | ||
+ | |||
+ | <code java> | ||
+ | import net.scrutari.dataexport.*; | ||
+ | import net.scrutari.dataexport.api.*; | ||
+ | import java.io.*; | ||
+ | |||
+ | public class ScrutariDataExportExample { | ||
+ | |||
+ | public static void main(String[] args) throws IOException { | ||
+ | /* Ouverture d'un fichier en écriture */ | ||
+ | File file = new File("test.scrutari-data.xml"); | ||
+ | BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), "UTF-8")); | ||
+ | |||
+ | /*Création d'une instance de ScrutariDataExport */ | ||
+ | ScrutariDataExport scrutariDataExport = ScrutariDataExportFactory.newInstance(bufferedWriter,0,true); | ||
+ | |||
+ | /*Début de l'export */ | ||
+ | BaseMetadataExport baseMetadataExport = scrutariDataExport.startExport(); | ||
+ | |||
+ | /*Définition des métadonnées de la base */ | ||
+ | baseMetadataExport.setAuthority("e17a05b0-c45e-11d8-9669-0800200c9a66"); | ||
+ | baseMetadataExport.setBaseName("test"); | ||
+ | baseMetadataExport.setBaseIcon("http://monsite.net/icon-16x16pixels.png"); | ||
+ | baseMetadataExport.setIntitule(BaseMetadataExport.INTITULE_SHORT, "fr", "Test"); | ||
+ | baseMetadataExport.setIntitule(BaseMetadataExport.INTITULE_SHORT, "en", "Test"); | ||
+ | baseMetadataExport.setIntitule(BaseMetadataExport.INTITULE_LONG, "fr", "Test du format scrutariData"); | ||
+ | baseMetadataExport.setIntitule(BaseMetadataExport.INTITULE_LONG, "en", "ScrutariData Format Test"); | ||
+ | baseMetadataExport.addLangUI("fr"); | ||
+ | baseMetadataExport.addLangUI("en"); | ||
+ | |||
+ | /*Insertion d'un corpus avec de nom « fiches » */ | ||
+ | CorpusMetadataExport corpusMetadataExport = scrutariDataExport.newCorpus("fiches"); | ||
+ | |||
+ | /*Définition des métadonnées du corpus */ | ||
+ | corpusMetadataExport.setCorpusType("EXP"); | ||
+ | corpusMetadataExport.setIntitule(CorpusMetadataExport.INTITULE_CORPUS, "fr","Fiches d'expérience"); | ||
+ | corpusMetadataExport.setIntitule(CorpusMetadataExport.INTITULE_FICHE, "fr", "Fiche d'expérience n° "); | ||
+ | |||
+ | /* Définition de deux champs complémentaires */ | ||
+ | int numero1 = corpusMetadataExport.addComplement(); | ||
+ | corpusMetadataExport.setComplementIntitule(numero1,"fr","Auteurs"); | ||
+ | corpusMetadataExport.setComplementIntitule(numero1,"en","Authors"); | ||
+ | int numero2 = corpusMetadataExport.addComplement(); | ||
+ | corpusMetadataExport.setComplementIntitule(numero2,"fr","Organismes"); | ||
+ | |||
+ | |||
+ | /* Premier exemple d'une fiche*/ | ||
+ | FicheExport ficheExport = scrutariDataExport.newFiche("1"); | ||
+ | ficheExport.setTitre("Première fiche"); | ||
+ | ficheExport.setFicheType("DOC"); | ||
+ | ficheExport.setDate("2006-03"); | ||
+ | ficheExport.addComplement(2,"Collectif"); | ||
+ | ficheExport.setFicheIcon("http://monsite.net/icon2-16x16pixels.png"); | ||
+ | |||
+ | /* Second exemple de fiche, on réutilise le pointeur ficheExport */ | ||
+ | ficheExport = scrutariDataExport.newFiche("fiche2"); | ||
+ | ficheExport.setSoustitre("le sous titre"); | ||
+ | ficheExport.setTitre("Seconde fiche"); | ||
+ | ficheExport.setDate("2006-03"); | ||
+ | ficheExport.setLang("fr"); | ||
+ | ficheExport.setHref("http://monsite.net/ma-fiche-1.html"); | ||
+ | ficheExport.addComplement(2,"L'ASSO"); | ||
+ | ficheExport.addComplement(1,"Martin Dupont"); | ||
+ | |||
+ | /* Exemple d'indexation : celle-ci peut de se faire à n'importe quel moment | ||
+ | * même s'il ne s'agit du mot-clé ou de la fiche en cours ou que le thésaurus ou le corpus | ||
+ | * n'ont pas encore été définis. */ | ||
+ | scrutariDataExport.addIndexation("fiches", "1", "motscles", "A01",1); | ||
+ | |||
+ | /* Insertion d'un thésaurus de nom « motscles » */ | ||
+ | ThesaurusMetadataExport thesaurusMetadataExport = scrutariDataExport.newThesaurus("motscles"); | ||
+ | |||
+ | /* Définition des métadonnées du thésaurus */ | ||
+ | thesaurusMetadataExport.setIntitule(ThesaurusMetadataExport.INTITULE_THESAURUS,"fr","Mots-clés"); | ||
+ | thesaurusMetadataExport.setIntitule(ThesaurusMetadataExport.INTITULE_THESAURUS,"en","Keywords"); | ||
+ | |||
+ | /* Exemple d'insertion d'un mot-clé au sein du thésaurus en cours */ | ||
+ | MotcleExport motcleExport = scrutariDataExport.newMotcle("A01"); | ||
+ | motcleExport.setLibelle("fr","Eau"); | ||
+ | |||
+ | /* Autre exemple d'insertion d'indexation n'importe où*/ | ||
+ | scrutariDataExport.addIndexation("fiches", "fiche2", "motscles", "A01",4); | ||
+ | |||
+ | /* L'indexation précédente n'a pas changé l'état de l'export, on travaille | ||
+ | * toujours sur le premier mot-clé */ | ||
+ | motcleExport.setLibelle("en","Water"); | ||
+ | |||
+ | /* Fin de l'export */ | ||
+ | scrutariDataExport.endExport(); | ||
+ | |||
+ | /* Fermeture du fichier */ | ||
+ | bufferedWriter.close(); | ||
+ | } | ||
+ | |||
+ | } | ||
+ | </code> | ||