001: /* CVS ID: $Id: ToplevelURLHandler.java,v 1.1.1.1 2002/10/02 18:42:51 wastl Exp $ */
002: package net.wastl.webmail.server;
003:
004: import java.util.*;
005: import net.wastl.webmail.xml.*;
006: import net.wastl.webmail.ui.*;
007: import net.wastl.webmail.ui.html.*;
008: import net.wastl.webmail.ui.xml.*;
009: import net.wastl.webmail.server.http.*;
010: import net.wastl.webmail.exceptions.*;
011:
012: import org.webengruven.webmail.auth.AuthDisplayMngr;
013:
014: import javax.servlet.ServletException;
015:
016: /*
017: * ToplevelURLHandler.java
018: *
019: * Created: Tue Aug 31 17:20:29 1999
020: *
021: * Copyright (C) 1999-2000 Sebastian Schaffert
022: *
023: * This program is free software; you can redistribute it and/or
024: * modify it under the terms of the GNU General Public License
025: * as published by the Free Software Foundation; either version 2
026: * of the License, or (at your option) any later version.
027: *
028: * This program is distributed in the hope that it will be useful,
029: * but WITHOUT ANY WARRANTY; without even the implied warranty of
030: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
031: * GNU General Public License for more details.
032: *
033: * You should have received a copy of the GNU General Public License
034: * along with this program; if not, write to the Free Software
035: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
036: */
037: /**
038: * Handle URLs. Give them to the appropriate Plugins/Program parts
039: *
040: * Created: Tue Aug 31 17:20:29 1999
041: *
042: * @author Sebastian Schaffert
043: * @version
044: */
045: /* 9/24/2000 devink -- changed for challenge/response authentication */
046:
047: public class ToplevelURLHandler implements URLHandler {
048:
049: WebMailServer parent;
050: //Hashtable urlhandlers;
051: URLHandlerTree urlhandlers;
052:
053: public ToplevelURLHandler(WebMailServer parent) {
054: System.err
055: .println("- Initializing WebMail URL Handler ... done.");
056: urlhandlers = new URLHandlerTree("/");
057: urlhandlers.addHandler("/", this );
058: this .parent = parent;
059: }
060:
061: public void registerHandler(String url, URLHandler handler) {
062: //urlhandlers.put(url,handler);
063: urlhandlers.addHandler(url, handler);
064: //System.err.println("Tree changed: "+urlhandlers.toString());
065: }
066:
067: public String getURL() {
068: return "/";
069: }
070:
071: public String getName() {
072: return "TopLevelURLHandler";
073: }
074:
075: public String getDescription() {
076: return "";
077: }
078:
079: public HTMLDocument handleException(Exception ex,
080: HTTPSession session, HTTPRequestHeader header)
081: throws ServletException {
082: try {
083: session.setException(ex);
084: String theme = parent.getDefaultTheme();
085: Locale locale = Locale.getDefault();
086: if (session instanceof WebMailSession) {
087: WebMailSession sess = (WebMailSession) session;
088: theme = sess.getUser().getTheme();
089: locale = sess.getUser().getPreferredLocale();
090: }
091: return new XHTMLDocument(session.getModel(), parent
092: .getStorage().getStylesheet("error.xsl", locale,
093: theme));
094: } catch (Exception myex) {
095: parent.getStorage().log(Storage.LOG_ERR,
096: "Error while handling exception:");
097: parent.getStorage().log(Storage.LOG_ERR, myex);
098: parent.getStorage().log(Storage.LOG_ERR,
099: "The handled exception was:");
100: parent.getStorage().log(Storage.LOG_ERR, ex);
101: throw new ServletException(myex);
102: }
103: }
104:
105: public HTMLDocument handleURL(String url, HTTPSession session,
106: HTTPRequestHeader header) throws WebMailException,
107: ServletException {
108:
109: HTMLDocument content;
110:
111: if (url.equals("/")) {
112: //content=new HTMLLoginScreen(parent,parent.getStorage(),false);
113: XMLGenericModel model = parent.getStorage()
114: .createXMLGenericModel();
115:
116: AuthDisplayMngr adm = parent.getStorage()
117: .getAuthenticator().getAuthDisplayMngr();
118:
119: if (header.isContentSet("login")) {
120: model.setStateVar("invalid password", "yes");
121: }
122:
123: // Let the authenticator setup the loginscreen
124: adm.setLoginScreenVars(model);
125:
126: // Modified by exce, start.
127: /**
128: * Show login screen depending on WebMailServer's default locale.
129: */
130: /*
131: content = new XHTMLDocument(model.getRoot(),
132: parent.getStorage().getStylesheet(adm.getLoginScreenFile(),
133: Locale.getDefault(),"default"));
134: */
135: content = new XHTMLDocument(
136: model.getRoot(),
137: parent
138: .getStorage()
139: .getStylesheet(
140: adm.getLoginScreenFile(),
141: parent.getDefaultLocale(),
142: parent
143: .getProperty("webmail.default.theme")));
144: // Modified by exce, end.
145: } else if (url.equals("/login")) {
146:
147: WebMailSession sess = (WebMailSession) session;
148: UserData user = sess.getUser();
149: content = new XHTMLDocument(session.getModel(), parent
150: .getStorage().getStylesheet("login.xsl",
151: user.getPreferredLocale(), user.getTheme()));
152: } else {
153: /* Let the plugins handle it */
154:
155: URLHandler uh = urlhandlers.getHandler(url);
156:
157: if (uh != null && uh != this ) {
158: // System.err.println("Handler: "+uh.getName()+" ("+uh.getURL()+")");
159: String suburl = url.substring(uh.getURL().length(), url
160: .length());
161: content = uh.handleURL(suburl, session, header);
162: } else {
163: throw new DocumentNotFoundException(url
164: + " was not found on this server");
165: }
166: }
167: return content;
168: }
169:
170: } // URLHandler
|