⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 toplevelurlhandler.java

📁 java 开发的一个电子邮局,挺实用的
💻 JAVA
字号:
/* CVS ID: $Id: ToplevelURLHandler.java,v 1.6 2000/12/31 15:44:14 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.*;
import net.wastl.webmail.exceptions.*;

import org.webengruven.webmail.auth.AuthDisplayMngr;

/*
 * 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
 */
/* 9/24/2000 devink -- changed for challenge/response authentication */

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 handleException(Exception ex, HTTPSession session, HTTPRequestHeader header) {
	try {
	    session.setException(ex);
	    String theme=parent.getDefaultTheme();
	    Locale locale=Locale.getDefault();
	    if(session instanceof WebMailSession) {
		WebMailSession sess=(WebMailSession)session;
		theme=sess.getUser().getTheme();
		locale=sess.getUser().getPreferredLocale();
	    }
	    return new XHTMLDocument(session.getModel(),parent.getStorage().getStylesheet("error.xsl",locale,theme));
	} catch(Exception myex) {
	    return new HTMLErrorMessage(parent.getStorage(),myex.getMessage());	    
	}
    }
	
    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();

	    AuthDisplayMngr adm = parent.getStorage().getAuthenticator().getAuthDisplayMngr();

	    if(header.isContentSet("login")) {
		model.setStateVar("invalid password","yes");
	    }

	    // Let the authenticator setup the loginscreen
	    adm.setLoginScreenVars(model);

		// Modified by exce, start.
		/**
		 * Show login screen depending on WebMailServer's default locale.
		 */
		/*
	    content = new XHTMLDocument(model.getRoot(), 
					parent.getStorage().getStylesheet(adm.getLoginScreenFile(), 
									  Locale.getDefault(),"default"));
		*/
	    content = new XHTMLDocument(model.getRoot(), 
					parent.getStorage().getStylesheet(adm.getLoginScreenFile(), 
										parent.getDefaultLocale(),parent.getProperty("webmail.default.theme")));
		// Modified by exce, end.
	} else if(url.equals("/login")) {

	    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

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -