/** * Copyright 2006 by Know-Center, Graz, Austria * PDF-AS has been contracted by the E-Government Innovation Center EGIZ, a * joint initiative of the Federal Chancellery Austria and Graz University of * Technology. * * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by * the European Commission - subsequent versions of the EUPL (the "Licence"); * You may not use this work except in compliance with the Licence. * You may obtain a copy of the Licence at: * http://www.osor.eu/eupl/ * * Unless required by applicable law or agreed to in writing, software * distributed under the Licence is distributed on an "AS IS" basis, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Licence for the specific language governing permissions and * limitations under the Licence. * * This product combines work with different licenses. See the "NOTICE" text * file for details on the various modules and licenses. * The "NOTICE" text file is part of the distribution. Any derivative works * that you distribute must include a readable copy of the "NOTICE" text file. * * $Id: PdfASServletContextListener.java,v 1.3 2006/10/31 08:22:04 wprinz Exp $ */ package at.gv.egiz.pdfas.web; import java.io.File; import javax.servlet.ServletContextEvent; import javax.servlet.ServletContextListener; import org.apache.commons.lang.StringUtils; import org.apache.log4j.Logger; import at.gv.egiz.pdfas.api.PdfAs; import at.gv.egiz.pdfas.api.commons.Constants; import at.gv.egiz.pdfas.api.internal.PdfAsInternal; import at.gv.egiz.pdfas.web.helper.ApiHelper; import at.gv.egiz.pdfas.web.helper.WebSettingsReader; import at.knowcenter.wag.egov.egiz.exceptions.SettingsException; import at.knowcenter.wag.egov.egiz.exceptions.WebException; /** * The ServletContextListener is notified when the webapplication starts up and * shuts down. * *

* Maintainance work is performed. *

* * @author wprinz */ public class PdfASServletContextListener implements ServletContextListener { /** * The logger. */ private static final Logger logger = Logger.getLogger(PdfASServletContextListener.class); /** * The servlet init parameter that may be used to declare the pdf-as * configuration folder. The init parameter may be set in web.xml or in * META-INF/context.xml resp. conf/Catalina/localhost/pdf-as.xml if deployed. */ private final static String CONFIG_SERVLET_INIT_PARAMETER = "work-dir"; /** * @see javax.servlet.ServletContextListener#contextInitialized(javax.servlet.ServletContextEvent) */ public void contextInitialized(ServletContextEvent sce) { logger.info("PDF-AS Context init"); //$NON-NLS-1$ String sysPropWorkdir = System.getProperty(Constants.CONFIG_DIR_SYSTEM_PROPERTY); String scWorkdir = sce.getServletContext().getInitParameter(CONFIG_SERVLET_INIT_PARAMETER); String work_dir; // search for system property if (!StringUtils.isEmpty(sysPropWorkdir)) { work_dir = sysPropWorkdir; logger.debug("Work-dir configuration via system property \"" + Constants.CONFIG_DIR_SYSTEM_PROPERTY + "\" = \"" + sysPropWorkdir + "\"."); // search for servlet parameter } else if (!StringUtils.isEmpty(scWorkdir)) { work_dir = scWorkdir; logger.debug("Work-dir configuration via servlet init parameter \"" + CONFIG_SERVLET_INIT_PARAMETER + "\" = \"" + scWorkdir + "\"."); // assume configuration to be located in webapp path } else { work_dir = sce.getServletContext().getRealPath("/"); logger.info("PDF-AS work-dir not explicitely given. Assuming configuration is located in webapp folder \"" + work_dir + "\"."); } logger.info("PDF-AS configuration location = \"" + work_dir + "\""); // try // { // logger.info("PDF-AS work directory = " + new File(work_dir).getCanonicalPath()); //$NON-NLS-1$ // logger.info("PDF-AS base directory = " + new File(base_dir).getCanonicalPath()); //$NON-NLS-1$ // } // catch (IOException e) // { // e.printStackTrace(); // } WebSettingsReader.initialize(work_dir); PdfAs pdfAs; try { pdfAs = ApiHelper.createApiObject(new File(WebSettingsReader.RESOURCES_PATH)); sce.getServletContext().setAttribute(ApiHelper.PDF_AS_OBJECT, pdfAs); } catch (WebException e) { logger.error(e.getMessage(), e); } PdfAsInternal pdfAsInternal; try { pdfAsInternal = ApiHelper.createInternalApiObject(); sce.getServletContext().setAttribute(ApiHelper.INTERNAL_PDF_AS_OBJECT, pdfAsInternal); } catch (WebException e) { logger.error(e.getMessage(), e); } try { WebSettingsReader.getInstance(); } catch (SettingsException e) { logger.error(e.getMessage(), e); } WebSettingsReader.clearTemporaryDirectory(); } /** * @see javax.servlet.ServletContextListener#contextDestroyed(javax.servlet.ServletContextEvent) */ public void contextDestroyed(ServletContextEvent sce) { WebSettingsReader.clearTemporaryDirectory(); logger.info("PDF-AS Context exit"); //$NON-NLS-1$ } }