view src/kryshen/catalina/startup/UserConfig.java @ 9:a3321ea9b33f

Update.
author Mikhail Kryshen <mikhail@kryshen.net>
date Mon, 02 Nov 2009 18:36:24 +0300
parents ff1e55a2171f
children 086a55aa2620
line wrap: on
line source

package kryshen.catalina.startup;

import java.io.File;
import org.apache.catalina.startup.HostConfig;

/**
 *
 * @author Mikhail Kryshen
 */
public abstract class UserConfig extends HostConfig {

    @Override
    protected void deployApps() {       
        deployUserApps();
    }

    @Override
    protected void deployApps(String name) {
        throw new UnsupportedOperationException
                ("deployApps(String) is not supported.");
    }

    protected abstract void deployUserApps();

    protected void deployUserApps(String user, File base) {
        if (!base.exists() || !base.isDirectory() || !base.canRead()) {
            return;
        }

        // TODO: deployWARs
        // deployWARs(appBase, appBase.list());

        // Deploy expanded folders
        deployDirectories(user, base, base.list());
    }

    /**
     * Deploy user webapp directories.
     */
    protected void deployDirectories(String user, File base, String[] files) {

        if (files == null) {
            return;
        }

        for (int i = 0; i < files.length; i++) {
            if (files[i].equalsIgnoreCase("META-INF")) {
                continue;
            }

            if (files[i].equalsIgnoreCase("WEB-INF")) {
                continue;
            }

            File dir = new File(base, files[i]);

            if (!dir.isDirectory() || !dir.canRead()) {
                continue;
            }

            String contextPath;

            if (files[i].equals("ROOT")) {
                contextPath = "/~" + user;
            } else {
                contextPath = "/~" + user + '/' + files[i].replace('#', '/');
            }

            if (isServiced(contextPath)) {
                continue;
            }

            deployDirectory(contextPath, dir, dir.getAbsolutePath());
        }
    }
}