in src/main/java/com/googlesource/gerrit/plugins/xdocs/formatter/Formatters.java [80:134]
public FormatterProvider get(ProjectState project, String fileName) {
XDocGlobalConfig globalCfg =
new XDocGlobalConfig(pluginCfgFactory.getGlobalPluginConfig(pluginName));
MimeType mimeType = fileTypeRegistry.getMimeType(fileName, (byte[]) null);
mimeType =
new MimeType(
FileContentUtil.resolveContentType(
project, fileName, FileMode.FILE, mimeType.toString()));
String extension = FilenameUtils.getExtension(fileName);
FormatterProvider formatter = null;
int formatterPrio = 0;
for (String pluginName : formatters.plugins()) {
for (Entry<String, Provider<Formatter>> e : formatters.byPlugin(pluginName).entrySet()) {
if (!globalCfg.getFormatterConfig(e.getKey()).getBoolean(KEY_ENABLED, true)) {
continue;
}
ConfigSection formatterCfg = getFormatterConfig(e.getKey(), project);
String[] prefixes = formatterCfg.getStringList(KEY_PREFIX);
if (prefixes.length > 0) {
boolean match = false;
for (String prefix : prefixes) {
if (fileName.startsWith(prefix)) {
match = true;
break;
}
}
if (!match) {
continue;
}
}
for (String mt : formatterCfg.getStringList(KEY_MIME_TYPE)) {
MimeType configuredMimeType = new MimeType(mt);
if (mimeType.equals(configuredMimeType)
|| ("*".equals(configuredMimeType.getSubType())
&& mimeType.getMediaType().equals(configuredMimeType.getMediaType()))) {
int prio = formatterCfg.getInt(KEY_PRIO, 0);
if (formatter == null || prio > formatterPrio) {
formatter = new FormatterProvider(e.getKey(), e.getValue());
formatterPrio = prio;
}
}
}
for (String ext : formatterCfg.getStringList(KEY_EXT)) {
if (extension.equals(ext) || "*".equals(ext)) {
int prio = formatterCfg.getInt(KEY_PRIO, 0);
if (formatter == null || prio > formatterPrio) {
formatter = new FormatterProvider(e.getKey(), e.getValue());
formatterPrio = prio;
}
}
}
}
}
return formatter;
}