01: /*
02: * Lucane - a collaborative platform
03: * Copyright (C) 2004 Vincent Fiack <vfiack@mail15.com>
04: *
05: * This library is free software; you can redistribute it and/or
06: * modify it under the terms of the GNU Lesser General Public
07: * License as published by the Free Software Foundation; either
08: * version 2.1 of the License, or (at your option) any later version.
09: *
10: * This library is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: * Lesser General Public License for more details.
14: *
15: * You should have received a copy of the GNU Lesser General Public
16: * License along with this library; if not, write to the Free Software
17: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18: */
19: package org.lucane.webconnector;
20:
21: import org.lucane.webconnector.JspHandler;
22: import org.mortbay.http.Authenticator;
23: import org.mortbay.http.HttpContext;
24: import org.mortbay.http.SecurityConstraint;
25: import org.mortbay.http.UserRealm;
26: import org.mortbay.http.handler.NotFoundHandler;
27: import org.mortbay.http.handler.ResourceHandler;
28: import org.mortbay.http.handler.SecurityHandler;
29:
30: public class ContextFactory {
31: private UserRealm realm;
32: private Authenticator authenticator;
33: private SecurityConstraint security;
34:
35: public ContextFactory(UserRealm realm, Authenticator auth,
36: SecurityConstraint security) {
37: this .realm = realm;
38: this .authenticator = auth;
39: this .security = security;
40: }
41:
42: public HttpContext createApplicationContext(WebApp app) {
43: HttpContext context = new HttpContext();
44:
45: context.setAttribute(HttpContext.__ErrorHandler,
46: new ErrorPageHandler());
47: context.setClassLoader(ContextFactory.class.getClassLoader());
48: context.setContextPath("/" + app.getName());
49: context.setResourceBase(app.getDirectory() + WebApp.WEB_DIR);
50: context.setRealm(realm);
51: context.setAuthenticator(authenticator);
52: context.addSecurityConstraint("/", security);
53:
54: context.addHandler(new SecurityHandler());
55: context.addHandler(new JspHandler(app));
56: context.addHandler(new ResourceHandler());
57: context.addHandler(new NotFoundHandler());
58:
59: return context;
60: }
61:
62: public HttpContext createImageContext(WebApp app) {
63: HttpContext context = new HttpContext();
64:
65: context.setAttribute(HttpContext.__ErrorHandler,
66: new ErrorPageHandler());
67: context.setContextPath("/" + app.getName() + "/"
68: + WebApp.IMAGES_DIR);
69: context.setResourceBase(app.getDirectory() + WebApp.IMAGES_DIR);
70:
71: context.addHandler(new ResourceHandler());
72: context.addHandler(new NotFoundHandler());
73:
74: return context;
75: }
76: }
|