FileSystemThemeProvider: Catch exception thrown if CcmFiles is not configured, return empty list
Former-commit-id: 0156551cae
pull/7/head
parent
d9546b466d
commit
21fd8b34c3
|
|
@ -172,9 +172,10 @@ public class CcmFiles {
|
||||||
if (adapter.isConfigured()) {
|
if (adapter.isConfigured()) {
|
||||||
return adapter;
|
return adapter;
|
||||||
} else {
|
} else {
|
||||||
throw new UnexpectedErrorException(
|
throw new CcmFilesNotConfiguredException(
|
||||||
"Only the default FileSystemAdapter is available but is "
|
"Only the default FileSystemAdapter is available but is "
|
||||||
+ "not correctly configured.");
|
+ "not correctly configured."
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -196,7 +197,9 @@ public class CcmFiles {
|
||||||
final String dataPath = filesConf.getDataPath();
|
final String dataPath = filesConf.getDataPath();
|
||||||
|
|
||||||
if (dataPath == null || dataPath.trim().isEmpty()) {
|
if (dataPath == null || dataPath.trim().isEmpty()) {
|
||||||
throw new UnexpectedErrorException("dataPath is not configured.");
|
throw new CcmFilesNotConfiguredException(
|
||||||
|
"dataPath is not configured."
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dataPath.endsWith("/")) {
|
if (dataPath.endsWith("/")) {
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,67 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2020 LibreCCM Foundation.
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||||
|
* MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.libreccm.files;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
|
*/
|
||||||
|
public class CcmFilesNotConfiguredException extends RuntimeException {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new instance of <code>CcmFilesNotConfiguredException</code> without detail message.
|
||||||
|
*/
|
||||||
|
public CcmFilesNotConfiguredException() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs an instance of <code>CcmFilesNotConfiguredException</code> with the specified detail message.
|
||||||
|
*
|
||||||
|
* @param msg The detail message.
|
||||||
|
*/
|
||||||
|
public CcmFilesNotConfiguredException(final String msg) {
|
||||||
|
super(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs an instance of <code>CcmFilesNotConfiguredException</code> which wraps the
|
||||||
|
* specified exception.
|
||||||
|
*
|
||||||
|
* @param exception The exception to wrap.
|
||||||
|
*/
|
||||||
|
public CcmFilesNotConfiguredException(final Exception exception) {
|
||||||
|
super(exception);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs an instance of <code>CcmFilesNotConfiguredException</code> with the specified message which also wraps the
|
||||||
|
* specified exception.
|
||||||
|
*
|
||||||
|
* @param msg The detail message.
|
||||||
|
* @param exception The exception to wrap.
|
||||||
|
*/
|
||||||
|
public CcmFilesNotConfiguredException(final String msg, final Exception exception) {
|
||||||
|
super(msg, exception);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -18,8 +18,11 @@
|
||||||
*/
|
*/
|
||||||
package org.libreccm.theming;
|
package org.libreccm.theming;
|
||||||
|
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.libreccm.core.UnexpectedErrorException;
|
import org.libreccm.core.UnexpectedErrorException;
|
||||||
import org.libreccm.files.CcmFiles;
|
import org.libreccm.files.CcmFiles;
|
||||||
|
import org.libreccm.files.CcmFilesNotConfiguredException;
|
||||||
import org.libreccm.files.DirectoryNotEmptyException;
|
import org.libreccm.files.DirectoryNotEmptyException;
|
||||||
import org.libreccm.files.FileAccessException;
|
import org.libreccm.files.FileAccessException;
|
||||||
import org.libreccm.files.FileAlreadyExistsException;
|
import org.libreccm.files.FileAlreadyExistsException;
|
||||||
|
|
@ -54,6 +57,10 @@ public class FileSystemThemeProvider implements ThemeProvider {
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LogManager.getLogger(
|
||||||
|
FileSystemThemeProvider.class
|
||||||
|
);
|
||||||
|
|
||||||
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";
|
||||||
|
|
@ -74,7 +81,6 @@ public class FileSystemThemeProvider implements ThemeProvider {
|
||||||
public List<ThemeInfo> getThemes() {
|
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)) {
|
||||||
|
|
||||||
|
|
@ -92,8 +98,10 @@ public class FileSystemThemeProvider implements ThemeProvider {
|
||||||
} catch (FileAccessException
|
} catch (FileAccessException
|
||||||
| FileDoesNotExistException
|
| FileDoesNotExistException
|
||||||
| InsufficientPermissionsException ex) {
|
| InsufficientPermissionsException ex) {
|
||||||
|
|
||||||
throw new UnexpectedErrorException(ex);
|
throw new UnexpectedErrorException(ex);
|
||||||
|
} catch(CcmFilesNotConfiguredException ex) {
|
||||||
|
LOGGER.warn(ex);
|
||||||
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -119,6 +127,9 @@ public class FileSystemThemeProvider implements ThemeProvider {
|
||||||
| InsufficientPermissionsException ex) {
|
| InsufficientPermissionsException ex) {
|
||||||
|
|
||||||
throw new UnexpectedErrorException(ex);
|
throw new UnexpectedErrorException(ex);
|
||||||
|
} catch(CcmFilesNotConfiguredException ex) {
|
||||||
|
LOGGER.warn(ex);
|
||||||
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue