From 3342729da8a4227003f58132c439124f013e11d7 Mon Sep 17 00:00:00 2001 From: Stian Thorgersen Date: Mon, 17 Feb 2014 09:55:17 +0000 Subject: [PATCH] Added priority to theme loaders to guarantee order --- .../java/org/keycloak/freemarker/ThemeLoader.java | 14 +++++++++++++- .../org/keycloak/freemarker/ThemeProvider.java | 2 ++ .../keycloak/theme/DefaultLoginThemeProvider.java | 5 +++++ .../org/keycloak/theme/FolderThemeProvider.java | 5 +++++ 4 files changed, 25 insertions(+), 1 deletion(-) diff --git a/forms/common-freemarker/src/main/java/org/keycloak/freemarker/ThemeLoader.java b/forms/common-freemarker/src/main/java/org/keycloak/freemarker/ThemeLoader.java index ce9f34a11e..63c52f18fa 100644 --- a/forms/common-freemarker/src/main/java/org/keycloak/freemarker/ThemeLoader.java +++ b/forms/common-freemarker/src/main/java/org/keycloak/freemarker/ThemeLoader.java @@ -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 providers = ProviderLoader.load(ThemeProvider.class); + List providers = new LinkedList(); + for (ThemeProvider p : ProviderLoader.load(ThemeProvider.class)) { + providers.add(p); + } + + Collections.sort(providers, new Comparator() { + @Override + public int compare(ThemeProvider o1, ThemeProvider o2) { + return o2.getProviderPriority() - o1.getProviderPriority(); + } + }); Theme theme = findTheme(providers, name, type); if (theme.getParentName() != null) { diff --git a/forms/common-freemarker/src/main/java/org/keycloak/freemarker/ThemeProvider.java b/forms/common-freemarker/src/main/java/org/keycloak/freemarker/ThemeProvider.java index 31de058f03..6ca677c741 100644 --- a/forms/common-freemarker/src/main/java/org/keycloak/freemarker/ThemeProvider.java +++ b/forms/common-freemarker/src/main/java/org/keycloak/freemarker/ThemeProvider.java @@ -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 nameSet(Theme.Type type); diff --git a/forms/common-themes/src/main/java/org/keycloak/theme/DefaultLoginThemeProvider.java b/forms/common-themes/src/main/java/org/keycloak/theme/DefaultLoginThemeProvider.java index fdfb18572e..11d38d1f63 100644 --- a/forms/common-themes/src/main/java/org/keycloak/theme/DefaultLoginThemeProvider.java +++ b/forms/common-themes/src/main/java/org/keycloak/theme/DefaultLoginThemeProvider.java @@ -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)) { diff --git a/forms/common-themes/src/main/java/org/keycloak/theme/FolderThemeProvider.java b/forms/common-themes/src/main/java/org/keycloak/theme/FolderThemeProvider.java index 0d328b2ffe..9a2ef1692a 100644 --- a/forms/common-themes/src/main/java/org/keycloak/theme/FolderThemeProvider.java +++ b/forms/common-themes/src/main/java/org/keycloak/theme/FolderThemeProvider.java @@ -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)) {