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 DRAFT_THEMES_PATH = BASE_PATH + "/draft";
|
||||
|
||||
private static final String LIVE_THEMES_PATH = BASE_PATH + "/live";
|
||||
|
||||
private static final String THEME_JSON = "%s/theme.json";
|
||||
|
||||
private static final String THEME_XML = "%s/theme.xml";
|
||||
|
||||
@Inject
|
||||
|
|
@ -83,8 +86,12 @@ public class FileSystemThemeProvider implements ThemeProvider {
|
|||
}
|
||||
|
||||
@Override
|
||||
public List<ThemeInfo> getThemes() {
|
||||
public String getClassName() {
|
||||
return FileSystemThemeProvider.class.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ThemeInfo> getThemes() {
|
||||
try {
|
||||
if (!ccmFiles.isDirectory(BASE_PATH)
|
||||
|| !ccmFiles.isDirectory(DRAFT_THEMES_PATH)) {
|
||||
|
|
@ -104,7 +111,7 @@ public class FileSystemThemeProvider implements ThemeProvider {
|
|||
| FileDoesNotExistException
|
||||
| InsufficientPermissionsException ex) {
|
||||
throw new UnexpectedErrorException(ex);
|
||||
} catch(CcmFilesNotConfiguredException ex) {
|
||||
} catch (CcmFilesNotConfiguredException ex) {
|
||||
LOGGER.warn(ex);
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
|
@ -132,7 +139,7 @@ public class FileSystemThemeProvider implements ThemeProvider {
|
|||
| InsufficientPermissionsException ex) {
|
||||
|
||||
throw new UnexpectedErrorException(ex);
|
||||
} catch(CcmFilesNotConfiguredException ex) {
|
||||
} catch (CcmFilesNotConfiguredException ex) {
|
||||
LOGGER.warn(ex);
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
|
@ -437,12 +444,15 @@ public class FileSystemThemeProvider implements ThemeProvider {
|
|||
private Optional<ThemeInfo> readInfo(final String themeName) {
|
||||
|
||||
final ThemeManifest manifest;
|
||||
final ThemeVersion themeVersion;
|
||||
try {
|
||||
|
||||
final String jsonPath = String.format(
|
||||
DRAFT_THEMES_PATH + "/" + THEME_JSON, themeName);
|
||||
DRAFT_THEMES_PATH + "/" + THEME_JSON, themeName
|
||||
);
|
||||
final String xmlPath = String.format(
|
||||
DRAFT_THEMES_PATH + "/" + THEME_XML, themeName);
|
||||
DRAFT_THEMES_PATH + "/" + THEME_XML, themeName
|
||||
);
|
||||
|
||||
if (ccmFiles.existsFile(jsonPath)) {
|
||||
final InputStream inputStream = ccmFiles
|
||||
|
|
@ -455,6 +465,21 @@ public class FileSystemThemeProvider implements ThemeProvider {
|
|||
} else {
|
||||
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
|
||||
| FileDoesNotExistException
|
||||
| InsufficientPermissionsException ex) {
|
||||
|
|
@ -464,6 +489,8 @@ public class FileSystemThemeProvider implements ThemeProvider {
|
|||
|
||||
final ThemeInfo themeInfo = new ThemeInfo();
|
||||
themeInfo.setManifest(manifest);
|
||||
themeInfo.setProvider(FileSystemThemeProvider.class);
|
||||
themeInfo.setVersion(themeVersion);
|
||||
|
||||
return Optional.of(themeInfo);
|
||||
}
|
||||
|
|
@ -476,7 +503,7 @@ public class FileSystemThemeProvider implements ThemeProvider {
|
|||
|| filePath.startsWith("/")) {
|
||||
path = String.join("", themePath, filePath);
|
||||
} else {
|
||||
path= String.join("/", themePath, filePath);
|
||||
path = String.join("/", themePath, filePath);
|
||||
}
|
||||
|
||||
final String name;
|
||||
|
|
|
|||
|
|
@ -92,6 +92,11 @@ public class StaticThemeProvider implements ThemeProvider {
|
|||
return "StaticThemeProvider";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getClassName() {
|
||||
return StaticThemeProvider.class.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ThemeInfo> getThemes() {
|
||||
|
||||
|
|
|
|||
|
|
@ -38,10 +38,20 @@ public interface ThemeProvider extends Serializable {
|
|||
|
||||
/**
|
||||
* A human readable name for the {@code ThemeProvider} implementation.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
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
|
||||
* 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}
|
||||
* or an empty optional if there is no such theme.
|
||||
*/
|
||||
public Optional<ThemeInfo> getTheme(final String name,
|
||||
final ThemeVersion version) {
|
||||
|
||||
public Optional<ThemeInfo> getTheme(
|
||||
final String name, final ThemeVersion version
|
||||
) {
|
||||
for (final ThemeProvider provider : providers) {
|
||||
if (provider.providesTheme(name, version)) {
|
||||
return provider.getThemeInfo(name, version);
|
||||
|
|
|
|||
|
|
@ -76,6 +76,11 @@ public class DatabaseThemeProvider implements ThemeProvider {
|
|||
return "DatabaseThemeProvider";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getClassName() {
|
||||
return DatabaseThemeProvider.class.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
public List<ThemeInfo> getThemes() {
|
||||
|
|
|
|||
|
|
@ -206,7 +206,8 @@ public class ThemesMvc {
|
|||
private ThemeInfo getTheme(
|
||||
final Site site,
|
||||
final String theme,
|
||||
final ThemeVersion themeVersion) {
|
||||
final ThemeVersion themeVersion
|
||||
) {
|
||||
if (DEFAULT_THEME_PARAM.equals(theme)) {
|
||||
return themes
|
||||
.getTheme(site.getDefaultTheme(), themeVersion)
|
||||
|
|
|
|||
|
|
@ -79,7 +79,7 @@ public class ThemesModel {
|
|||
.filter(ThemeProvider::supportsDraftThemes)
|
||||
.collect(
|
||||
Collectors.toMap(
|
||||
provider -> provider.getClass().getName(),
|
||||
provider -> provider.getClassName(),
|
||||
provider -> provider.getName()
|
||||
)
|
||||
);
|
||||
|
|
|
|||
Loading…
Reference in New Issue