servletdispatcher.java

来自「The ability to create groups of reports,」· Java 代码 · 共 100 行

JAVA
100
字号
/*
 * Copyright (C) 2004 Erik Swenson - eswenson@opensourcesoft.net
 * 
 * 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.
 *  
 */

package org.efs.openreports.dispatcher;

import java.io.IOException;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;

import com.opensymphony.webwork.config.Configuration;
import com.opensymphony.webwork.dispatcher.multipart.MultiPartRequest;
import com.opensymphony.webwork.dispatcher.multipart.MultiPartRequestWrapper;

import org.apache.log4j.Logger;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.impl.StdSchedulerFactory;

public class ServletDispatcher
		extends
			com.opensymphony.webwork.dispatcher.ServletDispatcher 
{
	protected static Logger log = Logger.getLogger(ServletDispatcher.class);
	
	private String saveDirectory;	

	public void init(ServletConfig servletConfig) throws ServletException
	{		
		super.init(servletConfig);			

		try
		{
			StdSchedulerFactory.getDefaultScheduler().start();
			
			log.info("Report Scheduler started.");
		}
		catch (SchedulerException se)
		{
			log.error(se.toString());
		}			
	}	
	
	public void destroy()
	{		
		super.destroy();
		
		try
		{			
			Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler();
            if (scheduler != null) scheduler.shutdown();

			log.info("Report Scheduler shutdown.");
		}
		catch (SchedulerException se)
		{
			log.error(se.toString());
		}		
	}
	
	protected void setSaveDirectory()
	{
		saveDirectory = Configuration.getString("webwork.multipart.saveDir").trim();		
		log.info("Report Upload Path: " + saveDirectory);		
	}

	protected HttpServletRequest wrapRequest(HttpServletRequest request) throws IOException
	{
		// don't wrap more than once
		if (request instanceof MultiPartRequestWrapper)
		{
			return request;
		}

		if (MultiPartRequest.isMultiPart(request))
		{
			if (saveDirectory == null) setSaveDirectory();
			request = new MultiPartRequestWrapper(request, saveDirectory, Integer.MAX_VALUE);
		}

		return request;
	}
}

⌨️ 快捷键说明

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