CcmNG: Some fixes

git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@5695 8810af33-2d31-482b-a856-94f89814c4df

Former-commit-id: aa8b20c4b1
pull/2/head
jensp 2018-09-20 10:25:47 +00:00
parent 019d07940a
commit 65a9570a8d
1 changed files with 63 additions and 40 deletions

View File

@ -90,8 +90,8 @@ public class FileSystemThemeProvider implements ThemeProvider {
.collect(Collectors.toList()); .collect(Collectors.toList());
} catch (FileAccessException } catch (FileAccessException
| FileDoesNotExistException | FileDoesNotExistException
| InsufficientPermissionsException ex) { | InsufficientPermissionsException ex) {
throw new UnexpectedErrorException(ex); throw new UnexpectedErrorException(ex);
} }
@ -115,8 +115,8 @@ public class FileSystemThemeProvider implements ThemeProvider {
.map(info -> info.get()) .map(info -> info.get())
.collect(Collectors.toList()); .collect(Collectors.toList());
} catch (FileAccessException } catch (FileAccessException
| FileDoesNotExistException | FileDoesNotExistException
| InsufficientPermissionsException ex) { | InsufficientPermissionsException ex) {
throw new UnexpectedErrorException(ex); throw new UnexpectedErrorException(ex);
} }
@ -156,8 +156,8 @@ public class FileSystemThemeProvider implements ThemeProvider {
ccmFiles.createDirectory(String.format(DRAFT_THEMES_PATH + "/%s", ccmFiles.createDirectory(String.format(DRAFT_THEMES_PATH + "/%s",
themeName)); themeName));
} catch (FileAccessException } catch (FileAccessException
| FileAlreadyExistsException | FileAlreadyExistsException
| InsufficientPermissionsException ex) { | InsufficientPermissionsException ex) {
throw new UnexpectedErrorException(ex); throw new UnexpectedErrorException(ex);
} }
@ -171,7 +171,7 @@ public class FileSystemThemeProvider implements ThemeProvider {
+ ThemeConstants.THEME_MANIFEST_JSON, + ThemeConstants.THEME_MANIFEST_JSON,
themeName)); themeName));
} catch (FileAccessException } catch (FileAccessException
| InsufficientPermissionsException ex) { | InsufficientPermissionsException ex) {
throw new UnexpectedErrorException(ex); throw new UnexpectedErrorException(ex);
} }
@ -215,9 +215,9 @@ public class FileSystemThemeProvider implements ThemeProvider {
themeName), themeName),
true); true);
} catch (FileAccessException } catch (FileAccessException
| FileDoesNotExistException | FileDoesNotExistException
| DirectoryNotEmptyException | DirectoryNotEmptyException
| InsufficientPermissionsException ex) { | InsufficientPermissionsException ex) {
throw new UnexpectedErrorException(ex); throw new UnexpectedErrorException(ex);
} }
} }
@ -228,7 +228,12 @@ public class FileSystemThemeProvider implements ThemeProvider {
final String path) { final String path) {
final String themePath = createThemePath(theme, version); final String themePath = createThemePath(theme, version);
final String filePath = String.join("/", themePath, path); final String filePath;
if ("/".equals(path)) {
filePath = String.join("", themePath, path);
} else {
filePath = String.join("/", themePath, path);
}
try { try {
if (ccmFiles.isDirectory(filePath)) { if (ccmFiles.isDirectory(filePath)) {
@ -236,19 +241,21 @@ public class FileSystemThemeProvider implements ThemeProvider {
.listFiles(filePath) .listFiles(filePath)
.stream() .stream()
.map(currentPath -> buildThemeFileInfo( .map(currentPath -> buildThemeFileInfo(
String.join("/", theme, currentPath))) themePath,
String.join("/", path, currentPath)))
.collect(Collectors.toList()); .collect(Collectors.toList());
} else { } else {
final List<ThemeFileInfo> result = new ArrayList<>(); final List<ThemeFileInfo> result = new ArrayList<>();
final ThemeFileInfo fileInfo = buildThemeFileInfo(filePath); final ThemeFileInfo fileInfo = buildThemeFileInfo(
themePath, path);
result.add(fileInfo); result.add(fileInfo);
return result; return result;
} }
} catch (FileAccessException } catch (FileAccessException
| FileDoesNotExistException | FileDoesNotExistException
| InsufficientPermissionsException ex) { | InsufficientPermissionsException ex) {
throw new UnexpectedErrorException(ex); throw new UnexpectedErrorException(ex);
} }
@ -264,8 +271,8 @@ public class FileSystemThemeProvider implements ThemeProvider {
try { try {
if (ccmFiles.existsFile(filePath)) { if (ccmFiles.existsFile(filePath)) {
return Optional.of(buildThemeFileInfo(filePath)); return Optional.of(buildThemeFileInfo(themePath, path));
} else { } else {
return Optional.empty(); return Optional.empty();
} }
@ -288,8 +295,8 @@ public class FileSystemThemeProvider implements ThemeProvider {
return Optional.of(ccmFiles.createInputStream(filePath)); return Optional.of(ccmFiles.createInputStream(filePath));
} }
} catch (FileAccessException } catch (FileAccessException
| FileDoesNotExistException | FileDoesNotExistException
| InsufficientPermissionsException ex) { | InsufficientPermissionsException ex) {
throw new UnexpectedErrorException(ex); throw new UnexpectedErrorException(ex);
} }
@ -307,7 +314,7 @@ public class FileSystemThemeProvider implements ThemeProvider {
return ccmFiles.createOutputStream(filePath); return ccmFiles.createOutputStream(filePath);
} catch (FileAccessException } catch (FileAccessException
| InsufficientPermissionsException ex) { | InsufficientPermissionsException ex) {
throw new UnexpectedErrorException(ex); throw new UnexpectedErrorException(ex);
} }
@ -322,9 +329,9 @@ public class FileSystemThemeProvider implements ThemeProvider {
try { try {
ccmFiles.deleteFile(filePath, true); ccmFiles.deleteFile(filePath, true);
} catch (FileAccessException } catch (FileAccessException
| FileDoesNotExistException | FileDoesNotExistException
| DirectoryNotEmptyException | DirectoryNotEmptyException
| InsufficientPermissionsException ex) { | InsufficientPermissionsException ex) {
throw new UnexpectedErrorException(ex); throw new UnexpectedErrorException(ex);
} }
@ -355,8 +362,8 @@ public class FileSystemThemeProvider implements ThemeProvider {
ccmFiles.createDirectory(LIVE_THEMES_PATH); ccmFiles.createDirectory(LIVE_THEMES_PATH);
} }
} catch (FileAccessException } catch (FileAccessException
| InsufficientPermissionsException | InsufficientPermissionsException
| FileAlreadyExistsException ex) { | FileAlreadyExistsException ex) {
throw new UnexpectedErrorException(ex); throw new UnexpectedErrorException(ex);
} }
@ -372,10 +379,10 @@ public class FileSystemThemeProvider implements ThemeProvider {
ccmFiles.moveFile(liveThemePathTmp, liveThemePath); ccmFiles.moveFile(liveThemePathTmp, liveThemePath);
} catch (DirectoryNotEmptyException } catch (DirectoryNotEmptyException
| FileAccessException | FileAccessException
| FileAlreadyExistsException | FileAlreadyExistsException
| FileDoesNotExistException | FileDoesNotExistException
| InsufficientPermissionsException ex) { | InsufficientPermissionsException ex) {
throw new UnexpectedErrorException(ex); throw new UnexpectedErrorException(ex);
} }
} }
@ -388,9 +395,9 @@ public class FileSystemThemeProvider implements ThemeProvider {
try { try {
ccmFiles.deleteFile(liveThemePath, true); ccmFiles.deleteFile(liveThemePath, true);
} catch (DirectoryNotEmptyException } catch (DirectoryNotEmptyException
| FileAccessException | FileAccessException
| FileDoesNotExistException | FileDoesNotExistException
| InsufficientPermissionsException ex) { | InsufficientPermissionsException ex) {
throw new UnexpectedErrorException(ex); throw new UnexpectedErrorException(ex);
} }
} }
@ -433,8 +440,8 @@ public class FileSystemThemeProvider implements ThemeProvider {
return Optional.empty(); return Optional.empty();
} }
} catch (FileAccessException } catch (FileAccessException
| FileDoesNotExistException | FileDoesNotExistException
| InsufficientPermissionsException ex) { | InsufficientPermissionsException ex) {
throw new UnexpectedErrorException(ex); throw new UnexpectedErrorException(ex);
} }
@ -445,20 +452,36 @@ public class FileSystemThemeProvider implements ThemeProvider {
return Optional.of(themeInfo); return Optional.of(themeInfo);
} }
private ThemeFileInfo buildThemeFileInfo(final String filePath) { private ThemeFileInfo buildThemeFileInfo(final String themePath,
final String filePath) {
final String path;
if (themePath.endsWith("/")
|| filePath.startsWith("/")) {
path = String.join("", themePath, filePath);
} else {
path= String.join("/", themePath, filePath);
}
final String name;
if (path.startsWith(("/"))) {
name = path;
} else {
name = String.format("/%s", path);
}
final ThemeFileInfo fileInfo = new ThemeFileInfo(); final ThemeFileInfo fileInfo = new ThemeFileInfo();
try { try {
fileInfo.setDirectory(ccmFiles.isDirectory(filePath)); fileInfo.setDirectory(ccmFiles.isDirectory(path));
fileInfo.setMimeType(ccmFiles.getMimeType(filePath)); fileInfo.setMimeType(ccmFiles.getMimeType(path));
fileInfo.setName(filePath); fileInfo.setName(name);
fileInfo.setWritable(true); fileInfo.setWritable(true);
return fileInfo; return fileInfo;
} catch (FileAccessException } catch (FileAccessException
| FileDoesNotExistException | FileDoesNotExistException
| InsufficientPermissionsException ex) { | InsufficientPermissionsException ex) {
throw new UnexpectedErrorException(ex); throw new UnexpectedErrorException(ex);
} }