use of org.codelibs.fess.exception.ThemeException in project fess by codelibs.
the class ThemeHelper method install.
public void install(final Artifact artifact) {
final Path jarPath = getJarFile(artifact);
final String themeName = getThemeName(artifact);
if (logger.isDebugEnabled()) {
logger.debug("Theme: {}", themeName);
}
try (ZipInputStream zis = new ZipInputStream(Files.newInputStream(jarPath))) {
ZipEntry entry;
while ((entry = zis.getNextEntry()) != null) {
if (!entry.isDirectory()) {
final String[] names = StreamUtil.split(entry.getName(), "/").get(stream -> stream.filter(s -> !"..".equals(s)).toArray(n -> new String[n]));
if (names.length < 2) {
continue;
}
if (logger.isDebugEnabled()) {
logger.debug("Loading {}", entry.getName());
}
if ("view".equals(names[0])) {
names[0] = themeName;
final Path path = ResourceUtil.getViewTemplatePath(names);
Files.createDirectories(path.getParent());
Files.copy(zis, path, StandardCopyOption.REPLACE_EXISTING);
} else if ("css".equals(names[0])) {
names[0] = themeName;
final Path path = ResourceUtil.getCssPath(names);
Files.createDirectories(path.getParent());
Files.copy(zis, path, StandardCopyOption.REPLACE_EXISTING);
} else if ("js".equals(names[0])) {
names[0] = themeName;
final Path path = ResourceUtil.getJavaScriptPath(names);
Files.createDirectories(path.getParent());
Files.copy(zis, path, StandardCopyOption.REPLACE_EXISTING);
} else if ("images".equals(names[0])) {
names[0] = themeName;
final Path path = ResourceUtil.getImagePath(names);
Files.createDirectories(path.getParent());
Files.copy(zis, path, StandardCopyOption.REPLACE_EXISTING);
}
}
}
} catch (final IOException e) {
throw new ThemeException("Failed to install " + artifact, e);
}
}
Aggregations