API Overview API Index Package Overview Direct link to this page
JavaOnTracks 0.1.2
  net.jot.web.server.impl.webapp. JOTWebappHolder View Javadoc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package net.jot.web.server.impl.webapp;

import java.io.File;
import java.net.URL;
import java.util.Vector;
import net.jot.logger.JOTLogger;
import net.jot.logger.JOTLoggerLocation;

/**
 *
 * @author thibautc
 */
public class JOTWebappHolder {

    private JOTLoggerLocation loc = new JOTLoggerLocation(JOTLogger.CAT_SERVER, getClass());
    private JOTWebappClassLoader loader;

    /**
     *
     * @param war : might be a war file or an expanded war (folder)
     * @param parentClassLoader
     */
    public JOTWebappHolder(File war, String context, ClassLoader parentClassLoader)
    {
        if (war.isDirectory())
        {
            Vector paths = new Vector();
            File libs = findFolder(war, "/web-inf/libs/");
            File classes = findFolder(war, "/web-inf/classes/");
            if (classes != null)
            {
                try
                {
                    loc.debug("Adding " + classes.getAbsolutePath() + " to webapp[" + context + "] classpath");
                    paths.add(classes.toURL());
                } catch (Exception e)
                {
                    loc.exception("Malformed Classpath URL: " + classes.getAbsolutePath(), e);
                }
            }
            if (libs.exists())
            {
                Vector jars = JOTWebappServer.findAllJars(libs);
                for (int i = 0; i != jars.size(); i++)
                {
                    File jar = (File) jars.get(i);
                    try
                    {
                        loc.debug("Adding " + jar.getAbsolutePath() + " to webapp[" + context + "] classpath");
                        paths.add(jar.toURL());
                    } catch (Exception e)
                    {
                        loc.exception("Malformed Classpath URL: " + classes.getAbsolutePath(), e);
                    }
                }
            }
            URL[] urls = (URL[]) paths.toArray(new URL[0]);
            // init loader
            loader = new JOTWebappClassLoader(urls, parentClassLoader);
        }

    }

    private File findFolder(File war, String file)
    {
        File[] files = war.listFiles();
        for (int i = 0; i != files.length; i++)
        {
            File f = files[i];
            if (f.getAbsolutePath().replaceAll("\\", "/").equalsIgnoreCase(war.getAbsolutePath() + "/" + file))
            {
                return f;
            }
            if (f.isDirectory())
            {
                File found = findFolder(f, file);
                if (found != null)
                {
                    return f;
                }
            }
        }
        return null;
    }
}

Generated By: JavaOnTracks Doclet 0.1.5     ©Thibaut Colar