2014-01-28 11:52:18 +00:00
|
|
|
package org.keycloak.theme;
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
import java.io.FileFilter;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.HashSet;
|
|
|
|
import java.util.Set;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @author <a href="mailto:sthorger@redhat.com">Stian Thorgersen</a>
|
|
|
|
*/
|
|
|
|
public class FolderThemeProvider implements ThemeProvider {
|
|
|
|
|
2015-03-23 07:41:51 +00:00
|
|
|
private File themesDir;
|
2014-01-28 11:52:18 +00:00
|
|
|
|
2015-03-23 07:41:51 +00:00
|
|
|
public FolderThemeProvider(File themesDir) {
|
|
|
|
this.themesDir = themesDir;
|
2014-01-28 11:52:18 +00:00
|
|
|
}
|
|
|
|
|
2014-02-17 09:55:17 +00:00
|
|
|
@Override
|
|
|
|
public int getProviderPriority() {
|
|
|
|
return 100;
|
|
|
|
}
|
|
|
|
|
2014-01-28 11:52:18 +00:00
|
|
|
@Override
|
2014-07-30 15:03:51 +00:00
|
|
|
public Theme getTheme(String name, Theme.Type type) throws IOException {
|
2015-03-23 07:41:51 +00:00
|
|
|
File themeDir = getThemeDir(name, type);
|
2015-03-23 09:45:54 +00:00
|
|
|
return themeDir.isDirectory() ? new FolderTheme(themeDir, name, type) : null;
|
2014-01-28 11:52:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Set<String> nameSet(Theme.Type type) {
|
2015-03-23 07:41:51 +00:00
|
|
|
final String typeName = type.name().toLowerCase();
|
|
|
|
File[] themeDirs = themesDir.listFiles(new FileFilter() {
|
|
|
|
@Override
|
|
|
|
public boolean accept(File pathname) {
|
|
|
|
return pathname.isDirectory() && new File(pathname, typeName).isDirectory();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
if (themeDirs != null) {
|
2014-01-28 11:52:18 +00:00
|
|
|
Set<String> names = new HashSet<String>();
|
2015-03-23 07:41:51 +00:00
|
|
|
for (File themeDir : themeDirs) {
|
|
|
|
names.add(themeDir.getName());
|
2014-01-28 11:52:18 +00:00
|
|
|
}
|
|
|
|
return names;
|
2015-03-23 07:41:51 +00:00
|
|
|
} else {
|
|
|
|
return Collections.emptySet();
|
2014-01-28 11:52:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean hasTheme(String name, Theme.Type type) {
|
2015-03-23 07:41:51 +00:00
|
|
|
return getThemeDir(name, type).isDirectory();
|
2014-01-28 11:52:18 +00:00
|
|
|
}
|
|
|
|
|
2014-05-19 11:58:45 +00:00
|
|
|
@Override
|
|
|
|
public void close() {
|
|
|
|
}
|
|
|
|
|
2015-03-23 07:41:51 +00:00
|
|
|
private File getThemeDir(String name, Theme.Type type) {
|
|
|
|
return new File(themesDir, name + File.separator + type.name().toLowerCase());
|
|
|
|
}
|
|
|
|
|
2014-01-28 11:52:18 +00:00
|
|
|
}
|