Skip to content

Commit

Permalink
KEYCLOAK-1127 Change theme structure from 'type/name' to 'name/type'
Browse files Browse the repository at this point in the history
  • Loading branch information
stianst committed Mar 23, 2015
1 parent acef322 commit 97d7fd6
Show file tree
Hide file tree
Showing 317 changed files with 24 additions and 41 deletions.
Expand Up @@ -2,13 +2,11 @@

import org.keycloak.freemarker.Theme;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.Locale;
import java.util.Properties;
import java.util.ResourceBundle;

/**
* @author <a href="mailto:sthorger@redhat.com">Stian Thorgersen</a>
Expand Down Expand Up @@ -42,7 +40,7 @@ public void init(String name, Type type, ClassLoader classLoader) throws IOExcep
this.type = type;
this.classLoader = classLoader;

String themeRoot = "theme/" + type.toString().toLowerCase() + "/" + name + "/";
String themeRoot = "theme/" + name + "/" + type.toString().toLowerCase() + "/";

this.templateRoot = themeRoot;
this.resourceRoot = themeRoot + "resources/";
Expand All @@ -60,10 +58,6 @@ public void init(String name, Type type, ClassLoader classLoader) throws IOExcep
}
}

public ClassLoaderTheme() {

}

@Override
public String getName() {
return name;
Expand Down
Expand Up @@ -15,10 +15,10 @@
*/
public class FolderThemeProvider implements ThemeProvider {

private File rootDir;
private File themesDir;

public FolderThemeProvider(File rootDir) {
this.rootDir = rootDir;
public FolderThemeProvider(File themesDir) {
this.themesDir = themesDir;
}

@Override
Expand All @@ -28,51 +28,41 @@ public int getProviderPriority() {

@Override
public Theme getTheme(String name, Theme.Type type) throws IOException {
if (hasTheme(name, type)) {
return new FolderTheme(new File(getTypeDir(type), name), type);
}
return null;
File themeDir = getThemeDir(name, type);
return themeDir.isDirectory() ? new FolderTheme(themeDir, type) : null;
}

@Override
public Set<String> nameSet(Theme.Type type) {
File typeDir = getTypeDir(type);
if (typeDir != null) {
File[] themes = typeDir.listFiles(new FileFilter() {
@Override
public boolean accept(File pathname) {
return pathname.isDirectory();
}
});

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) {
Set<String> names = new HashSet<String>();
for (File t : themes) {
names.add(t.getName());
for (File themeDir : themeDirs) {
names.add(themeDir.getName());
}
return names;
} else {
return Collections.emptySet();
}

return Collections.emptySet();
}

private File getTypeDir(Theme.Type type) {
if (rootDir != null && rootDir.isDirectory()) {
File typeDir = new File(rootDir, type.name().toLowerCase());
if (typeDir.isDirectory()) {
return typeDir;
}
}
return null;
}

@Override
public boolean hasTheme(String name, Theme.Type type) {
File typeDir = getTypeDir(type);
return typeDir != null && new File(typeDir, name).isDirectory();
return getThemeDir(name, type).isDirectory();
}

@Override
public void close() {
}

private File getThemeDir(String name, Theme.Type type) {
return new File(themesDir, name + File.separator + type.name().toLowerCase());
}

}

0 comments on commit 97d7fd6

Please sign in to comment.