Search in sources :

Example 1 with ThemeException

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);
    }
}
Also used : Path(java.nio.file.Path) ZipInputStream(java.util.zip.ZipInputStream) Artifact(org.codelibs.fess.helper.PluginHelper.Artifact) Files(java.nio.file.Files) ThemeException(org.codelibs.fess.exception.ThemeException) StringUtil(org.codelibs.core.lang.StringUtil) IOException(java.io.IOException) StandardCopyOption(java.nio.file.StandardCopyOption) ResourceUtil(org.codelibs.fess.util.ResourceUtil) Stream(java.util.stream.Stream) Logger(org.apache.logging.log4j.Logger) StreamUtil(org.codelibs.core.stream.StreamUtil) ArtifactType(org.codelibs.fess.helper.PluginHelper.ArtifactType) FileVisitOption(java.nio.file.FileVisitOption) Comparator(java.util.Comparator) Path(java.nio.file.Path) ZipEntry(java.util.zip.ZipEntry) LogManager(org.apache.logging.log4j.LogManager) ZipInputStream(java.util.zip.ZipInputStream) ThemeException(org.codelibs.fess.exception.ThemeException) ZipEntry(java.util.zip.ZipEntry) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)1 FileVisitOption (java.nio.file.FileVisitOption)1 Files (java.nio.file.Files)1 Path (java.nio.file.Path)1 StandardCopyOption (java.nio.file.StandardCopyOption)1 Comparator (java.util.Comparator)1 Stream (java.util.stream.Stream)1 ZipEntry (java.util.zip.ZipEntry)1 ZipInputStream (java.util.zip.ZipInputStream)1 LogManager (org.apache.logging.log4j.LogManager)1 Logger (org.apache.logging.log4j.Logger)1 StringUtil (org.codelibs.core.lang.StringUtil)1 StreamUtil (org.codelibs.core.stream.StreamUtil)1 ThemeException (org.codelibs.fess.exception.ThemeException)1 Artifact (org.codelibs.fess.helper.PluginHelper.Artifact)1 ArtifactType (org.codelibs.fess.helper.PluginHelper.ArtifactType)1 ResourceUtil (org.codelibs.fess.util.ResourceUtil)1