in DictionaryAnnotator/src/main/java/org/apache/uima/annotator/dict_annot/impl/DictionaryAnnotator.java [382:436]
private DictionaryFile resolveRelativeFilePath(String fileName, ArrayList<File> datapathElements)
throws DictionaryAnnotatorConfigException {
DictionaryFile dictionaryFile;
URL url = null;
// check first if the current fileName is an URL
if (fileName.startsWith("http")) {
// try to open http connection to get the stream
try {
// create URL object
url = new URL(fileName);
// create URL connection
URLConnection connection = url.openConnection();
// get stream from URL connection
dictionaryFile = new DictionaryFile(url.toString(), new BufferedInputStream(connection
.getInputStream()));
return dictionaryFile;
} catch (MalformedURLException ex) {
throw new DictionaryAnnotatorConfigException("dictionary_annotator_invalid_url_resource",
new Object[] { fileName }, ex);
} catch (IOException ex) {
throw new DictionaryAnnotatorConfigException("dictionary_annotator_invalid_url_resource",
new Object[] { fileName }, ex);
}
}
// try to use the class loader to load the file resource
else if ((url = this.getClass().getClassLoader().getResource(fileName)) != null) {
// we have successfully resolved the concept file, now also get it as
// stream
InputStream stream = this.getClass().getClassLoader().getResourceAsStream(fileName);
dictionaryFile = new DictionaryFile(url.getFile(), new BufferedInputStream(stream));
return dictionaryFile;
} else {
if (datapathElements == null || datapathElements.size() == 0) {
return null;
}
// try to use the datapath to load the file resource
for (int i = 0; i < datapathElements.size(); i++) {
File testFile = new File(datapathElements.get(i), fileName);
if (testFile.exists()) {
InputStream stream;
try {
stream = new BufferedInputStream(new FileInputStream(testFile));
} catch (FileNotFoundException ex) {
return null;
}
dictionaryFile = new DictionaryFile(testFile.getAbsolutePath(), stream);
return dictionaryFile;
}
}
}
return null;
}