Some bugfixes for themes
parent
d941a795c9
commit
0c0e1135c0
|
|
@ -62,10 +62,13 @@ public class FileSystemThemeProvider implements ThemeProvider {
|
||||||
);
|
);
|
||||||
|
|
||||||
private static final String BASE_PATH = "/themes";
|
private static final String BASE_PATH = "/themes";
|
||||||
|
|
||||||
private static final String DRAFT_THEMES_PATH = BASE_PATH + "/draft";
|
private static final String DRAFT_THEMES_PATH = BASE_PATH + "/draft";
|
||||||
|
|
||||||
private static final String LIVE_THEMES_PATH = BASE_PATH + "/live";
|
private static final String LIVE_THEMES_PATH = BASE_PATH + "/live";
|
||||||
|
|
||||||
private static final String THEME_JSON = "%s/theme.json";
|
private static final String THEME_JSON = "%s/theme.json";
|
||||||
|
|
||||||
private static final String THEME_XML = "%s/theme.xml";
|
private static final String THEME_XML = "%s/theme.xml";
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
|
|
@ -83,8 +86,12 @@ public class FileSystemThemeProvider implements ThemeProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<ThemeInfo> getThemes() {
|
public String getClassName() {
|
||||||
|
return FileSystemThemeProvider.class.getName();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<ThemeInfo> getThemes() {
|
||||||
try {
|
try {
|
||||||
if (!ccmFiles.isDirectory(BASE_PATH)
|
if (!ccmFiles.isDirectory(BASE_PATH)
|
||||||
|| !ccmFiles.isDirectory(DRAFT_THEMES_PATH)) {
|
|| !ccmFiles.isDirectory(DRAFT_THEMES_PATH)) {
|
||||||
|
|
@ -437,12 +444,15 @@ public class FileSystemThemeProvider implements ThemeProvider {
|
||||||
private Optional<ThemeInfo> readInfo(final String themeName) {
|
private Optional<ThemeInfo> readInfo(final String themeName) {
|
||||||
|
|
||||||
final ThemeManifest manifest;
|
final ThemeManifest manifest;
|
||||||
|
final ThemeVersion themeVersion;
|
||||||
try {
|
try {
|
||||||
|
|
||||||
final String jsonPath = String.format(
|
final String jsonPath = String.format(
|
||||||
DRAFT_THEMES_PATH + "/" + THEME_JSON, themeName);
|
DRAFT_THEMES_PATH + "/" + THEME_JSON, themeName
|
||||||
|
);
|
||||||
final String xmlPath = String.format(
|
final String xmlPath = String.format(
|
||||||
DRAFT_THEMES_PATH + "/" + THEME_XML, themeName);
|
DRAFT_THEMES_PATH + "/" + THEME_XML, themeName
|
||||||
|
);
|
||||||
|
|
||||||
if (ccmFiles.existsFile(jsonPath)) {
|
if (ccmFiles.existsFile(jsonPath)) {
|
||||||
final InputStream inputStream = ccmFiles
|
final InputStream inputStream = ccmFiles
|
||||||
|
|
@ -455,6 +465,21 @@ public class FileSystemThemeProvider implements ThemeProvider {
|
||||||
} else {
|
} else {
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final String liveJsonPath = String.format(
|
||||||
|
LIVE_THEMES_PATH + "/" + THEME_JSON, themeName
|
||||||
|
);
|
||||||
|
final String liveXmlPath = String.format(
|
||||||
|
LIVE_THEMES_PATH + "/" + THEME_XML, themeName
|
||||||
|
);
|
||||||
|
final boolean hasLiveVersion
|
||||||
|
= ccmFiles.existsFile(liveJsonPath)
|
||||||
|
|| ccmFiles.existsFile(liveXmlPath);
|
||||||
|
if (hasLiveVersion) {
|
||||||
|
themeVersion = ThemeVersion.LIVE;
|
||||||
|
} else {
|
||||||
|
themeVersion = ThemeVersion.DRAFT;
|
||||||
|
}
|
||||||
} catch (FileAccessException
|
} catch (FileAccessException
|
||||||
| FileDoesNotExistException
|
| FileDoesNotExistException
|
||||||
| InsufficientPermissionsException ex) {
|
| InsufficientPermissionsException ex) {
|
||||||
|
|
@ -464,6 +489,8 @@ public class FileSystemThemeProvider implements ThemeProvider {
|
||||||
|
|
||||||
final ThemeInfo themeInfo = new ThemeInfo();
|
final ThemeInfo themeInfo = new ThemeInfo();
|
||||||
themeInfo.setManifest(manifest);
|
themeInfo.setManifest(manifest);
|
||||||
|
themeInfo.setProvider(FileSystemThemeProvider.class);
|
||||||
|
themeInfo.setVersion(themeVersion);
|
||||||
|
|
||||||
return Optional.of(themeInfo);
|
return Optional.of(themeInfo);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -92,6 +92,11 @@ public class StaticThemeProvider implements ThemeProvider {
|
||||||
return "StaticThemeProvider";
|
return "StaticThemeProvider";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getClassName() {
|
||||||
|
return StaticThemeProvider.class.getName();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<ThemeInfo> getThemes() {
|
public List<ThemeInfo> getThemes() {
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -38,10 +38,20 @@ public interface ThemeProvider extends Serializable {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A human readable name for the {@code ThemeProvider} implementation.
|
* A human readable name for the {@code ThemeProvider} implementation.
|
||||||
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
String getName();
|
String getName();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The class name of the theme provider. This method is necessary because
|
||||||
|
* using {@link Object#getClass() } may return the class name of the CDI
|
||||||
|
* proxy and not of the implementing class.
|
||||||
|
*
|
||||||
|
* @return The class name of the {@code ThemeProvider} implementation.
|
||||||
|
*/
|
||||||
|
String getClassName();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides a list of all themes provided by this theme provider. The list
|
* Provides a list of all themes provided by this theme provider. The list
|
||||||
* should be ordered by the name of the theme.
|
* should be ordered by the name of the theme.
|
||||||
|
|
|
||||||
|
|
@ -99,9 +99,9 @@ public class Themes implements Serializable {
|
||||||
* @return An {@link Optional} with informations about theme {@code theme}
|
* @return An {@link Optional} with informations about theme {@code theme}
|
||||||
* or an empty optional if there is no such theme.
|
* or an empty optional if there is no such theme.
|
||||||
*/
|
*/
|
||||||
public Optional<ThemeInfo> getTheme(final String name,
|
public Optional<ThemeInfo> getTheme(
|
||||||
final ThemeVersion version) {
|
final String name, final ThemeVersion version
|
||||||
|
) {
|
||||||
for (final ThemeProvider provider : providers) {
|
for (final ThemeProvider provider : providers) {
|
||||||
if (provider.providesTheme(name, version)) {
|
if (provider.providesTheme(name, version)) {
|
||||||
return provider.getThemeInfo(name, version);
|
return provider.getThemeInfo(name, version);
|
||||||
|
|
|
||||||
|
|
@ -76,6 +76,11 @@ public class DatabaseThemeProvider implements ThemeProvider {
|
||||||
return "DatabaseThemeProvider";
|
return "DatabaseThemeProvider";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getClassName() {
|
||||||
|
return DatabaseThemeProvider.class.getName();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(Transactional.TxType.REQUIRED)
|
@Transactional(Transactional.TxType.REQUIRED)
|
||||||
public List<ThemeInfo> getThemes() {
|
public List<ThemeInfo> getThemes() {
|
||||||
|
|
|
||||||
|
|
@ -206,7 +206,8 @@ public class ThemesMvc {
|
||||||
private ThemeInfo getTheme(
|
private ThemeInfo getTheme(
|
||||||
final Site site,
|
final Site site,
|
||||||
final String theme,
|
final String theme,
|
||||||
final ThemeVersion themeVersion) {
|
final ThemeVersion themeVersion
|
||||||
|
) {
|
||||||
if (DEFAULT_THEME_PARAM.equals(theme)) {
|
if (DEFAULT_THEME_PARAM.equals(theme)) {
|
||||||
return themes
|
return themes
|
||||||
.getTheme(site.getDefaultTheme(), themeVersion)
|
.getTheme(site.getDefaultTheme(), themeVersion)
|
||||||
|
|
|
||||||
|
|
@ -79,7 +79,7 @@ public class ThemesModel {
|
||||||
.filter(ThemeProvider::supportsDraftThemes)
|
.filter(ThemeProvider::supportsDraftThemes)
|
||||||
.collect(
|
.collect(
|
||||||
Collectors.toMap(
|
Collectors.toMap(
|
||||||
provider -> provider.getClass().getName(),
|
provider -> provider.getClassName(),
|
||||||
provider -> provider.getName()
|
provider -> provider.getName()
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue