use of org.omegat.tokenizer.Tokenizer in project omegat by omegat-org.
the class PluginUtils method searchForTokenizer.
private static Class<?> searchForTokenizer(String lang) {
if (lang.isEmpty()) {
return null;
}
lang = lang.toLowerCase(Locale.ENGLISH);
// Choose first relevant tokenizer as fallback if no
// "default" tokenizer is found.
Class<?> fallback = null;
for (Class<?> c : TOKENIZER_CLASSES) {
Tokenizer ann = c.getAnnotation(Tokenizer.class);
if (ann == null) {
continue;
}
String[] languages = ann.languages();
try {
if (languages.length == 1 && languages[0].equals(Tokenizer.DISCOVER_AT_RUNTIME)) {
languages = ((ITokenizer) c.newInstance()).getSupportedLanguages();
}
} catch (IllegalAccessException | InstantiationException ex) {
Log.log(ex);
}
for (String s : languages) {
if (lang.equals(s)) {
if (ann.isDefault()) {
// Return best possible match.
return c;
} else if (fallback == null) {
fallback = c;
}
}
}
}
return fallback;
}
Aggregations