1
|
package eu.dnetlib.data.search.utils.vocabulary;
|
2
|
|
3
|
import gr.uoa.di.driver.xml.VocabularyXmlConverter;
|
4
|
|
5
|
import java.util.Locale;
|
6
|
|
7
|
abstract class VocabularyLoader {
|
8
|
|
9
|
//the local path where vocabularies are saved
|
10
|
//private String vocabularyPath;
|
11
|
|
12
|
private static final String EMPTY_FILE = "<?xml version=\"1.0\"?><RESOURCE_PROFILE></RESOURCE_PROFILE>";
|
13
|
|
14
|
//private static final Logger logger = Logger.getLogger(VocabularyLoader.class);
|
15
|
|
16
|
public eu.dnetlib.domain.enabling.Vocabulary loadVocabulary(Vocabulary vocabulary, Locale locale) throws Exception {
|
17
|
String xml = getVocabularyXml(vocabulary, locale);
|
18
|
VocabularyXmlConverter converter = new VocabularyXmlConverter();
|
19
|
return converter.XmlToObject(xml);
|
20
|
}
|
21
|
|
22
|
/**
|
23
|
* Returns the vocabulary file
|
24
|
* @param vocabulary
|
25
|
* @param locale
|
26
|
* @return the path of the vocabulary xml file
|
27
|
*/
|
28
|
protected abstract String getVocabularyXml(Vocabulary vocabulary, Locale locale);
|
29
|
|
30
|
/**
|
31
|
* Returns the vocabulary name
|
32
|
* @param vocabulary
|
33
|
* @param locale
|
34
|
* @return
|
35
|
|
36
|
protected String createVocabularyName(Vocabulary vocabulary, Locale locale) {
|
37
|
return vocabulary.getName() + "_" + locale.getLanguage() + "_" +
|
38
|
locale.getCountry();
|
39
|
}
|
40
|
*/
|
41
|
|
42
|
/**
|
43
|
* Saves the xml vocabulary file in the vocabulary local path.
|
44
|
* If the xml vocabulary file is null it saves an empty xml file.
|
45
|
* @param vocabulary
|
46
|
* @param xml
|
47
|
* @param locale
|
48
|
* @return The path where the vocabulary is saved
|
49
|
* @throws IOException
|
50
|
|
51
|
private String saveVocabularyXmlFile (Vocabulary vocabulary, String xml, Locale locale) throws IOException {
|
52
|
String xmlFilePath = vocabularyPath + createVocabularyName(vocabulary, locale);
|
53
|
File file = new File(xmlFilePath);
|
54
|
|
55
|
if (xml == null) {
|
56
|
logger.warn("Vocabulary " + xmlFilePath + " is an empty xml file.");
|
57
|
xml = EMPTY_FILE;
|
58
|
}
|
59
|
|
60
|
FileUtils.writeStringToFile(file, xml);
|
61
|
|
62
|
return xmlFilePath;
|
63
|
}
|
64
|
|
65
|
public void setVocabularyPath(String vocabularyPath) {
|
66
|
this.vocabularyPath = vocabularyPath;
|
67
|
}
|
68
|
*/
|
69
|
}
|