Added priority to theme loaders to guarantee order

This commit is contained in:
Stian Thorgersen 2014-02-17 09:55:17 +00:00
parent 81a90232d6
commit 3342729da8
4 changed files with 25 additions and 1 deletions

View file

@ -6,6 +6,8 @@ import org.keycloak.util.ProviderLoader;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.Collections;
import java.util.Comparator;
import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;
@ -25,7 +27,17 @@ public class ThemeLoader {
name = DEFAULT;
}
Iterable<ThemeProvider> providers = ProviderLoader.load(ThemeProvider.class);
List<ThemeProvider> providers = new LinkedList();
for (ThemeProvider p : ProviderLoader.load(ThemeProvider.class)) {
providers.add(p);
}
Collections.sort(providers, new Comparator<ThemeProvider>() {
@Override
public int compare(ThemeProvider o1, ThemeProvider o2) {
return o2.getProviderPriority() - o1.getProviderPriority();
}
});
Theme theme = findTheme(providers, name, type);
if (theme.getParentName() != null) {

View file

@ -8,6 +8,8 @@ import java.util.Set;
*/
public interface ThemeProvider {
public int getProviderPriority();
public Theme createTheme(String name, Theme.Type type) throws IOException;
public Set<String> nameSet(Theme.Type type);

View file

@ -34,6 +34,11 @@ public class DefaultLoginThemeProvider implements ThemeProvider {
defaultAccountThemes.add(KEYCLOAK);
}
@Override
public int getProviderPriority() {
return 0;
}
@Override
public Theme createTheme(String name, Theme.Type type) throws IOException {
if (hasTheme(name, type)) {

View file

@ -24,6 +24,11 @@ public class FolderThemeProvider implements ThemeProvider {
}
}
@Override
public int getProviderPriority() {
return 100;
}
@Override
public Theme createTheme(String name, Theme.Type type) throws IOException {
if (hasTheme(name, type)) {