Commit 9d3d557f authored by Vincent Calame's avatar Vincent Calame
Browse files

Initialisation du dépôt

parents
/.svn/*
\ No newline at end of file
The MIT License (MIT)
Copyright (c) 2016 Scrutari
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
# Implémentation en Java de l'API ScrutariDataExport
Ce dépôt contient les classes nécessaires à la « scrutarisation » de données, c'est à dire à la production d'une sortie au format ScrutariData.
L'ensemble est sous licence MIT.
## Pour en savoir plus :
- Scrutari : http://www.scrutari.net/
- API ScrutariDataExport : http://www.scrutari.net/dokuwiki/scrutaridata:exportapi
- sur l'implémentation en Java : http://www.scrutari.net/dokuwiki/scrutaridata:exportapi:java
/* ScrutariDataExport - Java implementation of ScrutariDataExport API
* http://www.scrutari.net/dokuwiki/scrutaridata:exportapi
*
* Copyright (c) 2010-2016 Vincent Calame - Exemole
* Licensed under MIT
* (http://en.wikipedia.org/wiki/MIT_License)
*/
package net.scrutari.dataexport;
import net.scrutari.dataexport.api.ScrutariDataExport;
import net.scrutari.dataexport.xml.XmlScrutariDataExport;
import net.scrutari.dataexport.xml.XmlWriter;
/**
*
* @author Vincent Calame
*/
public final class ScrutariDataExportFactory {
private ScrutariDataExportFactory() {
}
public static ScrutariDataExport newInstance(Appendable appendable, int indentLength, boolean includeXMLDeclaration) {
XmlWriter xmlWriter = new XmlWriter(appendable, indentLength, includeXMLDeclaration);
return new XmlScrutariDataExport(xmlWriter);
}
}
/* ScrutariDataExport - Java implementation of ScrutariDataExport API
* http://www.scrutari.net/dokuwiki/scrutaridata:exportapi
*
* Copyright (c) 2010-2016 Vincent Calame - Exemole
* Licensed under MIT
* (http://en.wikipedia.org/wiki/MIT_License)
*/
package net.scrutari.dataexport;
import java.text.SimpleDateFormat;
import java.util.Date;
import net.scrutari.dataexport.xml.XmlWriter;
/**
*
* @author Vincent Calame
*/
public class ScrutariInfoUtils {
private static final SimpleDateFormat ISO_FORMAT = new SimpleDateFormat("yyyy-MM-dd");
private ScrutariInfoUtils() {
}
public static void writeScrutariInfo(Appendable appendable, int indentLength, boolean includeXMLDeclaration, Date date, String[] urlArray) {
XmlWriter xmlWriter = new XmlWriter(appendable, indentLength, includeXMLDeclaration);
xmlWriter.openTag("info");
xmlWriter.addSimpleElement("date", ISO_FORMAT.format(date));
int length = urlArray.length;
for (int i = 0; i < length; i++) {
xmlWriter.addSimpleElement("scrutaridata-url", urlArray[i]);
}
xmlWriter.closeTag("info");
}
}
/* ScrutariDataExport - Java implementation of ScrutariDataExport API
* http://www.scrutari.net/dokuwiki/scrutaridata:exportapi
*
* Copyright (c) 2010-2016 Vincent Calame - Exemole
* Licensed under MIT
* (http://en.wikipedia.org/wiki/MIT_License)
*/
package net.scrutari.dataexport.api;
/**
*
* @author Vincent Calame
*/
public interface BaseMetadataExport {
public final static int INTITULE_SHORT = 1;
public final static int INTITULE_LONG = 2;
public void setAuthority(String authority);
public void setBaseName(String baseName);
public void setBaseIcon(String baseIcon);
public void setIntitule(int intituleType, String lang, String intituleValue);
public void addLangUI(String lang);
}
/* ScrutariDataExport - Java implementation of ScrutariDataExport API
* http://www.scrutari.net/dokuwiki/scrutaridata:exportapi
*
* Copyright (c) 2010-2016 Vincent Calame - Exemole
* Licensed under MIT
* (http://en.wikipedia.org/wiki/MIT_License)
*/
package net.scrutari.dataexport.api;
/**
*
* @author Vincent Calame
*/
public interface CorpusMetadataExport {
public final static int INTITULE_CORPUS = 1;
public final static int INTITULE_FICHE = 2;
public void setCorpusIcon(String corpusIcon);
public void setHrefParent(String hrefParent);
public void setIntitule(int intituleType, String lang, String intituleValue);
public int addComplement();
public void setComplementIntitule(int complementNumber, String lang, String intituleValue);
}
/* ScrutariDataExport - Java implementation of ScrutariDataExport API
* http://www.scrutari.net/dokuwiki/scrutaridata:exportapi
*
* Copyright (c) 2010-2016 Vincent Calame - Exemole
* Licensed under MIT
* (http://en.wikipedia.org/wiki/MIT_License)
*/
package net.scrutari.dataexport.api;
/**
*
* @author Vincent Calame
*/
public class ExportIOException extends RuntimeException {
public ExportIOException(Exception nestedException) {
super(nestedException);
}
}
/* ScrutariDataExport - Java implementation of ScrutariDataExport API
* http://www.scrutari.net/dokuwiki/scrutaridata:exportapi
*
* Copyright (c) 2010-2016 Vincent Calame - Exemole
* Licensed under MIT
* (http://en.wikipedia.org/wiki/MIT_License)
*/
package net.scrutari.dataexport.api;
/**
*
* @author Vincent Calame
*/
public class ExportStateException extends RuntimeException {
public ExportStateException(int currentState, String methodName) {
}
}
/* ScrutariDataExport - Java implementation of ScrutariDataExport API
* http://www.scrutari.net/dokuwiki/scrutaridata:exportapi
*
* Copyright (c) 2010-2016 Vincent Calame - Exemole
* Licensed under MIT
* (http://en.wikipedia.org/wiki/MIT_License)
*/
package net.scrutari.dataexport.api;
/**
*
* @author Vincent Calame
*/
public interface FicheExport {
public void setTitre(String titre);
public void setSoustitre(String soustitre);
public void setDate(String date);
public void setLang(String lang);
public void setHref(String href);
public void setFicheIcon(String ficheIcon);
public void setGeoloc(String latitude, String longitude);
public void addComplement(int complementNumber, String complementValue);
public void addAttributeValue(String nameSpace, String localKey, String attributeValue);
}
/* ScrutariDataExport - Java implementation of ScrutariDataExport API
* http://www.scrutari.net/dokuwiki/scrutaridata:exportapi
*
* Copyright (c) 2010-2016 Vincent Calame - Exemole
* Licensed under MIT
* (http://en.wikipedia.org/wiki/MIT_License)
*/
package net.scrutari.dataexport.api;
/**
*
* @author Vincent Calame
*/
public interface MotcleExport {
public void setLibelle(String lang, String libelleValue);
}
/* ScrutariDataExport - Java implementation of ScrutariDataExport API
* http://www.scrutari.net/dokuwiki/scrutaridata:exportapi
*
* Copyright (c) 2010-2016 Vincent Calame - Exemole
* Licensed under MIT
* (http://en.wikipedia.org/wiki/MIT_License)
*/
package net.scrutari.dataexport.api;
/**
*
* @author Vincent Calame
*/
public interface ScrutariDataExport {
public final static int START = 1;
public final static int BASEMETADATA = 2;
public final static int CORPUSMETADATA = 3;
public final static int FICHE = 4;
public final static int THESAURUSMETADATA = 5;
public final static int MOTCLE = 6;
public final static int END = 7;
public BaseMetadataExport startExport();
public CorpusMetadataExport newCorpus(String corpusName);
public FicheExport newFiche(String ficheId);
public ThesaurusMetadataExport newThesaurus(String thesaurusName);
public MotcleExport newMotcle(String motcleId);
public void addIndexation(String corpusName, String ficheId, String thesaurusName, String motcleId, int poids);
public void endExport();
public int getState();
}
/* ScrutariDataExport - Java implementation of ScrutariDataExport API
* http://www.scrutari.net/dokuwiki/scrutaridata:exportapi
*
* Copyright (c) 2010-2016 Vincent Calame - Exemole
* Licensed under MIT
* (http://en.wikipedia.org/wiki/MIT_License)
*/
package net.scrutari.dataexport.api;
/**
*
* @author Vincent Calame
*/
public interface ThesaurusMetadataExport {
public final static int INTITULE_THESAURUS = 1;
public void setIntitule(int intituleType, String lang, String intituleValue);
}
/* ScrutariDataExport - Java implementation of ScrutariDataExport API
* http://www.scrutari.net/dokuwiki/scrutaridata:exportapi
*
* Copyright (c) 2010-2016 Vincent Calame - Exemole
* Licensed under MIT
* (http://en.wikipedia.org/wiki/MIT_License)
*/
package net.scrutari.dataexport.xml;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import net.scrutari.dataexport.api.BaseMetadataExport;
/**
*
* @author Vincent Calame
*/
public class XmlBaseMetadataExport extends XmlBuilder implements BaseMetadataExport {
private final List<String> langUIList = new ArrayList<String>();
private final Map<String, String> shortMap = new LinkedHashMap<String, String>();
private final Map<String, String> longMap = new LinkedHashMap<String, String>();
private String authority;
private String baseName;
private String baseIcon;
public XmlBaseMetadataExport() {
}
@Override
public void setAuthority(String authority) {
this.authority = authority;
}
@Override
public void setBaseName(String baseName) {
this.baseName = baseName;
}
@Override
public void setBaseIcon(String baseIcon) {
this.baseIcon = baseIcon;
}
@Override
public void setIntitule(int intituleType, String lang, String intituleValue) {
Map<String, String> map = getMap(intituleType);
map.put(lang, intituleValue);
}
@Override
public void addLangUI(String lang) {
langUIList.add(lang);
}
@Override
public void writeXML(XmlWriter xmlWriter) {
xmlWriter.openTag("base-metadata");
xmlWriter.addSimpleElement("authority", authority);
xmlWriter.addSimpleElement("base-name", baseName);
xmlWriter.addSimpleElement("base-icon", baseIcon);
addMap(INTITULE_SHORT, xmlWriter);
addMap(INTITULE_LONG, xmlWriter);
int size = langUIList.size();
if (size > 0) {
xmlWriter.openTag("langs-ui");
for (int i = 0; i < size; i++) {
xmlWriter.addSimpleElement("lang", langUIList.get(i));
}
xmlWriter.closeTag("langs-ui");
}
xmlWriter.closeTag("base-metadata");
}
private void addMap(int intituleType, XmlWriter xmlWriter) {
Map<String, String> map = getMap(intituleType);
if (map.isEmpty()) {
return;
}
String suffix = getSuffix(intituleType);
xmlWriter.openTag("intitule-" + suffix);
for (Map.Entry<String, String> entry : map.entrySet()) {
xmlWriter.addLibElement(entry.getKey(), entry.getValue());
}
xmlWriter.closeTag("intitule-" + suffix);
}
private Map<String, String> getMap(int type) {
switch (type) {
case INTITULE_SHORT:
return shortMap;
case INTITULE_LONG:
return longMap;
default:
throw new IllegalArgumentException("Wrong intituleType = " + type);
}
}
private static String getSuffix(int type) {
switch (type) {
case INTITULE_SHORT:
return "short";
case INTITULE_LONG:
return "long";
default:
throw new IllegalArgumentException("Wrong intituleType = " + type);
}
}
}
/* ScrutariDataExport - Java implementation of ScrutariDataExport API
* http://www.scrutari.net/dokuwiki/scrutaridata:exportapi
*
* Copyright (c) 2010-2016 Vincent Calame - Exemole
* Licensed under MIT
* (http://en.wikipedia.org/wiki/MIT_License)
*/
package net.scrutari.dataexport.xml;
/**
*
* @author Vincent Calame
*/
public abstract class XmlBuilder {
public abstract void writeXML(XmlWriter xmlWriter);
}
/* ScrutariDataExport - Java implementation of ScrutariDataExport API
* http://www.scrutari.net/dokuwiki/scrutaridata:exportapi
*
* Copyright (c) 2010-2016 Vincent Calame - Exemole
* Licensed under MIT
* (http://en.wikipedia.org/wiki/MIT_License)
*/
package net.scrutari.dataexport.xml;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import net.scrutari.dataexport.api.CorpusMetadataExport;
/**
*
* @author Vincent Calame
*/
public class XmlCorpusMetadataExport extends XmlBuilder implements CorpusMetadataExport {
private final Map<String, String> corpusMap = new LinkedHashMap<String, String>();
private final Map<String, String> ficheMap = new LinkedHashMap<String, String>();
private final List<Map<String, String>> complementMapList = new ArrayList<Map<String, String>>();
private String corpusIcon;
private String hrefParent;
public XmlCorpusMetadataExport() {
}
@Override
public void setCorpusIcon(String corpusIcon) {
this.corpusIcon = corpusIcon;
}
@Override
public void setHrefParent(String hrefParent) {
this.hrefParent = hrefParent;
}
@Override
public void setIntitule(int intituleType, String lang, String intituleValue) {
Map<String, String> map = getMap(intituleType);
map.put(lang, intituleValue);
}
@Override
public int addComplement() {
complementMapList.add(new LinkedHashMap<String, String>());
return complementMapList.size();
}
@Override
public void setComplementIntitule(int complementNumber, String lang, String intituleValue) {
if ((complementNumber < 0) || (complementNumber > complementMapList.size())) {
return;
}
Map<String, String> map = complementMapList.get(complementNumber - 1);
map.put(lang, intituleValue);
}
@Override
public void writeXML(XmlWriter xmlWriter) {
xmlWriter.openTag("corpus-metadata");
addMap(INTITULE_CORPUS, xmlWriter);
addMap(INTITULE_FICHE, xmlWriter);
xmlWriter.addSimpleElement("href-parent", hrefParent);
xmlWriter.addSimpleElement("corpus-icon", corpusIcon);
for (Map<String, String> map : complementMapList) {
addComplementMap(map, xmlWriter);
}
xmlWriter.closeTag("corpus-metadata");
}
private void addComplementMap(Map<String, String> map, XmlWriter xmlWriter) {
xmlWriter.openTag("complement-metadata");
for (Map.Entry<String, String> entry : map.entrySet()) {
xmlWriter.addLibElement(entry.getKey(), entry.getValue());
}
xmlWriter.closeTag("complement-metadata");
}
private void addMap(int intituleType, XmlWriter xmlWriter) {
Map<String, String> map = getMap(intituleType);
if (map.isEmpty()) {
return;
}
String suffix = getSuffix(intituleType);
xmlWriter.openTag("intitule-" + suffix);
for (Map.Entry<String, String> entry : map.entrySet()) {
xmlWriter.addLibElement(entry.getKey(), entry.getValue());
}
xmlWriter.closeTag("intitule-" + suffix);
}
private Map<String, String> getMap(int type) {
switch (type) {
case INTITULE_CORPUS:
return corpusMap;
case INTITULE_FICHE:
return ficheMap;
default:
throw new IllegalArgumentException("Wrong intituleType = " + type);