ToplevelURLHandler.java
上传用户:huihesys
上传日期:2007-01-04
资源大小:3877k
文件大小:3k
- /* CVS ID: $Id: ToplevelURLHandler.java,v 1.3 2000/04/06 08:02:02 wastl Exp $ */
- package net.wastl.webmail.server;
- import java.util.*;
- import net.wastl.webmail.xml.*;
- import net.wastl.webmail.ui.*;
- import net.wastl.webmail.ui.html.*;
- import net.wastl.webmail.ui.xml.*;
- import net.wastl.webmail.server.http.*;
- /*
- * ToplevelURLHandler.java
- *
- * Created: Tue Aug 31 17:20:29 1999
- *
- * Copyright (C) 1999-2000 Sebastian Schaffert
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- */
- /**
- * Handle URLs. Give them to the appropriate Plugins/Program parts
- *
- * Created: Tue Aug 31 17:20:29 1999
- *
- * @author Sebastian Schaffert
- * @version
- */
- public class ToplevelURLHandler implements URLHandler {
-
- WebMailServer parent;
- //Hashtable urlhandlers;
- URLHandlerTree urlhandlers;
-
- public ToplevelURLHandler(WebMailServer parent) {
- System.err.println("- Initializing WebMail URL Handler ... done.");
- urlhandlers=new URLHandlerTree("/");
- urlhandlers.addHandler("/",this);
- this.parent=parent;
- }
-
- public void registerHandler(String url, URLHandler handler) {
- //urlhandlers.put(url,handler);
- urlhandlers.addHandler(url,handler);
- //System.err.println("Tree changed: "+urlhandlers.toString());
- }
-
- public String getURL() {
- return "/";
- }
-
- public String getName() {
- return "TopLevelURLHandler";
- }
-
- public String getDescription() {
- return "";
- }
-
- public HTMLDocument handleURL(String url, HTTPSession session, HTTPRequestHeader header) throws WebMailException {
-
- HTMLDocument content;
-
- if(url.equals("/")) {
- //content=new HTMLLoginScreen(parent,parent.getStorage(),false);
- XMLGenericModel model=parent.getStorage().createXMLGenericModel();
- if(header.isContentSet("login")) {
- model.setStateVar("invalid password","yes");
- }
- content=new XHTMLDocument(model.getRoot(),parent.getStorage().getStylesheet("loginscreen.xsl",Locale.getDefault(),"default"));
- } else if(url.equals("/login")) {
- //content=new HTMLParsedDocument(parent.getStorage(),session,"FrameSet");
- WebMailSession sess=(WebMailSession)session;
- UserData user=sess.getUser();
- content=new XHTMLDocument(session.getModel(),parent.getStorage().getStylesheet("login.xsl",user.getPreferredLocale(),user.getTheme()));
- } else {
- /* Let the plugins handle it */
-
- URLHandler uh=urlhandlers.getHandler(url);
-
- if(uh != null && uh != this) {
- // System.err.println("Handler: "+uh.getName()+" ("+uh.getURL()+")");
- String suburl=url.substring(uh.getURL().length(),url.length());
- content=uh.handleURL(suburl,session,header);
- } else {
- throw new DocumentNotFoundException(url + " was not found on this server");
- }
- }
- return content;
- }
-
- } // URLHandler